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)
260 if (!fixedToViewport())
265 void WebGraphicsLayer::setTransform(const TransformationMatrix& t)
267 if (transform() == t)
270 GraphicsLayer::setTransform(t);
274 void WebGraphicsLayer::setChildrenTransform(const TransformationMatrix& t)
276 if (childrenTransform() == t)
279 GraphicsLayer::setChildrenTransform(t);
283 void WebGraphicsLayer::setPreserves3D(bool b)
285 if (preserves3D() == b)
288 GraphicsLayer::setPreserves3D(b);
292 void WebGraphicsLayer::setMasksToBounds(bool b)
294 if (masksToBounds() == b)
296 GraphicsLayer::setMasksToBounds(b);
300 void WebGraphicsLayer::setDrawsContent(bool b)
302 if (drawsContent() == b)
304 GraphicsLayer::setDrawsContent(b);
306 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
310 didChangeLayerState();
313 void WebGraphicsLayer::setContentsVisible(bool b)
315 if (contentsAreVisible() == b)
317 GraphicsLayer::setContentsVisible(b);
319 didChangeLayerState();
322 void WebGraphicsLayer::setContentsOpaque(bool b)
324 if (contentsOpaque() == b)
326 if (m_mainBackingStore)
327 m_mainBackingStore->setSupportsAlpha(!b);
328 GraphicsLayer::setContentsOpaque(b);
329 didChangeLayerState();
332 void WebGraphicsLayer::setBackfaceVisibility(bool b)
334 if (backfaceVisibility() == b)
337 GraphicsLayer::setBackfaceVisibility(b);
338 didChangeLayerState();
341 void WebGraphicsLayer::setOpacity(float opacity)
343 if (this->opacity() == opacity)
346 GraphicsLayer::setOpacity(opacity);
347 didChangeLayerState();
350 void WebGraphicsLayer::setContentsRect(const IntRect& r)
352 if (contentsRect() == r)
355 GraphicsLayer::setContentsRect(r);
356 didChangeLayerState();
359 void WebGraphicsLayer::setContentsNeedsDisplay()
361 RefPtr<Image> image = m_image;
362 setContentsToImage(0);
363 setContentsToImage(image.get());
364 m_canvasNeedsDisplay = true;
366 client()->notifySyncRequired(this);
370 #if ENABLE(CSS_FILTERS)
371 bool WebGraphicsLayer::setFilters(const FilterOperations& newFilters)
373 if (filters() == newFilters)
376 return GraphicsLayer::setFilters(newFilters);
380 void WebGraphicsLayer::setContentsToBackgroundColor(const Color& color)
382 if (m_layerInfo.backgroundColor == color)
384 m_layerInfo.backgroundColor = color;
386 // This is in line with what CA does.
387 setBackgroundColor(color);
388 didChangeLayerState();
391 void WebGraphicsLayer::setContentsToImage(Image* image)
393 if (image == m_image)
396 if (m_webGraphicsLayerClient) {
397 // We adopt first, in case this is the same frame - that way we avoid destroying and recreating the image.
398 newID = m_webGraphicsLayerClient->adoptImageBackingStore(image);
399 m_webGraphicsLayerClient->releaseImageBackingStore(m_layerInfo.imageBackingStoreID);
400 didChangeLayerState();
401 if (m_layerInfo.imageBackingStoreID && newID == m_layerInfo.imageBackingStoreID)
404 // If m_webGraphicsLayerClient is not set yet there should be no backing store ID.
405 ASSERT(!m_layerInfo.imageBackingStoreID);
406 didChangeLayerState();
409 m_layerInfo.imageBackingStoreID = newID;
411 GraphicsLayer::setContentsToImage(image);
414 void WebGraphicsLayer::setContentsToCanvas(PlatformLayer* platformLayer)
416 m_canvasPlatformLayer = platformLayer;
417 m_canvasNeedsDisplay = true;
418 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
419 if (!m_canvasPlatformLayer)
422 if (static_cast<TextureMapperPlatformLayer*>(m_canvasPlatformLayer)->contentType() == WebKit::WebLayerInfo::Canvas2DContentType)
423 m_layerInfo.contentType = WebKit::WebLayerInfo::Canvas2DContentType;
425 m_layerInfo.contentType = WebKit::WebLayerInfo::Canvas3DContentType;
429 client()->notifySyncRequired(this);
432 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
433 void WebGraphicsLayer::setContentsToMedia(PlatformLayer* platformLayer)
435 m_canvasPlatformLayer = platformLayer;
436 m_canvasNeedsDisplay = true;
437 m_layerInfo.contentType = WebKit::WebLayerInfo::MediaContentType;
440 client()->notifySyncRequired(this);
444 void WebGraphicsLayer::setMaskLayer(GraphicsLayer* layer)
446 if (layer == maskLayer())
449 GraphicsLayer::setMaskLayer(layer);
454 layer->setSize(size());
455 WebGraphicsLayer* webGraphicsLayer = toWebGraphicsLayer(layer);
456 webGraphicsLayer->setWebGraphicsLayerClient(m_webGraphicsLayerClient);
457 webGraphicsLayer->setMaskTarget(this);
458 webGraphicsLayer->didChangeLayerState();
459 didChangeLayerState();
463 void WebGraphicsLayer::setReplicatedByLayer(GraphicsLayer* layer)
465 if (layer == replicaLayer())
469 toWebGraphicsLayer(layer)->setWebGraphicsLayerClient(m_webGraphicsLayerClient);
471 GraphicsLayer::setReplicatedByLayer(layer);
472 didChangeLayerState();
475 void WebGraphicsLayer::setNeedsDisplay()
477 setNeedsDisplayInRect(IntRect(IntPoint::zero(), IntSize(size().width(), size().height())));
480 void WebGraphicsLayer::setNeedsDisplayInRect(const FloatRect& rect)
482 if (m_mainBackingStore)
483 m_mainBackingStore->invalidate(IntRect(rect));
484 didChangeLayerState();
487 WebLayerID WebGraphicsLayer::id() const
492 void WebGraphicsLayer::syncCompositingState(const FloatRect& rect)
494 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
495 if (!m_webGraphicsLayerClient)
499 if (WebGraphicsLayer* mask = toWebGraphicsLayer(maskLayer()))
500 mask->syncCompositingStateForThisLayerOnly();
502 if (WebGraphicsLayer* replica = toWebGraphicsLayer(replicaLayer()))
503 replica->syncCompositingStateForThisLayerOnly();
505 #if !ENABLE(TIZEN_CSS_FIXED_ACCELERATION)
506 m_webGraphicsLayerClient->syncFixedLayers();
509 syncCompositingStateForThisLayerOnly();
511 for (size_t i = 0; i < children().size(); ++i)
512 children()[i]->syncCompositingState(rect);
515 WebGraphicsLayer* toWebGraphicsLayer(GraphicsLayer* layer)
517 return static_cast<WebGraphicsLayer*>(layer);
520 void WebGraphicsLayer::syncChildren()
522 if (!m_shouldSyncChildren)
524 m_shouldSyncChildren = false;
525 Vector<WebLayerID> childIDs;
526 for (size_t i = 0; i < children().size(); ++i)
527 childIDs.append(toWebLayerID(children()[i]));
529 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
530 if (m_webGraphicsLayerClient)
532 m_webGraphicsLayerClient->syncLayerChildren(m_id, childIDs);
535 #if ENABLE(CSS_FILTERS)
536 void WebGraphicsLayer::syncFilters()
538 if (!m_shouldSyncFilters)
540 m_shouldSyncFilters = false;
541 m_webGraphicsLayerClient->syncLayerFilters(m_id, filters());
545 void WebGraphicsLayer::syncLayerState()
547 if (!m_shouldSyncLayerState)
550 m_shouldSyncLayerState = false;
551 m_layerInfo.fixedToViewport = fixedToViewport();
552 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_SCROLLBAR)
553 m_layerInfo.isScrollbar = isScrollbar();
555 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
556 m_layerInfo.isScrollingContentsLayer = isOverflow();
557 if (m_layerInfo.isScrollingContentsLayer)
558 m_layerInfo.boundsOrigin = parent() ? parent()->boundsOrigin() : boundsOrigin();
561 m_layerInfo.anchorPoint = anchorPoint();
562 m_layerInfo.backfaceVisible = backfaceVisibility();
563 m_layerInfo.childrenTransform = childrenTransform();
564 m_layerInfo.contentsOpaque = contentsOpaque();
565 m_layerInfo.contentsRect = contentsRect();
566 m_layerInfo.drawsContent = drawsContent();
567 m_layerInfo.contentsVisible = contentsAreVisible();
568 m_layerInfo.mask = toWebLayerID(maskLayer());
569 m_layerInfo.masksToBounds = masksToBounds();
570 m_layerInfo.opacity = opacity();
571 m_layerInfo.parent = toWebLayerID(parent());
572 m_layerInfo.pos = position();
573 m_layerInfo.preserves3D = preserves3D();
574 m_layerInfo.replica = toWebLayerID(replicaLayer());
575 m_layerInfo.size = size();
576 m_layerInfo.transform = transform();
578 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
579 if (m_webGraphicsLayerClient)
581 m_webGraphicsLayerClient->syncLayerState(m_id, m_layerInfo);
583 #if ENABLE(TIZEN_DONT_PURGE_PLATFORM_SURFACE_BACKINGSTORE_ON_NODE_DETACH_FROM_WEBLAYER_TREE)
584 syncBackingStoreIfNeeded();
588 void WebGraphicsLayer::syncAnimations()
590 if (!m_shouldSyncAnimations)
593 m_shouldSyncAnimations = false;
595 m_webGraphicsLayerClient->setLayerAnimations(m_id, m_animations);
598 void WebGraphicsLayer::syncCanvas()
600 if (!m_canvasNeedsDisplay)
603 if (!m_canvasPlatformLayer)
606 #if USE(GRAPHICS_SURFACE) || ENABLE(TIZEN_CANVAS_GRAPHICS_SURFACE)
607 uint64_t token = m_canvasPlatformLayer->graphicsSurfaceToken();
610 uint32_t frontBuffer = m_canvasPlatformLayer->copyToGraphicsSurface();
611 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
612 int flags = m_canvasPlatformLayer->graphicsSurfaceFlags();
613 if (m_webGraphicsLayerClient)
614 m_webGraphicsLayerClient->syncCanvas(m_id, IntSize(contentsRect().width(), contentsRect().height()), token, frontBuffer, flags);
616 m_webGraphicsLayerClient->syncCanvas(m_id, IntSize(size().width(), size().height()), token, frontBuffer);
619 m_canvasNeedsDisplay = false;
622 void WebGraphicsLayer::ensureImageBackingStore()
627 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
628 if (!m_webGraphicsLayerClient)
632 if (!m_layerInfo.imageBackingStoreID)
633 m_layerInfo.imageBackingStoreID = m_webGraphicsLayerClient->adoptImageBackingStore(m_image.get());
636 #if ENABLE(TIZEN_DONT_PURGE_PLATFORM_SURFACE_BACKINGSTORE_ON_NODE_DETACH_FROM_WEBLAYER_TREE)
637 void WebGraphicsLayer::syncBackingStoreIfNeeded()
639 if (m_shouldSyncBackingStore) {
640 if (m_mainBackingStore)
641 m_mainBackingStore->reviewTiles();
642 m_shouldSyncBackingStore = false;
647 void WebGraphicsLayer::syncCompositingStateForThisLayerOnly()
649 // When we have a transform animation, we need to update visible rect every frame to adjust the visible rect of a backing store.
650 bool hasActiveTransformAnimation = selfOrAncestorHasActiveTransformAnimation();
651 if (hasActiveTransformAnimation)
652 m_movingVisibleRect = true;
654 // The remote image might have been released by purgeBackingStores.
655 ensureImageBackingStore();
659 computeTransformedVisibleRect();
661 #if ENABLE(CSS_FILTERS)
664 updateContentBuffers();
666 // Only unset m_movingVisibleRect after we have updated the visible rect after the animation stopped.
667 if (!hasActiveTransformAnimation)
668 m_movingVisibleRect = false;
671 void WebGraphicsLayer::tiledBackingStorePaintBegin()
675 void WebGraphicsLayer::setRootLayer(bool isRoot)
677 m_layerInfo.isRootLayer = isRoot;
678 didChangeLayerState();
681 void WebGraphicsLayer::setVisibleContentRectTrajectoryVector(const FloatPoint& trajectoryVector)
683 if (m_mainBackingStore)
684 m_mainBackingStore->coverWithTilesIfNeeded(trajectoryVector);
687 void WebGraphicsLayer::setContentsScale(float scale)
689 #if ENABLE(TIZEN_USE_FIXED_SCALE_ANIMATION)
690 if (!m_animations.hasActiveAnimationsOfType(AnimatedPropertyWebkitTransform))
691 m_fixedAnimationScale = scale;
694 m_contentsScale = scale;
695 adjustContentsScale();
698 float WebGraphicsLayer::effectiveContentsScale()
700 #if ENABLE(TIZEN_USE_FIXED_SCALE_ANIMATION)
701 if (m_animations.hasActiveAnimationsOfType(AnimatedPropertyWebkitTransform))
702 return m_fixedAnimationScale;
705 return selfOrAncestorHaveNonAffineTransforms() ? 1 : m_contentsScale;
708 void WebGraphicsLayer::adjustContentsScale()
713 if (!m_mainBackingStore || m_mainBackingStore->contentsScale() == effectiveContentsScale())
716 // Between creating the new backing store and painting the content,
717 // we do not want to drop the previous one as that might result in
718 // briefly seeing flickering as the old tiles may be dropped before
719 // something replaces them.
720 m_previousBackingStore = m_mainBackingStore.release();
722 // No reason to save the previous backing store for non-visible areas.
723 m_previousBackingStore->removeAllNonVisibleTiles();
725 createBackingStore();
728 void WebGraphicsLayer::createBackingStore()
730 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
731 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
732 if (!m_webGraphicsLayerClient->isGLAccelerationMode() || !SharedPlatformSurfaceTizen::supportsLockSurfaceExtension())
733 m_mainBackingStore = adoptPtr(new TiledBackingStore(this, TiledBackingStoreRemoteTileBackend::create(this)));
736 m_mainBackingStore = adoptPtr(new TiledBackingStore(this, TiledBackingStoreRemoteTileBackendTizen::create(this)));
738 m_mainBackingStore = adoptPtr(new TiledBackingStore(this, TiledBackingStoreRemoteTileBackend::create(this)));
740 m_mainBackingStore->setSupportsAlpha(!contentsOpaque());
741 m_mainBackingStore->setContentsScale(effectiveContentsScale());
744 void WebGraphicsLayer::tiledBackingStorePaint(GraphicsContext* context, const IntRect& rect)
749 paintGraphicsLayerContents(*context, rect);
752 void WebGraphicsLayer::tiledBackingStorePaintEnd(const Vector<IntRect>& updatedRects)
756 bool WebGraphicsLayer::tiledBackingStoreUpdatesAllowed() const
761 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
762 if (!m_webGraphicsLayerClient)
766 return m_webGraphicsLayerClient->layerTreeTileUpdatesAllowed();
769 IntRect WebGraphicsLayer::tiledBackingStoreContentsRect()
771 return IntRect(0, 0, size().width(), size().height());
774 IntRect WebGraphicsLayer::tiledBackingStoreVisibleRect()
776 // Non-invertible layers are not visible.
777 if (!m_layerTransform.combined().isInvertible())
780 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
781 if (!m_webGraphicsLayerClient)
785 FloatRect perspectiveRect = m_webGraphicsLayerClient->visibleContentsRect();
787 #if ENABLE(TIZEN_CSS_OVERFLOW_CLIPPING_BACKING_STORE)
788 if (GraphicsLayer::overflowClipping() && m_mainBackingStore) {
789 WebGraphicsLayer* parentLayer = toWebGraphicsLayer(parent());
791 perspectiveRect = parentLayer->clippingBounds();
795 if (m_movingVisibleRect) {
796 IntRect startAnimationRect = enclosingIntRect(m_layerTransform.combined().inverse().clampedBoundsOfProjectedQuad(FloatQuad(perspectiveRect)));
797 IntRect endAnimationRect = enclosingIntRect(m_layerSettledTransform.combined().inverse().clampedBoundsOfProjectedQuad(FloatQuad(perspectiveRect)));
798 endAnimationRect.unite(startAnimationRect);
799 return endAnimationRect;
802 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_SCROLLBAR)
804 WebGraphicsLayer* parentLayer = toWebGraphicsLayer(parent());
805 if (parentLayer && parentLayer->isOverflow()) {
806 GraphicsLayerTransform adjustedTransform = m_layerTransform;
807 adjustedTransform.setPosition(FloatPoint(position().x() - parentLayer->position().x(),
808 position().y() - parentLayer->position().y()));
809 adjustedTransform.combineTransforms(parent() ? toWebGraphicsLayer(parent())->m_layerTransform.combinedForChildren() : TransformationMatrix());
810 return enclosingIntRect(adjustedTransform.combined().inverse().clampedBoundsOfProjectedQuad(FloatQuad(perspectiveRect)));
815 // Return a projection of the visible rect (surface coordinates) onto the layer's plane (layer coordinates).
816 // The resulting quad might be squewed and the visible rect is the bounding box of this quad,
817 // so it might spread further than the real visible area (and then even more amplified by the cover rect multiplier).
818 return enclosingIntRect(m_layerTransform.combined().inverse().clampedBoundsOfProjectedQuad(FloatQuad(perspectiveRect)));
821 Color WebGraphicsLayer::tiledBackingStoreBackgroundColor() const
823 return contentsOpaque() ? Color::white : Color::transparent;
826 PassOwnPtr<WebCore::GraphicsContext> WebGraphicsLayer::beginContentUpdate(const WebCore::IntSize& size, ShareableSurface::Handle& handle, WebCore::IntPoint& offset)
828 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
829 if (!m_webGraphicsLayerClient)
833 return m_webGraphicsLayerClient->beginContentUpdate(size, contentsOpaque() ? 0 : ShareableBitmap::SupportsAlpha, handle, offset);
836 void WebGraphicsLayer::createTile(int tileID, const SurfaceUpdateInfo& updateInfo, const IntRect& targetRect)
838 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
839 if (m_webGraphicsLayerClient)
841 m_webGraphicsLayerClient->createTile(id(), tileID, updateInfo, targetRect);
844 void WebGraphicsLayer::updateTile(int tileID, const SurfaceUpdateInfo& updateInfo, const IntRect& targetRect)
846 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
847 if (m_webGraphicsLayerClient)
849 m_webGraphicsLayerClient->updateTile(id(), tileID, updateInfo, targetRect);
852 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
853 void WebGraphicsLayer::freePlatformSurface(int platformSurfaceID)
855 if (m_canvasPlatformLayer)
856 m_canvasPlatformLayer->freePlatformSurface(platformSurfaceID);
859 void WebGraphicsLayer::removePlatformSurface(int platformSurfaceID)
861 if (m_canvasPlatformLayer)
862 m_canvasPlatformLayer->removePlatformSurface(platformSurfaceID);
863 #if ENABLE(TIZEN_CANVAS_CAIRO_GLES_RENDERING) || ENABLE(TIZEN_CANVAS_SURFACE_LOCKING)
864 if (m_canvasPlatformLayer && m_layerInfo.contentType == WebKit::WebLayerInfo::Canvas2DContentType)
865 m_canvasNeedsDisplay = true;
868 if (m_canvasPlatformLayer && m_layerInfo.contentType == WebKit::WebLayerInfo::Canvas3DContentType)
869 m_canvasNeedsDisplay = true;
873 bool WebGraphicsLayer::swapPlatformSurfaces()
875 if (m_canvasPlatformLayer)
876 return m_canvasPlatformLayer->swapPlatformSurfaces();
881 #if ENABLE(TIZEN_ACCELERATED_2D_CANVAS_EFL)
882 void WebGraphicsLayer::flushPlatformSurfaces()
884 if (m_canvasPlatformLayer)
885 return m_canvasPlatformLayer->flushPlatformSurfaces();
889 void WebGraphicsLayer::removeTile(int tileID)
891 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
892 if (m_webGraphicsLayerClient)
894 m_webGraphicsLayerClient->removeTile(id(), tileID);
897 void WebGraphicsLayer::updateContentBuffers()
899 if (!drawsContent()) {
900 m_mainBackingStore.clear();
901 m_previousBackingStore.clear();
905 m_inUpdateMode = true;
906 // This is the only place we (re)create the main tiled backing store, once we
907 // have a remote client and we are ready to send our data to the UI process.
908 if (!m_mainBackingStore)
909 createBackingStore();
911 m_mainBackingStore->updateTileBuffers();
912 m_inUpdateMode = false;
914 // The previous backing store is kept around to avoid flickering between
915 // removing the existing tiles and painting the new ones. The first time
916 // the visibleRect is full painted we remove the previous backing store.
917 if (m_mainBackingStore->visibleAreaIsCovered())
918 m_previousBackingStore.clear();
921 void WebGraphicsLayer::purgeBackingStores()
923 m_mainBackingStore.clear();
924 m_previousBackingStore.clear();
926 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
927 if (m_webGraphicsLayerClient)
929 if (m_layerInfo.imageBackingStoreID) {
930 m_webGraphicsLayerClient->releaseImageBackingStore(m_layerInfo.imageBackingStoreID);
931 m_layerInfo.imageBackingStoreID = 0;
934 didChangeLayerState();
938 void WebGraphicsLayer::setWebGraphicsLayerClient(WebKit::WebGraphicsLayerClient* client)
940 if (m_webGraphicsLayerClient == client)
943 if (WebGraphicsLayer* replica = toWebGraphicsLayer(replicaLayer()))
944 replica->setWebGraphicsLayerClient(client);
945 if (WebGraphicsLayer* mask = toWebGraphicsLayer(maskLayer()))
946 mask->setWebGraphicsLayerClient(client);
947 for (size_t i = 0; i < children().size(); ++i) {
948 WebGraphicsLayer* layer = toWebGraphicsLayer(this->children()[i]);
949 layer->setWebGraphicsLayerClient(client);
952 // We have to release resources on the UI process here if the remote client has changed or is removed.
953 if (m_webGraphicsLayerClient) {
954 #if ENABLE(TIZEN_DONT_PURGE_PLATFORM_SURFACE_BACKINGSTORE_ON_NODE_DETACH_FROM_WEBLAYER_TREE)
955 didChangeLayerState();
957 m_shouldSyncBackingStore = true;
959 purgeBackingStores();
960 #endif // ENABLE(TIZEN_DONT_PURGE_PLATFORM_SURFACE_BACKINGSTORE_ON_NODE_DETACH_FROM_WEBLAYER_TREE)
961 m_webGraphicsLayerClient->detachLayer(this);
963 m_webGraphicsLayerClient = client;
965 client->attachLayer(this);
968 void WebGraphicsLayer::adjustVisibleRect()
970 if (m_mainBackingStore)
971 m_mainBackingStore->coverWithTilesIfNeeded();
974 bool WebGraphicsLayer::hasPendingVisibleChanges()
976 if (opacity() < 0.01 && !m_animations.hasActiveAnimationsOfType(AnimatedPropertyOpacity))
979 for (size_t i = 0; i < children().size(); ++i) {
980 if (toWebGraphicsLayer(children()[i])->hasPendingVisibleChanges())
984 if (!m_shouldSyncLayerState && !m_shouldSyncChildren && !m_shouldSyncFilters && !m_shouldSyncAnimations && !m_canvasNeedsDisplay)
987 return tiledBackingStoreVisibleRect().intersects(tiledBackingStoreContentsRect());
990 void WebGraphicsLayer::computeTransformedVisibleRect()
992 // When we have a transform animation, we need to update visible rect every frame to adjust the visible rect of a backing store.
993 if (!m_shouldUpdateVisibleRect && !m_movingVisibleRect)
996 m_shouldUpdateVisibleRect = false;
997 TransformationMatrix currentTransform = transform();
998 if (m_movingVisibleRect) {
999 m_layerSettledTransform.setLocalTransform(currentTransform);
1000 m_layerSettledTransform.setPosition(position());
1001 m_layerSettledTransform.setAnchorPoint(anchorPoint());
1002 m_layerSettledTransform.setSize(size());
1003 m_layerSettledTransform.setFlattening(!preserves3D());
1004 m_layerSettledTransform.setChildrenTransform(childrenTransform());
1005 m_layerSettledTransform.combineTransforms(parent() ? toWebGraphicsLayer(parent())->m_layerTransform.combinedForChildren() : TransformationMatrix());
1007 client()->getCurrentTransform(this, currentTransform);
1010 m_layerTransform.setLocalTransform(currentTransform);
1011 m_layerTransform.setPosition(position());
1012 m_layerTransform.setAnchorPoint(anchorPoint());
1013 m_layerTransform.setSize(size());
1014 m_layerTransform.setFlattening(!preserves3D());
1015 m_layerTransform.setChildrenTransform(childrenTransform());
1016 m_layerTransform.combineTransforms(parent() ? toWebGraphicsLayer(parent())->m_layerTransform.combinedForChildren() : TransformationMatrix());
1018 // The combined transform will be used in tiledBackingStoreVisibleRect.
1019 adjustVisibleRect();
1020 adjustContentsScale();
1023 static PassOwnPtr<GraphicsLayer> createWebGraphicsLayer(GraphicsLayerClient* client)
1025 return adoptPtr(new WebGraphicsLayer(client));
1028 void WebGraphicsLayer::initFactory()
1030 GraphicsLayer::setGraphicsLayerFactory(createWebGraphicsLayer);
1033 bool WebGraphicsLayer::selfOrAncestorHasActiveTransformAnimation()
1035 if (m_animations.hasActiveAnimationsOfType(AnimatedPropertyWebkitTransform))
1041 return toWebGraphicsLayer(parent())->selfOrAncestorHasActiveTransformAnimation();
1044 bool WebGraphicsLayer::selfOrAncestorHaveNonAffineTransforms()
1046 if (m_animations.hasActiveAnimationsOfType(AnimatedPropertyWebkitTransform))
1049 if (!m_layerTransform.combined().isAffine())
1055 bool WebGraphicsLayer::addAnimation(const KeyframeValueList& valueList, const IntSize& boxSize, const Animation* anim, const String& keyframesName, double timeOffset)
1057 ASSERT(!keyframesName.isEmpty());
1059 if (!anim || anim->isEmptyOrZeroDuration() || valueList.size() < 2 || (valueList.property() != AnimatedPropertyWebkitTransform && valueList.property() != AnimatedPropertyOpacity))
1062 bool listsMatch = false;
1063 bool ignoredHasBigRotation;
1065 if (valueList.property() == AnimatedPropertyWebkitTransform)
1066 listsMatch = validateTransformOperations(valueList, ignoredHasBigRotation) >= 0;
1068 m_animations.add(GraphicsLayerAnimation(keyframesName, valueList, boxSize, anim, WTF::currentTime() - timeOffset, listsMatch));
1069 m_animationStartedTimer.startOneShot(0);
1070 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
1071 didChangeAnimations();
1073 didChangeLayerState();
1077 void WebGraphicsLayer::pauseAnimation(const String& animationName, double timeOffset)
1079 m_animations.pause(animationName, timeOffset);
1080 didChangeAnimations();
1083 void WebGraphicsLayer::removeAnimation(const String& animationName)
1085 m_animations.remove(animationName);
1086 didChangeAnimations();
1089 void WebGraphicsLayer::animationStartedTimerFired(Timer<WebGraphicsLayer>*)
1091 client()->notifyAnimationStarted(this, /* DOM time */ WTF::currentTime());
1094 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
1095 void WebGraphicsLayer::setIsOverflow(const bool b)
1097 if (m_isOverflow == b)
1101 didChangeLayerState();
1105 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_SCROLLBAR)
1106 void WebGraphicsLayer::startAnimation()
1109 if (m_animationTimer.isActive())
1110 m_animationTimer.stop();
1111 m_animationTimer.startOneShot(1.0);
1114 void WebGraphicsLayer::animationTimerFired(Timer<WebGraphicsLayer>*)
1120 #if ENABLE(TIZEN_CUTOFF_TILES_OVER_MEMORY_LIMIT)
1121 Vector<TileCutOffInfo> WebGraphicsLayer::getCutOffInfoList()
1123 if (!m_mainBackingStore)
1124 return Vector<TileCutOffInfo>();
1126 return m_mainBackingStore->getCutOffInfoList();
1129 void WebGraphicsLayer::setCutOffDistance(double distance)
1131 if (!m_mainBackingStore)
1134 m_mainBackingStore->setCutOffDistance(distance);
1138 #if ENABLE(TIZEN_CSS_OVERFLOW_CLIPPING_BACKING_STORE)
1139 FloatRect WebGraphicsLayer::clippingBounds()
1141 LayoutRect layerRect = LayoutRect(GraphicsLayer::position(),GraphicsLayer::size());
1142 return enclosingIntRect(m_layerTransform.combined().clampedBoundsOfProjectedQuad(FloatQuad(FloatRect(pixelSnappedIntRect(layerRect)))));
1146 #if ENABLE(TIZEN_WEBKIT2_MEMORY_SAVING_MODE)
1147 bool WebGraphicsLayer::memorySavingModeEnabled()
1149 return WebProcess::shared().memorySavingModeEnabled();
1153 #if ENABLE(TIZEN_WEBKIT2_DEBUG_BORDERS)
1154 bool WebGraphicsLayer::drawTileInfo() const
1156 static bool drawTileInfo = String(getenv("TIZEN_WEBKIT_SHOW_COMPOSITING_DEBUG_VISUALS")) == "1";
1157 return drawTileInfo;
1161 #if ENABLE(TIZEN_CSS_FIXED_ACCELERATION)
1162 void WebGraphicsLayer::syncFixedLayers()
1164 if (m_webGraphicsLayerClient)
1165 m_webGraphicsLayerClient->syncFixedLayers();