2 Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
3 Copyright (C) 2012 Company 100, Inc.
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
23 #if USE(COORDINATED_GRAPHICS)
25 #include "CoordinatedGraphicsScene.h"
27 #include "CoordinatedBackingStore.h"
28 #include "TextureMapper.h"
29 #include "TextureMapperBackingStore.h"
30 #include "TextureMapperGL.h"
31 #include "TextureMapperLayer.h"
32 #include <wtf/Atomics.h>
33 #include <wtf/MainThread.h>
37 void CoordinatedGraphicsScene::dispatchOnMainThread(std::function<void()> function)
42 callOnMainThread(std::move(function));
45 static bool layerShouldHaveBackingStore(TextureMapperLayer* layer)
47 return layer->drawsContent() && layer->contentsAreVisible() && !layer->size().isEmpty();
50 CoordinatedGraphicsScene::CoordinatedGraphicsScene(CoordinatedGraphicsSceneClient* client)
53 , m_rootLayerID(InvalidCoordinatedLayerID)
54 , m_backgroundColor(Color::white)
55 , m_viewBackgroundColor(Color::white)
56 , m_setDrawsBackground(false)
58 ASSERT(isMainThread());
61 CoordinatedGraphicsScene::~CoordinatedGraphicsScene()
65 void CoordinatedGraphicsScene::paintToCurrentGLContext(const TransformationMatrix& matrix, float opacity, const FloatRect& clipRect, TextureMapper::PaintFlags PaintFlags)
67 if (!m_textureMapper) {
68 m_textureMapper = TextureMapper::create(TextureMapper::OpenGLMode);
69 static_cast<TextureMapperGL*>(m_textureMapper.get())->setEnableEdgeDistanceAntialiasing(true);
72 ASSERT(m_textureMapper->accelerationMode() == TextureMapper::OpenGLMode);
75 adjustPositionForFixedLayers();
76 TextureMapperLayer* currentRootLayer = rootLayer();
77 if (!currentRootLayer)
80 currentRootLayer->setTextureMapper(m_textureMapper.get());
81 currentRootLayer->applyAnimationsRecursively();
82 m_textureMapper->beginPainting(PaintFlags);
83 m_textureMapper->beginClip(TransformationMatrix(), clipRect);
85 if (m_setDrawsBackground) {
86 RGBA32 rgba = makeRGBA32FromFloats(m_backgroundColor.red(),
87 m_backgroundColor.green(), m_backgroundColor.blue(),
88 m_backgroundColor.alpha() * opacity);
89 m_textureMapper->drawSolidColor(clipRect, TransformationMatrix(), Color(rgba));
91 GraphicsContext3D* context = static_cast<TextureMapperGL*>(m_textureMapper.get())->graphicsContext3D();
92 context->clearColor(m_viewBackgroundColor.red() / 255.0f, m_viewBackgroundColor.green() / 255.0f, m_viewBackgroundColor.blue() / 255.0f, m_viewBackgroundColor.alpha() / 255.0f);
93 context->clear(GraphicsContext3D::COLOR_BUFFER_BIT);
96 if (currentRootLayer->opacity() != opacity || currentRootLayer->transform() != matrix) {
97 currentRootLayer->setOpacity(opacity);
98 currentRootLayer->setTransform(matrix);
101 currentRootLayer->paint();
102 m_fpsCounter.updateFPSAndDisplay(m_textureMapper.get(), clipRect.location(), matrix);
103 m_textureMapper->endClip();
104 m_textureMapper->endPainting();
106 if (currentRootLayer->descendantsOrSelfHaveRunningAnimations()) {
107 RefPtr<CoordinatedGraphicsScene> protector(this);
108 dispatchOnMainThread([=] {
109 protector->updateViewport();
114 void CoordinatedGraphicsScene::paintToGraphicsContext(PlatformGraphicsContext* platformContext)
116 if (!m_textureMapper)
117 m_textureMapper = TextureMapper::create();
118 ASSERT(m_textureMapper->accelerationMode() == TextureMapper::SoftwareMode);
120 TextureMapperLayer* layer = rootLayer();
125 GraphicsContext graphicsContext(platformContext);
126 m_textureMapper->setGraphicsContext(&graphicsContext);
127 m_textureMapper->beginPainting();
129 IntRect clipRect = graphicsContext.clipBounds();
130 if (m_setDrawsBackground)
131 m_textureMapper->drawSolidColor(clipRect, TransformationMatrix(), m_backgroundColor);
133 m_textureMapper->drawSolidColor(clipRect, TransformationMatrix(), m_viewBackgroundColor);
136 m_fpsCounter.updateFPSAndDisplay(m_textureMapper.get(), clipRect.location());
137 m_textureMapper->endPainting();
138 m_textureMapper->setGraphicsContext(0);
141 void CoordinatedGraphicsScene::setScrollPosition(const FloatPoint& scrollPosition)
143 m_scrollPosition = scrollPosition;
146 void CoordinatedGraphicsScene::updateViewport()
148 ASSERT(isMainThread());
150 m_client->updateViewport();
153 void CoordinatedGraphicsScene::adjustPositionForFixedLayers()
155 if (m_fixedLayers.isEmpty())
158 // Fixed layer positions are updated by the web process when we update the visible contents rect / scroll position.
159 // If we want those layers to follow accurately the viewport when we move between the web process updates, we have to offset
160 // them by the delta between the current position and the position of the viewport used for the last layout.
161 FloatSize delta = m_scrollPosition - m_renderedContentsScrollPosition;
163 LayerRawPtrMap::iterator end = m_fixedLayers.end();
164 for (LayerRawPtrMap::iterator it = m_fixedLayers.begin(); it != end; ++it)
165 it->value->setScrollPositionDeltaIfNeeded(delta);
168 #if USE(GRAPHICS_SURFACE)
169 void CoordinatedGraphicsScene::createCanvasIfNeeded(TextureMapperLayer* layer, const CoordinatedGraphicsLayerState& state)
171 if (!state.canvasToken.isValid())
174 RefPtr<TextureMapperSurfaceBackingStore> canvasBackingStore(TextureMapperSurfaceBackingStore::create());
175 m_surfaceBackingStores.set(layer, canvasBackingStore);
176 canvasBackingStore->setGraphicsSurface(GraphicsSurface::create(state.canvasSize, state.canvasSurfaceFlags, state.canvasToken));
177 layer->setContentsLayer(canvasBackingStore.get());
180 void CoordinatedGraphicsScene::syncCanvasIfNeeded(TextureMapperLayer* layer, const CoordinatedGraphicsLayerState& state)
182 ASSERT(m_textureMapper);
184 if (state.canvasChanged) {
185 destroyCanvasIfNeeded(layer, state);
186 createCanvasIfNeeded(layer, state);
189 if (state.canvasShouldSwapBuffers) {
190 ASSERT(m_surfaceBackingStores.contains(layer));
191 SurfaceBackingStoreMap::iterator it = m_surfaceBackingStores.find(layer);
192 RefPtr<TextureMapperSurfaceBackingStore> canvasBackingStore = it->value;
193 canvasBackingStore->swapBuffersIfNeeded(state.canvasFrontBuffer);
197 void CoordinatedGraphicsScene::destroyCanvasIfNeeded(TextureMapperLayer* layer, const CoordinatedGraphicsLayerState& state)
199 if (state.canvasToken.isValid())
202 m_surfaceBackingStores.remove(layer);
203 layer->setContentsLayer(0);
207 void CoordinatedGraphicsScene::setLayerRepaintCountIfNeeded(TextureMapperLayer* layer, const CoordinatedGraphicsLayerState& state)
209 if (!layer->isShowingRepaintCounter() || !state.repaintCountChanged)
212 layer->setRepaintCount(state.repaintCount);
215 void CoordinatedGraphicsScene::setLayerChildrenIfNeeded(TextureMapperLayer* layer, const CoordinatedGraphicsLayerState& state)
217 if (!state.childrenChanged)
220 Vector<TextureMapperLayer*> children;
222 for (size_t i = 0; i < state.children.size(); ++i) {
223 CoordinatedLayerID childID = state.children[i];
224 TextureMapperLayer* child = layerByID(childID);
225 children.append(child);
227 layer->setChildren(children);
230 #if ENABLE(CSS_FILTERS)
231 void CoordinatedGraphicsScene::setLayerFiltersIfNeeded(TextureMapperLayer* layer, const CoordinatedGraphicsLayerState& state)
233 if (!state.filtersChanged)
236 layer->setFilters(state.filters);
240 void CoordinatedGraphicsScene::setLayerState(CoordinatedLayerID id, const CoordinatedGraphicsLayerState& layerState)
242 ASSERT(m_rootLayerID != InvalidCoordinatedLayerID);
243 TextureMapperLayer* layer = layerByID(id);
245 if (layerState.positionChanged)
246 layer->setPosition(layerState.pos);
248 if (layerState.anchorPointChanged)
249 layer->setAnchorPoint(layerState.anchorPoint);
251 if (layerState.sizeChanged)
252 layer->setSize(layerState.size);
254 if (layerState.transformChanged)
255 layer->setTransform(layerState.transform);
257 if (layerState.childrenTransformChanged)
258 layer->setChildrenTransform(layerState.childrenTransform);
260 if (layerState.contentsRectChanged)
261 layer->setContentsRect(layerState.contentsRect);
263 if (layerState.contentsTilingChanged) {
264 layer->setContentsTilePhase(layerState.contentsTilePhase);
265 layer->setContentsTileSize(layerState.contentsTileSize);
268 if (layerState.opacityChanged)
269 layer->setOpacity(layerState.opacity);
271 if (layerState.solidColorChanged)
272 layer->setSolidColor(layerState.solidColor);
274 if (layerState.debugBorderColorChanged || layerState.debugBorderWidthChanged)
275 layer->setDebugVisuals(layerState.showDebugBorders, layerState.debugBorderColor, layerState.debugBorderWidth, layerState.showRepaintCounter);
277 if (layerState.replicaChanged)
278 layer->setReplicaLayer(getLayerByIDIfExists(layerState.replica));
280 if (layerState.maskChanged)
281 layer->setMaskLayer(getLayerByIDIfExists(layerState.mask));
283 if (layerState.imageChanged)
284 assignImageBackingToLayer(layer, layerState.imageID);
286 if (layerState.flagsChanged) {
287 layer->setContentsOpaque(layerState.contentsOpaque);
288 layer->setDrawsContent(layerState.drawsContent);
289 layer->setContentsVisible(layerState.contentsVisible);
290 layer->setBackfaceVisibility(layerState.backfaceVisible);
292 // Never clip the root layer.
293 layer->setMasksToBounds(id == m_rootLayerID ? false : layerState.masksToBounds);
294 layer->setPreserves3D(layerState.preserves3D);
296 bool fixedToViewportChanged = layer->fixedToViewport() != layerState.fixedToViewport;
297 layer->setFixedToViewport(layerState.fixedToViewport);
298 if (fixedToViewportChanged) {
299 if (layerState.fixedToViewport)
300 m_fixedLayers.add(id, layer);
302 m_fixedLayers.remove(id);
305 layer->setIsScrollable(layerState.isScrollable);
308 if (layerState.committedScrollOffsetChanged)
309 layer->didCommitScrollOffset(layerState.committedScrollOffset);
311 prepareContentBackingStore(layer);
314 setLayerChildrenIfNeeded(layer, layerState);
315 createTilesIfNeeded(layer, layerState);
316 removeTilesIfNeeded(layer, layerState);
317 updateTilesIfNeeded(layer, layerState);
318 #if ENABLE(CSS_FILTERS)
319 setLayerFiltersIfNeeded(layer, layerState);
321 setLayerAnimationsIfNeeded(layer, layerState);
322 #if USE(GRAPHICS_SURFACE)
323 syncCanvasIfNeeded(layer, layerState);
325 setLayerRepaintCountIfNeeded(layer, layerState);
328 TextureMapperLayer* CoordinatedGraphicsScene::getLayerByIDIfExists(CoordinatedLayerID id)
330 return (id != InvalidCoordinatedLayerID) ? layerByID(id) : 0;
333 void CoordinatedGraphicsScene::createLayers(const Vector<CoordinatedLayerID>& ids)
335 for (size_t index = 0; index < ids.size(); ++index)
336 createLayer(ids[index]);
339 void CoordinatedGraphicsScene::createLayer(CoordinatedLayerID id)
341 std::unique_ptr<TextureMapperLayer> newLayer = std::make_unique<TextureMapperLayer>();
343 newLayer->setScrollClient(this);
344 m_layers.add(id, std::move(newLayer));
347 void CoordinatedGraphicsScene::deleteLayers(const Vector<CoordinatedLayerID>& layerIDs)
349 for (size_t index = 0; index < layerIDs.size(); ++index)
350 deleteLayer(layerIDs[index]);
353 void CoordinatedGraphicsScene::deleteLayer(CoordinatedLayerID layerID)
355 std::unique_ptr<TextureMapperLayer> layer = m_layers.take(layerID);
358 m_backingStores.remove(layer.get());
359 m_fixedLayers.remove(layerID);
360 #if USE(GRAPHICS_SURFACE)
361 m_surfaceBackingStores.remove(layer.get());
365 void CoordinatedGraphicsScene::setRootLayerID(CoordinatedLayerID layerID)
367 ASSERT(layerID != InvalidCoordinatedLayerID);
368 ASSERT(m_rootLayerID == InvalidCoordinatedLayerID);
370 m_rootLayerID = layerID;
372 TextureMapperLayer* layer = layerByID(layerID);
373 ASSERT(m_rootLayer->children().isEmpty());
374 m_rootLayer->addChild(layer);
377 void CoordinatedGraphicsScene::prepareContentBackingStore(TextureMapperLayer* layer)
379 if (!layerShouldHaveBackingStore(layer)) {
380 removeBackingStoreIfNeeded(layer);
384 createBackingStoreIfNeeded(layer);
385 resetBackingStoreSizeToLayerSize(layer);
388 void CoordinatedGraphicsScene::createBackingStoreIfNeeded(TextureMapperLayer* layer)
390 if (m_backingStores.contains(layer))
393 RefPtr<CoordinatedBackingStore> backingStore(CoordinatedBackingStore::create());
394 m_backingStores.add(layer, backingStore);
395 layer->setBackingStore(backingStore);
398 void CoordinatedGraphicsScene::removeBackingStoreIfNeeded(TextureMapperLayer* layer)
400 RefPtr<CoordinatedBackingStore> backingStore = m_backingStores.take(layer);
404 layer->setBackingStore(0);
407 void CoordinatedGraphicsScene::resetBackingStoreSizeToLayerSize(TextureMapperLayer* layer)
409 RefPtr<CoordinatedBackingStore> backingStore = m_backingStores.get(layer);
410 ASSERT(backingStore);
411 backingStore->setSize(layer->size());
412 m_backingStoresWithPendingBuffers.add(backingStore);
415 void CoordinatedGraphicsScene::createTilesIfNeeded(TextureMapperLayer* layer, const CoordinatedGraphicsLayerState& state)
417 if (state.tilesToCreate.isEmpty())
420 RefPtr<CoordinatedBackingStore> backingStore = m_backingStores.get(layer);
421 ASSERT(backingStore);
423 for (size_t i = 0; i < state.tilesToCreate.size(); ++i)
424 backingStore->createTile(state.tilesToCreate[i].tileID, state.tilesToCreate[i].scale);
427 void CoordinatedGraphicsScene::removeTilesIfNeeded(TextureMapperLayer* layer, const CoordinatedGraphicsLayerState& state)
429 if (state.tilesToRemove.isEmpty())
432 RefPtr<CoordinatedBackingStore> backingStore = m_backingStores.get(layer);
436 for (size_t i = 0; i < state.tilesToRemove.size(); ++i)
437 backingStore->removeTile(state.tilesToRemove[i]);
439 m_backingStoresWithPendingBuffers.add(backingStore);
442 void CoordinatedGraphicsScene::updateTilesIfNeeded(TextureMapperLayer* layer, const CoordinatedGraphicsLayerState& state)
444 if (state.tilesToUpdate.isEmpty())
447 RefPtr<CoordinatedBackingStore> backingStore = m_backingStores.get(layer);
448 ASSERT(backingStore);
450 for (size_t i = 0; i < state.tilesToUpdate.size(); ++i) {
451 const TileUpdateInfo& tileInfo = state.tilesToUpdate[i];
452 const SurfaceUpdateInfo& surfaceUpdateInfo = tileInfo.updateInfo;
454 SurfaceMap::iterator surfaceIt = m_surfaces.find(surfaceUpdateInfo.atlasID);
455 ASSERT(surfaceIt != m_surfaces.end());
457 backingStore->updateTile(tileInfo.tileID, surfaceUpdateInfo.updateRect, tileInfo.tileRect, surfaceIt->value, surfaceUpdateInfo.surfaceOffset);
458 m_backingStoresWithPendingBuffers.add(backingStore);
462 void CoordinatedGraphicsScene::syncUpdateAtlases(const CoordinatedGraphicsState& state)
464 for (size_t i = 0; i < state.updateAtlasesToCreate.size(); ++i)
465 createUpdateAtlas(state.updateAtlasesToCreate[i].first, state.updateAtlasesToCreate[i].second);
467 for (size_t i = 0; i < state.updateAtlasesToRemove.size(); ++i)
468 removeUpdateAtlas(state.updateAtlasesToRemove[i]);
471 void CoordinatedGraphicsScene::createUpdateAtlas(uint32_t atlasID, PassRefPtr<CoordinatedSurface> surface)
473 ASSERT(!m_surfaces.contains(atlasID));
474 m_surfaces.add(atlasID, surface);
477 void CoordinatedGraphicsScene::removeUpdateAtlas(uint32_t atlasID)
479 ASSERT(m_surfaces.contains(atlasID));
480 m_surfaces.remove(atlasID);
483 void CoordinatedGraphicsScene::syncImageBackings(const CoordinatedGraphicsState& state)
485 for (size_t i = 0; i < state.imagesToRemove.size(); ++i)
486 removeImageBacking(state.imagesToRemove[i]);
488 for (size_t i = 0; i < state.imagesToCreate.size(); ++i)
489 createImageBacking(state.imagesToCreate[i]);
491 for (size_t i = 0; i < state.imagesToUpdate.size(); ++i)
492 updateImageBacking(state.imagesToUpdate[i].first, state.imagesToUpdate[i].second);
494 for (size_t i = 0; i < state.imagesToClear.size(); ++i)
495 clearImageBackingContents(state.imagesToClear[i]);
498 void CoordinatedGraphicsScene::createImageBacking(CoordinatedImageBackingID imageID)
500 ASSERT(!m_imageBackings.contains(imageID));
501 RefPtr<CoordinatedBackingStore> backingStore(CoordinatedBackingStore::create());
502 m_imageBackings.add(imageID, backingStore.release());
505 void CoordinatedGraphicsScene::updateImageBacking(CoordinatedImageBackingID imageID, PassRefPtr<CoordinatedSurface> surface)
507 ASSERT(m_imageBackings.contains(imageID));
508 ImageBackingMap::iterator it = m_imageBackings.find(imageID);
509 RefPtr<CoordinatedBackingStore> backingStore = it->value;
511 // CoordinatedImageBacking is realized to CoordinatedBackingStore with only one tile in UI Process.
512 backingStore->createTile(1 /* id */, 1 /* scale */);
513 IntRect rect(IntPoint::zero(), surface->size());
514 // See CoordinatedGraphicsLayer::shouldDirectlyCompositeImage()
515 ASSERT(2000 >= std::max(rect.width(), rect.height()));
516 backingStore->setSize(rect.size());
517 backingStore->updateTile(1 /* id */, rect, rect, surface, rect.location());
519 m_backingStoresWithPendingBuffers.add(backingStore);
522 void CoordinatedGraphicsScene::clearImageBackingContents(CoordinatedImageBackingID imageID)
524 ASSERT(m_imageBackings.contains(imageID));
525 ImageBackingMap::iterator it = m_imageBackings.find(imageID);
526 RefPtr<CoordinatedBackingStore> backingStore = it->value;
527 backingStore->removeAllTiles();
528 m_backingStoresWithPendingBuffers.add(backingStore);
531 void CoordinatedGraphicsScene::removeImageBacking(CoordinatedImageBackingID imageID)
533 ASSERT(m_imageBackings.contains(imageID));
535 // We don't want TextureMapperLayer refers a dangling pointer.
536 m_releasedImageBackings.append(m_imageBackings.take(imageID));
539 void CoordinatedGraphicsScene::assignImageBackingToLayer(TextureMapperLayer* layer, CoordinatedImageBackingID imageID)
541 #if USE(GRAPHICS_SURFACE)
542 if (m_surfaceBackingStores.contains(layer))
546 if (imageID == InvalidCoordinatedImageBackingID) {
547 layer->setContentsLayer(0);
551 ImageBackingMap::iterator it = m_imageBackings.find(imageID);
552 ASSERT(it != m_imageBackings.end());
553 layer->setContentsLayer(it->value.get());
556 void CoordinatedGraphicsScene::removeReleasedImageBackingsIfNeeded()
558 m_releasedImageBackings.clear();
561 void CoordinatedGraphicsScene::commitPendingBackingStoreOperations()
563 HashSet<RefPtr<CoordinatedBackingStore> >::iterator end = m_backingStoresWithPendingBuffers.end();
564 for (HashSet<RefPtr<CoordinatedBackingStore> >::iterator it = m_backingStoresWithPendingBuffers.begin(); it != end; ++it)
565 (*it)->commitTileOperations(m_textureMapper.get());
567 m_backingStoresWithPendingBuffers.clear();
570 void CoordinatedGraphicsScene::commitSceneState(const CoordinatedGraphicsState& state)
572 m_renderedContentsScrollPosition = state.scrollPosition;
574 createLayers(state.layersToCreate);
575 deleteLayers(state.layersToRemove);
577 if (state.rootCompositingLayer != m_rootLayerID)
578 setRootLayerID(state.rootCompositingLayer);
580 syncImageBackings(state);
581 syncUpdateAtlases(state);
583 for (size_t i = 0; i < state.layersToUpdate.size(); ++i)
584 setLayerState(state.layersToUpdate[i].first, state.layersToUpdate[i].second);
586 commitPendingBackingStoreOperations();
587 removeReleasedImageBackingsIfNeeded();
589 // The pending tiles state is on its way for the screen, tell the web process to render the next one.
590 RefPtr<CoordinatedGraphicsScene> protector(this);
591 dispatchOnMainThread([=] {
592 protector->renderNextFrame();
596 void CoordinatedGraphicsScene::renderNextFrame()
599 m_client->renderNextFrame();
602 void CoordinatedGraphicsScene::ensureRootLayer()
607 m_rootLayer = std::make_unique<TextureMapperLayer>();
608 m_rootLayer->setMasksToBounds(false);
609 m_rootLayer->setDrawsContent(false);
610 m_rootLayer->setAnchorPoint(FloatPoint3D(0, 0, 0));
612 // The root layer should not have zero size, or it would be optimized out.
613 m_rootLayer->setSize(FloatSize(1.0, 1.0));
615 ASSERT(m_textureMapper);
616 m_rootLayer->setTextureMapper(m_textureMapper.get());
619 void CoordinatedGraphicsScene::syncRemoteContent()
621 // We enqueue messages and execute them during paint, as they require an active GL context.
624 Vector<std::function<void()>> renderQueue;
625 bool calledOnMainThread = WTF::isMainThread();
626 if (!calledOnMainThread)
627 m_renderQueueMutex.lock();
628 renderQueue = std::move(m_renderQueue);
629 if (!calledOnMainThread)
630 m_renderQueueMutex.unlock();
632 for (auto& function : renderQueue)
636 void CoordinatedGraphicsScene::purgeGLResources()
638 m_imageBackings.clear();
639 m_releasedImageBackings.clear();
640 #if USE(GRAPHICS_SURFACE)
641 m_surfaceBackingStores.clear();
645 m_rootLayer = nullptr;
646 m_rootLayerID = InvalidCoordinatedLayerID;
648 m_fixedLayers.clear();
649 m_textureMapper.clear();
650 m_backingStores.clear();
651 m_backingStoresWithPendingBuffers.clear();
655 RefPtr<CoordinatedGraphicsScene> protector(this);
656 dispatchOnMainThread([=] {
657 protector->purgeBackingStores();
661 void CoordinatedGraphicsScene::dispatchCommitScrollOffset(uint32_t layerID, const IntSize& offset)
663 m_client->commitScrollOffset(layerID, offset);
666 void CoordinatedGraphicsScene::commitScrollOffset(uint32_t layerID, const IntSize& offset)
668 RefPtr<CoordinatedGraphicsScene> protector(this);
669 dispatchOnMainThread([=] {
670 protector->dispatchCommitScrollOffset(layerID, offset);
674 void CoordinatedGraphicsScene::purgeBackingStores()
677 m_client->purgeBackingStores();
680 void CoordinatedGraphicsScene::setLayerAnimationsIfNeeded(TextureMapperLayer* layer, const CoordinatedGraphicsLayerState& state)
682 if (!state.animationsChanged)
685 layer->setAnimations(state.animations);
688 void CoordinatedGraphicsScene::detach()
690 ASSERT(isMainThread());
691 m_renderQueue.clear();
695 void CoordinatedGraphicsScene::appendUpdate(std::function<void()> function)
700 ASSERT(isMainThread());
701 MutexLocker locker(m_renderQueueMutex);
702 m_renderQueue.append(std::move(function));
705 void CoordinatedGraphicsScene::setActive(bool active)
707 if (m_isActive == active)
710 // Have to clear render queue in both cases.
711 // If there are some updates in queue during activation then those updates are from previous instance of paint node
712 // and cannot be applied to the newly created instance.
713 m_renderQueue.clear();
716 RefPtr<CoordinatedGraphicsScene> protector(this);
717 dispatchOnMainThread([=] {
718 protector->renderNextFrame();
723 void CoordinatedGraphicsScene::setBackgroundColor(const Color& color)
725 m_backgroundColor = color;
728 TextureMapperLayer* CoordinatedGraphicsScene::findScrollableContentsLayerAt(const FloatPoint& point)
730 return rootLayer() ? rootLayer()->findScrollableContentsLayerAt(point) : 0;
733 } // namespace WebCore
735 #endif // USE(COORDINATED_GRAPHICS)