Implement EGL Lock Surface extension runtime check
[profile/ivi/webkit-efl.git] / Source / WebKit2 / WebProcess / WebPage / LayerTreeCoordinator / WebGraphicsLayer.cpp
1 /*
2  Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
3
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.
8
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.
13
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.
18  */
19
20 #include "config.h"
21
22 #if USE(UI_SIDE_COMPOSITING)
23 #include "WebGraphicsLayer.h"
24
25 #include "BackingStore.h"
26 #include "FloatQuad.h"
27 #include "Frame.h"
28 #include "FrameView.h"
29 #include "GraphicsContext.h"
30 #include "GraphicsLayer.h"
31 #include "LayerTreeCoordinatorProxyMessages.h"
32 #include "Page.h"
33 #include "TextureMapperPlatformLayer.h"
34 #include "TiledBackingStoreRemoteTile.h"
35 #include "SharedPlatformSurfaceEfl.h"
36 #include "WebPage.h"
37 #include <wtf/CurrentTime.h>
38 #include <wtf/HashMap.h>
39 #include <wtf/text/CString.h>
40
41 using namespace WebKit;
42
43 namespace WebCore {
44
45 #if ENABLE(TIZEN_RECORDING_SURFACE_PAINT_THREAD)
46 static const double cSemaphoreWaitTime = std::numeric_limits<double>::max(); // infinite time value for BinarySemaphore
47 #endif
48
49 static HashMap<WebLayerID, WebGraphicsLayer*>& layerByIDMap()
50 {
51     static HashMap<WebLayerID, WebGraphicsLayer*> globalMap;
52     return globalMap;
53 }
54
55 WebGraphicsLayer* WebGraphicsLayer::layerByID(WebKit::WebLayerID id)
56 {
57     HashMap<WebLayerID, WebGraphicsLayer*>& table = layerByIDMap();
58     HashMap<WebLayerID, WebGraphicsLayer*>::iterator it = table.find(id);
59     if (it == table.end())
60         return 0;
61     return it->second;
62 }
63
64 static WebLayerID toWebLayerID(GraphicsLayer* layer)
65 {
66     return layer ? toWebGraphicsLayer(layer)->id() : 0;
67 }
68
69 void WebGraphicsLayer::didChangeLayerState()
70 {
71     m_shouldSyncLayerState = true;
72     if (client())
73         client()->notifySyncRequired(this);
74 }
75
76 void WebGraphicsLayer::didChangeAnimations()
77 {
78     m_shouldSyncAnimations = true;
79     if (client())
80         client()->notifySyncRequired(this);
81 }
82
83 void WebGraphicsLayer::didChangeChildren()
84 {
85     m_shouldSyncChildren = true;
86     if (client())
87         client()->notifySyncRequired(this);
88 }
89
90 #if ENABLE(CSS_FILTERS)
91 void WebGraphicsLayer::didChangeFilters()
92 {
93     m_shouldSyncFilters = true;
94     if (client())
95         client()->notifySyncRequired(this);
96 }
97 #endif
98
99 void WebGraphicsLayer::setShouldUpdateVisibleRect()
100 {
101     m_shouldUpdateVisibleRect = true;
102     for (size_t i = 0; i < children().size(); ++i)
103         toWebGraphicsLayer(children()[i])->setShouldUpdateVisibleRect();
104     if (replicaLayer())
105         toWebGraphicsLayer(replicaLayer())->setShouldUpdateVisibleRect();
106 }
107
108 void WebGraphicsLayer::didChangeGeometry()
109 {
110     didChangeLayerState();
111     setShouldUpdateVisibleRect();
112 }
113
114 WebGraphicsLayer::WebGraphicsLayer(GraphicsLayerClient* client)
115     : GraphicsLayer(client)
116     , m_maskTarget(0)
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)
125 #endif
126     , m_canvasNeedsDisplay(false)
127 #if ENABLE(TIZEN_DONT_PURGE_PLATFORM_SURFACE_BACKINGSTORE_ON_NODE_DETACH_FROM_WEBLAYER_TREE)
128     , m_shouldSyncBackingStore(false)
129 #endif
130     , m_webGraphicsLayerClient(0)
131     , m_contentsScale(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)
136 #endif
137 {
138     static WebLayerID nextLayerID = 1;
139     m_id = nextLayerID++;
140     layerByIDMap().add(id(), this);
141
142 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
143     m_layerInfo.isRootLayer = false;
144     m_layerInfo.contentType = WebKit::WebLayerInfo::HTMLContentType;
145 #endif
146
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();
156 #endif
157 #endif
158 }
159
160 WebGraphicsLayer::~WebGraphicsLayer()
161 {
162     layerByIDMap().remove(id());
163
164     if (m_webGraphicsLayerClient) {
165         purgeBackingStores();
166         m_webGraphicsLayerClient->detachLayer(this);
167     }
168     willBeDestroyed();
169 }
170
171 void WebGraphicsLayer::willBeDestroyed()
172 {
173     GraphicsLayer::willBeDestroyed();
174 }
175
176 bool WebGraphicsLayer::setChildren(const Vector<GraphicsLayer*>& children)
177 {
178     bool ok = GraphicsLayer::setChildren(children);
179     if (!ok)
180         return false;
181     for (int i = 0; i < children.size(); ++i) {
182         WebGraphicsLayer* child = toWebGraphicsLayer(children[i]);
183         child->setWebGraphicsLayerClient(m_webGraphicsLayerClient);
184         child->didChangeLayerState();
185     }
186     didChangeChildren();
187     return true;
188 }
189
190 void WebGraphicsLayer::addChild(GraphicsLayer* layer)
191 {
192     GraphicsLayer::addChild(layer);
193     toWebGraphicsLayer(layer)->setWebGraphicsLayerClient(m_webGraphicsLayerClient);
194     toWebGraphicsLayer(layer)->didChangeLayerState();
195     didChangeChildren();
196 }
197
198 void WebGraphicsLayer::addChildAtIndex(GraphicsLayer* layer, int index)
199 {
200     GraphicsLayer::addChildAtIndex(layer, index);
201     toWebGraphicsLayer(layer)->setWebGraphicsLayerClient(m_webGraphicsLayerClient);
202     toWebGraphicsLayer(layer)->didChangeLayerState();
203     didChangeChildren();
204 }
205
206 void WebGraphicsLayer::addChildAbove(GraphicsLayer* layer, GraphicsLayer* sibling)
207 {
208     GraphicsLayer::addChildAbove(layer, sibling);
209     toWebGraphicsLayer(layer)->setWebGraphicsLayerClient(m_webGraphicsLayerClient);
210     toWebGraphicsLayer(layer)->didChangeLayerState();
211     didChangeChildren();
212 }
213
214 void WebGraphicsLayer::addChildBelow(GraphicsLayer* layer, GraphicsLayer* sibling)
215 {
216     GraphicsLayer::addChildBelow(layer, sibling);
217     toWebGraphicsLayer(layer)->setWebGraphicsLayerClient(m_webGraphicsLayerClient);
218     toWebGraphicsLayer(layer)->didChangeLayerState();
219     didChangeChildren();
220 }
221
222 bool WebGraphicsLayer::replaceChild(GraphicsLayer* oldChild, GraphicsLayer* newChild)
223 {
224     bool ok = GraphicsLayer::replaceChild(oldChild, newChild);
225     if (!ok)
226         return false;
227     didChangeChildren();
228     toWebGraphicsLayer(oldChild)->didChangeLayerState();
229     toWebGraphicsLayer(newChild)->setWebGraphicsLayerClient(m_webGraphicsLayerClient);
230     toWebGraphicsLayer(newChild)->didChangeLayerState();
231     return true;
232 }
233
234 void WebGraphicsLayer::removeFromParent()
235 {
236     if (WebGraphicsLayer* parentLayer = toWebGraphicsLayer(parent()))
237         parentLayer->didChangeChildren();
238     GraphicsLayer::removeFromParent();
239
240     didChangeLayerState();
241 }
242
243 void WebGraphicsLayer::setPosition(const FloatPoint& p)
244 {
245     if (position() == p)
246         return;
247
248     GraphicsLayer::setPosition(p);
249     didChangeGeometry();
250 }
251
252 void WebGraphicsLayer::setAnchorPoint(const FloatPoint3D& p)
253 {
254     if (anchorPoint() == p)
255         return;
256
257     GraphicsLayer::setAnchorPoint(p);
258     didChangeGeometry();
259 }
260
261 void WebGraphicsLayer::setSize(const FloatSize& size)
262 {
263     if (this->size() == size)
264         return;
265
266     GraphicsLayer::setSize(size);
267     setNeedsDisplay();
268     if (maskLayer())
269         maskLayer()->setSize(size);
270     didChangeGeometry();
271 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
272     adjustVisibleRect();
273 #endif
274 }
275
276 void WebGraphicsLayer::setTransform(const TransformationMatrix& t)
277 {
278     if (transform() == t)
279         return;
280
281     GraphicsLayer::setTransform(t);
282     didChangeGeometry();
283 }
284
285 void WebGraphicsLayer::setChildrenTransform(const TransformationMatrix& t)
286 {
287     if (childrenTransform() == t)
288         return;
289
290     GraphicsLayer::setChildrenTransform(t);
291     didChangeGeometry();
292 }
293
294 void WebGraphicsLayer::setPreserves3D(bool b)
295 {
296     if (preserves3D() == b)
297         return;
298
299     GraphicsLayer::setPreserves3D(b);
300     didChangeGeometry();
301 }
302
303 void WebGraphicsLayer::setMasksToBounds(bool b)
304 {
305     if (masksToBounds() == b)
306         return;
307     GraphicsLayer::setMasksToBounds(b);
308     didChangeGeometry();
309 }
310
311 void WebGraphicsLayer::setDrawsContent(bool b)
312 {
313     if (drawsContent() == b)
314         return;
315     GraphicsLayer::setDrawsContent(b);
316
317 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
318     if (b)
319         setNeedsDisplay();
320 #endif
321     didChangeLayerState();
322 }
323
324 void WebGraphicsLayer::setContentsVisible(bool b)
325 {
326     if (contentsAreVisible() == b)
327         return;
328     GraphicsLayer::setContentsVisible(b);
329
330     didChangeLayerState();
331 }
332
333 void WebGraphicsLayer::setContentsOpaque(bool b)
334 {
335     if (contentsOpaque() == b)
336         return;
337     if (m_mainBackingStore)
338         m_mainBackingStore->setSupportsAlpha(!b);
339     GraphicsLayer::setContentsOpaque(b);
340     didChangeLayerState();
341 }
342
343 void WebGraphicsLayer::setBackfaceVisibility(bool b)
344 {
345     if (backfaceVisibility() == b)
346         return;
347
348     GraphicsLayer::setBackfaceVisibility(b);
349     didChangeLayerState();
350 }
351
352 void WebGraphicsLayer::setOpacity(float opacity)
353 {
354     if (this->opacity() == opacity)
355         return;
356
357     GraphicsLayer::setOpacity(opacity);
358     didChangeLayerState();
359 }
360
361 void WebGraphicsLayer::setContentsRect(const IntRect& r)
362 {
363     if (contentsRect() == r)
364         return;
365
366     GraphicsLayer::setContentsRect(r);
367     didChangeLayerState();
368 }
369
370 void WebGraphicsLayer::setContentsNeedsDisplay()
371 {
372     RefPtr<Image> image = m_image;
373     setContentsToImage(0);
374     setContentsToImage(image.get());
375     m_canvasNeedsDisplay = true;
376     if (client())
377         client()->notifySyncRequired(this);
378 }
379
380
381 #if ENABLE(CSS_FILTERS)
382 bool WebGraphicsLayer::setFilters(const FilterOperations& newFilters)
383 {
384     if (filters() == newFilters)
385         return true;
386     didChangeFilters();
387     return GraphicsLayer::setFilters(newFilters);
388 }
389 #endif
390
391
392 void WebGraphicsLayer::setContentsToImage(Image* image)
393 {
394     if (image == m_image)
395         return;
396     int64_t newID = 0;
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)
403             return;
404     } else {
405         // If m_webGraphicsLayerClient is not set yet there should be no backing store ID.
406         ASSERT(!m_layerInfo.imageBackingStoreID);
407         didChangeLayerState();
408     }
409
410     m_layerInfo.imageBackingStoreID = newID;
411     m_image = image;
412     GraphicsLayer::setContentsToImage(image);
413 }
414
415 void WebGraphicsLayer::setContentsToCanvas(PlatformLayer* platformLayer)
416 {
417     m_canvasPlatformLayer = platformLayer;
418     m_canvasNeedsDisplay = true;
419 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
420     if (!m_canvasPlatformLayer)
421         return;
422
423     if (static_cast<TextureMapperPlatformLayer*>(m_canvasPlatformLayer)->contentType() == WebKit::WebLayerInfo::Canvas2DContentType)
424         m_layerInfo.contentType = WebKit::WebLayerInfo::Canvas2DContentType;
425     else
426         m_layerInfo.contentType = WebKit::WebLayerInfo::Canvas3DContentType;
427 #endif
428
429     if (client())
430        client()->notifySyncRequired(this);
431 }
432
433 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
434 void WebGraphicsLayer::setContentsToMedia(PlatformLayer* platformLayer)
435 {
436     m_canvasPlatformLayer = platformLayer;
437     m_canvasNeedsDisplay = true;
438     m_layerInfo.contentType = WebKit::WebLayerInfo::MediaContentType;
439
440     if (client())
441         client()->notifySyncRequired(this);
442 }
443 #endif
444
445 void WebGraphicsLayer::setMaskLayer(GraphicsLayer* layer)
446 {
447     if (layer == maskLayer())
448         return;
449
450     GraphicsLayer::setMaskLayer(layer);
451
452     if (!layer)
453         return;
454
455     layer->setSize(size());
456     WebGraphicsLayer* webGraphicsLayer = toWebGraphicsLayer(layer);
457     webGraphicsLayer->setWebGraphicsLayerClient(m_webGraphicsLayerClient);
458     webGraphicsLayer->setMaskTarget(this);
459     webGraphicsLayer->didChangeLayerState();
460     didChangeLayerState();
461
462 }
463
464 void WebGraphicsLayer::setReplicatedByLayer(GraphicsLayer* layer)
465 {
466     if (layer == replicaLayer())
467         return;
468
469     if (layer)
470         toWebGraphicsLayer(layer)->setWebGraphicsLayerClient(m_webGraphicsLayerClient);
471
472     GraphicsLayer::setReplicatedByLayer(layer);
473     didChangeLayerState();
474 }
475
476 #if ENABLE(TIZEN_RECORDING_SURFACE_SET)
477 IntRect WebGraphicsLayer::dirtyUnionRect()
478 {
479     return m_dirtyUnionRect;
480 }
481
482 void WebGraphicsLayer::setDirtyUnionRect(const IntRect& rect)
483 {
484     m_dirtyUnionRect = rect;
485 }
486
487 void WebGraphicsLayer::uniteDirtyUnionRect(const IntRect& rect)
488 {
489     m_dirtyUnionRect.unite(rect);
490 }
491
492 void WebGraphicsLayer::setDirtyRect(const IntRect& rect)
493 {
494     IntRect contentRect(0, 0, size().width(), size().height());
495
496     if (rect.isEmpty() || contentRect.isEmpty())
497         return;
498
499     IntRect dirtyRect(intersection(rect, contentRect));
500     unsigned size = m_dirtyRects.size();
501     if (size) {
502         for (int index = size - 1; index > 0; index--) {
503             if (m_dirtyRects[index].contains(dirtyRect))
504                 return;
505         }
506     }
507     m_dirtyRects.append(dirtyRect);
508 }
509
510 void WebGraphicsLayer::dirtyRectInvalidate()
511 {
512     unsigned size = m_dirtyRects.size();
513
514     if (size) {
515         for (int index = 0; index < size; index++)
516             m_mainBackingStore->invalidate(m_dirtyRects[index]);
517     }
518 }
519
520 void WebGraphicsLayer::setNonCompositedLayer(bool isNonCompositedLayer)
521 {
522     m_nonCompositedLayer = isNonCompositedLayer;
523 }
524
525 bool WebGraphicsLayer::recordingSurfaceSetEnableGet()
526 {
527     if (m_webGraphicsLayerClient)
528         if (m_webGraphicsLayerClient->recordingSurfaceSetEnableGet() && m_nonCompositedLayer)
529             return true;
530
531     return false;
532 }
533
534 bool WebGraphicsLayer::recordingSurfaceSetLoadStartGet()
535 {
536     if (m_webGraphicsLayerClient)
537         return m_webGraphicsLayerClient->recordingSurfaceSetLoadStartGet();
538     return false;
539 }
540
541 bool WebGraphicsLayer::recordingSurfaceSetLoadFinishedGet()
542 {
543     if (m_webGraphicsLayerClient)
544         return m_webGraphicsLayerClient->recordingSurfaceSetLoadFinishedGet();
545     return false;
546 }
547
548 void WebGraphicsLayer::recordingSurfaceSetRebuild(RecordingSurfaceSet* recordingSurfaceSet, float scale)
549 {
550     size_t size = recordingSurfaceSet->size();
551
552     for (size_t index = 0; index < size; index++) {
553         if (recordingSurfaceSet->upToDate(index))
554             continue;
555
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());
560
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());
570
571         recordingSurfaceSet->setRecordingSurface(index, recordingSurfaceCairo.get(), recordingContextCairo.get(), m_mainBackingStore->tileSize());
572     }
573 }
574
575 void WebGraphicsLayer::recordingSurfaceSetRecord()
576 {
577     IntRect contentRect(0, 0, size().width(), size().height());
578     m_recordingSurfaceSetStatus = RecordingSurfaceSetInit;
579
580     if (recordingSurfaceSetLoadFinishedGet() || recordingSurfaceSetLoadStartGet() || m_changedZoomSet) {
581         m_recordingSurfaceSet->clear();
582         m_recordingSurfaceSet->add(contentRect, m_contentsScale);
583     } else {
584         unsigned size = m_dirtyRects.size();
585         for (unsigned n = 0; n < size; n++)
586             m_recordingSurfaceSet->add(m_dirtyRects[n], m_contentsScale);
587     }
588
589     recordingSurfaceSetRebuild(m_recordingSurfaceSet, m_contentsScale);
590     m_recordingSurfaceSetStatus = RecordingSurfaceSetComplete;
591     m_changedZoomSet = false;
592     m_dirtyRects.clear();
593 }
594
595 void WebGraphicsLayer::recordingSurfaceSetReplay(WebCore::GraphicsContext& graphicsContext, const WebCore::IntRect& rect)
596 {
597     if (m_recordingSurfaceSetStatus == RecordingSurfaceSetComplete) {
598         RefPtr<cairo_t> cairoContext = ((WebCore::PlatformContextCairo *)graphicsContext.platformContext())->cr();
599         m_recordingSurfaceSet->draw(cairoContext.get(), rect);
600     }
601 }
602
603 #if ENABLE(TIZEN_RECORDING_SURFACE_PAINT_THREAD)
604 void WebGraphicsLayer::updateTileBuffers()
605 {
606     m_mainBackingStore->updateTileBuffers();
607     m_waitForSyncSemaphore.signal();
608 }
609
610 void WebGraphicsLayer::scheduleUpdateTileBuffersAsync()
611 {
612     if (m_mainBackingStore->contentsFrozen() || !tiledBackingStoreUpdatesAllowed())
613         return;
614
615     m_waitForSyncSemaphore.wait(cSemaphoreWaitTime);
616     m_mainBackingStore->setContentsInvalid(false);
617     m_mainBackingStore->updateTileBuffersBegin();
618     WebProcess::shared().paintThreadWorkQueue()->dispatch(bind(&WebGraphicsLayer::updateTileBuffers, this));
619 }
620 #endif
621 #endif
622
623 void WebGraphicsLayer::setNeedsDisplay()
624 {
625 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
626     if (!m_visibleRect.isEmpty()) {
627         setNeedsDisplayInRect(IntRect(m_visibleRect));
628         return;
629     }
630 #endif
631     setNeedsDisplayInRect(IntRect(IntPoint::zero(), IntSize(size().width(), size().height())));
632 }
633
634 void WebGraphicsLayer::setNeedsDisplayInRect(const FloatRect& rect)
635 {
636 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING_PLUGIN_LAYER_EFL)
637     if (drawsContent() && m_layerInfo.contentType == WebKit::WebLayerInfo::MediaContentType) {
638         uniteDirtyUnionRect(IntRect(rect));
639         didChangeLayerState();
640         return;
641     }
642 #endif
643
644 #if ENABLE(TIZEN_RECORDING_SURFACE_SET)
645     if (recordingSurfaceSetEnableGet()) {
646         setDirtyRect(IntRect(rect));
647
648 #if ENABLE(TIZEN_RECORDING_SURFACE_PAINT_THREAD)
649         if (m_mainBackingStore)
650             m_mainBackingStore->startTileBufferUpdateTimer();
651 #else
652         if (m_mainBackingStore)
653             m_mainBackingStore->invalidate(IntRect(rect));
654         didChangeLayerState();
655 #endif
656         return;
657     }
658 #endif
659
660     if (m_mainBackingStore)
661         m_mainBackingStore->invalidate(IntRect(rect));
662     didChangeLayerState();
663 }
664
665 WebLayerID WebGraphicsLayer::id() const
666 {
667     return m_id;
668 }
669
670 void WebGraphicsLayer::syncCompositingState(const FloatRect& rect)
671 {
672 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
673     if (!m_webGraphicsLayerClient)
674         return;
675 #endif
676
677     if (WebGraphicsLayer* mask = toWebGraphicsLayer(maskLayer()))
678         mask->syncCompositingStateForThisLayerOnly();
679
680     if (WebGraphicsLayer* replica = toWebGraphicsLayer(replicaLayer()))
681         replica->syncCompositingStateForThisLayerOnly();
682
683     m_webGraphicsLayerClient->syncFixedLayers();
684
685     syncCompositingStateForThisLayerOnly();
686
687     for (size_t i = 0; i < children().size(); ++i)
688         children()[i]->syncCompositingState(rect);
689 }
690
691 WebGraphicsLayer* toWebGraphicsLayer(GraphicsLayer* layer)
692 {
693     return static_cast<WebGraphicsLayer*>(layer);
694 }
695
696 void WebGraphicsLayer::syncChildren()
697 {
698     if (!m_shouldSyncChildren)
699         return;
700     m_shouldSyncChildren = false;
701     Vector<WebLayerID> childIDs;
702     for (size_t i = 0; i < children().size(); ++i)
703         childIDs.append(toWebLayerID(children()[i]));
704
705 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
706     if (m_webGraphicsLayerClient)
707 #endif
708     m_webGraphicsLayerClient->syncLayerChildren(m_id, childIDs);
709 }
710
711 #if ENABLE(CSS_FILTERS)
712 void WebGraphicsLayer::syncFilters()
713 {
714     if (!m_shouldSyncFilters)
715         return;
716     m_shouldSyncFilters = false;
717     m_webGraphicsLayerClient->syncLayerFilters(m_id, filters());
718 }
719 #endif
720
721 void WebGraphicsLayer::syncLayerState()
722 {
723     if (!m_shouldSyncLayerState)
724         return;
725
726     m_shouldSyncLayerState = false;
727     m_layerInfo.fixedToViewport = fixedToViewport();
728 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_SCROLLBAR)
729     m_layerInfo.isScrollbar = isScrollbar();
730 #endif
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();
735 #endif
736
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();
753
754 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
755     if (m_webGraphicsLayerClient)
756 #endif
757     m_webGraphicsLayerClient->syncLayerState(m_id, m_layerInfo);
758
759 #if ENABLE(TIZEN_DONT_PURGE_PLATFORM_SURFACE_BACKINGSTORE_ON_NODE_DETACH_FROM_WEBLAYER_TREE)
760     syncBackingStoreIfNeeded();
761 #endif
762 }
763
764 void WebGraphicsLayer::syncAnimations()
765 {
766     if (!m_shouldSyncAnimations)
767         return;
768
769     m_shouldSyncAnimations = false;
770
771     m_webGraphicsLayerClient->setLayerAnimations(m_id, m_animations);
772 }
773
774 void WebGraphicsLayer::syncCanvas()
775 {
776     if (!m_canvasNeedsDisplay)
777         return;
778
779     if (!m_canvasPlatformLayer)
780         return;
781
782 #if USE(GRAPHICS_SURFACE) || ENABLE(TIZEN_CANVAS_GRAPHICS_SURFACE)
783     uint64_t token = m_canvasPlatformLayer->graphicsSurfaceToken();
784     if (!token)
785         return;
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);
791 #else
792     m_webGraphicsLayerClient->syncCanvas(m_id, IntSize(size().width(), size().height()), token, frontBuffer);
793 #endif
794 #endif
795     m_canvasNeedsDisplay = false;
796 }
797
798 void WebGraphicsLayer::ensureImageBackingStore()
799 {
800     if (!m_image)
801         return;
802
803 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
804     if (!m_webGraphicsLayerClient)
805         return;
806 #endif
807
808     if (!m_layerInfo.imageBackingStoreID)
809         m_layerInfo.imageBackingStoreID = m_webGraphicsLayerClient->adoptImageBackingStore(m_image.get());
810 }
811
812 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING_PLUGIN_LAYER_EFL)
813 void WebGraphicsLayer::ensureMediaPlatformSurfaceID()
814 {
815     if (!m_canvasPlatformLayer || m_layerInfo.contentType != WebKit::WebLayerInfo::MediaContentType)
816         return;
817
818     TextureMapperPlatformLayer* platformLayer = static_cast<TextureMapperPlatformLayer*>(m_canvasPlatformLayer);
819
820     if (platformLayer->needsSyncLayerState()) {
821         m_shouldSyncLayerState = true;
822         platformLayer->setNeedsSyncLayerState(false);
823     }
824
825     if (!platformLayer->graphicsSurfaceToken())
826         return;
827
828     if (drawsContent())
829         setNeedsDisplay();
830 }
831 #endif
832
833 #if ENABLE(TIZEN_DONT_PURGE_PLATFORM_SURFACE_BACKINGSTORE_ON_NODE_DETACH_FROM_WEBLAYER_TREE)
834 void WebGraphicsLayer::syncBackingStoreIfNeeded()
835 {
836     if (m_shouldSyncBackingStore) {
837         if (m_mainBackingStore)
838             m_mainBackingStore->reviewTiles();
839         m_shouldSyncBackingStore = false;
840     }
841 }
842 #endif
843
844 void WebGraphicsLayer::syncCompositingStateForThisLayerOnly()
845 {
846     // The remote image might have been released by purgeBackingStores.
847     ensureImageBackingStore();
848     syncLayerState();
849     syncAnimations();
850
851 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING_PLUGIN_LAYER_EFL)
852     ensureMediaPlatformSurfaceID();
853 #endif
854     computeTransformedVisibleRect();
855     syncChildren();
856 #if ENABLE(CSS_FILTERS)
857     syncFilters();
858 #endif
859     updateContentBuffers();
860     syncCanvas();
861 }
862
863 void WebGraphicsLayer::tiledBackingStorePaintBegin()
864 {
865 #if ENABLE(TIZEN_RECORDING_SURFACE_SET)
866     if (recordingSurfaceSetEnableGet() && m_mainBackingStore) {
867         if (m_dirtyRects.isEmpty())
868             return;
869
870         recordingSurfaceSetRecord();
871     }
872 #endif
873 }
874
875 void WebGraphicsLayer::setRootLayer(bool isRoot)
876 {
877     m_layerInfo.isRootLayer = isRoot;
878     didChangeLayerState();
879 }
880
881 void WebGraphicsLayer::setVisibleContentRectTrajectoryVector(const FloatPoint& trajectoryVector)
882 {
883 #if ENABLE(TIZEN_RECORDING_SURFACE_PAINT_THREAD)
884     if (recordingSurfaceSetEnableGet())
885         m_waitForSyncSemaphore.wait(cSemaphoreWaitTime);
886 #endif
887
888     if (m_mainBackingStore)
889         m_mainBackingStore->coverWithTilesIfNeeded(trajectoryVector);
890
891 #if ENABLE(TIZEN_RECORDING_SURFACE_PAINT_THREAD)
892     if (recordingSurfaceSetEnableGet())
893         m_waitForSyncSemaphore.signal();
894 #endif
895 }
896
897 void WebGraphicsLayer::setContentsScale(float scale)
898 {
899     m_contentsScale = scale;
900     adjustContentsScale();
901 }
902
903 float WebGraphicsLayer::effectiveContentsScale()
904 {
905     return shouldUseTiledBackingStore() ? m_contentsScale : 1;
906 }
907
908 void WebGraphicsLayer::adjustContentsScale()
909 {
910     if (!drawsContent())
911         return;
912
913     if (!m_mainBackingStore || m_mainBackingStore->contentsScale() == effectiveContentsScale())
914         return;
915
916 #if ENABLE(TIZEN_RECORDING_SURFACE_SET)
917     if (recordingSurfaceSetEnableGet()) {
918 #if ENABLE(TIZEN_RECORDING_SURFACE_PAINT_THREAD)
919         m_waitForSyncSemaphore.wait(cSemaphoreWaitTime);
920 #endif
921         m_changedZoomSet = true;
922         recordingSurfaceSetRecord();
923     }
924 #endif
925
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();
931
932     // No reason to save the previous backing store for non-visible areas.
933     m_previousBackingStore->removeAllNonVisibleTiles();
934
935     createBackingStore();
936
937 #if ENABLE(TIZEN_RECORDING_SURFACE_PAINT_THREAD)
938     if (recordingSurfaceSetEnableGet())
939         m_waitForSyncSemaphore.signal();
940 #endif
941 }
942
943 void WebGraphicsLayer::createBackingStore()
944 {
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)));
950     else
951         m_mainBackingStore = adoptPtr(new TiledBackingStore(this, TiledBackingStoreRemoteTileBackend::create(this)));
952 #else
953     m_mainBackingStore = adoptPtr(new TiledBackingStore(this, TiledBackingStoreRemotePlatformSurfaceTileBackend::create(this)));
954 #endif
955 #endif
956     } else
957         m_mainBackingStore = adoptPtr(new TiledBackingStore(this, TiledBackingStoreRemoteTileBackend::create(this)));
958
959     m_mainBackingStore->setSupportsAlpha(!contentsOpaque());
960     m_mainBackingStore->setContentsScale(effectiveContentsScale());
961 }
962
963 void WebGraphicsLayer::tiledBackingStorePaint(GraphicsContext* context, const IntRect& rect)
964 {
965     if (rect.isEmpty())
966         return;
967
968 #if ENABLE(TIZEN_RECORDING_SURFACE_SET)
969     if (recordingSurfaceSetEnableGet()) {
970         recordingSurfaceSetReplay(*context, rect);
971         return;
972     }
973 #endif
974
975     paintGraphicsLayerContents(*context, rect);
976 }
977
978 void WebGraphicsLayer::tiledBackingStorePaintEnd(const Vector<IntRect>& updatedRects)
979 {
980 #if ENABLE(TIZEN_RECORDING_SURFACE_PAINT_THREAD)
981     if (recordingSurfaceSetEnableGet())
982         didChangeLayerState();
983 #endif
984 }
985
986 bool WebGraphicsLayer::tiledBackingStoreUpdatesAllowed() const
987 {
988     if (!m_inUpdateMode)
989         return false;
990
991 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
992     if (!m_webGraphicsLayerClient)
993         return false;
994 #endif
995
996     return m_webGraphicsLayerClient->layerTreeTileUpdatesAllowed();
997 }
998
999 IntRect WebGraphicsLayer::tiledBackingStoreContentsRect()
1000 {
1001     return IntRect(0, 0, size().width(), size().height());
1002 }
1003
1004 bool WebGraphicsLayer::shouldUseTiledBackingStore()
1005 {
1006     return !selfOrAncestorHaveNonAffineTransforms();
1007 }
1008
1009 IntRect WebGraphicsLayer::tiledBackingStoreVisibleRect()
1010 {
1011     if (!shouldUseTiledBackingStore())
1012         return tiledBackingStoreContentsRect();
1013
1014     // Non-invertible layers are not visible.
1015     if (!m_layerTransform.combined().isInvertible())
1016         return IntRect();
1017
1018 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
1019     if (!m_webGraphicsLayerClient)
1020         return IntRect();
1021 #endif
1022
1023 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
1024     if (!m_visibleRect.isEmpty())
1025         return m_visibleRect;
1026 #endif
1027
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()))));
1032 }
1033
1034 Color WebGraphicsLayer::tiledBackingStoreBackgroundColor() const
1035 {
1036     return contentsOpaque() ? Color::white : Color::transparent;
1037 }
1038
1039 PassOwnPtr<WebCore::GraphicsContext> WebGraphicsLayer::beginContentUpdate(const WebCore::IntSize& size, ShareableSurface::Handle& handle, WebCore::IntPoint& offset)
1040 {
1041 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
1042     if (!m_webGraphicsLayerClient)
1043         return PassOwnPtr<WebCore::GraphicsContext>();
1044 #endif
1045
1046     return m_webGraphicsLayerClient->beginContentUpdate(size, contentsOpaque() ? 0 : ShareableBitmap::SupportsAlpha, handle, offset);
1047 }
1048
1049 void WebGraphicsLayer::createTile(int tileID, const SurfaceUpdateInfo& updateInfo, const IntRect& targetRect)
1050 {
1051 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
1052     if (m_webGraphicsLayerClient)
1053 #endif
1054     m_webGraphicsLayerClient->createTile(id(), tileID, updateInfo, targetRect);
1055 }
1056
1057 void WebGraphicsLayer::updateTile(int tileID, const SurfaceUpdateInfo& updateInfo, const IntRect& targetRect)
1058 {
1059 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
1060     if (m_webGraphicsLayerClient)
1061 #endif
1062     m_webGraphicsLayerClient->updateTile(id(), tileID, updateInfo, targetRect);
1063 }
1064
1065 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
1066 void WebGraphicsLayer::freePlatformSurface(int platformSurfaceID)
1067 {
1068     if (m_canvasPlatformLayer)
1069         m_canvasPlatformLayer->freePlatformSurface(platformSurfaceID);
1070 }
1071
1072 void WebGraphicsLayer::removePlatformSurface(int platformSurfaceID)
1073 {
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;
1079 #endif
1080 }
1081
1082 bool WebGraphicsLayer::swapPlatformSurfaces()
1083 {
1084     if (m_canvasPlatformLayer)
1085         return m_canvasPlatformLayer->swapPlatformSurfaces();
1086     return true;
1087 }
1088 #endif
1089
1090 void WebGraphicsLayer::removeTile(int tileID)
1091 {
1092 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
1093     if (m_webGraphicsLayerClient)
1094 #endif
1095     m_webGraphicsLayerClient->removeTile(id(), tileID);
1096 }
1097
1098 void WebGraphicsLayer::updateContentBuffers()
1099 {
1100     if (!drawsContent()) {
1101         m_mainBackingStore.clear();
1102         m_previousBackingStore.clear();
1103         return;
1104     }
1105
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();
1110
1111         if (dirtyUnionRect().isEmpty())
1112             return;
1113
1114         if (m_canvasPlatformLayer) {
1115             LayoutSize offset = offsetFromRenderer();
1116             LayoutRect clipRect(dirtyUnionRect());
1117             clipRect.move(offset);
1118
1119             // Update media area.
1120             m_canvasPlatformLayer->updateContentBuffers(pixelSnappedIntRect(clipRect));
1121
1122             setDirtyUnionRect(IntRect());
1123         }
1124
1125         return;
1126     }
1127 #endif
1128
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();
1134
1135 #if ENABLE(TIZEN_RECORDING_SURFACE_PAINT_THREAD)
1136     if (recordingSurfaceSetEnableGet()) {
1137         m_waitForSyncSemaphore.wait(cSemaphoreWaitTime);
1138         m_waitForSyncSemaphore.signal();
1139
1140         scheduleUpdateTileBuffersAsync();
1141     } else
1142         m_mainBackingStore->updateTileBuffers();
1143 #else
1144     m_mainBackingStore->updateTileBuffers();
1145 #endif
1146     m_inUpdateMode = false;
1147
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();
1153 }
1154
1155 void WebGraphicsLayer::purgeBackingStores()
1156 {
1157 #if ENABLE(TIZEN_RECORDING_SURFACE_PAINT_THREAD)
1158     if (recordingSurfaceSetEnableGet()) {
1159         m_waitForSyncSemaphore.wait(cSemaphoreWaitTime);
1160         m_waitForSyncSemaphore.signal();
1161     }
1162 #endif
1163     m_mainBackingStore.clear();
1164     m_previousBackingStore.clear();
1165
1166 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
1167     if (m_webGraphicsLayerClient)
1168 #endif
1169     if (m_layerInfo.imageBackingStoreID) {
1170         m_webGraphicsLayerClient->releaseImageBackingStore(m_layerInfo.imageBackingStoreID);
1171         m_layerInfo.imageBackingStoreID = 0;
1172     }
1173
1174     didChangeLayerState();
1175     didChangeChildren();
1176 }
1177
1178 void WebGraphicsLayer::setWebGraphicsLayerClient(WebKit::WebGraphicsLayerClient* client)
1179 {
1180     if (m_webGraphicsLayerClient == client)
1181         return;
1182
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);
1190     }
1191
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;
1198 #else
1199         purgeBackingStores();
1200 #endif // ENABLE(TIZEN_DONT_PURGE_PLATFORM_SURFACE_BACKINGSTORE_ON_NODE_DETACH_FROM_WEBLAYER_TREE)
1201         m_webGraphicsLayerClient->detachLayer(this);
1202     }
1203     m_webGraphicsLayerClient = client;
1204     if (client)
1205         client->attachLayer(this);
1206 }
1207
1208 void WebGraphicsLayer::adjustVisibleRect()
1209 {
1210     if (m_mainBackingStore)
1211         m_mainBackingStore->coverWithTilesIfNeeded();
1212 }
1213
1214 bool WebGraphicsLayer::hasPendingVisibleChanges()
1215 {
1216     if (opacity() < 0.01 && !m_animations.hasActiveAnimationsOfType(AnimatedPropertyOpacity))
1217         return false;
1218
1219     for (size_t i = 0; i < children().size(); ++i) {
1220         if (toWebGraphicsLayer(children()[i])->hasPendingVisibleChanges())
1221             return true;
1222     }
1223
1224     if (!m_shouldSyncLayerState && !m_shouldSyncChildren && !m_shouldSyncFilters && !m_shouldSyncAnimations && !m_canvasNeedsDisplay)
1225         return false;
1226
1227     return selfOrAncestorHaveNonAffineTransforms() || !tiledBackingStoreVisibleRect().isEmpty();
1228
1229 }
1230
1231 void WebGraphicsLayer::computeTransformedVisibleRect()
1232 {
1233     if (!m_shouldUpdateVisibleRect)
1234         return;
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());
1243
1244     // The combined transform will be used in tiledBackingStoreVisibleRect.
1245     adjustVisibleRect();
1246     adjustContentsScale();
1247 }
1248
1249 static PassOwnPtr<GraphicsLayer> createWebGraphicsLayer(GraphicsLayerClient* client)
1250 {
1251     return adoptPtr(new WebGraphicsLayer(client));
1252 }
1253
1254 void WebGraphicsLayer::initFactory()
1255 {
1256     GraphicsLayer::setGraphicsLayerFactory(createWebGraphicsLayer);
1257 }
1258
1259 bool WebGraphicsLayer::selfOrAncestorHaveNonAffineTransforms()
1260 {
1261     if (m_animations.hasActiveAnimationsOfType(AnimatedPropertyWebkitTransform))
1262         return true;
1263
1264     if (!m_layerTransform.combined().isAffine())
1265         return true;
1266
1267     return false;
1268 }
1269
1270 #if ENABLE(TIZEN_CUTOFF_TILES_OVER_MEMORY_LIMIT)
1271 bool WebGraphicsLayer::selfOrAncestorHasActiveTransformAnimation() const
1272 {
1273     if (m_animations.hasActiveAnimationsOfType(AnimatedPropertyWebkitTransform))
1274         return true;
1275
1276     if (!parent())
1277         return false;
1278
1279     return toWebGraphicsLayer(parent())->selfOrAncestorHasActiveTransformAnimation();
1280 }
1281 #endif
1282
1283 bool WebGraphicsLayer::addAnimation(const KeyframeValueList& valueList, const IntSize& boxSize, const Animation* anim, const String& keyframesName, double timeOffset)
1284 {
1285     ASSERT(!keyframesName.isEmpty());
1286
1287     if (!anim || anim->isEmptyOrZeroDuration() || valueList.size() < 2 || (valueList.property() != AnimatedPropertyWebkitTransform && valueList.property() != AnimatedPropertyOpacity))
1288         return false;
1289
1290     bool listsMatch = false;
1291     bool ignoredHasBigRotation;
1292
1293     if (valueList.property() == AnimatedPropertyWebkitTransform)
1294         listsMatch = validateTransformOperations(valueList, ignoredHasBigRotation) >= 0;
1295
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();
1300 #endif
1301     didChangeLayerState();
1302     return true;
1303 }
1304
1305 void WebGraphicsLayer::pauseAnimation(const String& animationName, double timeOffset)
1306 {
1307     m_animations.pause(animationName, timeOffset);
1308     didChangeAnimations();
1309 }
1310
1311 void WebGraphicsLayer::removeAnimation(const String& animationName)
1312 {
1313     m_animations.remove(animationName);
1314     didChangeAnimations();
1315 }
1316
1317 void WebGraphicsLayer::animationStartedTimerFired(Timer<WebGraphicsLayer>*)
1318 {
1319     client()->notifyAnimationStarted(this, /* DOM time */ WTF::currentTime());
1320 }
1321
1322 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
1323 void WebGraphicsLayer::setIsOverflow(const bool b)
1324 {
1325     if (m_isOverflow == b)
1326         return;
1327
1328     m_isOverflow = b;
1329     didChangeLayerState();
1330 }
1331 #endif
1332
1333 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_SCROLLBAR)
1334 void WebGraphicsLayer::startAnimation()
1335 {
1336     setOpacity(1.0);
1337     if (m_animationTimer.isActive())
1338         m_animationTimer.stop();
1339     m_animationTimer.startOneShot(1.0);
1340 }
1341
1342 void WebGraphicsLayer::animationTimerFired(Timer<WebGraphicsLayer>*)
1343 {
1344     setOpacity(0.0);
1345 }
1346 #endif
1347
1348 #if ENABLE(TIZEN_CUTOFF_TILES_OVER_MEMORY_LIMIT)
1349 Vector<TileCutOffInfo> WebGraphicsLayer::getCutOffInfoList()
1350 {
1351     if (!m_mainBackingStore)
1352         return Vector<TileCutOffInfo>();
1353
1354     return m_mainBackingStore->getCutOffInfoList();
1355 }
1356
1357 void WebGraphicsLayer::setCutOffDistance(double distance)
1358 {
1359     if (!m_mainBackingStore)
1360         return;
1361
1362     if (!selfOrAncestorHasActiveTransformAnimation())
1363         m_mainBackingStore->setCutOffDistance(distance);
1364 }
1365 #endif
1366
1367 }
1368 #endif