2 Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
22 #if USE(UI_SIDE_COMPOSITING)
23 #include "WebGraphicsLayer.h"
25 #include "BackingStore.h"
26 #include "FloatQuad.h"
28 #include "FrameView.h"
29 #include "GraphicsContext.h"
30 #include "GraphicsLayer.h"
31 #include "LayerTreeCoordinatorProxyMessages.h"
33 #include "TextureMapperPlatformLayer.h"
34 #include "TiledBackingStoreRemoteTile.h"
35 #include "SharedPlatformSurfaceTizen.h"
37 #include <wtf/CurrentTime.h>
38 #include <wtf/HashMap.h>
39 #include <wtf/text/CString.h>
41 using namespace WebKit;
45 static HashMap<WebLayerID, WebGraphicsLayer*>& layerByIDMap()
47 static HashMap<WebLayerID, WebGraphicsLayer*> globalMap;
51 WebGraphicsLayer* WebGraphicsLayer::layerByID(WebKit::WebLayerID id)
53 HashMap<WebLayerID, WebGraphicsLayer*>& table = layerByIDMap();
54 HashMap<WebLayerID, WebGraphicsLayer*>::iterator it = table.find(id);
55 if (it == table.end())
60 static WebLayerID toWebLayerID(GraphicsLayer* layer)
62 return layer ? toWebGraphicsLayer(layer)->id() : 0;
65 void WebGraphicsLayer::didChangeLayerState()
67 m_shouldSyncLayerState = true;
69 client()->notifySyncRequired(this);
72 void WebGraphicsLayer::didChangeAnimations()
74 m_shouldSyncAnimations = true;
76 client()->notifySyncRequired(this);
79 void WebGraphicsLayer::didChangeChildren()
81 m_shouldSyncChildren = true;
83 client()->notifySyncRequired(this);
86 #if ENABLE(CSS_FILTERS)
87 void WebGraphicsLayer::didChangeFilters()
89 m_shouldSyncFilters = true;
91 client()->notifySyncRequired(this);
95 void WebGraphicsLayer::setShouldUpdateVisibleRect()
97 m_shouldUpdateVisibleRect = true;
98 for (size_t i = 0; i < children().size(); ++i)
99 toWebGraphicsLayer(children()[i])->setShouldUpdateVisibleRect();
101 toWebGraphicsLayer(replicaLayer())->setShouldUpdateVisibleRect();
104 void WebGraphicsLayer::didChangeGeometry()
106 didChangeLayerState();
107 setShouldUpdateVisibleRect();
110 WebGraphicsLayer::WebGraphicsLayer(GraphicsLayerClient* client)
111 : GraphicsLayer(client)
113 , m_inUpdateMode(false)
114 , m_shouldUpdateVisibleRect(true)
115 , m_shouldSyncLayerState(true)
116 , m_shouldSyncChildren(true)
117 , m_shouldSyncAnimations(true)
118 , m_fixedToViewport(false)
119 , m_movingVisibleRect(false)
120 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
121 , m_isOverflow(false)
123 , m_canvasNeedsDisplay(false)
124 #if ENABLE(TIZEN_DONT_PURGE_PLATFORM_SURFACE_BACKINGSTORE_ON_NODE_DETACH_FROM_WEBLAYER_TREE)
125 , m_shouldSyncBackingStore(false)
127 , m_webGraphicsLayerClient(0)
129 #if ENABLE(TIZEN_USE_FIXED_SCALE_ANIMATION)
130 , m_fixedAnimationScale(1)
132 , m_canvasPlatformLayer(0)
133 , m_animationStartedTimer(this, &WebGraphicsLayer::animationStartedTimerFired)
134 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_SCROLLBAR)
135 , m_animationTimer(this, &WebGraphicsLayer::animationTimerFired)
138 static WebLayerID nextLayerID = 1;
139 m_id = nextLayerID++;
140 layerByIDMap().add(id(), this);
142 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
143 m_layerInfo.isRootLayer = false;
144 m_layerInfo.contentType = WebKit::WebLayerInfo::HTMLContentType;
148 WebGraphicsLayer::~WebGraphicsLayer()
150 layerByIDMap().remove(id());
152 if (m_webGraphicsLayerClient) {
153 purgeBackingStores();
154 m_webGraphicsLayerClient->detachLayer(this);
159 void WebGraphicsLayer::willBeDestroyed()
161 GraphicsLayer::willBeDestroyed();
164 bool WebGraphicsLayer::setChildren(const Vector<GraphicsLayer*>& children)
166 bool ok = GraphicsLayer::setChildren(children);
169 for (size_t i = 0; i < children.size(); ++i) {
170 WebGraphicsLayer* child = toWebGraphicsLayer(children[i]);
171 child->setWebGraphicsLayerClient(m_webGraphicsLayerClient);
172 child->didChangeLayerState();
178 void WebGraphicsLayer::addChild(GraphicsLayer* layer)
180 GraphicsLayer::addChild(layer);
181 toWebGraphicsLayer(layer)->setWebGraphicsLayerClient(m_webGraphicsLayerClient);
182 toWebGraphicsLayer(layer)->didChangeLayerState();
186 void WebGraphicsLayer::addChildAtIndex(GraphicsLayer* layer, int index)
188 GraphicsLayer::addChildAtIndex(layer, index);
189 toWebGraphicsLayer(layer)->setWebGraphicsLayerClient(m_webGraphicsLayerClient);
190 toWebGraphicsLayer(layer)->didChangeLayerState();
194 void WebGraphicsLayer::addChildAbove(GraphicsLayer* layer, GraphicsLayer* sibling)
196 GraphicsLayer::addChildAbove(layer, sibling);
197 toWebGraphicsLayer(layer)->setWebGraphicsLayerClient(m_webGraphicsLayerClient);
198 toWebGraphicsLayer(layer)->didChangeLayerState();
202 void WebGraphicsLayer::addChildBelow(GraphicsLayer* layer, GraphicsLayer* sibling)
204 GraphicsLayer::addChildBelow(layer, sibling);
205 toWebGraphicsLayer(layer)->setWebGraphicsLayerClient(m_webGraphicsLayerClient);
206 toWebGraphicsLayer(layer)->didChangeLayerState();
210 bool WebGraphicsLayer::replaceChild(GraphicsLayer* oldChild, GraphicsLayer* newChild)
212 bool ok = GraphicsLayer::replaceChild(oldChild, newChild);
216 toWebGraphicsLayer(oldChild)->didChangeLayerState();
217 toWebGraphicsLayer(newChild)->setWebGraphicsLayerClient(m_webGraphicsLayerClient);
218 toWebGraphicsLayer(newChild)->didChangeLayerState();
222 void WebGraphicsLayer::removeFromParent()
224 if (WebGraphicsLayer* parentLayer = toWebGraphicsLayer(parent()))
225 parentLayer->didChangeChildren();
226 GraphicsLayer::removeFromParent();
228 didChangeLayerState();
231 void WebGraphicsLayer::setPosition(const FloatPoint& p)
236 GraphicsLayer::setPosition(p);
240 void WebGraphicsLayer::setAnchorPoint(const FloatPoint3D& p)
242 if (anchorPoint() == p)
245 GraphicsLayer::setAnchorPoint(p);
249 void WebGraphicsLayer::setSize(const FloatSize& size)
251 if (this->size() == size)
254 GraphicsLayer::setSize(size);
257 maskLayer()->setSize(size);
259 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
264 void WebGraphicsLayer::setTransform(const TransformationMatrix& t)
266 if (transform() == t)
269 GraphicsLayer::setTransform(t);
273 void WebGraphicsLayer::setChildrenTransform(const TransformationMatrix& t)
275 if (childrenTransform() == t)
278 GraphicsLayer::setChildrenTransform(t);
282 void WebGraphicsLayer::setPreserves3D(bool b)
284 if (preserves3D() == b)
287 GraphicsLayer::setPreserves3D(b);
291 void WebGraphicsLayer::setMasksToBounds(bool b)
293 if (masksToBounds() == b)
295 GraphicsLayer::setMasksToBounds(b);
299 void WebGraphicsLayer::setDrawsContent(bool b)
301 if (drawsContent() == b)
303 GraphicsLayer::setDrawsContent(b);
305 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
309 didChangeLayerState();
312 void WebGraphicsLayer::setContentsVisible(bool b)
314 if (contentsAreVisible() == b)
316 GraphicsLayer::setContentsVisible(b);
318 didChangeLayerState();
321 void WebGraphicsLayer::setContentsOpaque(bool b)
323 if (contentsOpaque() == b)
325 if (m_mainBackingStore)
326 m_mainBackingStore->setSupportsAlpha(!b);
327 GraphicsLayer::setContentsOpaque(b);
328 didChangeLayerState();
331 void WebGraphicsLayer::setBackfaceVisibility(bool b)
333 if (backfaceVisibility() == b)
336 GraphicsLayer::setBackfaceVisibility(b);
337 didChangeLayerState();
340 void WebGraphicsLayer::setOpacity(float opacity)
342 if (this->opacity() == opacity)
345 GraphicsLayer::setOpacity(opacity);
346 didChangeLayerState();
349 void WebGraphicsLayer::setContentsRect(const IntRect& r)
351 if (contentsRect() == r)
354 GraphicsLayer::setContentsRect(r);
355 didChangeLayerState();
358 void WebGraphicsLayer::setContentsNeedsDisplay()
360 RefPtr<Image> image = m_image;
361 setContentsToImage(0);
362 setContentsToImage(image.get());
363 m_canvasNeedsDisplay = true;
365 client()->notifySyncRequired(this);
369 #if ENABLE(CSS_FILTERS)
370 bool WebGraphicsLayer::setFilters(const FilterOperations& newFilters)
372 if (filters() == newFilters)
375 return GraphicsLayer::setFilters(newFilters);
379 void WebGraphicsLayer::setContentsToBackgroundColor(const Color& color)
381 if (m_layerInfo.backgroundColor == color)
383 m_layerInfo.backgroundColor = color;
385 // This is in line with what CA does.
386 setBackgroundColor(color);
387 didChangeLayerState();
390 void WebGraphicsLayer::setContentsToImage(Image* image)
392 if (image == m_image)
395 if (m_webGraphicsLayerClient) {
396 // We adopt first, in case this is the same frame - that way we avoid destroying and recreating the image.
397 newID = m_webGraphicsLayerClient->adoptImageBackingStore(image);
398 m_webGraphicsLayerClient->releaseImageBackingStore(m_layerInfo.imageBackingStoreID);
399 didChangeLayerState();
400 if (m_layerInfo.imageBackingStoreID && newID == m_layerInfo.imageBackingStoreID)
403 // If m_webGraphicsLayerClient is not set yet there should be no backing store ID.
404 ASSERT(!m_layerInfo.imageBackingStoreID);
405 didChangeLayerState();
408 m_layerInfo.imageBackingStoreID = newID;
410 GraphicsLayer::setContentsToImage(image);
413 void WebGraphicsLayer::setContentsToCanvas(PlatformLayer* platformLayer)
415 m_canvasPlatformLayer = platformLayer;
416 m_canvasNeedsDisplay = true;
417 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
418 if (!m_canvasPlatformLayer)
421 if (static_cast<TextureMapperPlatformLayer*>(m_canvasPlatformLayer)->contentType() == WebKit::WebLayerInfo::Canvas2DContentType)
422 m_layerInfo.contentType = WebKit::WebLayerInfo::Canvas2DContentType;
424 m_layerInfo.contentType = WebKit::WebLayerInfo::Canvas3DContentType;
428 client()->notifySyncRequired(this);
431 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
432 void WebGraphicsLayer::setContentsToMedia(PlatformLayer* platformLayer)
434 m_canvasPlatformLayer = platformLayer;
435 m_canvasNeedsDisplay = true;
436 m_layerInfo.contentType = WebKit::WebLayerInfo::MediaContentType;
439 client()->notifySyncRequired(this);
443 void WebGraphicsLayer::setMaskLayer(GraphicsLayer* layer)
445 if (layer == maskLayer())
448 GraphicsLayer::setMaskLayer(layer);
453 layer->setSize(size());
454 WebGraphicsLayer* webGraphicsLayer = toWebGraphicsLayer(layer);
455 webGraphicsLayer->setWebGraphicsLayerClient(m_webGraphicsLayerClient);
456 webGraphicsLayer->setMaskTarget(this);
457 webGraphicsLayer->didChangeLayerState();
458 didChangeLayerState();
462 void WebGraphicsLayer::setReplicatedByLayer(GraphicsLayer* layer)
464 if (layer == replicaLayer())
468 toWebGraphicsLayer(layer)->setWebGraphicsLayerClient(m_webGraphicsLayerClient);
470 GraphicsLayer::setReplicatedByLayer(layer);
471 didChangeLayerState();
474 void WebGraphicsLayer::setNeedsDisplay()
476 setNeedsDisplayInRect(IntRect(IntPoint::zero(), IntSize(size().width(), size().height())));
479 void WebGraphicsLayer::setNeedsDisplayInRect(const FloatRect& rect)
481 if (m_mainBackingStore)
482 m_mainBackingStore->invalidate(IntRect(rect));
483 didChangeLayerState();
486 WebLayerID WebGraphicsLayer::id() const
491 void WebGraphicsLayer::syncCompositingState(const FloatRect& rect)
493 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
494 if (!m_webGraphicsLayerClient)
498 if (WebGraphicsLayer* mask = toWebGraphicsLayer(maskLayer()))
499 mask->syncCompositingStateForThisLayerOnly();
501 if (WebGraphicsLayer* replica = toWebGraphicsLayer(replicaLayer()))
502 replica->syncCompositingStateForThisLayerOnly();
504 m_webGraphicsLayerClient->syncFixedLayers();
506 syncCompositingStateForThisLayerOnly();
508 for (size_t i = 0; i < children().size(); ++i)
509 children()[i]->syncCompositingState(rect);
512 WebGraphicsLayer* toWebGraphicsLayer(GraphicsLayer* layer)
514 return static_cast<WebGraphicsLayer*>(layer);
517 void WebGraphicsLayer::syncChildren()
519 if (!m_shouldSyncChildren)
521 m_shouldSyncChildren = false;
522 Vector<WebLayerID> childIDs;
523 for (size_t i = 0; i < children().size(); ++i)
524 childIDs.append(toWebLayerID(children()[i]));
526 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
527 if (m_webGraphicsLayerClient)
529 m_webGraphicsLayerClient->syncLayerChildren(m_id, childIDs);
532 #if ENABLE(CSS_FILTERS)
533 void WebGraphicsLayer::syncFilters()
535 if (!m_shouldSyncFilters)
537 m_shouldSyncFilters = false;
538 m_webGraphicsLayerClient->syncLayerFilters(m_id, filters());
542 void WebGraphicsLayer::syncLayerState()
544 if (!m_shouldSyncLayerState)
547 m_shouldSyncLayerState = false;
548 m_layerInfo.fixedToViewport = fixedToViewport();
549 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_SCROLLBAR)
550 m_layerInfo.isScrollbar = isScrollbar();
552 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
553 m_layerInfo.isScrollingContentsLayer = isOverflow();
554 if (m_layerInfo.isScrollingContentsLayer)
555 m_layerInfo.boundsOrigin = parent() ? parent()->boundsOrigin() : boundsOrigin();
558 m_layerInfo.anchorPoint = anchorPoint();
559 m_layerInfo.backfaceVisible = backfaceVisibility();
560 m_layerInfo.childrenTransform = childrenTransform();
561 m_layerInfo.contentsOpaque = contentsOpaque();
562 m_layerInfo.contentsRect = contentsRect();
563 m_layerInfo.drawsContent = drawsContent();
564 m_layerInfo.contentsVisible = contentsAreVisible();
565 m_layerInfo.mask = toWebLayerID(maskLayer());
566 m_layerInfo.masksToBounds = masksToBounds();
567 m_layerInfo.opacity = opacity();
568 m_layerInfo.parent = toWebLayerID(parent());
569 m_layerInfo.pos = position();
570 m_layerInfo.preserves3D = preserves3D();
571 m_layerInfo.replica = toWebLayerID(replicaLayer());
572 m_layerInfo.size = size();
573 m_layerInfo.transform = transform();
575 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
576 if (m_webGraphicsLayerClient)
578 m_webGraphicsLayerClient->syncLayerState(m_id, m_layerInfo);
580 #if ENABLE(TIZEN_DONT_PURGE_PLATFORM_SURFACE_BACKINGSTORE_ON_NODE_DETACH_FROM_WEBLAYER_TREE)
581 syncBackingStoreIfNeeded();
585 void WebGraphicsLayer::syncAnimations()
587 if (!m_shouldSyncAnimations)
590 m_shouldSyncAnimations = false;
592 m_webGraphicsLayerClient->setLayerAnimations(m_id, m_animations);
595 void WebGraphicsLayer::syncCanvas()
597 if (!m_canvasNeedsDisplay)
600 if (!m_canvasPlatformLayer)
603 #if USE(GRAPHICS_SURFACE) || ENABLE(TIZEN_CANVAS_GRAPHICS_SURFACE)
604 uint64_t token = m_canvasPlatformLayer->graphicsSurfaceToken();
607 uint32_t frontBuffer = m_canvasPlatformLayer->copyToGraphicsSurface();
608 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
609 int flags = m_canvasPlatformLayer->graphicsSurfaceFlags();
610 if (m_webGraphicsLayerClient)
611 m_webGraphicsLayerClient->syncCanvas(m_id, IntSize(contentsRect().width(), contentsRect().height()), token, frontBuffer, flags);
613 m_webGraphicsLayerClient->syncCanvas(m_id, IntSize(size().width(), size().height()), token, frontBuffer);
616 m_canvasNeedsDisplay = false;
619 void WebGraphicsLayer::ensureImageBackingStore()
624 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
625 if (!m_webGraphicsLayerClient)
629 if (!m_layerInfo.imageBackingStoreID)
630 m_layerInfo.imageBackingStoreID = m_webGraphicsLayerClient->adoptImageBackingStore(m_image.get());
633 #if ENABLE(TIZEN_DONT_PURGE_PLATFORM_SURFACE_BACKINGSTORE_ON_NODE_DETACH_FROM_WEBLAYER_TREE)
634 void WebGraphicsLayer::syncBackingStoreIfNeeded()
636 if (m_shouldSyncBackingStore) {
637 if (m_mainBackingStore)
638 m_mainBackingStore->reviewTiles();
639 m_shouldSyncBackingStore = false;
644 void WebGraphicsLayer::syncCompositingStateForThisLayerOnly()
646 // When we have a transform animation, we need to update visible rect every frame to adjust the visible rect of a backing store.
647 bool hasActiveTransformAnimation = selfOrAncestorHasActiveTransformAnimation();
648 if (hasActiveTransformAnimation)
649 m_movingVisibleRect = true;
651 // The remote image might have been released by purgeBackingStores.
652 ensureImageBackingStore();
656 computeTransformedVisibleRect();
658 #if ENABLE(CSS_FILTERS)
661 updateContentBuffers();
663 // Only unset m_movingVisibleRect after we have updated the visible rect after the animation stopped.
664 if (!hasActiveTransformAnimation)
665 m_movingVisibleRect = false;
668 void WebGraphicsLayer::tiledBackingStorePaintBegin()
672 void WebGraphicsLayer::setRootLayer(bool isRoot)
674 m_layerInfo.isRootLayer = isRoot;
675 didChangeLayerState();
678 void WebGraphicsLayer::setVisibleContentRectTrajectoryVector(const FloatPoint& trajectoryVector)
680 if (m_mainBackingStore)
681 m_mainBackingStore->coverWithTilesIfNeeded(trajectoryVector);
684 void WebGraphicsLayer::setContentsScale(float scale)
686 #if ENABLE(TIZEN_USE_FIXED_SCALE_ANIMATION)
687 if (!m_animations.hasActiveAnimationsOfType(AnimatedPropertyWebkitTransform))
688 m_fixedAnimationScale = scale;
691 m_contentsScale = scale;
692 adjustContentsScale();
695 float WebGraphicsLayer::effectiveContentsScale()
697 #if ENABLE(TIZEN_USE_FIXED_SCALE_ANIMATION)
698 if (m_animations.hasActiveAnimationsOfType(AnimatedPropertyWebkitTransform))
699 return m_fixedAnimationScale;
702 return selfOrAncestorHaveNonAffineTransforms() ? 1 : m_contentsScale;
705 void WebGraphicsLayer::adjustContentsScale()
710 if (!m_mainBackingStore || m_mainBackingStore->contentsScale() == effectiveContentsScale())
713 // Between creating the new backing store and painting the content,
714 // we do not want to drop the previous one as that might result in
715 // briefly seeing flickering as the old tiles may be dropped before
716 // something replaces them.
717 m_previousBackingStore = m_mainBackingStore.release();
719 // No reason to save the previous backing store for non-visible areas.
720 m_previousBackingStore->removeAllNonVisibleTiles();
722 createBackingStore();
725 void WebGraphicsLayer::createBackingStore()
727 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
728 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
729 if (!m_webGraphicsLayerClient->isGLAccelerationMode() || !SharedPlatformSurfaceTizen::supportsLockSurfaceExtension())
730 m_mainBackingStore = adoptPtr(new TiledBackingStore(this, TiledBackingStoreRemoteTileBackend::create(this)));
733 m_mainBackingStore = adoptPtr(new TiledBackingStore(this, TiledBackingStoreRemoteTileBackendTizen::create(this)));
735 m_mainBackingStore = adoptPtr(new TiledBackingStore(this, TiledBackingStoreRemoteTileBackend::create(this)));
737 m_mainBackingStore->setSupportsAlpha(!contentsOpaque());
738 m_mainBackingStore->setContentsScale(effectiveContentsScale());
741 void WebGraphicsLayer::tiledBackingStorePaint(GraphicsContext* context, const IntRect& rect)
746 paintGraphicsLayerContents(*context, rect);
749 void WebGraphicsLayer::tiledBackingStorePaintEnd(const Vector<IntRect>& updatedRects)
753 bool WebGraphicsLayer::tiledBackingStoreUpdatesAllowed() const
758 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
759 if (!m_webGraphicsLayerClient)
763 return m_webGraphicsLayerClient->layerTreeTileUpdatesAllowed();
766 IntRect WebGraphicsLayer::tiledBackingStoreContentsRect()
768 return IntRect(0, 0, size().width(), size().height());
771 IntRect WebGraphicsLayer::tiledBackingStoreVisibleRect()
773 // Non-invertible layers are not visible.
774 if (!m_layerTransform.combined().isInvertible())
777 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
778 if (!m_webGraphicsLayerClient)
782 FloatRect perspectiveRect = m_webGraphicsLayerClient->visibleContentsRect();
784 #if ENABLE(TIZEN_CSS_OVERFLOW_CLIPPING_BACKING_STORE)
785 if (GraphicsLayer::overflowClipping() && m_mainBackingStore) {
786 WebGraphicsLayer* parentLayer = toWebGraphicsLayer(parent());
788 perspectiveRect = parentLayer->clippingBounds();
792 if (m_movingVisibleRect) {
793 IntRect startAnimationRect = enclosingIntRect(m_layerTransform.combined().inverse().clampedBoundsOfProjectedQuad(FloatQuad(perspectiveRect)));
794 IntRect endAnimationRect = enclosingIntRect(m_layerSettledTransform.combined().inverse().clampedBoundsOfProjectedQuad(FloatQuad(perspectiveRect)));
795 endAnimationRect.unite(startAnimationRect);
796 return endAnimationRect;
799 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_SCROLLBAR)
801 WebGraphicsLayer* parentLayer = toWebGraphicsLayer(parent());
802 if (parentLayer && parentLayer->isOverflow()) {
803 GraphicsLayerTransform adjustedTransform = m_layerTransform;
804 adjustedTransform.setPosition(FloatPoint(position().x() - parentLayer->position().x(),
805 position().y() - parentLayer->position().y()));
806 adjustedTransform.combineTransforms(parent() ? toWebGraphicsLayer(parent())->m_layerTransform.combinedForChildren() : TransformationMatrix());
807 return enclosingIntRect(adjustedTransform.combined().inverse().clampedBoundsOfProjectedQuad(FloatQuad(perspectiveRect)));
812 // Return a projection of the visible rect (surface coordinates) onto the layer's plane (layer coordinates).
813 // The resulting quad might be squewed and the visible rect is the bounding box of this quad,
814 // so it might spread further than the real visible area (and then even more amplified by the cover rect multiplier).
815 return enclosingIntRect(m_layerTransform.combined().inverse().clampedBoundsOfProjectedQuad(FloatQuad(perspectiveRect)));
818 Color WebGraphicsLayer::tiledBackingStoreBackgroundColor() const
820 return contentsOpaque() ? Color::white : Color::transparent;
823 PassOwnPtr<WebCore::GraphicsContext> WebGraphicsLayer::beginContentUpdate(const WebCore::IntSize& size, ShareableSurface::Handle& handle, WebCore::IntPoint& offset)
825 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
826 if (!m_webGraphicsLayerClient)
827 return PassOwnPtr<WebCore::GraphicsContext>();
830 return m_webGraphicsLayerClient->beginContentUpdate(size, contentsOpaque() ? 0 : ShareableBitmap::SupportsAlpha, handle, offset);
833 void WebGraphicsLayer::createTile(int tileID, const SurfaceUpdateInfo& updateInfo, const IntRect& targetRect)
835 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
836 if (m_webGraphicsLayerClient)
838 m_webGraphicsLayerClient->createTile(id(), tileID, updateInfo, targetRect);
841 void WebGraphicsLayer::updateTile(int tileID, const SurfaceUpdateInfo& updateInfo, const IntRect& targetRect)
843 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
844 if (m_webGraphicsLayerClient)
846 m_webGraphicsLayerClient->updateTile(id(), tileID, updateInfo, targetRect);
849 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
850 void WebGraphicsLayer::freePlatformSurface(int platformSurfaceID)
852 if (m_canvasPlatformLayer)
853 m_canvasPlatformLayer->freePlatformSurface(platformSurfaceID);
856 void WebGraphicsLayer::removePlatformSurface(int platformSurfaceID)
858 if (m_canvasPlatformLayer)
859 m_canvasPlatformLayer->removePlatformSurface(platformSurfaceID);
860 #if ENABLE(TIZEN_CANVAS_CAIRO_GLES_RENDERING) || ENABLE(TIZEN_CANVAS_SURFACE_LOCKING)
861 if (m_canvasPlatformLayer && m_layerInfo.contentType == WebKit::WebLayerInfo::Canvas2DContentType)
862 m_canvasNeedsDisplay = true;
865 if (m_canvasPlatformLayer && m_layerInfo.contentType == WebKit::WebLayerInfo::Canvas3DContentType)
866 m_canvasNeedsDisplay = true;
870 bool WebGraphicsLayer::swapPlatformSurfaces()
872 if (m_canvasPlatformLayer)
873 return m_canvasPlatformLayer->swapPlatformSurfaces();
878 #if ENABLE(TIZEN_ACCELERATED_2D_CANVAS_EFL)
879 void WebGraphicsLayer::flushPlatformSurfaces()
881 if (m_canvasPlatformLayer)
882 return m_canvasPlatformLayer->flushPlatformSurfaces();
886 void WebGraphicsLayer::removeTile(int tileID)
888 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
889 if (m_webGraphicsLayerClient)
891 m_webGraphicsLayerClient->removeTile(id(), tileID);
894 void WebGraphicsLayer::updateContentBuffers()
896 if (!drawsContent()) {
897 m_mainBackingStore.clear();
898 m_previousBackingStore.clear();
902 m_inUpdateMode = true;
903 // This is the only place we (re)create the main tiled backing store, once we
904 // have a remote client and we are ready to send our data to the UI process.
905 if (!m_mainBackingStore)
906 createBackingStore();
908 m_mainBackingStore->updateTileBuffers();
909 m_inUpdateMode = false;
911 // The previous backing store is kept around to avoid flickering between
912 // removing the existing tiles and painting the new ones. The first time
913 // the visibleRect is full painted we remove the previous backing store.
914 if (m_mainBackingStore->visibleAreaIsCovered())
915 m_previousBackingStore.clear();
918 void WebGraphicsLayer::purgeBackingStores()
920 m_mainBackingStore.clear();
921 m_previousBackingStore.clear();
923 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
924 if (m_webGraphicsLayerClient)
926 if (m_layerInfo.imageBackingStoreID) {
927 m_webGraphicsLayerClient->releaseImageBackingStore(m_layerInfo.imageBackingStoreID);
928 m_layerInfo.imageBackingStoreID = 0;
931 didChangeLayerState();
935 void WebGraphicsLayer::setWebGraphicsLayerClient(WebKit::WebGraphicsLayerClient* client)
937 if (m_webGraphicsLayerClient == client)
940 if (WebGraphicsLayer* replica = toWebGraphicsLayer(replicaLayer()))
941 replica->setWebGraphicsLayerClient(client);
942 if (WebGraphicsLayer* mask = toWebGraphicsLayer(maskLayer()))
943 mask->setWebGraphicsLayerClient(client);
944 for (size_t i = 0; i < children().size(); ++i) {
945 WebGraphicsLayer* layer = toWebGraphicsLayer(this->children()[i]);
946 layer->setWebGraphicsLayerClient(client);
949 // We have to release resources on the UI process here if the remote client has changed or is removed.
950 if (m_webGraphicsLayerClient) {
951 #if ENABLE(TIZEN_DONT_PURGE_PLATFORM_SURFACE_BACKINGSTORE_ON_NODE_DETACH_FROM_WEBLAYER_TREE)
952 didChangeLayerState();
954 m_shouldSyncBackingStore = true;
956 purgeBackingStores();
957 #endif // ENABLE(TIZEN_DONT_PURGE_PLATFORM_SURFACE_BACKINGSTORE_ON_NODE_DETACH_FROM_WEBLAYER_TREE)
958 m_webGraphicsLayerClient->detachLayer(this);
960 m_webGraphicsLayerClient = client;
962 client->attachLayer(this);
965 void WebGraphicsLayer::adjustVisibleRect()
967 if (m_mainBackingStore)
968 m_mainBackingStore->coverWithTilesIfNeeded();
971 bool WebGraphicsLayer::hasPendingVisibleChanges()
973 if (opacity() < 0.01 && !m_animations.hasActiveAnimationsOfType(AnimatedPropertyOpacity))
976 for (size_t i = 0; i < children().size(); ++i) {
977 if (toWebGraphicsLayer(children()[i])->hasPendingVisibleChanges())
981 if (!m_shouldSyncLayerState && !m_shouldSyncChildren && !m_shouldSyncFilters && !m_shouldSyncAnimations && !m_canvasNeedsDisplay)
984 return tiledBackingStoreVisibleRect().intersects(tiledBackingStoreContentsRect());
987 void WebGraphicsLayer::computeTransformedVisibleRect()
989 // When we have a transform animation, we need to update visible rect every frame to adjust the visible rect of a backing store.
990 if (!m_shouldUpdateVisibleRect && !m_movingVisibleRect)
993 m_shouldUpdateVisibleRect = false;
994 TransformationMatrix currentTransform = transform();
995 if (m_movingVisibleRect) {
996 m_layerSettledTransform.setLocalTransform(currentTransform);
997 m_layerSettledTransform.setPosition(position());
998 m_layerSettledTransform.setAnchorPoint(anchorPoint());
999 m_layerSettledTransform.setSize(size());
1000 m_layerSettledTransform.setFlattening(!preserves3D());
1001 m_layerSettledTransform.setChildrenTransform(childrenTransform());
1002 m_layerSettledTransform.combineTransforms(parent() ? toWebGraphicsLayer(parent())->m_layerTransform.combinedForChildren() : TransformationMatrix());
1004 client()->getCurrentTransform(this, currentTransform);
1007 m_layerTransform.setLocalTransform(currentTransform);
1008 m_layerTransform.setPosition(position());
1009 m_layerTransform.setAnchorPoint(anchorPoint());
1010 m_layerTransform.setSize(size());
1011 m_layerTransform.setFlattening(!preserves3D());
1012 m_layerTransform.setChildrenTransform(childrenTransform());
1013 m_layerTransform.combineTransforms(parent() ? toWebGraphicsLayer(parent())->m_layerTransform.combinedForChildren() : TransformationMatrix());
1015 // The combined transform will be used in tiledBackingStoreVisibleRect.
1016 adjustVisibleRect();
1017 adjustContentsScale();
1020 static PassOwnPtr<GraphicsLayer> createWebGraphicsLayer(GraphicsLayerClient* client)
1022 return adoptPtr(new WebGraphicsLayer(client));
1025 void WebGraphicsLayer::initFactory()
1027 GraphicsLayer::setGraphicsLayerFactory(createWebGraphicsLayer);
1030 bool WebGraphicsLayer::selfOrAncestorHasActiveTransformAnimation()
1032 if (m_animations.hasActiveAnimationsOfType(AnimatedPropertyWebkitTransform))
1038 return toWebGraphicsLayer(parent())->selfOrAncestorHasActiveTransformAnimation();
1041 bool WebGraphicsLayer::selfOrAncestorHaveNonAffineTransforms()
1043 if (m_animations.hasActiveAnimationsOfType(AnimatedPropertyWebkitTransform))
1046 if (!m_layerTransform.combined().isAffine())
1052 bool WebGraphicsLayer::addAnimation(const KeyframeValueList& valueList, const IntSize& boxSize, const Animation* anim, const String& keyframesName, double timeOffset)
1054 ASSERT(!keyframesName.isEmpty());
1056 if (!anim || anim->isEmptyOrZeroDuration() || valueList.size() < 2 || (valueList.property() != AnimatedPropertyWebkitTransform && valueList.property() != AnimatedPropertyOpacity))
1059 bool listsMatch = false;
1060 bool ignoredHasBigRotation;
1062 if (valueList.property() == AnimatedPropertyWebkitTransform)
1063 listsMatch = validateTransformOperations(valueList, ignoredHasBigRotation) >= 0;
1065 m_animations.add(GraphicsLayerAnimation(keyframesName, valueList, boxSize, anim, WTF::currentTime() - timeOffset, listsMatch));
1066 m_animationStartedTimer.startOneShot(0);
1067 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
1068 didChangeAnimations();
1070 didChangeLayerState();
1074 void WebGraphicsLayer::pauseAnimation(const String& animationName, double timeOffset)
1076 m_animations.pause(animationName, timeOffset);
1077 didChangeAnimations();
1080 void WebGraphicsLayer::removeAnimation(const String& animationName)
1082 m_animations.remove(animationName);
1083 didChangeAnimations();
1086 void WebGraphicsLayer::animationStartedTimerFired(Timer<WebGraphicsLayer>*)
1088 client()->notifyAnimationStarted(this, /* DOM time */ WTF::currentTime());
1091 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
1092 void WebGraphicsLayer::setIsOverflow(const bool b)
1094 if (m_isOverflow == b)
1098 didChangeLayerState();
1102 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_SCROLLBAR)
1103 void WebGraphicsLayer::startAnimation()
1106 if (m_animationTimer.isActive())
1107 m_animationTimer.stop();
1108 m_animationTimer.startOneShot(1.0);
1111 void WebGraphicsLayer::animationTimerFired(Timer<WebGraphicsLayer>*)
1117 #if ENABLE(TIZEN_CUTOFF_TILES_OVER_MEMORY_LIMIT)
1118 Vector<TileCutOffInfo> WebGraphicsLayer::getCutOffInfoList()
1120 if (!m_mainBackingStore)
1121 return Vector<TileCutOffInfo>();
1123 return m_mainBackingStore->getCutOffInfoList();
1126 void WebGraphicsLayer::setCutOffDistance(double distance)
1128 if (!m_mainBackingStore)
1131 m_mainBackingStore->setCutOffDistance(distance);
1135 #if ENABLE(TIZEN_CSS_OVERFLOW_CLIPPING_BACKING_STORE)
1136 FloatRect WebGraphicsLayer::clippingBounds()
1138 LayoutRect layerRect = LayoutRect(GraphicsLayer::position(),GraphicsLayer::size());
1139 return enclosingIntRect(m_layerTransform.combined().clampedBoundsOfProjectedQuad(FloatQuad(FloatRect(pixelSnappedIntRect(layerRect)))));
1143 #if ENABLE(TIZEN_WEBKIT2_MEMORY_SAVING_MODE)
1144 bool WebGraphicsLayer::memorySavingModeEnabled()
1146 return WebProcess::shared().memorySavingModeEnabled();
1150 #if ENABLE(TIZEN_WEBKIT2_DEBUG_BORDERS)
1151 bool WebGraphicsLayer::drawTileInfo() const
1153 static bool drawTileInfo = String(getenv("TIZEN_WEBKIT_SHOW_COMPOSITING_DEBUG_VISUALS")) == "1";
1154 return drawTileInfo;