2
* Copyright (C) 2012 Igalia, S.L.
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Lesser General Public License for more details.
14
* You should have received a copy of the GNU Lesser General Public
15
* License along with this library; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
#include "AcceleratedCompositingContext.h"
22
#if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER_CAIRO)
24
#include "CairoUtilities.h"
26
#include "ChromeClientGtk.h"
28
#include "FrameView.h"
29
#include "PlatformContextCairo.h"
30
#include "TextureMapperImageBuffer.h"
31
#include "TextureMapperLayer.h"
32
#include "webkitwebviewprivate.h"
37
using namespace WebCore;
41
AcceleratedCompositingContext::AcceleratedCompositingContext(WebKitWebView* webView)
43
, m_syncTimerCallbackId(0)
44
, m_rootTextureMapperLayer(0)
48
AcceleratedCompositingContext::~AcceleratedCompositingContext()
50
if (m_syncTimerCallbackId)
51
g_source_remove(m_syncTimerCallbackId);
54
bool AcceleratedCompositingContext::enabled()
56
return m_rootTextureMapperLayer && m_textureMapper;
59
bool AcceleratedCompositingContext::renderLayersToWindow(cairo_t* cr, const IntRect& clipRect)
61
if (!cr || !enabled())
64
GraphicsContext context(cr);
65
m_textureMapper->setGraphicsContext(&context);
67
m_textureMapper->beginPainting();
68
m_rootTextureMapperLayer->paint();
69
m_textureMapper->endPainting();
74
void AcceleratedCompositingContext::attachRootGraphicsLayer(GraphicsLayer* graphicsLayer)
77
m_rootGraphicsLayer.clear();
78
m_rootTextureMapperLayer = 0;
82
m_rootGraphicsLayer = GraphicsLayer::create(this);
83
m_rootTextureMapperLayer = toTextureMapperLayer(m_rootGraphicsLayer.get());
84
m_rootGraphicsLayer->addChild(graphicsLayer);
85
m_rootGraphicsLayer->setDrawsContent(true);
86
m_rootGraphicsLayer->setMasksToBounds(false);
87
m_rootGraphicsLayer->setNeedsDisplay();
88
m_rootGraphicsLayer->setSize(core(m_webView)->mainFrame()->view()->frameRect().size());
90
m_textureMapper = TextureMapperImageBuffer::create();
91
m_rootTextureMapperLayer->setTextureMapper(m_textureMapper.get());
92
m_rootGraphicsLayer->flushCompositingStateForThisLayerOnly();
95
void AcceleratedCompositingContext::scheduleRootLayerRepaint(const IntRect& rect)
97
if (!m_rootGraphicsLayer)
100
m_rootGraphicsLayer->setNeedsDisplay();
103
m_rootGraphicsLayer->setNeedsDisplayInRect(rect);
105
gtk_widget_queue_draw_area(GTK_WIDGET(m_webView), rect.x(), rect.y(), rect.width(), rect.height());
108
void AcceleratedCompositingContext::resizeRootLayer(const IntSize& size)
110
if (!m_rootGraphicsLayer)
112
m_rootGraphicsLayer->setSize(size);
113
m_rootGraphicsLayer->flushCompositingStateForThisLayerOnly();
116
static gboolean syncLayersTimeoutCallback(AcceleratedCompositingContext* context)
118
context->syncLayersTimeout();
122
void AcceleratedCompositingContext::markForSync()
124
if (m_syncTimerCallbackId)
127
// We use a GLib timer because otherwise GTK+ event handling during
128
// dragging can starve WebCore timers, which have a lower priority.
129
m_syncTimerCallbackId = g_timeout_add_full(GDK_PRIORITY_EVENTS, 0, reinterpret_cast<GSourceFunc>(syncLayersTimeoutCallback), this, 0);
132
void AcceleratedCompositingContext::syncLayersNow()
134
if (core(m_webView)->mainFrame()->view()->needsLayout())
135
core(m_webView)->mainFrame()->view()->layout();
137
if (m_rootGraphicsLayer)
138
m_rootGraphicsLayer->flushCompositingStateForThisLayerOnly();
140
core(m_webView)->mainFrame()->view()->flushCompositingStateIncludingSubframes();
143
void AcceleratedCompositingContext::syncLayersTimeout()
145
m_syncTimerCallbackId = 0;
147
if (!m_rootGraphicsLayer)
150
// FIXME: Invalidate just the animations rectangles.
151
gtk_widget_queue_draw(GTK_WIDGET(m_webView));
153
if (toTextureMapperLayer(m_rootGraphicsLayer.get())->descendantsOrSelfHaveRunningAnimations())
154
m_syncTimerCallbackId = g_timeout_add_full(GDK_PRIORITY_EVENTS, 1000.0 / 60.0, reinterpret_cast<GSourceFunc>(syncLayersTimeoutCallback), this, 0);
157
void AcceleratedCompositingContext::notifyAnimationStarted(const GraphicsLayer*, double time)
161
void AcceleratedCompositingContext::notifyFlushRequired(const GraphicsLayer*)
166
void AcceleratedCompositingContext::paintContents(const GraphicsLayer*, GraphicsContext& context, GraphicsLayerPaintingPhase, const IntRect& rectToPaint)
168
cairo_t* cr = context.platformContext()->cr();
169
copyRectFromCairoSurfaceToContext(m_webView->priv->backingStore->cairoSurface(), cr, IntSize(), rectToPaint);
172
} // namespace WebKit
174
#endif // USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER_CAIRO)