OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 10 matching lines...) Loading... |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "config.h" | 26 #include "config.h" |
27 #include "platform/graphics/GraphicsLayer.h" | 27 #include "platform/graphics/GraphicsLayer.h" |
28 | 28 |
29 #include "SkImageFilter.h" | 29 #include "SkImageFilter.h" |
30 #include "SkMatrix44.h" | 30 #include "SkMatrix44.h" |
| 31 #include "base/trace_event/trace_event_argument.h" |
31 #include "platform/DragImage.h" | 32 #include "platform/DragImage.h" |
| 33 #include "platform/JSONValues.h" |
32 #include "platform/TraceEvent.h" | 34 #include "platform/TraceEvent.h" |
33 #include "platform/geometry/FloatRect.h" | 35 #include "platform/geometry/FloatRect.h" |
34 #include "platform/geometry/LayoutRect.h" | 36 #include "platform/geometry/LayoutRect.h" |
35 #include "platform/graphics/BitmapImage.h" | 37 #include "platform/graphics/BitmapImage.h" |
36 #include "platform/graphics/FirstPaintInvalidationTracking.h" | 38 #include "platform/graphics/FirstPaintInvalidationTracking.h" |
37 #include "platform/graphics/GraphicsContext.h" | 39 #include "platform/graphics/GraphicsContext.h" |
38 #include "platform/graphics/GraphicsLayerFactory.h" | 40 #include "platform/graphics/GraphicsLayerFactory.h" |
39 #include "platform/graphics/Image.h" | 41 #include "platform/graphics/Image.h" |
40 #include "platform/graphics/LinkHighlight.h" | 42 #include "platform/graphics/LinkHighlight.h" |
41 #include "platform/graphics/filters/SkiaImageFilterBuilder.h" | 43 #include "platform/graphics/filters/SkiaImageFilterBuilder.h" |
42 #include "platform/graphics/paint/DrawingRecorder.h" | 44 #include "platform/graphics/paint/DrawingRecorder.h" |
43 #include "platform/graphics/paint/PaintController.h" | 45 #include "platform/graphics/paint/PaintController.h" |
44 #include "platform/scroll/ScrollableArea.h" | 46 #include "platform/scroll/ScrollableArea.h" |
45 #include "platform/text/TextStream.h" | 47 #include "platform/text/TextStream.h" |
46 #include "public/platform/Platform.h" | 48 #include "public/platform/Platform.h" |
47 #include "public/platform/WebCompositorAnimation.h" | 49 #include "public/platform/WebCompositorAnimation.h" |
48 #include "public/platform/WebCompositorSupport.h" | 50 #include "public/platform/WebCompositorSupport.h" |
49 #include "public/platform/WebFilterOperations.h" | 51 #include "public/platform/WebFilterOperations.h" |
50 #include "public/platform/WebFloatPoint.h" | 52 #include "public/platform/WebFloatPoint.h" |
51 #include "public/platform/WebFloatRect.h" | 53 #include "public/platform/WebFloatRect.h" |
52 #include "public/platform/WebGraphicsLayerDebugInfo.h" | |
53 #include "public/platform/WebLayer.h" | 54 #include "public/platform/WebLayer.h" |
54 #include "public/platform/WebPoint.h" | 55 #include "public/platform/WebPoint.h" |
55 #include "public/platform/WebSize.h" | 56 #include "public/platform/WebSize.h" |
56 #include "wtf/CurrentTime.h" | 57 #include "wtf/CurrentTime.h" |
57 #include "wtf/HashMap.h" | 58 #include "wtf/HashMap.h" |
58 #include "wtf/HashSet.h" | 59 #include "wtf/HashSet.h" |
59 #include "wtf/text/WTFString.h" | 60 #include "wtf/text/WTFString.h" |
60 #include <algorithm> | 61 #include <algorithm> |
61 | 62 |
62 #ifndef NDEBUG | 63 #ifndef NDEBUG |
(...skipping 54 matching lines...) Loading... |
117 , m_3dRenderingContext(0) | 118 , m_3dRenderingContext(0) |
118 { | 119 { |
119 #if ENABLE(ASSERT) | 120 #if ENABLE(ASSERT) |
120 if (m_client) | 121 if (m_client) |
121 m_client->verifyNotPainting(); | 122 m_client->verifyNotPainting(); |
122 #endif | 123 #endif |
123 | 124 |
124 m_contentLayerDelegate = adoptPtr(new ContentLayerDelegate(this)); | 125 m_contentLayerDelegate = adoptPtr(new ContentLayerDelegate(this)); |
125 m_layer = adoptPtr(Platform::current()->compositorSupport()->createContentLa
yer(m_contentLayerDelegate.get())); | 126 m_layer = adoptPtr(Platform::current()->compositorSupport()->createContentLa
yer(m_contentLayerDelegate.get())); |
126 m_layer->layer()->setDrawsContent(m_drawsContent && m_contentsVisible); | 127 m_layer->layer()->setDrawsContent(m_drawsContent && m_contentsVisible); |
127 m_layer->layer()->setWebLayerClient(this); | 128 m_layer->layer()->setLayerClient(this); |
128 m_layer->setAutomaticallyComputeRasterScale(true); | 129 m_layer->setAutomaticallyComputeRasterScale(true); |
129 | 130 |
130 // TODO(rbyers): Expose control over this to the web - crbug.com/489802: | 131 // TODO(rbyers): Expose control over this to the web - crbug.com/489802: |
131 setScrollBlocksOn(WebScrollBlocksOnStartTouch | WebScrollBlocksOnWheelEvent)
; | 132 setScrollBlocksOn(WebScrollBlocksOnStartTouch | WebScrollBlocksOnWheelEvent)
; |
132 } | 133 } |
133 | 134 |
134 GraphicsLayer::~GraphicsLayer() | 135 GraphicsLayer::~GraphicsLayer() |
135 { | 136 { |
136 for (size_t i = 0; i < m_linkHighlights.size(); ++i) | 137 for (size_t i = 0; i < m_linkHighlights.size(); ++i) |
137 m_linkHighlights[i]->clearCurrentGraphicsLayer(); | 138 m_linkHighlights[i]->clearCurrentGraphicsLayer(); |
(...skipping 296 matching lines...) Loading... |
434 if (childrenChanged) | 435 if (childrenChanged) |
435 updateChildList(); | 436 updateChildList(); |
436 } | 437 } |
437 | 438 |
438 void GraphicsLayer::setupContentsLayer(WebLayer* contentsLayer) | 439 void GraphicsLayer::setupContentsLayer(WebLayer* contentsLayer) |
439 { | 440 { |
440 ASSERT(contentsLayer); | 441 ASSERT(contentsLayer); |
441 m_contentsLayer = contentsLayer; | 442 m_contentsLayer = contentsLayer; |
442 m_contentsLayerId = m_contentsLayer->id(); | 443 m_contentsLayerId = m_contentsLayer->id(); |
443 | 444 |
444 m_contentsLayer->setWebLayerClient(this); | 445 m_contentsLayer->setLayerClient(this); |
445 m_contentsLayer->setTransformOrigin(FloatPoint3D()); | 446 m_contentsLayer->setTransformOrigin(FloatPoint3D()); |
446 m_contentsLayer->setUseParentBackfaceVisibility(true); | 447 m_contentsLayer->setUseParentBackfaceVisibility(true); |
447 | 448 |
448 // It is necessary to call setDrawsContent as soon as we receive the new con
tentsLayer, for | 449 // It is necessary to call setDrawsContent as soon as we receive the new con
tentsLayer, for |
449 // the correctness of early exit conditions in setDrawsContent() and setCont
entsVisible(). | 450 // the correctness of early exit conditions in setDrawsContent() and setCont
entsVisible(). |
450 m_contentsLayer->setDrawsContent(m_contentsVisible); | 451 m_contentsLayer->setDrawsContent(m_contentsVisible); |
451 | 452 |
452 // Insert the content layer first. Video elements require this, because they
have | 453 // Insert the content layer first. Video elements require this, because they
have |
453 // shadow content that must display in front of the video. | 454 // shadow content that must display in front of the video. |
454 m_layer->layer()->insertChild(m_contentsLayer, 0); | 455 m_layer->layer()->insertChild(m_contentsLayer, 0); |
(...skipping 10 matching lines...) Loading... |
465 | 466 |
466 m_contentsLayer = 0; | 467 m_contentsLayer = 0; |
467 m_contentsLayerId = 0; | 468 m_contentsLayerId = 0; |
468 } | 469 } |
469 | 470 |
470 GraphicsLayerDebugInfo& GraphicsLayer::debugInfo() | 471 GraphicsLayerDebugInfo& GraphicsLayer::debugInfo() |
471 { | 472 { |
472 return m_debugInfo; | 473 return m_debugInfo; |
473 } | 474 } |
474 | 475 |
475 WebGraphicsLayerDebugInfo* GraphicsLayer::takeDebugInfoFor(WebLayer* layer) | |
476 { | |
477 GraphicsLayerDebugInfo* clone = m_debugInfo.clone(); | |
478 clone->setDebugName(debugName(layer)); | |
479 return clone; | |
480 } | |
481 | |
482 WebLayer* GraphicsLayer::contentsLayerIfRegistered() | 476 WebLayer* GraphicsLayer::contentsLayerIfRegistered() |
483 { | 477 { |
484 clearContentsLayerIfUnregistered(); | 478 clearContentsLayerIfUnregistered(); |
485 return m_contentsLayer; | 479 return m_contentsLayer; |
486 } | 480 } |
487 | 481 |
488 void GraphicsLayer::resetTrackedPaintInvalidations() | 482 void GraphicsLayer::resetTrackedPaintInvalidations() |
489 { | 483 { |
490 paintInvalidationTrackingMap().remove(this); | 484 paintInvalidationTrackingMap().remove(this); |
491 } | 485 } |
(...skipping 259 matching lines...) Loading... |
751 return json; | 745 return json; |
752 } | 746 } |
753 | 747 |
754 String GraphicsLayer::layerTreeAsText(LayerTreeFlags flags) const | 748 String GraphicsLayer::layerTreeAsText(LayerTreeFlags flags) const |
755 { | 749 { |
756 RenderingContextMap renderingContextMap; | 750 RenderingContextMap renderingContextMap; |
757 RefPtr<JSONObject> json = layerTreeAsJSON(flags, renderingContextMap); | 751 RefPtr<JSONObject> json = layerTreeAsJSON(flags, renderingContextMap); |
758 return json->toPrettyJSONString(); | 752 return json->toPrettyJSONString(); |
759 } | 753 } |
760 | 754 |
761 String GraphicsLayer::debugName(WebLayer* webLayer) const | 755 static const cc::Layer* ccLayerForWebLayer(const WebLayer* webLayer) |
| 756 { |
| 757 return webLayer ? webLayer->ccLayer() : nullptr; |
| 758 } |
| 759 |
| 760 String GraphicsLayer::debugName(cc::Layer* layer) const |
762 { | 761 { |
763 String name; | 762 String name; |
764 if (!m_client) | 763 if (!m_client) |
765 return name; | 764 return name; |
766 | 765 |
767 String highlightDebugName; | 766 String highlightDebugName; |
768 for (size_t i = 0; i < m_linkHighlights.size(); ++i) { | 767 for (size_t i = 0; i < m_linkHighlights.size(); ++i) { |
769 if (webLayer == m_linkHighlights[i]->layer()) { | 768 if (layer == ccLayerForWebLayer(m_linkHighlights[i]->layer())) { |
770 highlightDebugName = "LinkHighlight[" + String::number(i) + "] for "
+ m_client->debugName(this); | 769 highlightDebugName = "LinkHighlight[" + String::number(i) + "] for "
+ m_client->debugName(this); |
771 break; | 770 break; |
772 } | 771 } |
773 } | 772 } |
774 | 773 |
775 if (webLayer == m_contentsLayer) { | 774 if (layer == ccLayerForWebLayer(m_contentsLayer)) { |
776 name = "ContentsLayer for " + m_client->debugName(this); | 775 name = "ContentsLayer for " + m_client->debugName(this); |
777 } else if (!highlightDebugName.isEmpty()) { | 776 } else if (!highlightDebugName.isEmpty()) { |
778 name = highlightDebugName; | 777 name = highlightDebugName; |
779 } else if (webLayer == m_layer->layer()) { | 778 } else if (layer == ccLayerForWebLayer(m_layer->layer())) { |
780 name = m_client->debugName(this); | 779 name = m_client->debugName(this); |
781 } else { | 780 } else { |
782 ASSERT_NOT_REACHED(); | 781 ASSERT_NOT_REACHED(); |
783 } | 782 } |
784 return name; | 783 return name; |
785 } | 784 } |
786 | 785 |
787 void GraphicsLayer::setCompositingReasons(CompositingReasons reasons) | 786 void GraphicsLayer::setCompositingReasons(CompositingReasons reasons) |
788 { | 787 { |
789 m_debugInfo.setCompositingReasons(reasons); | 788 m_debugInfo.setCompositingReasons(reasons); |
(...skipping 333 matching lines...) Loading... |
1123 if (m_paintingPhase == phase) | 1122 if (m_paintingPhase == phase) |
1124 return; | 1123 return; |
1125 m_paintingPhase = phase; | 1124 m_paintingPhase = phase; |
1126 setNeedsDisplay(); | 1125 setNeedsDisplay(); |
1127 } | 1126 } |
1128 | 1127 |
1129 void GraphicsLayer::addLinkHighlight(LinkHighlight* linkHighlight) | 1128 void GraphicsLayer::addLinkHighlight(LinkHighlight* linkHighlight) |
1130 { | 1129 { |
1131 ASSERT(linkHighlight && !m_linkHighlights.contains(linkHighlight)); | 1130 ASSERT(linkHighlight && !m_linkHighlights.contains(linkHighlight)); |
1132 m_linkHighlights.append(linkHighlight); | 1131 m_linkHighlights.append(linkHighlight); |
1133 linkHighlight->layer()->setWebLayerClient(this); | 1132 linkHighlight->layer()->setLayerClient(this); |
1134 updateChildList(); | 1133 updateChildList(); |
1135 } | 1134 } |
1136 | 1135 |
1137 void GraphicsLayer::removeLinkHighlight(LinkHighlight* linkHighlight) | 1136 void GraphicsLayer::removeLinkHighlight(LinkHighlight* linkHighlight) |
1138 { | 1137 { |
1139 m_linkHighlights.remove(m_linkHighlights.find(linkHighlight)); | 1138 m_linkHighlights.remove(m_linkHighlights.find(linkHighlight)); |
1140 updateChildList(); | 1139 updateChildList(); |
1141 } | 1140 } |
1142 | 1141 |
1143 void GraphicsLayer::setScrollableArea(ScrollableArea* scrollableArea, bool isVie
wport) | 1142 void GraphicsLayer::setScrollableArea(ScrollableArea* scrollableArea, bool isVie
wport) |
(...skipping 27 matching lines...) Loading... |
1171 { | 1170 { |
1172 if (m_scrollableArea) { | 1171 if (m_scrollableArea) { |
1173 DoublePoint newPosition = m_scrollableArea->minimumScrollPosition() + to
DoubleSize(m_layer->layer()->scrollPositionDouble()); | 1172 DoublePoint newPosition = m_scrollableArea->minimumScrollPosition() + to
DoubleSize(m_layer->layer()->scrollPositionDouble()); |
1174 | 1173 |
1175 // FrameView::setScrollPosition doesn't work for compositor commits (int
eracts poorly with programmatic scroll animations) | 1174 // FrameView::setScrollPosition doesn't work for compositor commits (int
eracts poorly with programmatic scroll animations) |
1176 // so we need to use the ScrollableArea version. The FrameView method sh
ould go away soon anyway. | 1175 // so we need to use the ScrollableArea version. The FrameView method sh
ould go away soon anyway. |
1177 m_scrollableArea->ScrollableArea::setScrollPosition(newPosition, Composi
torScroll); | 1176 m_scrollableArea->ScrollableArea::setScrollPosition(newPosition, Composi
torScroll); |
1178 } | 1177 } |
1179 } | 1178 } |
1180 | 1179 |
| 1180 scoped_refptr<base::trace_event::ConvertableToTraceFormat> GraphicsLayer::TakeDe
bugInfo(cc::Layer* layer) |
| 1181 { |
| 1182 CString layerName = debugName(layer).utf8(); |
| 1183 scoped_refptr<base::trace_event::TracedValue> tracedValue = m_debugInfo.asTr
acedValue(); |
| 1184 tracedValue->SetString("layer_name", std::string(layerName.data(), layerName
.length())); |
| 1185 return tracedValue; |
| 1186 } |
| 1187 |
1181 PaintController* GraphicsLayer::paintController() | 1188 PaintController* GraphicsLayer::paintController() |
1182 { | 1189 { |
1183 if (!m_paintController) | 1190 if (!m_paintController) |
1184 m_paintController = PaintController::create(); | 1191 m_paintController = PaintController::create(); |
1185 return m_paintController.get(); | 1192 return m_paintController.get(); |
1186 } | 1193 } |
1187 | 1194 |
1188 } // namespace blink | 1195 } // namespace blink |
1189 | 1196 |
1190 #ifndef NDEBUG | 1197 #ifndef NDEBUG |
1191 void showGraphicsLayerTree(const blink::GraphicsLayer* layer) | 1198 void showGraphicsLayerTree(const blink::GraphicsLayer* layer) |
1192 { | 1199 { |
1193 if (!layer) { | 1200 if (!layer) { |
1194 fprintf(stderr, "Cannot showGraphicsLayerTree for (nil).\n"); | 1201 fprintf(stderr, "Cannot showGraphicsLayerTree for (nil).\n"); |
1195 return; | 1202 return; |
1196 } | 1203 } |
1197 | 1204 |
1198 String output = layer->layerTreeAsText(blink::LayerTreeIncludesDebugInfo); | 1205 String output = layer->layerTreeAsText(blink::LayerTreeIncludesDebugInfo); |
1199 fprintf(stderr, "%s\n", output.utf8().data()); | 1206 fprintf(stderr, "%s\n", output.utf8().data()); |
1200 } | 1207 } |
1201 #endif | 1208 #endif |
OLD | NEW |