1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
/*
* Copyright (C) 2011 Collabora Ltd.
* Copyright (C) 2012 Igalia, S.L.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "config.h"
#include "AcceleratedCompositingContext.h"
#if USE(ACCELERATED_COMPOSITING) && USE(CLUTTER)
#include "Frame.h"
#include "FrameView.h"
#include "GraphicsLayer.h"
#include "NotImplemented.h"
#include "webkitwebviewprivate.h"
#include <clutter-gtk/clutter-gtk.h>
#include <clutter/clutter.h>
using namespace WebCore;
namespace WebKit {
AcceleratedCompositingContext::AcceleratedCompositingContext(WebKitWebView* webView)
: m_webView(webView)
, m_layerFlushTimerCallbackId(0)
, m_rootGraphicsLayer(0)
, m_rootLayerEmbedder(0)
{
}
AcceleratedCompositingContext::~AcceleratedCompositingContext()
{
if (m_layerFlushTimerCallbackId)
g_source_remove(m_layerFlushTimerCallbackId);
}
bool AcceleratedCompositingContext::enabled()
{
return m_rootGraphicsLayer;
}
bool AcceleratedCompositingContext::renderLayersToWindow(cairo_t*, const IntRect& clipRect)
{
notImplemented();
return false;
}
void AcceleratedCompositingContext::setRootCompositingLayer(GraphicsLayer* graphicsLayer)
{
if (!graphicsLayer) {
gtk_container_remove(GTK_CONTAINER(m_webView), m_rootLayerEmbedder);
m_rootLayerEmbedder = 0;
m_rootGraphicsLayer = 0;
return;
}
// Create an instance of GtkClutterEmbed to host actors as web layers.
if (!m_rootLayerEmbedder) {
m_rootLayerEmbedder = gtk_clutter_embed_new();
gtk_container_add(GTK_CONTAINER(m_webView), m_rootLayerEmbedder);
gtk_widget_show(m_rootLayerEmbedder);
}
// Add a root layer to the stage.
if (graphicsLayer) {
m_rootGraphicsLayer = graphicsLayer;
ClutterColor stageColor = { 0xFF, 0xFF, 0xFF, 0xFF };
ClutterActor* stage = gtk_clutter_embed_get_stage(GTK_CLUTTER_EMBED(m_rootLayerEmbedder));
clutter_stage_set_color(CLUTTER_STAGE(stage), &stageColor);
clutter_container_add_actor(CLUTTER_CONTAINER(stage), m_rootGraphicsLayer->platformLayer());
clutter_actor_show_all(stage);
}
}
void AcceleratedCompositingContext::setNonCompositedContentsNeedDisplay(const IntRect& rect)
{
if (!m_rootGraphicsLayer)
return;
if (rect.isEmpty()) {
m_rootGraphicsLayer->setNeedsDisplay();
return;
}
m_rootGraphicsLayer->setNeedsDisplayInRect(rect);
}
void AcceleratedCompositingContext::resizeRootLayer(const IntSize& size)
{
if (!m_rootLayerEmbedder)
return;
GtkAllocation allocation;
allocation.x = 0;
allocation.y = 0;
allocation.width = size.width();
allocation.height = size.height();
gtk_widget_size_allocate(GTK_WIDGET(m_rootLayerEmbedder), &allocation);
}
void AcceleratedCompositingContext::scrollNonCompositedContents(const IntRect& scrollRect, const IntSize& scrollOffset)
{
notImplemented();
}
static gboolean flushAndRenderLayersCallback(AcceleratedCompositingContext* context)
{
context->flushAndRenderLayers();
return FALSE;
}
void AcceleratedCompositingContext::scheduleLayerFlush()
{
if (m_layerFlushTimerCallbackId)
return;
// We use a GLib timer because otherwise GTK+ event handling during
// dragging can starve WebCore timers, which have a lower priority.
m_layerFlushTimerCallbackId = g_timeout_add_full(GDK_PRIORITY_EVENTS, 0, reinterpret_cast<GSourceFunc>(flushAndRenderLayersCallback), this, 0);
}
bool AcceleratedCompositingContext::flushPendingLayerChanges()
{
if (m_rootGraphicsLayer)
m_rootGraphicsLayer->flushCompositingStateForThisLayerOnly();
return core(m_webView)->mainFrame()->view()->flushCompositingStateIncludingSubframes();
}
void AcceleratedCompositingContext::flushAndRenderLayers()
{
m_layerFlushTimerCallbackId = 0;
flushPendingLayerChanges();
if (!m_rootGraphicsLayer)
return;
renderLayersToWindow(0, IntRect());
}
void AcceleratedCompositingContext::notifyAnimationStarted(const WebCore::GraphicsLayer*, double time)
{
ASSERT_NOT_REACHED();
}
void AcceleratedCompositingContext::notifyFlushRequired(const WebCore::GraphicsLayer*)
{
ASSERT_NOT_REACHED();
}
void AcceleratedCompositingContext::paintContents(const WebCore::GraphicsLayer*, WebCore::GraphicsContext&, WebCore::GraphicsLayerPaintingPhase, const WebCore::IntRect&)
{
ASSERT_NOT_REACHED();
}
} // namespace WebKit
#endif // USE(ACCELERATED_COMPOSITING) && USE(CLUTTER)
|