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 "SharedPlatformSurfaceEfl.h"
37 #include <wtf/CurrentTime.h>
38 #include <wtf/HashMap.h>
39 #include <wtf/text/CString.h>
41 using namespace WebKit;
45 #if ENABLE(TIZEN_RECORDING_SURFACE_PAINT_THREAD)
46 static const double cSemaphoreWaitTime = std::numeric_limits<double>::max(); // infinite time value for BinarySemaphore
49 static HashMap<WebLayerID, WebGraphicsLayer*>& layerByIDMap()
51 static HashMap<WebLayerID, WebGraphicsLayer*> globalMap;
55 WebGraphicsLayer* WebGraphicsLayer::layerByID(WebKit::WebLayerID id)
57 HashMap<WebLayerID, WebGraphicsLayer*>& table = layerByIDMap();
58 HashMap<WebLayerID, WebGraphicsLayer*>::iterator it = table.find(id);
59 if (it == table.end())
64 static WebLayerID toWebLayerID(GraphicsLayer* layer)
66 return layer ? toWebGraphicsLayer(layer)->id() : 0;
69 void WebGraphicsLayer::didChangeLayerState()
71 m_shouldSyncLayerState = true;
73 client()->notifySyncRequired(this);
76 void WebGraphicsLayer::didChangeAnimations()
78 m_shouldSyncAnimations = true;
80 client()->notifySyncRequired(this);
83 void WebGraphicsLayer::didChangeChildren()
85 m_shouldSyncChildren = true;
87 client()->notifySyncRequired(this);
90 #if ENABLE(CSS_FILTERS)
91 void WebGraphicsLayer::didChangeFilters()
93 m_shouldSyncFilters = true;
95 client()->notifySyncRequired(this);
99 void WebGraphicsLayer::setShouldUpdateVisibleRect()
101 m_shouldUpdateVisibleRect = true;
102 for (size_t i = 0; i < children().size(); ++i)
103 toWebGraphicsLayer(children()[i])->setShouldUpdateVisibleRect();
105 toWebGraphicsLayer(replicaLayer())->setShouldUpdateVisibleRect();
108 void WebGraphicsLayer::didChangeGeometry()
110 didChangeLayerState();
111 setShouldUpdateVisibleRect();
114 WebGraphicsLayer::WebGraphicsLayer(GraphicsLayerClient* client)
115 : GraphicsLayer(client)
117 , m_inUpdateMode(false)
118 , m_shouldUpdateVisibleRect(true)
119 , m_shouldSyncLayerState(true)
120 , m_shouldSyncChildren(true)
121 , m_shouldSyncAnimations(true)
122 , m_fixedToViewport(false)
123 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
124 , m_isOverflow(false)
126 , m_canvasNeedsDisplay(false)
127 #if ENABLE(TIZEN_DONT_PURGE_PLATFORM_SURFACE_BACKINGSTORE_ON_NODE_DETACH_FROM_WEBLAYER_TREE)
128 , m_shouldSyncBackingStore(false)
130 , m_webGraphicsLayerClient(0)
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;
147 #if ENABLE(TIZEN_RECORDING_SURFACE_SET)
148 m_recordingSurfaceSet = new RecordingSurfaceSet();
149 m_recordingSurfaceSetStatus = RecordingSurfaceSetInit;
150 m_recordingSurfaceSetIsReplaying = false;
151 m_changedZoomSet = false;
152 m_nonCompositedLayer = false;
153 m_dirtyRects.clear();
154 #if ENABLE(TIZEN_RECORDING_SURFACE_PAINT_THREAD)
155 m_waitForSyncSemaphore.signal();
160 WebGraphicsLayer::~WebGraphicsLayer()
162 layerByIDMap().remove(id());
164 if (m_webGraphicsLayerClient) {
165 purgeBackingStores();
166 m_webGraphicsLayerClient->detachLayer(this);
171 void WebGraphicsLayer::willBeDestroyed()
173 GraphicsLayer::willBeDestroyed();
176 bool WebGraphicsLayer::setChildren(const Vector<GraphicsLayer*>& children)
178 bool ok = GraphicsLayer::setChildren(children);
181 for (int i = 0; i < children.size(); ++i) {
182 WebGraphicsLayer* child = toWebGraphicsLayer(children[i]);
183 child->setWebGraphicsLayerClient(m_webGraphicsLayerClient);
184 child->didChangeLayerState();
190 void WebGraphicsLayer::addChild(GraphicsLayer* layer)
192 GraphicsLayer::addChild(layer);
193 toWebGraphicsLayer(layer)->setWebGraphicsLayerClient(m_webGraphicsLayerClient);
194 toWebGraphicsLayer(layer)->didChangeLayerState();
198 void WebGraphicsLayer::addChildAtIndex(GraphicsLayer* layer, int index)
200 GraphicsLayer::addChildAtIndex(layer, index);
201 toWebGraphicsLayer(layer)->setWebGraphicsLayerClient(m_webGraphicsLayerClient);
202 toWebGraphicsLayer(layer)->didChangeLayerState();
206 void WebGraphicsLayer::addChildAbove(GraphicsLayer* layer, GraphicsLayer* sibling)
208 GraphicsLayer::addChildAbove(layer, sibling);
209 toWebGraphicsLayer(layer)->setWebGraphicsLayerClient(m_webGraphicsLayerClient);
210 toWebGraphicsLayer(layer)->didChangeLayerState();
214 void WebGraphicsLayer::addChildBelow(GraphicsLayer* layer, GraphicsLayer* sibling)
216 GraphicsLayer::addChildBelow(layer, sibling);
217 toWebGraphicsLayer(layer)->setWebGraphicsLayerClient(m_webGraphicsLayerClient);
218 toWebGraphicsLayer(layer)->didChangeLayerState();
222 bool WebGraphicsLayer::replaceChild(GraphicsLayer* oldChild, GraphicsLayer* newChild)
224 bool ok = GraphicsLayer::replaceChild(oldChild, newChild);
228 toWebGraphicsLayer(oldChild)->didChangeLayerState();
229 toWebGraphicsLayer(newChild)->setWebGraphicsLayerClient(m_webGraphicsLayerClient);
230 toWebGraphicsLayer(newChild)->didChangeLayerState();
234 void WebGraphicsLayer::removeFromParent()
236 if (WebGraphicsLayer* parentLayer = toWebGraphicsLayer(parent()))
237 parentLayer->didChangeChildren();
238 GraphicsLayer::removeFromParent();
240 didChangeLayerState();
243 void WebGraphicsLayer::setPosition(const FloatPoint& p)
248 GraphicsLayer::setPosition(p);
252 void WebGraphicsLayer::setAnchorPoint(const FloatPoint3D& p)
254 if (anchorPoint() == p)
257 GraphicsLayer::setAnchorPoint(p);
261 void WebGraphicsLayer::setSize(const FloatSize& size)
263 if (this->size() == size)
266 GraphicsLayer::setSize(size);
269 maskLayer()->setSize(size);
271 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
276 void WebGraphicsLayer::setTransform(const TransformationMatrix& t)
278 if (transform() == t)
281 GraphicsLayer::setTransform(t);
285 void WebGraphicsLayer::setChildrenTransform(const TransformationMatrix& t)
287 if (childrenTransform() == t)
290 GraphicsLayer::setChildrenTransform(t);
294 void WebGraphicsLayer::setPreserves3D(bool b)
296 if (preserves3D() == b)
299 GraphicsLayer::setPreserves3D(b);
303 void WebGraphicsLayer::setMasksToBounds(bool b)
305 if (masksToBounds() == b)
307 GraphicsLayer::setMasksToBounds(b);
311 void WebGraphicsLayer::setDrawsContent(bool b)
313 if (drawsContent() == b)
315 GraphicsLayer::setDrawsContent(b);
317 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
321 didChangeLayerState();
324 void WebGraphicsLayer::setContentsVisible(bool b)
326 if (contentsAreVisible() == b)
328 GraphicsLayer::setContentsVisible(b);
330 didChangeLayerState();
333 void WebGraphicsLayer::setContentsOpaque(bool b)
335 if (contentsOpaque() == b)
337 if (m_mainBackingStore)
338 m_mainBackingStore->setSupportsAlpha(!b);
339 GraphicsLayer::setContentsOpaque(b);
340 didChangeLayerState();
343 void WebGraphicsLayer::setBackfaceVisibility(bool b)
345 if (backfaceVisibility() == b)
348 GraphicsLayer::setBackfaceVisibility(b);
349 didChangeLayerState();
352 void WebGraphicsLayer::setOpacity(float opacity)
354 if (this->opacity() == opacity)
357 GraphicsLayer::setOpacity(opacity);
358 didChangeLayerState();
361 void WebGraphicsLayer::setContentsRect(const IntRect& r)
363 if (contentsRect() == r)
366 GraphicsLayer::setContentsRect(r);
367 didChangeLayerState();
370 void WebGraphicsLayer::setContentsNeedsDisplay()
372 RefPtr<Image> image = m_image;
373 setContentsToImage(0);
374 setContentsToImage(image.get());
375 m_canvasNeedsDisplay = true;
377 client()->notifySyncRequired(this);
381 #if ENABLE(CSS_FILTERS)
382 bool WebGraphicsLayer::setFilters(const FilterOperations& newFilters)
384 if (filters() == newFilters)
387 return GraphicsLayer::setFilters(newFilters);
392 void WebGraphicsLayer::setContentsToImage(Image* image)
394 if (image == m_image)
397 if (m_webGraphicsLayerClient) {
398 // We adopt first, in case this is the same frame - that way we avoid destroying and recreating the image.
399 newID = m_webGraphicsLayerClient->adoptImageBackingStore(image);
400 m_webGraphicsLayerClient->releaseImageBackingStore(m_layerInfo.imageBackingStoreID);
401 didChangeLayerState();
402 if (m_layerInfo.imageBackingStoreID && newID == m_layerInfo.imageBackingStoreID)
405 // If m_webGraphicsLayerClient is not set yet there should be no backing store ID.
406 ASSERT(!m_layerInfo.imageBackingStoreID);
407 didChangeLayerState();
410 m_layerInfo.imageBackingStoreID = newID;
412 GraphicsLayer::setContentsToImage(image);
415 void WebGraphicsLayer::setContentsToCanvas(PlatformLayer* platformLayer)
417 m_canvasPlatformLayer = platformLayer;
418 m_canvasNeedsDisplay = true;
419 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
420 if (!m_canvasPlatformLayer)
423 if (static_cast<TextureMapperPlatformLayer*>(m_canvasPlatformLayer)->contentType() == WebKit::WebLayerInfo::Canvas2DContentType)
424 m_layerInfo.contentType = WebKit::WebLayerInfo::Canvas2DContentType;
426 m_layerInfo.contentType = WebKit::WebLayerInfo::Canvas3DContentType;
430 client()->notifySyncRequired(this);
433 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
434 void WebGraphicsLayer::setContentsToMedia(PlatformLayer* platformLayer)
436 m_canvasPlatformLayer = platformLayer;
437 m_canvasNeedsDisplay = true;
438 m_layerInfo.contentType = WebKit::WebLayerInfo::MediaContentType;
441 client()->notifySyncRequired(this);
445 void WebGraphicsLayer::setMaskLayer(GraphicsLayer* layer)
447 if (layer == maskLayer())
450 GraphicsLayer::setMaskLayer(layer);
455 layer->setSize(size());
456 WebGraphicsLayer* webGraphicsLayer = toWebGraphicsLayer(layer);
457 webGraphicsLayer->setWebGraphicsLayerClient(m_webGraphicsLayerClient);
458 webGraphicsLayer->setMaskTarget(this);
459 webGraphicsLayer->didChangeLayerState();
460 didChangeLayerState();
464 void WebGraphicsLayer::setReplicatedByLayer(GraphicsLayer* layer)
466 if (layer == replicaLayer())
470 toWebGraphicsLayer(layer)->setWebGraphicsLayerClient(m_webGraphicsLayerClient);
472 GraphicsLayer::setReplicatedByLayer(layer);
473 didChangeLayerState();
476 #if ENABLE(TIZEN_RECORDING_SURFACE_SET)
477 IntRect WebGraphicsLayer::dirtyUnionRect()
479 return m_dirtyUnionRect;
482 void WebGraphicsLayer::setDirtyUnionRect(const IntRect& rect)
484 m_dirtyUnionRect = rect;
487 void WebGraphicsLayer::uniteDirtyUnionRect(const IntRect& rect)
489 m_dirtyUnionRect.unite(rect);
492 void WebGraphicsLayer::setDirtyRect(const IntRect& rect)
494 IntRect contentRect(0, 0, size().width(), size().height());
496 if (rect.isEmpty() || contentRect.isEmpty())
499 IntRect dirtyRect(intersection(rect, contentRect));
500 unsigned size = m_dirtyRects.size();
502 for (int index = size - 1; index > 0; index--) {
503 if (m_dirtyRects[index].contains(dirtyRect))
507 m_dirtyRects.append(dirtyRect);
510 void WebGraphicsLayer::dirtyRectInvalidate()
512 unsigned size = m_dirtyRects.size();
515 for (int index = 0; index < size; index++)
516 m_mainBackingStore->invalidate(m_dirtyRects[index]);
520 void WebGraphicsLayer::setNonCompositedLayer(bool isNonCompositedLayer)
522 m_nonCompositedLayer = isNonCompositedLayer;
525 bool WebGraphicsLayer::recordingSurfaceSetEnableGet()
527 if (m_webGraphicsLayerClient)
528 if (m_webGraphicsLayerClient->recordingSurfaceSetEnableGet() && m_nonCompositedLayer)
534 bool WebGraphicsLayer::recordingSurfaceSetLoadStartGet()
536 if (m_webGraphicsLayerClient)
537 return m_webGraphicsLayerClient->recordingSurfaceSetLoadStartGet();
541 bool WebGraphicsLayer::recordingSurfaceSetLoadFinishedGet()
543 if (m_webGraphicsLayerClient)
544 return m_webGraphicsLayerClient->recordingSurfaceSetLoadFinishedGet();
548 void WebGraphicsLayer::recordingSurfaceSetRebuild(RecordingSurfaceSet* recordingSurfaceSet, float scale)
550 size_t size = recordingSurfaceSet->size();
552 for (size_t index = 0; index < size; index++) {
553 if (recordingSurfaceSet->upToDate(index))
556 const WebCore::IntRect& rect = recordingSurfaceSet->bounds(index);
557 cairo_rectangle_t extents = {0, 0, static_cast<int>(rect.width() * scale), static_cast<int>(rect.height() * scale)};
558 RefPtr<cairo_surface_t> recordingSurfaceCairo = cairo_recording_surface_create(CAIRO_CONTENT_COLOR_ALPHA, &extents);
559 RefPtr<cairo_t> recordingContextCairo = cairo_create(recordingSurfaceCairo.get());
561 OwnPtr<WebCore::GraphicsContext> graphicsContext = adoptPtr(new GraphicsContext(recordingContextCairo.get()));
562 cairo_save(recordingContextCairo.get());
563 graphicsContext->save();
564 cairo_translate(recordingContextCairo.get(), -static_cast<int>(rect.x() * scale), -static_cast<int>(rect.y() * scale));
565 cairo_scale(recordingContextCairo.get(), scale, scale);
566 graphicsContext->clip(rect);
567 paintGraphicsLayerContents(*graphicsContext.get(), rect);
568 graphicsContext->restore();
569 cairo_restore(recordingContextCairo.get());
571 recordingSurfaceSet->setRecordingSurface(index, recordingSurfaceCairo.get(), recordingContextCairo.get(), m_mainBackingStore->tileSize());
575 void WebGraphicsLayer::recordingSurfaceSetRecord()
577 IntRect contentRect(0, 0, size().width(), size().height());
578 m_recordingSurfaceSetStatus = RecordingSurfaceSetInit;
580 if (recordingSurfaceSetLoadFinishedGet() || recordingSurfaceSetLoadStartGet() || m_changedZoomSet) {
581 m_recordingSurfaceSet->clear();
582 m_recordingSurfaceSet->add(contentRect, m_contentsScale);
584 unsigned size = m_dirtyRects.size();
585 for (unsigned n = 0; n < size; n++)
586 m_recordingSurfaceSet->add(m_dirtyRects[n], m_contentsScale);
589 recordingSurfaceSetRebuild(m_recordingSurfaceSet, m_contentsScale);
590 m_recordingSurfaceSetStatus = RecordingSurfaceSetComplete;
591 m_changedZoomSet = false;
592 m_dirtyRects.clear();
595 void WebGraphicsLayer::recordingSurfaceSetReplay(WebCore::GraphicsContext& graphicsContext, const WebCore::IntRect& rect)
597 if (m_recordingSurfaceSetStatus == RecordingSurfaceSetComplete) {
598 RefPtr<cairo_t> cairoContext = ((WebCore::PlatformContextCairo *)graphicsContext.platformContext())->cr();
599 m_recordingSurfaceSet->draw(cairoContext.get(), rect);
603 #if ENABLE(TIZEN_RECORDING_SURFACE_PAINT_THREAD)
604 void WebGraphicsLayer::updateTileBuffers()
606 m_mainBackingStore->updateTileBuffers();
607 m_waitForSyncSemaphore.signal();
610 void WebGraphicsLayer::scheduleUpdateTileBuffersAsync()
612 if (m_mainBackingStore->contentsFrozen() || !tiledBackingStoreUpdatesAllowed())
615 m_waitForSyncSemaphore.wait(cSemaphoreWaitTime);
616 m_mainBackingStore->setContentsInvalid(false);
617 m_mainBackingStore->updateTileBuffersBegin();
618 WebProcess::shared().paintThreadWorkQueue()->dispatch(bind(&WebGraphicsLayer::updateTileBuffers, this));
623 void WebGraphicsLayer::setNeedsDisplay()
625 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
626 if (!m_visibleRect.isEmpty()) {
627 setNeedsDisplayInRect(IntRect(m_visibleRect));
631 setNeedsDisplayInRect(IntRect(IntPoint::zero(), IntSize(size().width(), size().height())));
634 void WebGraphicsLayer::setNeedsDisplayInRect(const FloatRect& rect)
636 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING_PLUGIN_LAYER_EFL)
637 if (drawsContent() && m_layerInfo.contentType == WebKit::WebLayerInfo::MediaContentType) {
638 uniteDirtyUnionRect(IntRect(rect));
639 didChangeLayerState();
644 #if ENABLE(TIZEN_RECORDING_SURFACE_SET)
645 if (recordingSurfaceSetEnableGet()) {
646 setDirtyRect(IntRect(rect));
648 #if ENABLE(TIZEN_RECORDING_SURFACE_PAINT_THREAD)
649 if (m_mainBackingStore)
650 m_mainBackingStore->startTileBufferUpdateTimer();
652 if (m_mainBackingStore)
653 m_mainBackingStore->invalidate(IntRect(rect));
654 didChangeLayerState();
660 if (m_mainBackingStore)
661 m_mainBackingStore->invalidate(IntRect(rect));
662 didChangeLayerState();
665 WebLayerID WebGraphicsLayer::id() const
670 void WebGraphicsLayer::syncCompositingState(const FloatRect& rect)
672 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
673 if (!m_webGraphicsLayerClient)
677 if (WebGraphicsLayer* mask = toWebGraphicsLayer(maskLayer()))
678 mask->syncCompositingStateForThisLayerOnly();
680 if (WebGraphicsLayer* replica = toWebGraphicsLayer(replicaLayer()))
681 replica->syncCompositingStateForThisLayerOnly();
683 m_webGraphicsLayerClient->syncFixedLayers();
685 syncCompositingStateForThisLayerOnly();
687 for (size_t i = 0; i < children().size(); ++i)
688 children()[i]->syncCompositingState(rect);
691 WebGraphicsLayer* toWebGraphicsLayer(GraphicsLayer* layer)
693 return static_cast<WebGraphicsLayer*>(layer);
696 void WebGraphicsLayer::syncChildren()
698 if (!m_shouldSyncChildren)
700 m_shouldSyncChildren = false;
701 Vector<WebLayerID> childIDs;
702 for (size_t i = 0; i < children().size(); ++i)
703 childIDs.append(toWebLayerID(children()[i]));
705 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
706 if (m_webGraphicsLayerClient)
708 m_webGraphicsLayerClient->syncLayerChildren(m_id, childIDs);
711 #if ENABLE(CSS_FILTERS)
712 void WebGraphicsLayer::syncFilters()
714 if (!m_shouldSyncFilters)
716 m_shouldSyncFilters = false;
717 m_webGraphicsLayerClient->syncLayerFilters(m_id, filters());
721 void WebGraphicsLayer::syncLayerState()
723 if (!m_shouldSyncLayerState)
726 m_shouldSyncLayerState = false;
727 m_layerInfo.fixedToViewport = fixedToViewport();
728 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_SCROLLBAR)
729 m_layerInfo.isScrollbar = isScrollbar();
731 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
732 m_layerInfo.isScrollingContentsLayer = isOverflow();
733 if (m_layerInfo.isScrollingContentsLayer)
734 m_layerInfo.boundsOrigin = parent() ? parent()->boundsOrigin() : boundsOrigin();
737 m_layerInfo.anchorPoint = anchorPoint();
738 m_layerInfo.backfaceVisible = backfaceVisibility();
739 m_layerInfo.childrenTransform = childrenTransform();
740 m_layerInfo.contentsOpaque = contentsOpaque();
741 m_layerInfo.contentsRect = contentsRect();
742 m_layerInfo.drawsContent = drawsContent();
743 m_layerInfo.contentsVisible = contentsAreVisible();
744 m_layerInfo.mask = toWebLayerID(maskLayer());
745 m_layerInfo.masksToBounds = masksToBounds();
746 m_layerInfo.opacity = opacity();
747 m_layerInfo.parent = toWebLayerID(parent());
748 m_layerInfo.pos = position();
749 m_layerInfo.preserves3D = preserves3D();
750 m_layerInfo.replica = toWebLayerID(replicaLayer());
751 m_layerInfo.size = size();
752 m_layerInfo.transform = transform();
754 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
755 if (m_webGraphicsLayerClient)
757 m_webGraphicsLayerClient->syncLayerState(m_id, m_layerInfo);
759 #if ENABLE(TIZEN_DONT_PURGE_PLATFORM_SURFACE_BACKINGSTORE_ON_NODE_DETACH_FROM_WEBLAYER_TREE)
760 syncBackingStoreIfNeeded();
764 void WebGraphicsLayer::syncAnimations()
766 if (!m_shouldSyncAnimations)
769 m_shouldSyncAnimations = false;
771 m_webGraphicsLayerClient->setLayerAnimations(m_id, m_animations);
774 void WebGraphicsLayer::syncCanvas()
776 if (!m_canvasNeedsDisplay)
779 if (!m_canvasPlatformLayer)
782 #if USE(GRAPHICS_SURFACE) || ENABLE(TIZEN_CANVAS_GRAPHICS_SURFACE)
783 uint64_t token = m_canvasPlatformLayer->graphicsSurfaceToken();
786 uint32_t frontBuffer = m_canvasPlatformLayer->copyToGraphicsSurface();
787 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
788 int flags = m_canvasPlatformLayer->graphicsSurfaceFlags();
789 if (m_webGraphicsLayerClient)
790 m_webGraphicsLayerClient->syncCanvas(m_id, IntSize(contentsRect().width(), contentsRect().height()), token, frontBuffer, flags);
792 m_webGraphicsLayerClient->syncCanvas(m_id, IntSize(size().width(), size().height()), token, frontBuffer);
795 m_canvasNeedsDisplay = false;
798 void WebGraphicsLayer::ensureImageBackingStore()
803 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
804 if (!m_webGraphicsLayerClient)
808 if (!m_layerInfo.imageBackingStoreID)
809 m_layerInfo.imageBackingStoreID = m_webGraphicsLayerClient->adoptImageBackingStore(m_image.get());
812 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING_PLUGIN_LAYER_EFL)
813 void WebGraphicsLayer::ensureMediaPlatformSurfaceID()
815 if (!m_canvasPlatformLayer || m_layerInfo.contentType != WebKit::WebLayerInfo::MediaContentType)
818 TextureMapperPlatformLayer* platformLayer = static_cast<TextureMapperPlatformLayer*>(m_canvasPlatformLayer);
820 if (platformLayer->needsSyncLayerState()) {
821 m_shouldSyncLayerState = true;
822 platformLayer->setNeedsSyncLayerState(false);
825 if (!platformLayer->graphicsSurfaceToken())
833 #if ENABLE(TIZEN_DONT_PURGE_PLATFORM_SURFACE_BACKINGSTORE_ON_NODE_DETACH_FROM_WEBLAYER_TREE)
834 void WebGraphicsLayer::syncBackingStoreIfNeeded()
836 if (m_shouldSyncBackingStore) {
837 if (m_mainBackingStore)
838 m_mainBackingStore->reviewTiles();
839 m_shouldSyncBackingStore = false;
844 void WebGraphicsLayer::syncCompositingStateForThisLayerOnly()
846 // The remote image might have been released by purgeBackingStores.
847 ensureImageBackingStore();
851 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING_PLUGIN_LAYER_EFL)
852 ensureMediaPlatformSurfaceID();
854 computeTransformedVisibleRect();
856 #if ENABLE(CSS_FILTERS)
859 updateContentBuffers();
863 void WebGraphicsLayer::tiledBackingStorePaintBegin()
865 #if ENABLE(TIZEN_RECORDING_SURFACE_SET)
866 if (recordingSurfaceSetEnableGet() && m_mainBackingStore) {
867 if (m_dirtyRects.isEmpty())
870 recordingSurfaceSetRecord();
875 void WebGraphicsLayer::setRootLayer(bool isRoot)
877 m_layerInfo.isRootLayer = isRoot;
878 didChangeLayerState();
881 void WebGraphicsLayer::setVisibleContentRectTrajectoryVector(const FloatPoint& trajectoryVector)
883 #if ENABLE(TIZEN_RECORDING_SURFACE_PAINT_THREAD)
884 if (recordingSurfaceSetEnableGet())
885 m_waitForSyncSemaphore.wait(cSemaphoreWaitTime);
888 if (m_mainBackingStore)
889 m_mainBackingStore->coverWithTilesIfNeeded(trajectoryVector);
891 #if ENABLE(TIZEN_RECORDING_SURFACE_PAINT_THREAD)
892 if (recordingSurfaceSetEnableGet())
893 m_waitForSyncSemaphore.signal();
897 void WebGraphicsLayer::setContentsScale(float scale)
899 m_contentsScale = scale;
900 adjustContentsScale();
903 float WebGraphicsLayer::effectiveContentsScale()
905 return shouldUseTiledBackingStore() ? m_contentsScale : 1;
908 void WebGraphicsLayer::adjustContentsScale()
913 if (!m_mainBackingStore || m_mainBackingStore->contentsScale() == effectiveContentsScale())
916 #if ENABLE(TIZEN_RECORDING_SURFACE_SET)
917 if (recordingSurfaceSetEnableGet()) {
918 #if ENABLE(TIZEN_RECORDING_SURFACE_PAINT_THREAD)
919 m_waitForSyncSemaphore.wait(cSemaphoreWaitTime);
921 m_changedZoomSet = true;
922 recordingSurfaceSetRecord();
926 // Between creating the new backing store and painting the content,
927 // we do not want to drop the previous one as that might result in
928 // briefly seeing flickering as the old tiles may be dropped before
929 // something replaces them.
930 m_previousBackingStore = m_mainBackingStore.release();
932 // No reason to save the previous backing store for non-visible areas.
933 m_previousBackingStore->removeAllNonVisibleTiles();
935 createBackingStore();
937 #if ENABLE(TIZEN_RECORDING_SURFACE_PAINT_THREAD)
938 if (recordingSurfaceSetEnableGet())
939 m_waitForSyncSemaphore.signal();
943 void WebGraphicsLayer::createBackingStore()
945 if (SharedPlatformSurfaceEfl::supportsLockSurfaceExtension()) {
946 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
947 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
948 if (m_webGraphicsLayerClient->isGLAccelerationMode())
949 m_mainBackingStore = adoptPtr(new TiledBackingStore(this, TiledBackingStoreRemotePlatformSurfaceTileBackend::create(this)));
951 m_mainBackingStore = adoptPtr(new TiledBackingStore(this, TiledBackingStoreRemoteTileBackend::create(this)));
953 m_mainBackingStore = adoptPtr(new TiledBackingStore(this, TiledBackingStoreRemotePlatformSurfaceTileBackend::create(this)));
957 m_mainBackingStore = adoptPtr(new TiledBackingStore(this, TiledBackingStoreRemoteTileBackend::create(this)));
959 m_mainBackingStore->setSupportsAlpha(!contentsOpaque());
960 m_mainBackingStore->setContentsScale(effectiveContentsScale());
963 void WebGraphicsLayer::tiledBackingStorePaint(GraphicsContext* context, const IntRect& rect)
968 #if ENABLE(TIZEN_RECORDING_SURFACE_SET)
969 if (recordingSurfaceSetEnableGet()) {
970 recordingSurfaceSetReplay(*context, rect);
975 paintGraphicsLayerContents(*context, rect);
978 void WebGraphicsLayer::tiledBackingStorePaintEnd(const Vector<IntRect>& updatedRects)
980 #if ENABLE(TIZEN_RECORDING_SURFACE_PAINT_THREAD)
981 if (recordingSurfaceSetEnableGet())
982 didChangeLayerState();
986 bool WebGraphicsLayer::tiledBackingStoreUpdatesAllowed() const
991 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
992 if (!m_webGraphicsLayerClient)
996 return m_webGraphicsLayerClient->layerTreeTileUpdatesAllowed();
999 IntRect WebGraphicsLayer::tiledBackingStoreContentsRect()
1001 return IntRect(0, 0, size().width(), size().height());
1004 bool WebGraphicsLayer::shouldUseTiledBackingStore()
1006 return !selfOrAncestorHaveNonAffineTransforms();
1009 IntRect WebGraphicsLayer::tiledBackingStoreVisibleRect()
1011 if (!shouldUseTiledBackingStore())
1012 return tiledBackingStoreContentsRect();
1014 // Non-invertible layers are not visible.
1015 if (!m_layerTransform.combined().isInvertible())
1018 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
1019 if (!m_webGraphicsLayerClient)
1023 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
1024 if (!m_visibleRect.isEmpty())
1025 return m_visibleRect;
1028 // Return a projection of the visible rect (surface coordinates) onto the layer's plane (layer coordinates).
1029 // The resulting quad might be squewed and the visible rect is the bounding box of this quad,
1030 // so it might spread further than the real visible area (and then even more amplified by the cover rect multiplier).
1031 return enclosingIntRect(m_layerTransform.combined().inverse().clampedBoundsOfProjectedQuad(FloatQuad(FloatRect(m_webGraphicsLayerClient->visibleContentsRect()))));
1034 Color WebGraphicsLayer::tiledBackingStoreBackgroundColor() const
1036 return contentsOpaque() ? Color::white : Color::transparent;
1039 PassOwnPtr<WebCore::GraphicsContext> WebGraphicsLayer::beginContentUpdate(const WebCore::IntSize& size, ShareableSurface::Handle& handle, WebCore::IntPoint& offset)
1041 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
1042 if (!m_webGraphicsLayerClient)
1043 return PassOwnPtr<WebCore::GraphicsContext>();
1046 return m_webGraphicsLayerClient->beginContentUpdate(size, contentsOpaque() ? 0 : ShareableBitmap::SupportsAlpha, handle, offset);
1049 void WebGraphicsLayer::createTile(int tileID, const SurfaceUpdateInfo& updateInfo, const IntRect& targetRect)
1051 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
1052 if (m_webGraphicsLayerClient)
1054 m_webGraphicsLayerClient->createTile(id(), tileID, updateInfo, targetRect);
1057 void WebGraphicsLayer::updateTile(int tileID, const SurfaceUpdateInfo& updateInfo, const IntRect& targetRect)
1059 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
1060 if (m_webGraphicsLayerClient)
1062 m_webGraphicsLayerClient->updateTile(id(), tileID, updateInfo, targetRect);
1065 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
1066 void WebGraphicsLayer::freePlatformSurface(int platformSurfaceID)
1068 if (m_canvasPlatformLayer)
1069 m_canvasPlatformLayer->freePlatformSurface(platformSurfaceID);
1072 void WebGraphicsLayer::removePlatformSurface(int platformSurfaceID)
1074 if (m_canvasPlatformLayer)
1075 m_canvasPlatformLayer->removePlatformSurface(platformSurfaceID);
1076 #if ENABLE(TIZEN_CANVAS_CAIRO_GLES_RENDERING) || ENABLE(TIZEN_CANVAS_SURFACE_LOCKING)
1077 if (m_canvasPlatformLayer && m_layerInfo.contentType == WebKit::WebLayerInfo::Canvas2DContentType)
1078 m_canvasNeedsDisplay = true;
1082 bool WebGraphicsLayer::swapPlatformSurfaces()
1084 if (m_canvasPlatformLayer)
1085 return m_canvasPlatformLayer->swapPlatformSurfaces();
1090 void WebGraphicsLayer::removeTile(int tileID)
1092 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
1093 if (m_webGraphicsLayerClient)
1095 m_webGraphicsLayerClient->removeTile(id(), tileID);
1098 void WebGraphicsLayer::updateContentBuffers()
1100 if (!drawsContent()) {
1101 m_mainBackingStore.clear();
1102 m_previousBackingStore.clear();
1106 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING_PLUGIN_LAYER_EFL)
1107 if (m_layerInfo.contentType == WebKit::WebLayerInfo::MediaContentType) {
1108 m_mainBackingStore.clear();
1109 m_previousBackingStore.clear();
1111 if (dirtyUnionRect().isEmpty())
1114 if (m_canvasPlatformLayer) {
1115 LayoutSize offset = offsetFromRenderer();
1116 LayoutRect clipRect(dirtyUnionRect());
1117 clipRect.move(offset);
1119 // Update media area.
1120 m_canvasPlatformLayer->updateContentBuffers(pixelSnappedIntRect(clipRect));
1122 setDirtyUnionRect(IntRect());
1129 m_inUpdateMode = true;
1130 // This is the only place we (re)create the main tiled backing store, once we
1131 // have a remote client and we are ready to send our data to the UI process.
1132 if (!m_mainBackingStore)
1133 createBackingStore();
1135 #if ENABLE(TIZEN_RECORDING_SURFACE_PAINT_THREAD)
1136 if (recordingSurfaceSetEnableGet()) {
1137 m_waitForSyncSemaphore.wait(cSemaphoreWaitTime);
1138 m_waitForSyncSemaphore.signal();
1140 scheduleUpdateTileBuffersAsync();
1142 m_mainBackingStore->updateTileBuffers();
1144 m_mainBackingStore->updateTileBuffers();
1146 m_inUpdateMode = false;
1148 // The previous backing store is kept around to avoid flickering between
1149 // removing the existing tiles and painting the new ones. The first time
1150 // the visibleRect is full painted we remove the previous backing store.
1151 if (m_mainBackingStore->visibleAreaIsCovered())
1152 m_previousBackingStore.clear();
1155 void WebGraphicsLayer::purgeBackingStores()
1157 #if ENABLE(TIZEN_RECORDING_SURFACE_PAINT_THREAD)
1158 if (recordingSurfaceSetEnableGet()) {
1159 m_waitForSyncSemaphore.wait(cSemaphoreWaitTime);
1160 m_waitForSyncSemaphore.signal();
1163 m_mainBackingStore.clear();
1164 m_previousBackingStore.clear();
1166 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
1167 if (m_webGraphicsLayerClient)
1169 if (m_layerInfo.imageBackingStoreID) {
1170 m_webGraphicsLayerClient->releaseImageBackingStore(m_layerInfo.imageBackingStoreID);
1171 m_layerInfo.imageBackingStoreID = 0;
1174 didChangeLayerState();
1175 didChangeChildren();
1178 void WebGraphicsLayer::setWebGraphicsLayerClient(WebKit::WebGraphicsLayerClient* client)
1180 if (m_webGraphicsLayerClient == client)
1183 if (WebGraphicsLayer* replica = toWebGraphicsLayer(replicaLayer()))
1184 replica->setWebGraphicsLayerClient(client);
1185 if (WebGraphicsLayer* mask = toWebGraphicsLayer(maskLayer()))
1186 mask->setWebGraphicsLayerClient(client);
1187 for (size_t i = 0; i < children().size(); ++i) {
1188 WebGraphicsLayer* layer = toWebGraphicsLayer(this->children()[i]);
1189 layer->setWebGraphicsLayerClient(client);
1192 // We have to release resources on the UI process here if the remote client has changed or is removed.
1193 if (m_webGraphicsLayerClient) {
1194 #if ENABLE(TIZEN_DONT_PURGE_PLATFORM_SURFACE_BACKINGSTORE_ON_NODE_DETACH_FROM_WEBLAYER_TREE)
1195 didChangeLayerState();
1196 didChangeChildren();
1197 m_shouldSyncBackingStore = true;
1199 purgeBackingStores();
1200 #endif // ENABLE(TIZEN_DONT_PURGE_PLATFORM_SURFACE_BACKINGSTORE_ON_NODE_DETACH_FROM_WEBLAYER_TREE)
1201 m_webGraphicsLayerClient->detachLayer(this);
1203 m_webGraphicsLayerClient = client;
1205 client->attachLayer(this);
1208 void WebGraphicsLayer::adjustVisibleRect()
1210 if (m_mainBackingStore)
1211 m_mainBackingStore->coverWithTilesIfNeeded();
1214 bool WebGraphicsLayer::hasPendingVisibleChanges()
1216 if (opacity() < 0.01 && !m_animations.hasActiveAnimationsOfType(AnimatedPropertyOpacity))
1219 for (size_t i = 0; i < children().size(); ++i) {
1220 if (toWebGraphicsLayer(children()[i])->hasPendingVisibleChanges())
1224 if (!m_shouldSyncLayerState && !m_shouldSyncChildren && !m_shouldSyncFilters && !m_shouldSyncAnimations && !m_canvasNeedsDisplay)
1227 return selfOrAncestorHaveNonAffineTransforms() || !tiledBackingStoreVisibleRect().isEmpty();
1231 void WebGraphicsLayer::computeTransformedVisibleRect()
1233 if (!m_shouldUpdateVisibleRect)
1235 m_shouldUpdateVisibleRect = false;
1236 m_layerTransform.setLocalTransform(transform());
1237 m_layerTransform.setPosition(position());
1238 m_layerTransform.setAnchorPoint(anchorPoint());
1239 m_layerTransform.setSize(size());
1240 m_layerTransform.setFlattening(!preserves3D());
1241 m_layerTransform.setChildrenTransform(childrenTransform());
1242 m_layerTransform.combineTransforms(parent() ? toWebGraphicsLayer(parent())->m_layerTransform.combinedForChildren() : TransformationMatrix());
1244 // The combined transform will be used in tiledBackingStoreVisibleRect.
1245 adjustVisibleRect();
1246 adjustContentsScale();
1249 static PassOwnPtr<GraphicsLayer> createWebGraphicsLayer(GraphicsLayerClient* client)
1251 return adoptPtr(new WebGraphicsLayer(client));
1254 void WebGraphicsLayer::initFactory()
1256 GraphicsLayer::setGraphicsLayerFactory(createWebGraphicsLayer);
1259 bool WebGraphicsLayer::selfOrAncestorHaveNonAffineTransforms()
1261 if (m_animations.hasActiveAnimationsOfType(AnimatedPropertyWebkitTransform))
1264 if (!m_layerTransform.combined().isAffine())
1270 #if ENABLE(TIZEN_CUTOFF_TILES_OVER_MEMORY_LIMIT)
1271 bool WebGraphicsLayer::selfOrAncestorHasActiveTransformAnimation() const
1273 if (m_animations.hasActiveAnimationsOfType(AnimatedPropertyWebkitTransform))
1279 return toWebGraphicsLayer(parent())->selfOrAncestorHasActiveTransformAnimation();
1283 bool WebGraphicsLayer::addAnimation(const KeyframeValueList& valueList, const IntSize& boxSize, const Animation* anim, const String& keyframesName, double timeOffset)
1285 ASSERT(!keyframesName.isEmpty());
1287 if (!anim || anim->isEmptyOrZeroDuration() || valueList.size() < 2 || (valueList.property() != AnimatedPropertyWebkitTransform && valueList.property() != AnimatedPropertyOpacity))
1290 bool listsMatch = false;
1291 bool ignoredHasBigRotation;
1293 if (valueList.property() == AnimatedPropertyWebkitTransform)
1294 listsMatch = validateTransformOperations(valueList, ignoredHasBigRotation) >= 0;
1296 m_animations.add(GraphicsLayerAnimation(keyframesName, valueList, boxSize, anim, WTF::currentTime() - timeOffset, listsMatch));
1297 m_animationStartedTimer.startOneShot(0);
1298 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
1299 didChangeAnimations();
1301 didChangeLayerState();
1305 void WebGraphicsLayer::pauseAnimation(const String& animationName, double timeOffset)
1307 m_animations.pause(animationName, timeOffset);
1308 didChangeAnimations();
1311 void WebGraphicsLayer::removeAnimation(const String& animationName)
1313 m_animations.remove(animationName);
1314 didChangeAnimations();
1317 void WebGraphicsLayer::animationStartedTimerFired(Timer<WebGraphicsLayer>*)
1319 client()->notifyAnimationStarted(this, /* DOM time */ WTF::currentTime());
1322 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
1323 void WebGraphicsLayer::setIsOverflow(const bool b)
1325 if (m_isOverflow == b)
1329 didChangeLayerState();
1333 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_SCROLLBAR)
1334 void WebGraphicsLayer::startAnimation()
1337 if (m_animationTimer.isActive())
1338 m_animationTimer.stop();
1339 m_animationTimer.startOneShot(1.0);
1342 void WebGraphicsLayer::animationTimerFired(Timer<WebGraphicsLayer>*)
1348 #if ENABLE(TIZEN_CUTOFF_TILES_OVER_MEMORY_LIMIT)
1349 Vector<TileCutOffInfo> WebGraphicsLayer::getCutOffInfoList()
1351 if (!m_mainBackingStore)
1352 return Vector<TileCutOffInfo>();
1354 return m_mainBackingStore->getCutOffInfoList();
1357 void WebGraphicsLayer::setCutOffDistance(double distance)
1359 if (!m_mainBackingStore)
1362 if (!selfOrAncestorHasActiveTransformAnimation())
1363 m_mainBackingStore->setCutOffDistance(distance);