Diff
Modified: trunk/Source/WebCore/ChangeLog (202674 => 202675)
--- trunk/Source/WebCore/ChangeLog 2016-06-30 06:28:58 UTC (rev 202674)
+++ trunk/Source/WebCore/ChangeLog 2016-06-30 07:32:32 UTC (rev 202675)
@@ -1,3 +1,14 @@
+2016-06-30 Carlos Garcia Campos <cgar...@igalia.com>
+
+ [Coordinated Graphics] Move CompositingCoordinator from platform to WebKit2 layer
+ https://bugs.webkit.org/show_bug.cgi?id=159209
+
+ Reviewed by Žan Doberšek.
+
+ Remove CompositingCoordinator and its helper classes from the platform layer.
+
+ * platform/TextureMapper.cmake:
+
2016-06-29 Youenn Fablet <you...@apple.com>
Pass SecurityOrigin as references in CORS check code
Modified: trunk/Source/WebCore/platform/TextureMapper.cmake (202674 => 202675)
--- trunk/Source/WebCore/platform/TextureMapper.cmake 2016-06-30 06:28:58 UTC (rev 202674)
+++ trunk/Source/WebCore/platform/TextureMapper.cmake 2016-06-30 07:32:32 UTC (rev 202675)
@@ -33,14 +33,11 @@
page/scrolling/coordinatedgraphics/ScrollingCoordinatorCoordinatedGraphics.cpp
page/scrolling/coordinatedgraphics/ScrollingStateNodeCoordinatedGraphics.cpp
- platform/graphics/texmap/coordinated/AreaAllocator.cpp
- platform/graphics/texmap/coordinated/CompositingCoordinator.cpp
platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp
platform/graphics/texmap/coordinated/CoordinatedImageBacking.cpp
platform/graphics/texmap/coordinated/CoordinatedSurface.cpp
platform/graphics/texmap/coordinated/Tile.cpp
platform/graphics/texmap/coordinated/TiledBackingStore.cpp
- platform/graphics/texmap/coordinated/UpdateAtlas.cpp
)
endif ()
Deleted: trunk/Source/WebCore/platform/graphics/texmap/coordinated/AreaAllocator.cpp (202674 => 202675)
--- trunk/Source/WebCore/platform/graphics/texmap/coordinated/AreaAllocator.cpp 2016-06-30 06:28:58 UTC (rev 202674)
+++ trunk/Source/WebCore/platform/graphics/texmap/coordinated/AreaAllocator.cpp 2016-06-30 07:32:32 UTC (rev 202675)
@@ -1,335 +0,0 @@
-/*
- * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
- *
- * 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.1 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"
-
-#if USE(COORDINATED_GRAPHICS)
-
-#include "AreaAllocator.h"
-
-namespace WebCore {
-
-AreaAllocator::AreaAllocator(const IntSize& size)
- : m_size(size)
- , m_minAlloc(1, 1)
- , m_margin(0, 0)
-{
-}
-
-AreaAllocator::~AreaAllocator()
-{
-}
-
-void AreaAllocator::expand(const IntSize& size)
-{
- m_size = m_size.expandedTo(size);
-}
-
-void AreaAllocator::expandBy(const IntSize& size)
-{
- m_size += size;
-}
-
-void AreaAllocator::release(const IntRect&)
-{
-}
-
-int AreaAllocator::overhead() const
-{
- return 0;
-}
-
-IntSize AreaAllocator::roundAllocation(const IntSize& size) const
-{
- int width = size.width() + m_margin.width();
- int height = size.height() + m_margin.height();
- int extra = width % m_minAlloc.width();
- if (extra)
- width += m_minAlloc.width() - extra;
- extra = height % m_minAlloc.height();
- if (extra)
- height += m_minAlloc.height() - extra;
-
- return IntSize(width, height);
-}
-
-GeneralAreaAllocator::GeneralAreaAllocator(const IntSize& size)
- : AreaAllocator(nextPowerOfTwo(size))
-{
- m_root = new Node();
- m_root->rect = IntRect(0, 0, m_size.width(), m_size.height());
- m_root->largestFree = m_size;
- m_root->parent = 0;
- m_root->left = 0;
- m_root->right = 0;
- m_nodeCount = 1;
- setMinimumAllocation(IntSize(8, 8));
-}
-
-GeneralAreaAllocator::~GeneralAreaAllocator()
-{
- freeNode(m_root);
-}
-
-void GeneralAreaAllocator::freeNode(Node* node)
-{
- if (node) {
- freeNode(node->left);
- freeNode(node->right);
- }
- delete node;
-}
-
-void GeneralAreaAllocator::expand(const IntSize& size)
-{
- AreaAllocator::expand(nextPowerOfTwo(size));
-
- if (m_root->rect.size() == m_size)
- return; // No change.
-
- if (!m_root->left && m_root->largestFree.width() > 0) {
- // No allocations have occurred, so just adjust the root size.
- m_root->rect = IntRect(0, 0, m_size.width(), m_size.height());
- m_root->largestFree = m_size;
- return;
- }
-
- // Add extra nodes above the current root to expand the tree.
- Node* oldRoot = m_root;
- Split split;
- if (m_size.width() >= m_size.height())
- split = SplitOnX;
- else
- split = SplitOnY;
-
- while (m_root->rect.size() != m_size) {
- if (m_root->rect.width() == m_size.width())
- split = SplitOnY;
- else if (m_root->rect.height() == m_size.height())
- split = SplitOnX;
- Node* parent = new Node();
- Node* right = new Node();
- m_nodeCount += 2;
- m_root->parent = parent;
- parent->parent = 0;
- parent->left = m_root;
- parent->right = right;
- parent->largestFree = m_root->rect.size();
- right->parent = parent;
- right->left = 0;
- right->right = 0;
- right->largestFree = m_root->rect.size();
- if (split == SplitOnX) {
- parent->rect = IntRect(m_root->rect.x(), m_root->rect.y(),
- m_root->rect.width() * 2, m_root->rect.height());
- right->rect = IntRect(m_root->rect.x() + m_root->rect.width(), m_root->rect.y(),
- m_root->rect.width(), m_root->rect.height());
- } else {
- parent->rect = IntRect(m_root->rect.x(), m_root->rect.y(),
- m_root->rect.width(), m_root->rect.height() * 2);
- right->rect = IntRect(m_root->rect.x(), m_root->rect.y() + m_root->rect.width(),
- m_root->rect.width(), m_root->rect.height());
- }
- split = (split == SplitOnX ? SplitOnY : SplitOnX);
- m_root = parent;
- }
- updateLargestFree(oldRoot);
-}
-
-static inline bool fitsWithin(const IntSize& size1, const IntSize& size2)
-{
- return size1.width() <= size2.width() && size1.height() <= size2.height();
-}
-
-IntRect GeneralAreaAllocator::allocate(const IntSize& size)
-{
- IntSize rounded = roundAllocation(size);
- rounded = nextPowerOfTwo(rounded);
- if (rounded.width() <= 0 || rounded.width() > m_size.width()
- || rounded.height() <= 0 || rounded.height() > m_size.height())
- return IntRect();
-
- IntPoint point = allocateFromNode(rounded, m_root);
- if (point.x() >= 0)
- return IntRect(point, size);
- return IntRect();
-}
-
-IntPoint GeneralAreaAllocator::allocateFromNode(const IntSize& size, Node* node)
-{
- // Find the best node to insert into, which should be
- // a node with the least amount of unused space that is
- // big enough to contain the requested size.
- while (node) {
- // Go down a level and determine if the left or right
- // sub-tree contains the best chance of allocation.
- Node* left = node->left;
- Node* right = node->right;
- if (left && fitsWithin(size, left->largestFree)) {
- if (right && fitsWithin(size, right->largestFree)) {
- if (left->largestFree.width() < right->largestFree.width()
- || left->largestFree.height() < right->largestFree.height()) {
- // The largestFree values may be a little oversized,
- // so try the left sub-tree and then the right sub-tree.
- IntPoint point = allocateFromNode(size, left);
- if (point.x() >= 0)
- return point;
- return allocateFromNode(size, right);
- }
- node = right;
- } else
- node = left;
- } else if (right && fitsWithin(size, right->largestFree))
- node = right;
- else if (left || right) {
- // Neither sub-node has enough space to allocate from.
- return IntPoint(-1, -1);
- } else if (fitsWithin(size, node->largestFree)) {
- // Do we need to split this node into smaller pieces?
- Split split;
- if (fitsWithin(IntSize(size.width() * 2, size.height() * 2), node->largestFree)) {
- // Split in either direction: choose the inverse of
- // the parent node's split direction to try to balance
- // out the wasted space as further subdivisions happen.
- if (node->parent
- && node->parent->left->rect.x() == node->parent->right->rect.x())
- split = SplitOnX;
- else if (node->parent)
- split = SplitOnY;
- else if (node->rect.width() >= node->rect.height())
- split = SplitOnX;
- else
- split = SplitOnY;
- } else if (fitsWithin(IntSize(size.width() * 2, size.height()), node->largestFree)) {
- // Split along the X direction.
- split = SplitOnX;
- } else if (fitsWithin(IntSize(size.width(), size.height() * 2), node->largestFree)) {
- // Split along the Y direction.
- split = SplitOnY;
- } else {
- // Cannot split further - allocate this node.
- node->largestFree = IntSize(0, 0);
- updateLargestFree(node);
- return node->rect.location();
- }
-
- // Split the node, then go around again using the left sub-tree.
- node = splitNode(node, split);
- } else {
- // Cannot possibly fit into this node.
- break;
- }
- }
- return IntPoint(-1, -1);
-}
-
-GeneralAreaAllocator::Node* GeneralAreaAllocator::splitNode
- (Node* node, Split split)
-{
- Node* left = new Node();
- Node* right = new Node();
- m_nodeCount += 2;
- left->parent = node;
- left->left = 0;
- left->right = 0;
- right->parent = node;
- right->left = 0;
- right->right = 0;
- node->left = left;
- node->right = right;
-
- if (split == SplitOnX) {
- left->rect = IntRect(node->rect.x(), node->rect.y(),
- node->rect.width() / 2, node->rect.height());
- right->rect = IntRect(left->rect.maxX(), node->rect.y(),
- node->rect.width() / 2, node->rect.height());
- } else {
- left->rect = IntRect(node->rect.x(), node->rect.y(),
- node->rect.width(), node->rect.height() / 2);
- right->rect = IntRect(node->rect.x(), left->rect.maxY(),
- node->rect.width(), node->rect.height() / 2);
- }
-
- left->largestFree = left->rect.size();
- right->largestFree = right->rect.size();
- node->largestFree = right->largestFree;
- return left;
-}
-
-void GeneralAreaAllocator::updateLargestFree(Node* node)
-{
- while ((node = node->parent)) {
- node->largestFree = IntSize(
- std::max(node->left->largestFree.width(), node->right->largestFree.width()),
- std::max(node->left->largestFree.height(), node->right->largestFree.height())
- );
- }
-}
-
-void GeneralAreaAllocator::release(const IntRect& rect)
-{
- // Locate the node that contains the allocated region.
- Node* node = m_root;
- IntPoint point = rect.location();
- while (node) {
- if (node->left && node->left->rect.contains(point))
- node = node->left;
- else if (node->right && node->right->rect.contains(point))
- node = node->right;
- else if (node->rect.contains(point))
- break;
- else
- return; // Point is completely outside the tree.
- }
- if (!node)
- return;
-
- // Mark the node as free and then work upwards through the tree
- // recombining and deleting nodes until we reach a sibling
- // that is still allocated.
- node->largestFree = node->rect.size();
- while (node->parent) {
- if (node->parent->left == node) {
- if (node->parent->right->largestFree != node->parent->right->rect.size())
- break;
- } else {
- if (node->parent->left->largestFree != node->parent->left->rect.size())
- break;
- }
- node = node->parent;
- freeNode(node->left);
- freeNode(node->right);
- m_nodeCount -= 2;
- node->left = 0;
- node->right = 0;
- node->largestFree = node->rect.size();
- }
-
- // Make the rest of our ancestors have the correct "largest free size".
- updateLargestFree(node);
-}
-
-int GeneralAreaAllocator::overhead() const
-{
- return m_nodeCount * sizeof(Node);
-}
-
-} // namespace WebCore
-
-#endif // USE(COORDINATED_GRAPHICS)
Deleted: trunk/Source/WebCore/platform/graphics/texmap/coordinated/AreaAllocator.h (202674 => 202675)
--- trunk/Source/WebCore/platform/graphics/texmap/coordinated/AreaAllocator.h 2016-06-30 06:28:58 UTC (rev 202674)
+++ trunk/Source/WebCore/platform/graphics/texmap/coordinated/AreaAllocator.h 2016-06-30 07:32:32 UTC (rev 202675)
@@ -1,114 +0,0 @@
-/*
- * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
- *
- * 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.1 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
- *
- */
-
-#ifndef AreaAllocator_h
-#define AreaAllocator_h
-
-#include "IntPoint.h"
-#include "IntRect.h"
-#include "IntSize.h"
-
-#if USE(COORDINATED_GRAPHICS)
-
-namespace WebCore {
-
-inline int nextPowerOfTwo(int number)
-{
- // This is a fast trick to get nextPowerOfTwo for an integer.
- --number;
- number |= number >> 1;
- number |= number >> 2;
- number |= number >> 4;
- number |= number >> 8;
- number |= number >> 16;
- number++;
- return number;
-}
-
-inline IntSize nextPowerOfTwo(const IntSize& size)
-{
- return IntSize(nextPowerOfTwo(size.width()), nextPowerOfTwo(size.height()));
-}
-
-class AreaAllocator {
- WTF_MAKE_FAST_ALLOCATED;
-public:
- explicit AreaAllocator(const IntSize&);
- virtual ~AreaAllocator();
-
- IntSize size() const { return m_size; }
-
- IntSize minimumAllocation() const { return m_minAlloc; }
- void setMinimumAllocation(const IntSize& size) { m_minAlloc = size; }
-
- IntSize margin() const { return m_margin; }
- void setMargin(const IntSize &margin) { m_margin = margin; }
-
- virtual void expand(const IntSize&);
- void expandBy(const IntSize&);
-
- virtual IntRect allocate(const IntSize&) = 0;
- virtual void release(const IntRect&);
-
- virtual int overhead() const;
-
-protected:
- IntSize m_size;
- IntSize m_minAlloc;
- IntSize m_margin;
-
- IntSize roundAllocation(const IntSize&) const;
-};
-
-class GeneralAreaAllocator : public AreaAllocator {
- WTF_MAKE_FAST_ALLOCATED;
-public:
- explicit GeneralAreaAllocator(const IntSize&);
- virtual ~GeneralAreaAllocator();
-
- void expand(const IntSize&);
- IntRect allocate(const IntSize&);
- void release(const IntRect&);
- int overhead() const;
-
-private:
- enum Split { SplitOnX, SplitOnY };
-
- struct Node {
- IntRect rect;
- IntSize largestFree;
- Node* parent;
- Node* left;
- Node* right;
- };
-
- Node* m_root;
- int m_nodeCount;
-
- static void freeNode(Node*);
- IntPoint allocateFromNode(const IntSize&, Node*);
- Node* splitNode(Node*, Split);
- static void updateLargestFree(Node*);
-};
-
-} // namespace WebCore
-
-#endif // USE(COORDINATED_GRAPHICS)
-
-#endif // AreaAllocator_h
Deleted: trunk/Source/WebCore/platform/graphics/texmap/coordinated/CompositingCoordinator.cpp (202674 => 202675)
--- trunk/Source/WebCore/platform/graphics/texmap/coordinated/CompositingCoordinator.cpp 2016-06-30 06:28:58 UTC (rev 202674)
+++ trunk/Source/WebCore/platform/graphics/texmap/coordinated/CompositingCoordinator.cpp 2016-06-30 07:32:32 UTC (rev 202675)
@@ -1,453 +0,0 @@
-/*
- * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
- * Copyright (C) 2013 Company 100, Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-
-#if USE(COORDINATED_GRAPHICS)
-
-#include "CompositingCoordinator.h"
-
-#include "DOMWindow.h"
-#include "Document.h"
-#include "FrameView.h"
-#include "GraphicsContext.h"
-#include "InspectorController.h"
-#include "MainFrame.h"
-#include "Page.h"
-#include "Settings.h"
-#include <wtf/CurrentTime.h>
-#include <wtf/TemporaryChange.h>
-
-// FIXME: Having this in the platform directory is a layering violation. This does not belong here.
-
-namespace WebCore {
-
-CompositingCoordinator::CompositingCoordinator(Page* page, CompositingCoordinator::Client* client)
- : m_page(page)
- , m_client(client)
- , m_rootCompositingLayer(nullptr)
- , m_overlayCompositingLayer(nullptr)
- , m_isDestructing(false)
- , m_isPurging(false)
- , m_isFlushingLayerChanges(false)
- , m_shouldSyncFrame(false)
- , m_didInitializeRootCompositingLayer(false)
- , m_releaseInactiveAtlasesTimer(*this, &CompositingCoordinator::releaseInactiveAtlasesTimerFired)
-#if ENABLE(REQUEST_ANIMATION_FRAME)
- , m_lastAnimationServiceTime(0)
-#endif
-{
-}
-
-CompositingCoordinator::~CompositingCoordinator()
-{
- m_isDestructing = true;
-
- purgeBackingStores();
-
- for (auto& registeredLayer : m_registeredLayers.values())
- registeredLayer->setCoordinator(nullptr);
-}
-
-void CompositingCoordinator::setRootCompositingLayer(GraphicsLayer* graphicsLayer)
-{
- if (m_rootCompositingLayer == graphicsLayer)
- return;
-
- if (m_rootCompositingLayer)
- m_rootCompositingLayer->removeFromParent();
-
- m_rootCompositingLayer = graphicsLayer;
- if (m_rootCompositingLayer)
- m_rootLayer->addChildAtIndex(m_rootCompositingLayer, 0);
-}
-
-void CompositingCoordinator::setViewOverlayRootLayer(GraphicsLayer* graphicsLayer)
-{
- if (m_overlayCompositingLayer == graphicsLayer)
- return;
-
- if (m_overlayCompositingLayer)
- m_overlayCompositingLayer->removeFromParent();
-
- m_overlayCompositingLayer = graphicsLayer;
- if (m_overlayCompositingLayer)
- m_rootLayer->addChild(m_overlayCompositingLayer);
-}
-
-void CompositingCoordinator::sizeDidChange(const IntSize& newSize)
-{
- m_rootLayer->setSize(newSize);
- notifyFlushRequired(m_rootLayer.get());
-}
-
-bool CompositingCoordinator::flushPendingLayerChanges()
-{
- TemporaryChange<bool> protector(m_isFlushingLayerChanges, true);
-
- initializeRootCompositingLayerIfNeeded();
-
- bool viewportIsStable = m_page->mainFrame().view()->viewportIsStable();
- m_rootLayer->flushCompositingStateForThisLayerOnly(viewportIsStable);
- m_client->didFlushRootLayer(m_visibleContentsRect);
-
- if (m_overlayCompositingLayer)
- m_overlayCompositingLayer->flushCompositingState(FloatRect(FloatPoint(), m_rootLayer->size()), viewportIsStable);
-
- bool didSync = m_page->mainFrame().view()->flushCompositingStateIncludingSubframes();
-
- toCoordinatedGraphicsLayer(m_rootLayer.get())->updateContentBuffersIncludingSubLayers();
- toCoordinatedGraphicsLayer(m_rootLayer.get())->syncPendingStateChangesIncludingSubLayers();
-
- flushPendingImageBackingChanges();
-
- if (m_shouldSyncFrame) {
- didSync = true;
-
- if (m_rootCompositingLayer) {
- m_state.contentsSize = roundedIntSize(m_rootCompositingLayer->size());
- if (CoordinatedGraphicsLayer* contentsLayer = mainContentsLayer())
- m_state.coveredRect = contentsLayer->coverRect();
- }
- m_state.scrollPosition = m_visibleContentsRect.location();
-
- m_client->commitSceneState(m_state);
-
- clearPendingStateChanges();
- m_shouldSyncFrame = false;
- }
-
- return didSync;
-}
-
-double CompositingCoordinator::timestamp() const
-{
- auto* document = m_page->mainFrame().document();
- if (!document)
- return 0;
- return document->domWindow() ? document->domWindow()->nowTimestamp() : document->monotonicTimestamp();
-}
-
-void CompositingCoordinator::syncDisplayState()
-{
-#if ENABLE(REQUEST_ANIMATION_FRAME) && !USE(REQUEST_ANIMATION_FRAME_TIMER) && !USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
- // Make sure that any previously registered animation callbacks are being executed before we flush the layers.
- m_lastAnimationServiceTime = timestamp();
- m_page->mainFrame().view()->serviceScriptedAnimations();
-#endif
- m_page->mainFrame().view()->updateLayoutAndStyleIfNeededRecursive();
-}
-
-#if ENABLE(REQUEST_ANIMATION_FRAME)
-double CompositingCoordinator::nextAnimationServiceTime() const
-{
- // According to the requestAnimationFrame spec, rAF callbacks should not be faster than 60FPS.
- static const double MinimalTimeoutForAnimations = 1. / 60.;
- return std::max<double>(0., MinimalTimeoutForAnimations - timestamp() + m_lastAnimationServiceTime);
-}
-#endif
-
-void CompositingCoordinator::clearPendingStateChanges()
-{
- m_state.layersToCreate.clear();
- m_state.layersToUpdate.clear();
- m_state.layersToRemove.clear();
-
- m_state.imagesToCreate.clear();
- m_state.imagesToRemove.clear();
- m_state.imagesToUpdate.clear();
- m_state.imagesToClear.clear();
-
- m_state.updateAtlasesToCreate.clear();
- m_state.updateAtlasesToRemove.clear();
-}
-
-void CompositingCoordinator::initializeRootCompositingLayerIfNeeded()
-{
- if (m_didInitializeRootCompositingLayer)
- return;
-
- m_state.rootCompositingLayer = toCoordinatedGraphicsLayer(m_rootLayer.get())->id();
- m_didInitializeRootCompositingLayer = true;
- m_shouldSyncFrame = true;
-}
-
-void CompositingCoordinator::createRootLayer(const IntSize& size)
-{
- ASSERT(!m_rootLayer);
- // Create a root layer.
- m_rootLayer = GraphicsLayer::create(this, *this);
-#ifndef NDEBUG
- m_rootLayer->setName("CompositingCoordinator root layer");
-#endif
- m_rootLayer->setDrawsContent(false);
- m_rootLayer->setSize(size);
-}
-
-void CompositingCoordinator::syncLayerState(CoordinatedLayerID id, CoordinatedGraphicsLayerState& state)
-{
- m_shouldSyncFrame = true;
- m_state.layersToUpdate.append(std::make_pair(id, state));
-}
-
-PassRefPtr<CoordinatedImageBacking> CompositingCoordinator::createImageBackingIfNeeded(Image* image)
-{
- CoordinatedImageBackingID imageID = CoordinatedImageBacking::getCoordinatedImageBackingID(image);
- ImageBackingMap::iterator it = m_imageBackings.find(imageID);
- RefPtr<CoordinatedImageBacking> imageBacking;
- if (it == m_imageBackings.end()) {
- imageBacking = CoordinatedImageBacking::create(this, image);
- m_imageBackings.add(imageID, imageBacking);
- } else
- imageBacking = it->value;
-
- return imageBacking;
-}
-
-void CompositingCoordinator::createImageBacking(CoordinatedImageBackingID imageID)
-{
- m_state.imagesToCreate.append(imageID);
-}
-
-void CompositingCoordinator::updateImageBacking(CoordinatedImageBackingID imageID, PassRefPtr<CoordinatedSurface> coordinatedSurface)
-{
- m_shouldSyncFrame = true;
- m_state.imagesToUpdate.append(std::make_pair(imageID, coordinatedSurface));
-}
-
-void CompositingCoordinator::clearImageBackingContents(CoordinatedImageBackingID imageID)
-{
- m_shouldSyncFrame = true;
- m_state.imagesToClear.append(imageID);
-}
-
-void CompositingCoordinator::removeImageBacking(CoordinatedImageBackingID imageID)
-{
- if (m_isPurging)
- return;
-
- ASSERT(m_imageBackings.contains(imageID));
- m_imageBackings.remove(imageID);
-
- m_state.imagesToRemove.append(imageID);
-
- size_t imageIDPosition = m_state.imagesToClear.find(imageID);
- if (imageIDPosition != notFound)
- m_state.imagesToClear.remove(imageIDPosition);
-}
-
-void CompositingCoordinator::flushPendingImageBackingChanges()
-{
- for (auto& imageBacking : m_imageBackings.values())
- imageBacking->update();
-}
-
-void CompositingCoordinator::notifyAnimationStarted(const GraphicsLayer*, const String&, double /* time */)
-{
-}
-
-void CompositingCoordinator::notifyFlushRequired(const GraphicsLayer*)
-{
- if (!m_isDestructing && !isFlushingLayerChanges())
- m_client->notifyFlushRequired();
-}
-
-void CompositingCoordinator::paintContents(const GraphicsLayer* graphicsLayer, GraphicsContext& graphicsContext, GraphicsLayerPaintingPhase, const FloatRect& clipRect)
-{
- m_client->paintLayerContents(graphicsLayer, graphicsContext, enclosingIntRect(clipRect));
-}
-
-std::unique_ptr<GraphicsLayer> CompositingCoordinator::createGraphicsLayer(GraphicsLayer::Type layerType, GraphicsLayerClient& client)
-{
- CoordinatedGraphicsLayer* layer = new CoordinatedGraphicsLayer(layerType, client);
- layer->setCoordinator(this);
- m_registeredLayers.add(layer->id(), layer);
- m_state.layersToCreate.append(layer->id());
- layer->setNeedsVisibleRectAdjustment();
- notifyFlushRequired(layer);
- return std::unique_ptr<GraphicsLayer>(layer);
-}
-
-float CompositingCoordinator::deviceScaleFactor() const
-{
- return m_page->deviceScaleFactor();
-}
-
-float CompositingCoordinator::pageScaleFactor() const
-{
- return m_page->pageScaleFactor();
-}
-
-void CompositingCoordinator::createUpdateAtlas(uint32_t atlasID, PassRefPtr<CoordinatedSurface> coordinatedSurface)
-{
- m_state.updateAtlasesToCreate.append(std::make_pair(atlasID, coordinatedSurface));
-}
-
-void CompositingCoordinator::removeUpdateAtlas(uint32_t atlasID)
-{
- if (m_isPurging)
- return;
- m_state.updateAtlasesToRemove.append(atlasID);
-}
-
-FloatRect CompositingCoordinator::visibleContentsRect() const
-{
- return m_visibleContentsRect;
-}
-
-CoordinatedGraphicsLayer* CompositingCoordinator::mainContentsLayer()
-{
- if (!m_rootCompositingLayer)
- return 0;
-
- return toCoordinatedGraphicsLayer(m_rootCompositingLayer)->findFirstDescendantWithContentsRecursively();
-}
-
-void CompositingCoordinator::setVisibleContentsRect(const FloatRect& rect, const FloatPoint& trajectoryVector)
-{
- // A zero trajectoryVector indicates that tiles all around the viewport are requested.
- if (CoordinatedGraphicsLayer* contentsLayer = mainContentsLayer())
- contentsLayer->setVisibleContentRectTrajectoryVector(trajectoryVector);
-
- bool contentsRectDidChange = rect != m_visibleContentsRect;
- if (contentsRectDidChange) {
- m_visibleContentsRect = rect;
-
- for (auto& registeredLayer : m_registeredLayers.values())
- registeredLayer->setNeedsVisibleRectAdjustment();
- }
-
- FrameView* view = m_page->mainFrame().view();
- if (view->useFixedLayout() && contentsRectDidChange) {
- // Round the rect instead of enclosing it to make sure that its size stays
- // the same while panning. This can have nasty effects on layout.
- view->setFixedVisibleContentRect(roundedIntRect(rect));
- }
-}
-
-void CompositingCoordinator::deviceOrPageScaleFactorChanged()
-{
- m_rootLayer->deviceOrPageScaleFactorChanged();
-}
-
-void CompositingCoordinator::detachLayer(CoordinatedGraphicsLayer* layer)
-{
- if (m_isPurging)
- return;
-
- m_registeredLayers.remove(layer->id());
-
- size_t index = m_state.layersToCreate.find(layer->id());
- if (index != notFound) {
- m_state.layersToCreate.remove(index);
- return;
- }
-
- m_state.layersToRemove.append(layer->id());
- notifyFlushRequired(layer);
-}
-
-void CompositingCoordinator::commitScrollOffset(uint32_t layerID, const WebCore::IntSize& offset)
-{
- LayerMap::iterator i = m_registeredLayers.find(layerID);
- if (i == m_registeredLayers.end())
- return;
-
- i->value->commitScrollOffset(offset);
-}
-
-void CompositingCoordinator::renderNextFrame()
-{
- for (auto& atlas : m_updateAtlases)
- atlas->didSwapBuffers();
-}
-
-void CompositingCoordinator::purgeBackingStores()
-{
- TemporaryChange<bool> purgingToggle(m_isPurging, true);
-
- for (auto& registeredLayer : m_registeredLayers.values())
- registeredLayer->purgeBackingStores();
-
- m_imageBackings.clear();
- m_updateAtlases.clear();
-}
-
-bool CompositingCoordinator::paintToSurface(const IntSize& size, CoordinatedSurface::Flags flags, uint32_t& atlasID, IntPoint& offset, CoordinatedSurface::Client* client)
-{
- for (auto& updateAtlas : m_updateAtlases) {
- UpdateAtlas* atlas = updateAtlas.get();
- if (atlas->supportsAlpha() == (flags & CoordinatedSurface::SupportsAlpha)) {
- // This will be false if there is no available buffer space.
- if (atlas->paintOnAvailableBuffer(size, atlasID, offset, client))
- return true;
- }
- }
-
- static const int ScratchBufferDimension = 1024; // Should be a power of two.
- m_updateAtlases.append(std::make_unique<UpdateAtlas>(this, ScratchBufferDimension, flags));
- scheduleReleaseInactiveAtlases();
- return m_updateAtlases.last()->paintOnAvailableBuffer(size, atlasID, offset, client);
-}
-
-const double ReleaseInactiveAtlasesTimerInterval = 0.5;
-
-void CompositingCoordinator::scheduleReleaseInactiveAtlases()
-{
- if (!m_releaseInactiveAtlasesTimer.isActive())
- m_releaseInactiveAtlasesTimer.startRepeating(ReleaseInactiveAtlasesTimerInterval);
-}
-
-void CompositingCoordinator::releaseInactiveAtlasesTimerFired()
-{
- // We always want to keep one atlas for root contents layer.
- std::unique_ptr<UpdateAtlas> atlasToKeepAnyway;
- bool foundActiveAtlasForRootContentsLayer = false;
- for (int i = m_updateAtlases.size() - 1; i >= 0; --i) {
- UpdateAtlas* atlas = m_updateAtlases[i].get();
- if (!atlas->isInUse())
- atlas->addTimeInactive(ReleaseInactiveAtlasesTimerInterval);
- bool usableForRootContentsLayer = !atlas->supportsAlpha();
- if (atlas->isInactive()) {
- if (!foundActiveAtlasForRootContentsLayer && !atlasToKeepAnyway && usableForRootContentsLayer)
- atlasToKeepAnyway = WTFMove(m_updateAtlases[i]);
- m_updateAtlases.remove(i);
- } else if (usableForRootContentsLayer)
- foundActiveAtlasForRootContentsLayer = true;
- }
-
- if (!foundActiveAtlasForRootContentsLayer && atlasToKeepAnyway)
- m_updateAtlases.append(atlasToKeepAnyway.release());
-
- m_updateAtlases.shrinkToFit();
-
- if (m_updateAtlases.size() <= 1)
- m_releaseInactiveAtlasesTimer.stop();
-}
-
-} // namespace WebCore
-
-#endif // USE(COORDINATED_GRAPHICS)
Deleted: trunk/Source/WebCore/platform/graphics/texmap/coordinated/CompositingCoordinator.h (202674 => 202675)
--- trunk/Source/WebCore/platform/graphics/texmap/coordinated/CompositingCoordinator.h 2016-06-30 06:28:58 UTC (rev 202674)
+++ trunk/Source/WebCore/platform/graphics/texmap/coordinated/CompositingCoordinator.h 2016-06-30 07:32:32 UTC (rev 202675)
@@ -1,165 +0,0 @@
-/*
- * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
- * Copyright (C) 2013 Company 100, Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef CompositingCoordinator_h
-#define CompositingCoordinator_h
-
-#if USE(COORDINATED_GRAPHICS)
-
-#include "CoordinatedGraphicsLayer.h"
-#include "CoordinatedGraphicsState.h"
-#include "CoordinatedImageBacking.h"
-#include "FloatPoint.h"
-#include "GraphicsLayerClient.h"
-#include "GraphicsLayerFactory.h"
-#include "IntRect.h"
-#include "Timer.h"
-#include "UpdateAtlas.h"
-
-namespace WebCore {
-
-class Page;
-class GraphicsContext;
-class GraphicsLayer;
-class CoordinatedSurface;
-
-class CompositingCoordinator : public GraphicsLayerClient
- , public CoordinatedGraphicsLayerClient
- , public CoordinatedImageBacking::Client
- , public UpdateAtlas::Client
- , public GraphicsLayerFactory {
- WTF_MAKE_NONCOPYABLE(CompositingCoordinator); WTF_MAKE_FAST_ALLOCATED;
-public:
- class Client {
- public:
- virtual void didFlushRootLayer(const FloatRect& visibleContentRect) = 0;
- virtual void notifyFlushRequired() = 0;
- virtual void commitSceneState(const CoordinatedGraphicsState&) = 0;
- virtual void paintLayerContents(const GraphicsLayer*, GraphicsContext&, const IntRect& clipRect) = 0;
- };
-
- CompositingCoordinator(Page*, CompositingCoordinator::Client*);
- virtual ~CompositingCoordinator();
-
- void setRootCompositingLayer(GraphicsLayer*);
- void setViewOverlayRootLayer(GraphicsLayer*);
- void sizeDidChange(const IntSize& newSize);
- void deviceOrPageScaleFactorChanged();
-
- void setVisibleContentsRect(const FloatRect&, const FloatPoint&);
- void renderNextFrame();
- void purgeBackingStores();
- void commitScrollOffset(uint32_t layerID, const IntSize& offset);
-
- void createRootLayer(const IntSize&);
- void clearRootLayer() { m_rootLayer = nullptr; }
- GraphicsLayer* rootLayer() const { return m_rootLayer.get(); }
- CoordinatedGraphicsLayer* mainContentsLayer();
-
- bool flushPendingLayerChanges();
- CoordinatedGraphicsState& state() { return m_state; }
-
- void syncDisplayState();
-
-#if ENABLE(REQUEST_ANIMATION_FRAME)
- double nextAnimationServiceTime() const;
-#endif
-
-private:
- // GraphicsLayerClient
- void notifyAnimationStarted(const GraphicsLayer*, const String&, double time) override;
- void notifyFlushRequired(const GraphicsLayer*) override;
- void paintContents(const GraphicsLayer*, GraphicsContext&, GraphicsLayerPaintingPhase, const FloatRect& clipRect) override;
- float deviceScaleFactor() const override;
- float pageScaleFactor() const override;
-
- // CoordinatedImageBacking::Client
- void createImageBacking(CoordinatedImageBackingID) override;
- void updateImageBacking(CoordinatedImageBackingID, PassRefPtr<CoordinatedSurface>) override;
- void clearImageBackingContents(CoordinatedImageBackingID) override;
- void removeImageBacking(CoordinatedImageBackingID) override;
-
- // CoordinatedGraphicsLayerClient
- bool isFlushingLayerChanges() const override { return m_isFlushingLayerChanges; }
- FloatRect visibleContentsRect() const override;
- PassRefPtr<CoordinatedImageBacking> createImageBackingIfNeeded(Image*) override;
- void detachLayer(CoordinatedGraphicsLayer*) override;
- bool paintToSurface(const WebCore::IntSize&, WebCore::CoordinatedSurface::Flags, uint32_t& /* atlasID */, WebCore::IntPoint&, WebCore::CoordinatedSurface::Client*) override;
- void syncLayerState(CoordinatedLayerID, CoordinatedGraphicsLayerState&) override;
-
- // UpdateAtlas::Client
- void createUpdateAtlas(uint32_t atlasID, PassRefPtr<CoordinatedSurface>) override;
- void removeUpdateAtlas(uint32_t atlasID) override;
-
- // GraphicsLayerFactory
- std::unique_ptr<GraphicsLayer> createGraphicsLayer(GraphicsLayer::Type, GraphicsLayerClient&) override;
-
- void initializeRootCompositingLayerIfNeeded();
- void flushPendingImageBackingChanges();
- void clearPendingStateChanges();
-
- void scheduleReleaseInactiveAtlases();
-
- void releaseInactiveAtlasesTimerFired();
-
- double timestamp() const;
-
- Page* m_page;
- CompositingCoordinator::Client* m_client;
-
- std::unique_ptr<GraphicsLayer> m_rootLayer;
- GraphicsLayer* m_rootCompositingLayer;
- GraphicsLayer* m_overlayCompositingLayer;
-
- CoordinatedGraphicsState m_state;
-
- typedef HashMap<CoordinatedLayerID, CoordinatedGraphicsLayer*> LayerMap;
- LayerMap m_registeredLayers;
- typedef HashMap<CoordinatedImageBackingID, RefPtr<CoordinatedImageBacking> > ImageBackingMap;
- ImageBackingMap m_imageBackings;
- Vector<std::unique_ptr<UpdateAtlas>> m_updateAtlases;
-
- // We don't send the messages related to releasing resources to renderer during purging, because renderer already had removed all resources.
- bool m_isDestructing;
- bool m_isPurging;
- bool m_isFlushingLayerChanges;
-
- FloatRect m_visibleContentsRect;
-
- bool m_shouldSyncFrame;
- bool m_didInitializeRootCompositingLayer;
- Timer m_releaseInactiveAtlasesTimer;
-
-#if ENABLE(REQUEST_ANIMATION_FRAME)
- double m_lastAnimationServiceTime;
-#endif
-};
-
-}
-
-#endif
-
-#endif // CompositingCoordinator_h
Deleted: trunk/Source/WebCore/platform/graphics/texmap/coordinated/UpdateAtlas.cpp (202674 => 202675)
--- trunk/Source/WebCore/platform/graphics/texmap/coordinated/UpdateAtlas.cpp 2016-06-30 06:28:58 UTC (rev 202674)
+++ trunk/Source/WebCore/platform/graphics/texmap/coordinated/UpdateAtlas.cpp 2016-06-30 07:32:32 UTC (rev 202675)
@@ -1,116 +0,0 @@
-/*
- Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
- Copyright (C) 2012 Company 100, Inc.
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public License
- along with this library; see the file COPYING.LIB. If not, write to
- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
- */
-
-#include "config.h"
-#include "UpdateAtlas.h"
-
-#if USE(COORDINATED_GRAPHICS)
-
-#include "CoordinatedGraphicsState.h"
-#include "GraphicsContext.h"
-#include "IntRect.h"
-#include <wtf/MathExtras.h>
-
-namespace WebCore {
-
-class UpdateAtlasSurfaceClient : public CoordinatedSurface::Client {
-public:
- UpdateAtlasSurfaceClient(CoordinatedSurface::Client* client, const IntSize& size, bool supportsAlpha)
- : m_client(client)
- , m_size(size)
- , m_supportsAlpha(supportsAlpha)
- {
- }
-
- void paintToSurfaceContext(GraphicsContext& context) override
- {
- if (m_supportsAlpha) {
- context.setCompositeOperation(CompositeCopy);
- context.fillRect(IntRect(IntPoint::zero(), m_size), Color::transparent);
- context.setCompositeOperation(CompositeSourceOver);
- }
-
- m_client->paintToSurfaceContext(context);
- }
-
-private:
- CoordinatedSurface::Client* m_client;
- IntSize m_size;
- bool m_supportsAlpha;
-};
-
-UpdateAtlas::UpdateAtlas(Client* client, int dimension, CoordinatedSurface::Flags flags)
- : m_client(client)
- , m_inactivityInSeconds(0)
-{
- static uint32_t nextID = 0;
- m_ID = ++nextID;
- IntSize size = nextPowerOfTwo(IntSize(dimension, dimension));
- m_surface = CoordinatedSurface::create(size, flags);
-
- m_client->createUpdateAtlas(m_ID, m_surface);
-}
-
-UpdateAtlas::~UpdateAtlas()
-{
- if (m_surface)
- m_client->removeUpdateAtlas(m_ID);
-}
-
-void UpdateAtlas::buildLayoutIfNeeded()
-{
- if (!m_areaAllocator) {
- m_areaAllocator = std::make_unique<GeneralAreaAllocator>(size());
- m_areaAllocator->setMinimumAllocation(IntSize(32, 32));
- }
-}
-
-void UpdateAtlas::didSwapBuffers()
-{
- m_areaAllocator = nullptr;
-}
-
-
-bool UpdateAtlas::paintOnAvailableBuffer(const IntSize& size, uint32_t& atlasID, IntPoint& offset, CoordinatedSurface::Client* client)
-{
- m_inactivityInSeconds = 0;
- buildLayoutIfNeeded();
- IntRect rect = m_areaAllocator->allocate(size);
-
- // No available buffer was found.
- if (rect.isEmpty())
- return false;
-
- if (!m_surface)
- return false;
-
- atlasID = m_ID;
-
- // FIXME: Use tri-state buffers, to allow faster updates.
- offset = rect.location();
-
- UpdateAtlasSurfaceClient surfaceClient(client, size, supportsAlpha());
- m_surface->paintToSurface(rect, &surfaceClient);
-
- return true;
-}
-
-} // namespace WebCore
-#endif // USE(COORDINATED_GRAPHICS)
Deleted: trunk/Source/WebCore/platform/graphics/texmap/coordinated/UpdateAtlas.h (202674 => 202675)
--- trunk/Source/WebCore/platform/graphics/texmap/coordinated/UpdateAtlas.h 2016-06-30 06:28:58 UTC (rev 202674)
+++ trunk/Source/WebCore/platform/graphics/texmap/coordinated/UpdateAtlas.h 2016-06-30 07:32:32 UTC (rev 202675)
@@ -1,80 +0,0 @@
-/*
- Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
- Copyright (C) 2012 Company 100, Inc.
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public License
- along with this library; see the file COPYING.LIB. If not, write to
- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
- */
-
-#ifndef UpdateAtlas_h
-#define UpdateAtlas_h
-
-#include "AreaAllocator.h"
-#include "CoordinatedSurface.h"
-#include "IntSize.h"
-#include <wtf/PassRefPtr.h>
-#include <wtf/RefPtr.h>
-
-#if USE(COORDINATED_GRAPHICS)
-
-namespace WebCore {
-class GraphicsContext;
-class IntPoint;
-
-class UpdateAtlas {
- WTF_MAKE_NONCOPYABLE(UpdateAtlas);
-public:
- class Client {
- public:
- virtual void createUpdateAtlas(uint32_t /* id */, PassRefPtr<CoordinatedSurface>) = 0;
- virtual void removeUpdateAtlas(uint32_t /* id */) = 0;
- };
-
- UpdateAtlas(Client*, int dimension, CoordinatedSurface::Flags);
- ~UpdateAtlas();
-
- inline IntSize size() const { return m_surface->size(); }
-
- // Returns false if there is no available buffer.
- bool paintOnAvailableBuffer(const IntSize&, uint32_t& atlasID, IntPoint& offset, CoordinatedSurface::Client*);
- void didSwapBuffers();
- bool supportsAlpha() const { return m_surface->supportsAlpha(); }
-
- void addTimeInactive(double seconds)
- {
- ASSERT(!isInUse());
- m_inactivityInSeconds += seconds;
- }
- bool isInactive() const
- {
- const double inactiveSecondsTolerance = 3;
- return m_inactivityInSeconds > inactiveSecondsTolerance;
- }
- bool isInUse() const { return !!m_areaAllocator; }
-
-private:
- void buildLayoutIfNeeded();
-
-private:
- Client* m_client;
- std::unique_ptr<GeneralAreaAllocator> m_areaAllocator;
- RefPtr<CoordinatedSurface> m_surface;
- double m_inactivityInSeconds;
- uint32_t m_ID;
-};
-
-} // namespace WebCore
-#endif // USE(COORDINATED_GRAPHICS)
-#endif // UpdateAtlas_h
Modified: trunk/Source/WebKit2/ChangeLog (202674 => 202675)
--- trunk/Source/WebKit2/ChangeLog 2016-06-30 06:28:58 UTC (rev 202674)
+++ trunk/Source/WebKit2/ChangeLog 2016-06-30 07:32:32 UTC (rev 202675)
@@ -1,3 +1,98 @@
+2016-06-30 Carlos Garcia Campos <cgar...@igalia.com>
+
+ [Coordinated Graphics] Move CompositingCoordinator from platform to WebKit2 layer
+ https://bugs.webkit.org/show_bug.cgi?id=159209
+
+ Reviewed by Žan Doberšek.
+
+ Move CompositingCoordinator and its helper classes to the WebKit2 layer.
+
+ * PlatformEfl.cmake:
+ * PlatformGTK.cmake:
+ * WebProcess/WebPage/CoordinatedGraphics/AreaAllocator.cpp: Renamed from Source/WebCore/platform/graphics/texmap/coordinated/AreaAllocator.cpp.
+ (WebKit::AreaAllocator::AreaAllocator):
+ (WebKit::AreaAllocator::~AreaAllocator):
+ (WebKit::AreaAllocator::expand):
+ (WebKit::AreaAllocator::expandBy):
+ (WebKit::AreaAllocator::release):
+ (WebKit::AreaAllocator::overhead):
+ (WebKit::AreaAllocator::roundAllocation):
+ (WebKit::GeneralAreaAllocator::GeneralAreaAllocator):
+ (WebKit::GeneralAreaAllocator::~GeneralAreaAllocator):
+ (WebKit::GeneralAreaAllocator::freeNode):
+ (WebKit::GeneralAreaAllocator::expand):
+ (WebKit::fitsWithin):
+ (WebKit::GeneralAreaAllocator::allocate):
+ (WebKit::GeneralAreaAllocator::allocateFromNode):
+ (WebKit::GeneralAreaAllocator::splitNode):
+ (WebKit::GeneralAreaAllocator::updateLargestFree):
+ (WebKit::GeneralAreaAllocator::release):
+ (WebKit::GeneralAreaAllocator::overhead):
+ * WebProcess/WebPage/CoordinatedGraphics/AreaAllocator.h: Renamed from Source/WebCore/platform/graphics/texmap/coordinated/AreaAllocator.h.
+ (WebKit::nextPowerOfTwo):
+ (WebKit::AreaAllocator::size):
+ (WebKit::AreaAllocator::minimumAllocation):
+ (WebKit::AreaAllocator::setMinimumAllocation):
+ (WebKit::AreaAllocator::margin):
+ (WebKit::AreaAllocator::setMargin):
+ * WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.cpp: Renamed from Source/WebCore/platform/graphics/texmap/coordinated/CompositingCoordinator.cpp.
+ (WebKit::CompositingCoordinator::CompositingCoordinator):
+ (WebKit::CompositingCoordinator::~CompositingCoordinator):
+ (WebKit::CompositingCoordinator::setRootCompositingLayer):
+ (WebKit::CompositingCoordinator::setViewOverlayRootLayer):
+ (WebKit::CompositingCoordinator::sizeDidChange):
+ (WebKit::CompositingCoordinator::flushPendingLayerChanges):
+ (WebKit::CompositingCoordinator::timestamp):
+ (WebKit::CompositingCoordinator::syncDisplayState):
+ (WebKit::CompositingCoordinator::nextAnimationServiceTime):
+ (WebKit::CompositingCoordinator::clearPendingStateChanges):
+ (WebKit::CompositingCoordinator::initializeRootCompositingLayerIfNeeded):
+ (WebKit::CompositingCoordinator::createRootLayer):
+ (WebKit::CompositingCoordinator::syncLayerState):
+ (WebKit::CompositingCoordinator::createImageBackingIfNeeded):
+ (WebKit::CompositingCoordinator::createImageBacking):
+ (WebKit::CompositingCoordinator::updateImageBacking):
+ (WebKit::CompositingCoordinator::clearImageBackingContents):
+ (WebKit::CompositingCoordinator::removeImageBacking):
+ (WebKit::CompositingCoordinator::flushPendingImageBackingChanges):
+ (WebKit::CompositingCoordinator::notifyAnimationStarted):
+ (WebKit::CompositingCoordinator::notifyFlushRequired):
+ (WebKit::CompositingCoordinator::paintContents):
+ (WebKit::CompositingCoordinator::createGraphicsLayer):
+ (WebKit::CompositingCoordinator::deviceScaleFactor):
+ (WebKit::CompositingCoordinator::pageScaleFactor):
+ (WebKit::CompositingCoordinator::createUpdateAtlas):
+ (WebKit::CompositingCoordinator::removeUpdateAtlas):
+ (WebKit::CompositingCoordinator::visibleContentsRect):
+ (WebKit::CompositingCoordinator::mainContentsLayer):
+ (WebKit::CompositingCoordinator::setVisibleContentsRect):
+ (WebKit::CompositingCoordinator::deviceOrPageScaleFactorChanged):
+ (WebKit::CompositingCoordinator::detachLayer):
+ (WebKit::CompositingCoordinator::commitScrollOffset):
+ (WebKit::CompositingCoordinator::renderNextFrame):
+ (WebKit::CompositingCoordinator::purgeBackingStores):
+ (WebKit::CompositingCoordinator::paintToSurface):
+ (WebKit::CompositingCoordinator::scheduleReleaseInactiveAtlases):
+ (WebKit::CompositingCoordinator::releaseInactiveAtlasesTimerFired):
+ * WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.h: Renamed from Source/WebCore/platform/graphics/texmap/coordinated/CompositingCoordinator.h.
+ (WebKit::CompositingCoordinator::clearRootLayer):
+ (WebKit::CompositingCoordinator::rootLayer):
+ (WebKit::CompositingCoordinator::state):
+ * WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.h:
+ * WebProcess/WebPage/CoordinatedGraphics/UpdateAtlas.cpp: Renamed from Source/WebCore/platform/graphics/texmap/coordinated/UpdateAtlas.cpp.
+ (WebKit::UpdateAtlasSurfaceClient::UpdateAtlasSurfaceClient):
+ (WebKit::UpdateAtlas::UpdateAtlas):
+ (WebKit::UpdateAtlas::~UpdateAtlas):
+ (WebKit::UpdateAtlas::buildLayoutIfNeeded):
+ (WebKit::UpdateAtlas::didSwapBuffers):
+ (WebKit::UpdateAtlas::paintOnAvailableBuffer):
+ * WebProcess/WebPage/CoordinatedGraphics/UpdateAtlas.h: Renamed from Source/WebCore/platform/graphics/texmap/coordinated/UpdateAtlas.h.
+ (WebKit::UpdateAtlas::size):
+ (WebKit::UpdateAtlas::supportsAlpha):
+ (WebKit::UpdateAtlas::addTimeInactive):
+ (WebKit::UpdateAtlas::isInactive):
+ (WebKit::UpdateAtlas::isInUse):
+
2016-06-29 Hunseop Jeong <hs85.je...@samsung.com>
Unreviewed, CMake build fix.
Modified: trunk/Source/WebKit2/PlatformEfl.cmake (202674 => 202675)
--- trunk/Source/WebKit2/PlatformEfl.cmake 2016-06-30 06:28:58 UTC (rev 202674)
+++ trunk/Source/WebKit2/PlatformEfl.cmake 2016-06-30 07:32:32 UTC (rev 202675)
@@ -198,8 +198,11 @@
WebProcess/WebPage/DrawingAreaImpl.cpp
+ WebProcess/WebPage/CoordinatedGraphics/AreaAllocator.cpp
+ WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.cpp
WebProcess/WebPage/CoordinatedGraphics/CoordinatedDrawingArea.cpp
WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp
+ WebProcess/WebPage/CoordinatedGraphics/UpdateAtlas.cpp
WebProcess/WebPage/CoordinatedGraphics/WebPageCoordinatedGraphics.cpp
WebProcess/WebPage/atk/WebPageAccessibilityObjectAtk.cpp
Modified: trunk/Source/WebKit2/PlatformGTK.cmake (202674 => 202675)
--- trunk/Source/WebKit2/PlatformGTK.cmake 2016-06-30 06:28:58 UTC (rev 202674)
+++ trunk/Source/WebKit2/PlatformGTK.cmake 2016-06-30 07:32:32 UTC (rev 202675)
@@ -826,8 +826,11 @@
Shared/CoordinatedGraphics/threadedcompositor/ThreadSafeCoordinatedSurface.cpp
Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.cpp
+ WebProcess/WebPage/CoordinatedGraphics/AreaAllocator.cpp
+ WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.cpp
WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp
WebProcess/WebPage/CoordinatedGraphics/ThreadedCoordinatedLayerTreeHost.cpp
+ WebProcess/WebPage/CoordinatedGraphics/UpdateAtlas.cpp
)
list(APPEND WebKit2_INCLUDE_DIRECTORIES
"${WEBCORE_DIR}/platform/graphics/texmap/coordinated"
Copied: trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/AreaAllocator.cpp (from rev 202674, trunk/Source/WebCore/platform/graphics/texmap/coordinated/AreaAllocator.cpp) (0 => 202675)
--- trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/AreaAllocator.cpp (rev 0)
+++ trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/AreaAllocator.cpp 2016-06-30 07:32:32 UTC (rev 202675)
@@ -0,0 +1,336 @@
+/*
+ * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
+ *
+ * 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.1 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 "AreaAllocator.h"
+
+#if USE(COORDINATED_GRAPHICS)
+
+using namespace WebCore;
+
+namespace WebKit {
+
+AreaAllocator::AreaAllocator(const IntSize& size)
+ : m_size(size)
+ , m_minAlloc(1, 1)
+ , m_margin(0, 0)
+{
+}
+
+AreaAllocator::~AreaAllocator()
+{
+}
+
+void AreaAllocator::expand(const IntSize& size)
+{
+ m_size = m_size.expandedTo(size);
+}
+
+void AreaAllocator::expandBy(const IntSize& size)
+{
+ m_size += size;
+}
+
+void AreaAllocator::release(const IntRect&)
+{
+}
+
+int AreaAllocator::overhead() const
+{
+ return 0;
+}
+
+IntSize AreaAllocator::roundAllocation(const IntSize& size) const
+{
+ int width = size.width() + m_margin.width();
+ int height = size.height() + m_margin.height();
+ int extra = width % m_minAlloc.width();
+ if (extra)
+ width += m_minAlloc.width() - extra;
+ extra = height % m_minAlloc.height();
+ if (extra)
+ height += m_minAlloc.height() - extra;
+
+ return IntSize(width, height);
+}
+
+GeneralAreaAllocator::GeneralAreaAllocator(const IntSize& size)
+ : AreaAllocator(nextPowerOfTwo(size))
+{
+ m_root = new Node();
+ m_root->rect = IntRect(0, 0, m_size.width(), m_size.height());
+ m_root->largestFree = m_size;
+ m_root->parent = 0;
+ m_root->left = 0;
+ m_root->right = 0;
+ m_nodeCount = 1;
+ setMinimumAllocation(IntSize(8, 8));
+}
+
+GeneralAreaAllocator::~GeneralAreaAllocator()
+{
+ freeNode(m_root);
+}
+
+void GeneralAreaAllocator::freeNode(Node* node)
+{
+ if (node) {
+ freeNode(node->left);
+ freeNode(node->right);
+ }
+ delete node;
+}
+
+void GeneralAreaAllocator::expand(const IntSize& size)
+{
+ AreaAllocator::expand(nextPowerOfTwo(size));
+
+ if (m_root->rect.size() == m_size)
+ return; // No change.
+
+ if (!m_root->left && m_root->largestFree.width() > 0) {
+ // No allocations have occurred, so just adjust the root size.
+ m_root->rect = IntRect(0, 0, m_size.width(), m_size.height());
+ m_root->largestFree = m_size;
+ return;
+ }
+
+ // Add extra nodes above the current root to expand the tree.
+ Node* oldRoot = m_root;
+ Split split;
+ if (m_size.width() >= m_size.height())
+ split = SplitOnX;
+ else
+ split = SplitOnY;
+
+ while (m_root->rect.size() != m_size) {
+ if (m_root->rect.width() == m_size.width())
+ split = SplitOnY;
+ else if (m_root->rect.height() == m_size.height())
+ split = SplitOnX;
+ Node* parent = new Node();
+ Node* right = new Node();
+ m_nodeCount += 2;
+ m_root->parent = parent;
+ parent->parent = 0;
+ parent->left = m_root;
+ parent->right = right;
+ parent->largestFree = m_root->rect.size();
+ right->parent = parent;
+ right->left = 0;
+ right->right = 0;
+ right->largestFree = m_root->rect.size();
+ if (split == SplitOnX) {
+ parent->rect = IntRect(m_root->rect.x(), m_root->rect.y(),
+ m_root->rect.width() * 2, m_root->rect.height());
+ right->rect = IntRect(m_root->rect.x() + m_root->rect.width(), m_root->rect.y(),
+ m_root->rect.width(), m_root->rect.height());
+ } else {
+ parent->rect = IntRect(m_root->rect.x(), m_root->rect.y(),
+ m_root->rect.width(), m_root->rect.height() * 2);
+ right->rect = IntRect(m_root->rect.x(), m_root->rect.y() + m_root->rect.width(),
+ m_root->rect.width(), m_root->rect.height());
+ }
+ split = (split == SplitOnX ? SplitOnY : SplitOnX);
+ m_root = parent;
+ }
+ updateLargestFree(oldRoot);
+}
+
+static inline bool fitsWithin(const IntSize& size1, const IntSize& size2)
+{
+ return size1.width() <= size2.width() && size1.height() <= size2.height();
+}
+
+IntRect GeneralAreaAllocator::allocate(const IntSize& size)
+{
+ IntSize rounded = roundAllocation(size);
+ rounded = nextPowerOfTwo(rounded);
+ if (rounded.width() <= 0 || rounded.width() > m_size.width()
+ || rounded.height() <= 0 || rounded.height() > m_size.height())
+ return IntRect();
+
+ IntPoint point = allocateFromNode(rounded, m_root);
+ if (point.x() >= 0)
+ return IntRect(point, size);
+ return IntRect();
+}
+
+IntPoint GeneralAreaAllocator::allocateFromNode(const IntSize& size, Node* node)
+{
+ // Find the best node to insert into, which should be
+ // a node with the least amount of unused space that is
+ // big enough to contain the requested size.
+ while (node) {
+ // Go down a level and determine if the left or right
+ // sub-tree contains the best chance of allocation.
+ Node* left = node->left;
+ Node* right = node->right;
+ if (left && fitsWithin(size, left->largestFree)) {
+ if (right && fitsWithin(size, right->largestFree)) {
+ if (left->largestFree.width() < right->largestFree.width()
+ || left->largestFree.height() < right->largestFree.height()) {
+ // The largestFree values may be a little oversized,
+ // so try the left sub-tree and then the right sub-tree.
+ IntPoint point = allocateFromNode(size, left);
+ if (point.x() >= 0)
+ return point;
+ return allocateFromNode(size, right);
+ }
+ node = right;
+ } else
+ node = left;
+ } else if (right && fitsWithin(size, right->largestFree))
+ node = right;
+ else if (left || right) {
+ // Neither sub-node has enough space to allocate from.
+ return IntPoint(-1, -1);
+ } else if (fitsWithin(size, node->largestFree)) {
+ // Do we need to split this node into smaller pieces?
+ Split split;
+ if (fitsWithin(IntSize(size.width() * 2, size.height() * 2), node->largestFree)) {
+ // Split in either direction: choose the inverse of
+ // the parent node's split direction to try to balance
+ // out the wasted space as further subdivisions happen.
+ if (node->parent
+ && node->parent->left->rect.x() == node->parent->right->rect.x())
+ split = SplitOnX;
+ else if (node->parent)
+ split = SplitOnY;
+ else if (node->rect.width() >= node->rect.height())
+ split = SplitOnX;
+ else
+ split = SplitOnY;
+ } else if (fitsWithin(IntSize(size.width() * 2, size.height()), node->largestFree)) {
+ // Split along the X direction.
+ split = SplitOnX;
+ } else if (fitsWithin(IntSize(size.width(), size.height() * 2), node->largestFree)) {
+ // Split along the Y direction.
+ split = SplitOnY;
+ } else {
+ // Cannot split further - allocate this node.
+ node->largestFree = IntSize(0, 0);
+ updateLargestFree(node);
+ return node->rect.location();
+ }
+
+ // Split the node, then go around again using the left sub-tree.
+ node = splitNode(node, split);
+ } else {
+ // Cannot possibly fit into this node.
+ break;
+ }
+ }
+ return IntPoint(-1, -1);
+}
+
+GeneralAreaAllocator::Node* GeneralAreaAllocator::splitNode
+ (Node* node, Split split)
+{
+ Node* left = new Node();
+ Node* right = new Node();
+ m_nodeCount += 2;
+ left->parent = node;
+ left->left = 0;
+ left->right = 0;
+ right->parent = node;
+ right->left = 0;
+ right->right = 0;
+ node->left = left;
+ node->right = right;
+
+ if (split == SplitOnX) {
+ left->rect = IntRect(node->rect.x(), node->rect.y(),
+ node->rect.width() / 2, node->rect.height());
+ right->rect = IntRect(left->rect.maxX(), node->rect.y(),
+ node->rect.width() / 2, node->rect.height());
+ } else {
+ left->rect = IntRect(node->rect.x(), node->rect.y(),
+ node->rect.width(), node->rect.height() / 2);
+ right->rect = IntRect(node->rect.x(), left->rect.maxY(),
+ node->rect.width(), node->rect.height() / 2);
+ }
+
+ left->largestFree = left->rect.size();
+ right->largestFree = right->rect.size();
+ node->largestFree = right->largestFree;
+ return left;
+}
+
+void GeneralAreaAllocator::updateLargestFree(Node* node)
+{
+ while ((node = node->parent)) {
+ node->largestFree = IntSize(
+ std::max(node->left->largestFree.width(), node->right->largestFree.width()),
+ std::max(node->left->largestFree.height(), node->right->largestFree.height())
+ );
+ }
+}
+
+void GeneralAreaAllocator::release(const IntRect& rect)
+{
+ // Locate the node that contains the allocated region.
+ Node* node = m_root;
+ IntPoint point = rect.location();
+ while (node) {
+ if (node->left && node->left->rect.contains(point))
+ node = node->left;
+ else if (node->right && node->right->rect.contains(point))
+ node = node->right;
+ else if (node->rect.contains(point))
+ break;
+ else
+ return; // Point is completely outside the tree.
+ }
+ if (!node)
+ return;
+
+ // Mark the node as free and then work upwards through the tree
+ // recombining and deleting nodes until we reach a sibling
+ // that is still allocated.
+ node->largestFree = node->rect.size();
+ while (node->parent) {
+ if (node->parent->left == node) {
+ if (node->parent->right->largestFree != node->parent->right->rect.size())
+ break;
+ } else {
+ if (node->parent->left->largestFree != node->parent->left->rect.size())
+ break;
+ }
+ node = node->parent;
+ freeNode(node->left);
+ freeNode(node->right);
+ m_nodeCount -= 2;
+ node->left = 0;
+ node->right = 0;
+ node->largestFree = node->rect.size();
+ }
+
+ // Make the rest of our ancestors have the correct "largest free size".
+ updateLargestFree(node);
+}
+
+int GeneralAreaAllocator::overhead() const
+{
+ return m_nodeCount * sizeof(Node);
+}
+
+} // namespace WebKit
+
+#endif // USE(COORDINATED_GRAPHICS)
Copied: trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/AreaAllocator.h (from rev 202674, trunk/Source/WebCore/platform/graphics/texmap/coordinated/AreaAllocator.h) (0 => 202675)
--- trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/AreaAllocator.h (rev 0)
+++ trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/AreaAllocator.h 2016-06-30 07:32:32 UTC (rev 202675)
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
+ *
+ * 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.1 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
+ *
+ */
+
+#ifndef AreaAllocator_h
+#define AreaAllocator_h
+
+#if USE(COORDINATED_GRAPHICS)
+
+#include <WebCore/IntPoint.h>
+#include <WebCore/IntRect.h>
+#include <WebCore/IntSize.h>
+
+namespace WebKit {
+
+inline int nextPowerOfTwo(int number)
+{
+ // This is a fast trick to get nextPowerOfTwo for an integer.
+ --number;
+ number |= number >> 1;
+ number |= number >> 2;
+ number |= number >> 4;
+ number |= number >> 8;
+ number |= number >> 16;
+ number++;
+ return number;
+}
+
+inline WebCore::IntSize nextPowerOfTwo(const WebCore::IntSize& size)
+{
+ return WebCore::IntSize(nextPowerOfTwo(size.width()), nextPowerOfTwo(size.height()));
+}
+
+class AreaAllocator {
+ WTF_MAKE_FAST_ALLOCATED;
+public:
+ explicit AreaAllocator(const WebCore::IntSize&);
+ virtual ~AreaAllocator();
+
+ WebCore::IntSize size() const { return m_size; }
+
+ WebCore::IntSize minimumAllocation() const { return m_minAlloc; }
+ void setMinimumAllocation(const WebCore::IntSize& size) { m_minAlloc = size; }
+
+ WebCore::IntSize margin() const { return m_margin; }
+ void setMargin(const WebCore::IntSize &margin) { m_margin = margin; }
+
+ virtual void expand(const WebCore::IntSize&);
+ void expandBy(const WebCore::IntSize&);
+
+ virtual WebCore::IntRect allocate(const WebCore::IntSize&) = 0;
+ virtual void release(const WebCore::IntRect&);
+
+ virtual int overhead() const;
+
+protected:
+ WebCore::IntSize m_size;
+ WebCore::IntSize m_minAlloc;
+ WebCore::IntSize m_margin;
+
+ WebCore::IntSize roundAllocation(const WebCore::IntSize&) const;
+};
+
+class GeneralAreaAllocator : public AreaAllocator {
+ WTF_MAKE_FAST_ALLOCATED;
+public:
+ explicit GeneralAreaAllocator(const WebCore::IntSize&);
+ virtual ~GeneralAreaAllocator();
+
+ void expand(const WebCore::IntSize&);
+ WebCore::IntRect allocate(const WebCore::IntSize&);
+ void release(const WebCore::IntRect&);
+ int overhead() const;
+
+private:
+ enum Split { SplitOnX, SplitOnY };
+
+ struct Node {
+ WebCore::IntRect rect;
+ WebCore::IntSize largestFree;
+ Node* parent;
+ Node* left;
+ Node* right;
+ };
+
+ Node* m_root;
+ int m_nodeCount;
+
+ static void freeNode(Node*);
+ WebCore::IntPoint allocateFromNode(const WebCore::IntSize&, Node*);
+ Node* splitNode(Node*, Split);
+ static void updateLargestFree(Node*);
+};
+
+} // namespace WebKit
+
+#endif // USE(COORDINATED_GRAPHICS)
+#endif // AreaAllocator_h
Copied: trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.cpp (from rev 202674, trunk/Source/WebCore/platform/graphics/texmap/coordinated/CompositingCoordinator.cpp) (0 => 202675)
--- trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.cpp (rev 0)
+++ trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.cpp 2016-06-30 07:32:32 UTC (rev 202675)
@@ -0,0 +1,452 @@
+/*
+ * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+ * Copyright (C) 2013 Company 100, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "CompositingCoordinator.h"
+
+#if USE(COORDINATED_GRAPHICS)
+
+#include <WebCore/DOMWindow.h>
+#include <WebCore/Document.h>
+#include <WebCore/FrameView.h>
+#include <WebCore/GraphicsContext.h>
+#include <WebCore/InspectorController.h>
+#include <WebCore/MainFrame.h>
+#include <WebCore/Page.h>
+#include <WebCore/Settings.h>
+#include <wtf/CurrentTime.h>
+#include <wtf/TemporaryChange.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+CompositingCoordinator::CompositingCoordinator(Page* page, CompositingCoordinator::Client* client)
+ : m_page(page)
+ , m_client(client)
+ , m_rootCompositingLayer(nullptr)
+ , m_overlayCompositingLayer(nullptr)
+ , m_isDestructing(false)
+ , m_isPurging(false)
+ , m_isFlushingLayerChanges(false)
+ , m_shouldSyncFrame(false)
+ , m_didInitializeRootCompositingLayer(false)
+ , m_releaseInactiveAtlasesTimer(*this, &CompositingCoordinator::releaseInactiveAtlasesTimerFired)
+#if ENABLE(REQUEST_ANIMATION_FRAME)
+ , m_lastAnimationServiceTime(0)
+#endif
+{
+}
+
+CompositingCoordinator::~CompositingCoordinator()
+{
+ m_isDestructing = true;
+
+ purgeBackingStores();
+
+ for (auto& registeredLayer : m_registeredLayers.values())
+ registeredLayer->setCoordinator(nullptr);
+}
+
+void CompositingCoordinator::setRootCompositingLayer(GraphicsLayer* graphicsLayer)
+{
+ if (m_rootCompositingLayer == graphicsLayer)
+ return;
+
+ if (m_rootCompositingLayer)
+ m_rootCompositingLayer->removeFromParent();
+
+ m_rootCompositingLayer = graphicsLayer;
+ if (m_rootCompositingLayer)
+ m_rootLayer->addChildAtIndex(m_rootCompositingLayer, 0);
+}
+
+void CompositingCoordinator::setViewOverlayRootLayer(GraphicsLayer* graphicsLayer)
+{
+ if (m_overlayCompositingLayer == graphicsLayer)
+ return;
+
+ if (m_overlayCompositingLayer)
+ m_overlayCompositingLayer->removeFromParent();
+
+ m_overlayCompositingLayer = graphicsLayer;
+ if (m_overlayCompositingLayer)
+ m_rootLayer->addChild(m_overlayCompositingLayer);
+}
+
+void CompositingCoordinator::sizeDidChange(const IntSize& newSize)
+{
+ m_rootLayer->setSize(newSize);
+ notifyFlushRequired(m_rootLayer.get());
+}
+
+bool CompositingCoordinator::flushPendingLayerChanges()
+{
+ TemporaryChange<bool> protector(m_isFlushingLayerChanges, true);
+
+ initializeRootCompositingLayerIfNeeded();
+
+ bool viewportIsStable = m_page->mainFrame().view()->viewportIsStable();
+ m_rootLayer->flushCompositingStateForThisLayerOnly(viewportIsStable);
+ m_client->didFlushRootLayer(m_visibleContentsRect);
+
+ if (m_overlayCompositingLayer)
+ m_overlayCompositingLayer->flushCompositingState(FloatRect(FloatPoint(), m_rootLayer->size()), viewportIsStable);
+
+ bool didSync = m_page->mainFrame().view()->flushCompositingStateIncludingSubframes();
+
+ toCoordinatedGraphicsLayer(m_rootLayer.get())->updateContentBuffersIncludingSubLayers();
+ toCoordinatedGraphicsLayer(m_rootLayer.get())->syncPendingStateChangesIncludingSubLayers();
+
+ flushPendingImageBackingChanges();
+
+ if (m_shouldSyncFrame) {
+ didSync = true;
+
+ if (m_rootCompositingLayer) {
+ m_state.contentsSize = roundedIntSize(m_rootCompositingLayer->size());
+ if (CoordinatedGraphicsLayer* contentsLayer = mainContentsLayer())
+ m_state.coveredRect = contentsLayer->coverRect();
+ }
+ m_state.scrollPosition = m_visibleContentsRect.location();
+
+ m_client->commitSceneState(m_state);
+
+ clearPendingStateChanges();
+ m_shouldSyncFrame = false;
+ }
+
+ return didSync;
+}
+
+double CompositingCoordinator::timestamp() const
+{
+ auto* document = m_page->mainFrame().document();
+ if (!document)
+ return 0;
+ return document->domWindow() ? document->domWindow()->nowTimestamp() : document->monotonicTimestamp();
+}
+
+void CompositingCoordinator::syncDisplayState()
+{
+#if ENABLE(REQUEST_ANIMATION_FRAME) && !USE(REQUEST_ANIMATION_FRAME_TIMER) && !USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
+ // Make sure that any previously registered animation callbacks are being executed before we flush the layers.
+ m_lastAnimationServiceTime = timestamp();
+ m_page->mainFrame().view()->serviceScriptedAnimations();
+#endif
+ m_page->mainFrame().view()->updateLayoutAndStyleIfNeededRecursive();
+}
+
+#if ENABLE(REQUEST_ANIMATION_FRAME)
+double CompositingCoordinator::nextAnimationServiceTime() const
+{
+ // According to the requestAnimationFrame spec, rAF callbacks should not be faster than 60FPS.
+ static const double MinimalTimeoutForAnimations = 1. / 60.;
+ return std::max<double>(0., MinimalTimeoutForAnimations - timestamp() + m_lastAnimationServiceTime);
+}
+#endif
+
+void CompositingCoordinator::clearPendingStateChanges()
+{
+ m_state.layersToCreate.clear();
+ m_state.layersToUpdate.clear();
+ m_state.layersToRemove.clear();
+
+ m_state.imagesToCreate.clear();
+ m_state.imagesToRemove.clear();
+ m_state.imagesToUpdate.clear();
+ m_state.imagesToClear.clear();
+
+ m_state.updateAtlasesToCreate.clear();
+ m_state.updateAtlasesToRemove.clear();
+}
+
+void CompositingCoordinator::initializeRootCompositingLayerIfNeeded()
+{
+ if (m_didInitializeRootCompositingLayer)
+ return;
+
+ m_state.rootCompositingLayer = toCoordinatedGraphicsLayer(m_rootLayer.get())->id();
+ m_didInitializeRootCompositingLayer = true;
+ m_shouldSyncFrame = true;
+}
+
+void CompositingCoordinator::createRootLayer(const IntSize& size)
+{
+ ASSERT(!m_rootLayer);
+ // Create a root layer.
+ m_rootLayer = GraphicsLayer::create(this, *this);
+#ifndef NDEBUG
+ m_rootLayer->setName("CompositingCoordinator root layer");
+#endif
+ m_rootLayer->setDrawsContent(false);
+ m_rootLayer->setSize(size);
+}
+
+void CompositingCoordinator::syncLayerState(CoordinatedLayerID id, CoordinatedGraphicsLayerState& state)
+{
+ m_shouldSyncFrame = true;
+ m_state.layersToUpdate.append(std::make_pair(id, state));
+}
+
+PassRefPtr<CoordinatedImageBacking> CompositingCoordinator::createImageBackingIfNeeded(Image* image)
+{
+ CoordinatedImageBackingID imageID = CoordinatedImageBacking::getCoordinatedImageBackingID(image);
+ ImageBackingMap::iterator it = m_imageBackings.find(imageID);
+ RefPtr<CoordinatedImageBacking> imageBacking;
+ if (it == m_imageBackings.end()) {
+ imageBacking = CoordinatedImageBacking::create(this, image);
+ m_imageBackings.add(imageID, imageBacking);
+ } else
+ imageBacking = it->value;
+
+ return imageBacking;
+}
+
+void CompositingCoordinator::createImageBacking(CoordinatedImageBackingID imageID)
+{
+ m_state.imagesToCreate.append(imageID);
+}
+
+void CompositingCoordinator::updateImageBacking(CoordinatedImageBackingID imageID, PassRefPtr<CoordinatedSurface> coordinatedSurface)
+{
+ m_shouldSyncFrame = true;
+ m_state.imagesToUpdate.append(std::make_pair(imageID, coordinatedSurface));
+}
+
+void CompositingCoordinator::clearImageBackingContents(CoordinatedImageBackingID imageID)
+{
+ m_shouldSyncFrame = true;
+ m_state.imagesToClear.append(imageID);
+}
+
+void CompositingCoordinator::removeImageBacking(CoordinatedImageBackingID imageID)
+{
+ if (m_isPurging)
+ return;
+
+ ASSERT(m_imageBackings.contains(imageID));
+ m_imageBackings.remove(imageID);
+
+ m_state.imagesToRemove.append(imageID);
+
+ size_t imageIDPosition = m_state.imagesToClear.find(imageID);
+ if (imageIDPosition != notFound)
+ m_state.imagesToClear.remove(imageIDPosition);
+}
+
+void CompositingCoordinator::flushPendingImageBackingChanges()
+{
+ for (auto& imageBacking : m_imageBackings.values())
+ imageBacking->update();
+}
+
+void CompositingCoordinator::notifyAnimationStarted(const GraphicsLayer*, const String&, double /* time */)
+{
+}
+
+void CompositingCoordinator::notifyFlushRequired(const GraphicsLayer*)
+{
+ if (!m_isDestructing && !isFlushingLayerChanges())
+ m_client->notifyFlushRequired();
+}
+
+void CompositingCoordinator::paintContents(const GraphicsLayer* graphicsLayer, GraphicsContext& graphicsContext, GraphicsLayerPaintingPhase, const FloatRect& clipRect)
+{
+ m_client->paintLayerContents(graphicsLayer, graphicsContext, enclosingIntRect(clipRect));
+}
+
+std::unique_ptr<GraphicsLayer> CompositingCoordinator::createGraphicsLayer(GraphicsLayer::Type layerType, GraphicsLayerClient& client)
+{
+ CoordinatedGraphicsLayer* layer = new CoordinatedGraphicsLayer(layerType, client);
+ layer->setCoordinator(this);
+ m_registeredLayers.add(layer->id(), layer);
+ m_state.layersToCreate.append(layer->id());
+ layer->setNeedsVisibleRectAdjustment();
+ notifyFlushRequired(layer);
+ return std::unique_ptr<GraphicsLayer>(layer);
+}
+
+float CompositingCoordinator::deviceScaleFactor() const
+{
+ return m_page->deviceScaleFactor();
+}
+
+float CompositingCoordinator::pageScaleFactor() const
+{
+ return m_page->pageScaleFactor();
+}
+
+void CompositingCoordinator::createUpdateAtlas(uint32_t atlasID, PassRefPtr<CoordinatedSurface> coordinatedSurface)
+{
+ m_state.updateAtlasesToCreate.append(std::make_pair(atlasID, coordinatedSurface));
+}
+
+void CompositingCoordinator::removeUpdateAtlas(uint32_t atlasID)
+{
+ if (m_isPurging)
+ return;
+ m_state.updateAtlasesToRemove.append(atlasID);
+}
+
+FloatRect CompositingCoordinator::visibleContentsRect() const
+{
+ return m_visibleContentsRect;
+}
+
+CoordinatedGraphicsLayer* CompositingCoordinator::mainContentsLayer()
+{
+ if (!m_rootCompositingLayer)
+ return 0;
+
+ return toCoordinatedGraphicsLayer(m_rootCompositingLayer)->findFirstDescendantWithContentsRecursively();
+}
+
+void CompositingCoordinator::setVisibleContentsRect(const FloatRect& rect, const FloatPoint& trajectoryVector)
+{
+ // A zero trajectoryVector indicates that tiles all around the viewport are requested.
+ if (CoordinatedGraphicsLayer* contentsLayer = mainContentsLayer())
+ contentsLayer->setVisibleContentRectTrajectoryVector(trajectoryVector);
+
+ bool contentsRectDidChange = rect != m_visibleContentsRect;
+ if (contentsRectDidChange) {
+ m_visibleContentsRect = rect;
+
+ for (auto& registeredLayer : m_registeredLayers.values())
+ registeredLayer->setNeedsVisibleRectAdjustment();
+ }
+
+ FrameView* view = m_page->mainFrame().view();
+ if (view->useFixedLayout() && contentsRectDidChange) {
+ // Round the rect instead of enclosing it to make sure that its size stays
+ // the same while panning. This can have nasty effects on layout.
+ view->setFixedVisibleContentRect(roundedIntRect(rect));
+ }
+}
+
+void CompositingCoordinator::deviceOrPageScaleFactorChanged()
+{
+ m_rootLayer->deviceOrPageScaleFactorChanged();
+}
+
+void CompositingCoordinator::detachLayer(CoordinatedGraphicsLayer* layer)
+{
+ if (m_isPurging)
+ return;
+
+ m_registeredLayers.remove(layer->id());
+
+ size_t index = m_state.layersToCreate.find(layer->id());
+ if (index != notFound) {
+ m_state.layersToCreate.remove(index);
+ return;
+ }
+
+ m_state.layersToRemove.append(layer->id());
+ notifyFlushRequired(layer);
+}
+
+void CompositingCoordinator::commitScrollOffset(uint32_t layerID, const WebCore::IntSize& offset)
+{
+ LayerMap::iterator i = m_registeredLayers.find(layerID);
+ if (i == m_registeredLayers.end())
+ return;
+
+ i->value->commitScrollOffset(offset);
+}
+
+void CompositingCoordinator::renderNextFrame()
+{
+ for (auto& atlas : m_updateAtlases)
+ atlas->didSwapBuffers();
+}
+
+void CompositingCoordinator::purgeBackingStores()
+{
+ TemporaryChange<bool> purgingToggle(m_isPurging, true);
+
+ for (auto& registeredLayer : m_registeredLayers.values())
+ registeredLayer->purgeBackingStores();
+
+ m_imageBackings.clear();
+ m_updateAtlases.clear();
+}
+
+bool CompositingCoordinator::paintToSurface(const IntSize& size, CoordinatedSurface::Flags flags, uint32_t& atlasID, IntPoint& offset, CoordinatedSurface::Client* client)
+{
+ for (auto& updateAtlas : m_updateAtlases) {
+ UpdateAtlas* atlas = updateAtlas.get();
+ if (atlas->supportsAlpha() == (flags & CoordinatedSurface::SupportsAlpha)) {
+ // This will be false if there is no available buffer space.
+ if (atlas->paintOnAvailableBuffer(size, atlasID, offset, client))
+ return true;
+ }
+ }
+
+ static const int ScratchBufferDimension = 1024; // Should be a power of two.
+ m_updateAtlases.append(std::make_unique<UpdateAtlas>(this, ScratchBufferDimension, flags));
+ scheduleReleaseInactiveAtlases();
+ return m_updateAtlases.last()->paintOnAvailableBuffer(size, atlasID, offset, client);
+}
+
+const double ReleaseInactiveAtlasesTimerInterval = 0.5;
+
+void CompositingCoordinator::scheduleReleaseInactiveAtlases()
+{
+ if (!m_releaseInactiveAtlasesTimer.isActive())
+ m_releaseInactiveAtlasesTimer.startRepeating(ReleaseInactiveAtlasesTimerInterval);
+}
+
+void CompositingCoordinator::releaseInactiveAtlasesTimerFired()
+{
+ // We always want to keep one atlas for root contents layer.
+ std::unique_ptr<UpdateAtlas> atlasToKeepAnyway;
+ bool foundActiveAtlasForRootContentsLayer = false;
+ for (int i = m_updateAtlases.size() - 1; i >= 0; --i) {
+ UpdateAtlas* atlas = m_updateAtlases[i].get();
+ if (!atlas->isInUse())
+ atlas->addTimeInactive(ReleaseInactiveAtlasesTimerInterval);
+ bool usableForRootContentsLayer = !atlas->supportsAlpha();
+ if (atlas->isInactive()) {
+ if (!foundActiveAtlasForRootContentsLayer && !atlasToKeepAnyway && usableForRootContentsLayer)
+ atlasToKeepAnyway = WTFMove(m_updateAtlases[i]);
+ m_updateAtlases.remove(i);
+ } else if (usableForRootContentsLayer)
+ foundActiveAtlasForRootContentsLayer = true;
+ }
+
+ if (!foundActiveAtlasForRootContentsLayer && atlasToKeepAnyway)
+ m_updateAtlases.append(atlasToKeepAnyway.release());
+
+ m_updateAtlases.shrinkToFit();
+
+ if (m_updateAtlases.size() <= 1)
+ m_releaseInactiveAtlasesTimer.stop();
+}
+
+} // namespace WebKit
+
+#endif // USE(COORDINATED_GRAPHICS)
Copied: trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.h (from rev 202674, trunk/Source/WebCore/platform/graphics/texmap/coordinated/CompositingCoordinator.h) (0 => 202675)
--- trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.h (rev 0)
+++ trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.h 2016-06-30 07:32:32 UTC (rev 202675)
@@ -0,0 +1,167 @@
+/*
+ * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
+ * Copyright (C) 2013 Company 100, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef CompositingCoordinator_h
+#define CompositingCoordinator_h
+
+#if USE(COORDINATED_GRAPHICS)
+
+#include "UpdateAtlas.h"
+#include <WebCore/CoordinatedGraphicsLayer.h>
+#include <WebCore/CoordinatedGraphicsState.h>
+#include <WebCore/CoordinatedImageBacking.h>
+#include <WebCore/FloatPoint.h>
+#include <WebCore/GraphicsLayerClient.h>
+#include <WebCore/GraphicsLayerFactory.h>
+#include <WebCore/IntRect.h>
+#include <WebCore/Timer.h>
+
+namespace WebCore {
+class Page;
+class GraphicsContext;
+class GraphicsLayer;
+class CoordinatedSurface;
+}
+
+namespace WebKit {
+
+class CompositingCoordinator : public WebCore::GraphicsLayerClient
+ , public WebCore::CoordinatedGraphicsLayerClient
+ , public WebCore::CoordinatedImageBacking::Client
+ , public UpdateAtlas::Client
+ , public WebCore::GraphicsLayerFactory {
+ WTF_MAKE_NONCOPYABLE(CompositingCoordinator); WTF_MAKE_FAST_ALLOCATED;
+public:
+ class Client {
+ public:
+ virtual void didFlushRootLayer(const WebCore::FloatRect& visibleContentRect) = 0;
+ virtual void notifyFlushRequired() = 0;
+ virtual void commitSceneState(const WebCore::CoordinatedGraphicsState&) = 0;
+ virtual void paintLayerContents(const WebCore::GraphicsLayer*, WebCore::GraphicsContext&, const WebCore::IntRect& clipRect) = 0;
+ };
+
+ CompositingCoordinator(WebCore::Page*, CompositingCoordinator::Client*);
+ virtual ~CompositingCoordinator();
+
+ void setRootCompositingLayer(WebCore::GraphicsLayer*);
+ void setViewOverlayRootLayer(WebCore::GraphicsLayer*);
+ void sizeDidChange(const WebCore::IntSize&);
+ void deviceOrPageScaleFactorChanged();
+
+ void setVisibleContentsRect(const WebCore::FloatRect&, const WebCore::FloatPoint&);
+ void renderNextFrame();
+ void purgeBackingStores();
+ void commitScrollOffset(uint32_t layerID, const WebCore::IntSize& offset);
+
+ void createRootLayer(const WebCore::IntSize&);
+ void clearRootLayer() { m_rootLayer = nullptr; }
+ WebCore::GraphicsLayer* rootLayer() const { return m_rootLayer.get(); }
+ WebCore::CoordinatedGraphicsLayer* mainContentsLayer();
+
+ bool flushPendingLayerChanges();
+ WebCore::CoordinatedGraphicsState& state() { return m_state; }
+
+ void syncDisplayState();
+
+#if ENABLE(REQUEST_ANIMATION_FRAME)
+ double nextAnimationServiceTime() const;
+#endif
+
+private:
+ // GraphicsLayerClient
+ void notifyAnimationStarted(const WebCore::GraphicsLayer*, const String&, double time) override;
+ void notifyFlushRequired(const WebCore::GraphicsLayer*) override;
+ void paintContents(const WebCore::GraphicsLayer*, WebCore::GraphicsContext&, WebCore::GraphicsLayerPaintingPhase, const WebCore::FloatRect& clipRect) override;
+ float deviceScaleFactor() const override;
+ float pageScaleFactor() const override;
+
+ // CoordinatedImageBacking::Client
+ void createImageBacking(WebCore::CoordinatedImageBackingID) override;
+ void updateImageBacking(WebCore::CoordinatedImageBackingID, PassRefPtr<WebCore::CoordinatedSurface>) override;
+ void clearImageBackingContents(WebCore::CoordinatedImageBackingID) override;
+ void removeImageBacking(WebCore::CoordinatedImageBackingID) override;
+
+ // CoordinatedGraphicsLayerClient
+ bool isFlushingLayerChanges() const override { return m_isFlushingLayerChanges; }
+ WebCore::FloatRect visibleContentsRect() const override;
+ PassRefPtr<WebCore::CoordinatedImageBacking> createImageBackingIfNeeded(WebCore::Image*) override;
+ void detachLayer(WebCore::CoordinatedGraphicsLayer*) override;
+ bool paintToSurface(const WebCore::IntSize&, WebCore::CoordinatedSurface::Flags, uint32_t& /* atlasID */, WebCore::IntPoint&, WebCore::CoordinatedSurface::Client*) override;
+ void syncLayerState(WebCore::CoordinatedLayerID, WebCore::CoordinatedGraphicsLayerState&) override;
+
+ // UpdateAtlas::Client
+ void createUpdateAtlas(uint32_t atlasID, PassRefPtr<WebCore::CoordinatedSurface>) override;
+ void removeUpdateAtlas(uint32_t atlasID) override;
+
+ // GraphicsLayerFactory
+ std::unique_ptr<WebCore::GraphicsLayer> createGraphicsLayer(WebCore::GraphicsLayer::Type, WebCore::GraphicsLayerClient&) override;
+
+ void initializeRootCompositingLayerIfNeeded();
+ void flushPendingImageBackingChanges();
+ void clearPendingStateChanges();
+
+ void scheduleReleaseInactiveAtlases();
+
+ void releaseInactiveAtlasesTimerFired();
+
+ double timestamp() const;
+
+ WebCore::Page* m_page;
+ CompositingCoordinator::Client* m_client;
+
+ std::unique_ptr<WebCore::GraphicsLayer> m_rootLayer;
+ WebCore::GraphicsLayer* m_rootCompositingLayer;
+ WebCore::GraphicsLayer* m_overlayCompositingLayer;
+
+ WebCore::CoordinatedGraphicsState m_state;
+
+ typedef HashMap<WebCore::CoordinatedLayerID, WebCore::CoordinatedGraphicsLayer*> LayerMap;
+ LayerMap m_registeredLayers;
+ typedef HashMap<WebCore::CoordinatedImageBackingID, RefPtr<WebCore::CoordinatedImageBacking> > ImageBackingMap;
+ ImageBackingMap m_imageBackings;
+ Vector<std::unique_ptr<UpdateAtlas>> m_updateAtlases;
+
+ // We don't send the messages related to releasing resources to renderer during purging, because renderer already had removed all resources.
+ bool m_isDestructing;
+ bool m_isPurging;
+ bool m_isFlushingLayerChanges;
+
+ WebCore::FloatRect m_visibleContentsRect;
+
+ bool m_shouldSyncFrame;
+ bool m_didInitializeRootCompositingLayer;
+ WebCore::Timer m_releaseInactiveAtlasesTimer;
+
+#if ENABLE(REQUEST_ANIMATION_FRAME)
+ double m_lastAnimationServiceTime;
+#endif
+};
+
+}
+
+#endif // namespace WebKit
+
+#endif // CompositingCoordinator_h
Modified: trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.h (202674 => 202675)
--- trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.h 2016-06-30 06:28:58 UTC (rev 202674)
+++ trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.h 2016-06-30 07:32:32 UTC (rev 202675)
@@ -23,8 +23,8 @@
#if USE(COORDINATED_GRAPHICS)
+#include "CompositingCoordinator.h"
#include "LayerTreeHost.h"
-#include <WebCore/CompositingCoordinator.h>
#include <wtf/RunLoop.h>
namespace WebCore {
@@ -36,7 +36,7 @@
class WebPage;
-class CoordinatedLayerTreeHost : public LayerTreeHost, public WebCore::CompositingCoordinator::Client
+class CoordinatedLayerTreeHost : public LayerTreeHost, public CompositingCoordinator::Client
{
public:
static Ref<CoordinatedLayerTreeHost> create(WebPage&);
@@ -85,7 +85,7 @@
static RefPtr<WebCore::CoordinatedSurface> createCoordinatedSurface(const WebCore::IntSize&, WebCore::CoordinatedSurface::Flags);
- std::unique_ptr<WebCore::CompositingCoordinator> m_coordinator;
+ std::unique_ptr<CompositingCoordinator> m_coordinator;
bool m_isWaitingForRenderer { true };
uint64_t m_forceRepaintAsyncCallbackID { 0 };
RunLoop::Timer<CoordinatedLayerTreeHost> m_layerFlushTimer;
Copied: trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/UpdateAtlas.cpp (from rev 202674, trunk/Source/WebCore/platform/graphics/texmap/coordinated/UpdateAtlas.cpp) (0 => 202675)
--- trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/UpdateAtlas.cpp (rev 0)
+++ trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/UpdateAtlas.cpp 2016-06-30 07:32:32 UTC (rev 202675)
@@ -0,0 +1,118 @@
+/*
+ Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
+ Copyright (C) 2012 Company 100, Inc.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "UpdateAtlas.h"
+
+#if USE(COORDINATED_GRAPHICS)
+
+#include <WebCore/CoordinatedGraphicsState.h>
+#include <WebCore/GraphicsContext.h>
+#include <WebCore/IntRect.h>
+#include <wtf/MathExtras.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+class UpdateAtlasSurfaceClient : public CoordinatedSurface::Client {
+public:
+ UpdateAtlasSurfaceClient(CoordinatedSurface::Client* client, const IntSize& size, bool supportsAlpha)
+ : m_client(client)
+ , m_size(size)
+ , m_supportsAlpha(supportsAlpha)
+ {
+ }
+
+ void paintToSurfaceContext(GraphicsContext& context) override
+ {
+ if (m_supportsAlpha) {
+ context.setCompositeOperation(CompositeCopy);
+ context.fillRect(IntRect(IntPoint::zero(), m_size), Color::transparent);
+ context.setCompositeOperation(CompositeSourceOver);
+ }
+
+ m_client->paintToSurfaceContext(context);
+ }
+
+private:
+ CoordinatedSurface::Client* m_client;
+ IntSize m_size;
+ bool m_supportsAlpha;
+};
+
+UpdateAtlas::UpdateAtlas(Client* client, int dimension, CoordinatedSurface::Flags flags)
+ : m_client(client)
+ , m_inactivityInSeconds(0)
+{
+ static uint32_t nextID = 0;
+ m_ID = ++nextID;
+ IntSize size = nextPowerOfTwo(IntSize(dimension, dimension));
+ m_surface = CoordinatedSurface::create(size, flags);
+
+ m_client->createUpdateAtlas(m_ID, m_surface);
+}
+
+UpdateAtlas::~UpdateAtlas()
+{
+ if (m_surface)
+ m_client->removeUpdateAtlas(m_ID);
+}
+
+void UpdateAtlas::buildLayoutIfNeeded()
+{
+ if (!m_areaAllocator) {
+ m_areaAllocator = std::make_unique<GeneralAreaAllocator>(size());
+ m_areaAllocator->setMinimumAllocation(IntSize(32, 32));
+ }
+}
+
+void UpdateAtlas::didSwapBuffers()
+{
+ m_areaAllocator = nullptr;
+}
+
+
+bool UpdateAtlas::paintOnAvailableBuffer(const IntSize& size, uint32_t& atlasID, IntPoint& offset, CoordinatedSurface::Client* client)
+{
+ m_inactivityInSeconds = 0;
+ buildLayoutIfNeeded();
+ IntRect rect = m_areaAllocator->allocate(size);
+
+ // No available buffer was found.
+ if (rect.isEmpty())
+ return false;
+
+ if (!m_surface)
+ return false;
+
+ atlasID = m_ID;
+
+ // FIXME: Use tri-state buffers, to allow faster updates.
+ offset = rect.location();
+
+ UpdateAtlasSurfaceClient surfaceClient(client, size, supportsAlpha());
+ m_surface->paintToSurface(rect, &surfaceClient);
+
+ return true;
+}
+
+} // namespace WebCore
+#endif // USE(COORDINATED_GRAPHICS)
Copied: trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/UpdateAtlas.h (from rev 202674, trunk/Source/WebCore/platform/graphics/texmap/coordinated/UpdateAtlas.h) (0 => 202675)
--- trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/UpdateAtlas.h (rev 0)
+++ trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/UpdateAtlas.h 2016-06-30 07:32:32 UTC (rev 202675)
@@ -0,0 +1,84 @@
+/*
+ Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
+ Copyright (C) 2012 Company 100, Inc.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#ifndef UpdateAtlas_h
+#define UpdateAtlas_h
+
+#include "AreaAllocator.h"
+#include <WebCore/CoordinatedSurface.h>
+#include <WebCore/IntSize.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefPtr.h>
+
+#if USE(COORDINATED_GRAPHICS)
+
+namespace WebCore {
+class GraphicsContext;
+class IntPoint;
+}
+
+namespace WebKit {
+
+class UpdateAtlas {
+ WTF_MAKE_NONCOPYABLE(UpdateAtlas);
+public:
+ class Client {
+ public:
+ virtual void createUpdateAtlas(uint32_t /* id */, PassRefPtr<WebCore::CoordinatedSurface>) = 0;
+ virtual void removeUpdateAtlas(uint32_t /* id */) = 0;
+ };
+
+ UpdateAtlas(Client*, int dimension, WebCore::CoordinatedSurface::Flags);
+ ~UpdateAtlas();
+
+ inline WebCore::IntSize size() const { return m_surface->size(); }
+
+ // Returns false if there is no available buffer.
+ bool paintOnAvailableBuffer(const WebCore::IntSize&, uint32_t& atlasID, WebCore::IntPoint& offset, WebCore::CoordinatedSurface::Client*);
+ void didSwapBuffers();
+ bool supportsAlpha() const { return m_surface->supportsAlpha(); }
+
+ void addTimeInactive(double seconds)
+ {
+ ASSERT(!isInUse());
+ m_inactivityInSeconds += seconds;
+ }
+ bool isInactive() const
+ {
+ const double inactiveSecondsTolerance = 3;
+ return m_inactivityInSeconds > inactiveSecondsTolerance;
+ }
+ bool isInUse() const { return !!m_areaAllocator; }
+
+private:
+ void buildLayoutIfNeeded();
+
+private:
+ Client* m_client;
+ std::unique_ptr<GeneralAreaAllocator> m_areaAllocator;
+ RefPtr<WebCore::CoordinatedSurface> m_surface;
+ double m_inactivityInSeconds;
+ uint32_t m_ID;
+};
+
+} // namespace WebKit
+
+#endif // USE(COORDINATED_GRAPHICS)
+#endif // UpdateAtlas_h