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...) Expand all 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" |
| 32 #include "cc/layers/layer.h" |
31 #include "platform/DragImage.h" | 33 #include "platform/DragImage.h" |
| 34 #include "platform/JSONValues.h" |
32 #include "platform/TraceEvent.h" | 35 #include "platform/TraceEvent.h" |
33 #include "platform/geometry/FloatRect.h" | 36 #include "platform/geometry/FloatRect.h" |
34 #include "platform/geometry/LayoutRect.h" | 37 #include "platform/geometry/LayoutRect.h" |
35 #include "platform/graphics/BitmapImage.h" | 38 #include "platform/graphics/BitmapImage.h" |
36 #include "platform/graphics/FirstPaintInvalidationTracking.h" | 39 #include "platform/graphics/FirstPaintInvalidationTracking.h" |
37 #include "platform/graphics/GraphicsContext.h" | 40 #include "platform/graphics/GraphicsContext.h" |
38 #include "platform/graphics/GraphicsLayerFactory.h" | 41 #include "platform/graphics/GraphicsLayerFactory.h" |
39 #include "platform/graphics/Image.h" | 42 #include "platform/graphics/Image.h" |
40 #include "platform/graphics/LinkHighlight.h" | 43 #include "platform/graphics/LinkHighlight.h" |
41 #include "platform/graphics/filters/SkiaImageFilterBuilder.h" | 44 #include "platform/graphics/filters/SkiaImageFilterBuilder.h" |
42 #include "platform/graphics/paint/DrawingRecorder.h" | 45 #include "platform/graphics/paint/DrawingRecorder.h" |
43 #include "platform/graphics/paint/PaintController.h" | 46 #include "platform/graphics/paint/PaintController.h" |
44 #include "platform/scroll/ScrollableArea.h" | 47 #include "platform/scroll/ScrollableArea.h" |
45 #include "platform/text/TextStream.h" | 48 #include "platform/text/TextStream.h" |
46 #include "public/platform/Platform.h" | 49 #include "public/platform/Platform.h" |
47 #include "public/platform/WebCompositorAnimation.h" | 50 #include "public/platform/WebCompositorAnimation.h" |
48 #include "public/platform/WebCompositorSupport.h" | 51 #include "public/platform/WebCompositorSupport.h" |
49 #include "public/platform/WebFilterOperations.h" | 52 #include "public/platform/WebFilterOperations.h" |
50 #include "public/platform/WebFloatPoint.h" | 53 #include "public/platform/WebFloatPoint.h" |
51 #include "public/platform/WebFloatRect.h" | 54 #include "public/platform/WebFloatRect.h" |
52 #include "public/platform/WebGraphicsLayerDebugInfo.h" | |
53 #include "public/platform/WebLayer.h" | 55 #include "public/platform/WebLayer.h" |
54 #include "public/platform/WebPoint.h" | 56 #include "public/platform/WebPoint.h" |
55 #include "public/platform/WebSize.h" | 57 #include "public/platform/WebSize.h" |
56 #include "wtf/CurrentTime.h" | 58 #include "wtf/CurrentTime.h" |
57 #include "wtf/HashMap.h" | 59 #include "wtf/HashMap.h" |
58 #include "wtf/HashSet.h" | 60 #include "wtf/HashSet.h" |
| 61 #include "wtf/text/StringUTF8Adaptor.h" |
59 #include "wtf/text/WTFString.h" | 62 #include "wtf/text/WTFString.h" |
60 #include <algorithm> | 63 #include <algorithm> |
61 | 64 |
62 #ifndef NDEBUG | 65 #ifndef NDEBUG |
63 #include <stdio.h> | 66 #include <stdio.h> |
64 #endif | 67 #endif |
65 | 68 |
66 namespace blink { | 69 namespace blink { |
67 | 70 |
68 static bool s_drawDebugRedFill = true; | 71 static bool s_drawDebugRedFill = true; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 , m_3dRenderingContext(0) | 120 , m_3dRenderingContext(0) |
118 { | 121 { |
119 #if ENABLE(ASSERT) | 122 #if ENABLE(ASSERT) |
120 if (m_client) | 123 if (m_client) |
121 m_client->verifyNotPainting(); | 124 m_client->verifyNotPainting(); |
122 #endif | 125 #endif |
123 | 126 |
124 m_contentLayerDelegate = adoptPtr(new ContentLayerDelegate(this)); | 127 m_contentLayerDelegate = adoptPtr(new ContentLayerDelegate(this)); |
125 m_layer = adoptPtr(Platform::current()->compositorSupport()->createContentLa
yer(m_contentLayerDelegate.get())); | 128 m_layer = adoptPtr(Platform::current()->compositorSupport()->createContentLa
yer(m_contentLayerDelegate.get())); |
126 m_layer->layer()->setDrawsContent(m_drawsContent && m_contentsVisible); | 129 m_layer->layer()->setDrawsContent(m_drawsContent && m_contentsVisible); |
127 m_layer->layer()->setWebLayerClient(this); | 130 m_layer->layer()->setLayerClient(this); |
128 | 131 |
129 // TODO(rbyers): Expose control over this to the web - crbug.com/489802: | 132 // TODO(rbyers): Expose control over this to the web - crbug.com/489802: |
130 setScrollBlocksOn(WebScrollBlocksOnStartTouch | WebScrollBlocksOnWheelEvent)
; | 133 setScrollBlocksOn(WebScrollBlocksOnStartTouch | WebScrollBlocksOnWheelEvent)
; |
131 } | 134 } |
132 | 135 |
133 GraphicsLayer::~GraphicsLayer() | 136 GraphicsLayer::~GraphicsLayer() |
134 { | 137 { |
135 for (size_t i = 0; i < m_linkHighlights.size(); ++i) | 138 for (size_t i = 0; i < m_linkHighlights.size(); ++i) |
136 m_linkHighlights[i]->clearCurrentGraphicsLayer(); | 139 m_linkHighlights[i]->clearCurrentGraphicsLayer(); |
137 m_linkHighlights.clear(); | 140 m_linkHighlights.clear(); |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 if (childrenChanged) | 450 if (childrenChanged) |
448 updateChildList(); | 451 updateChildList(); |
449 } | 452 } |
450 | 453 |
451 void GraphicsLayer::setupContentsLayer(WebLayer* contentsLayer) | 454 void GraphicsLayer::setupContentsLayer(WebLayer* contentsLayer) |
452 { | 455 { |
453 ASSERT(contentsLayer); | 456 ASSERT(contentsLayer); |
454 m_contentsLayer = contentsLayer; | 457 m_contentsLayer = contentsLayer; |
455 m_contentsLayerId = m_contentsLayer->id(); | 458 m_contentsLayerId = m_contentsLayer->id(); |
456 | 459 |
457 m_contentsLayer->setWebLayerClient(this); | 460 m_contentsLayer->setLayerClient(this); |
458 m_contentsLayer->setTransformOrigin(FloatPoint3D()); | 461 m_contentsLayer->setTransformOrigin(FloatPoint3D()); |
459 m_contentsLayer->setUseParentBackfaceVisibility(true); | 462 m_contentsLayer->setUseParentBackfaceVisibility(true); |
460 | 463 |
461 // It is necessary to call setDrawsContent as soon as we receive the new con
tentsLayer, for | 464 // It is necessary to call setDrawsContent as soon as we receive the new con
tentsLayer, for |
462 // the correctness of early exit conditions in setDrawsContent() and setCont
entsVisible(). | 465 // the correctness of early exit conditions in setDrawsContent() and setCont
entsVisible(). |
463 m_contentsLayer->setDrawsContent(m_contentsVisible); | 466 m_contentsLayer->setDrawsContent(m_contentsVisible); |
464 | 467 |
465 // Insert the content layer first. Video elements require this, because they
have | 468 // Insert the content layer first. Video elements require this, because they
have |
466 // shadow content that must display in front of the video. | 469 // shadow content that must display in front of the video. |
467 m_layer->layer()->insertChild(m_contentsLayer, 0); | 470 m_layer->layer()->insertChild(m_contentsLayer, 0); |
(...skipping 10 matching lines...) Expand all Loading... |
478 | 481 |
479 m_contentsLayer = 0; | 482 m_contentsLayer = 0; |
480 m_contentsLayerId = 0; | 483 m_contentsLayerId = 0; |
481 } | 484 } |
482 | 485 |
483 GraphicsLayerDebugInfo& GraphicsLayer::debugInfo() | 486 GraphicsLayerDebugInfo& GraphicsLayer::debugInfo() |
484 { | 487 { |
485 return m_debugInfo; | 488 return m_debugInfo; |
486 } | 489 } |
487 | 490 |
488 WebGraphicsLayerDebugInfo* GraphicsLayer::takeDebugInfoFor(WebLayer* layer) | |
489 { | |
490 GraphicsLayerDebugInfo* clone = m_debugInfo.clone(); | |
491 clone->setDebugName(debugName(layer)); | |
492 return clone; | |
493 } | |
494 | |
495 WebLayer* GraphicsLayer::contentsLayerIfRegistered() | 491 WebLayer* GraphicsLayer::contentsLayerIfRegistered() |
496 { | 492 { |
497 clearContentsLayerIfUnregistered(); | 493 clearContentsLayerIfUnregistered(); |
498 return m_contentsLayer; | 494 return m_contentsLayer; |
499 } | 495 } |
500 | 496 |
501 void GraphicsLayer::resetTrackedPaintInvalidations() | 497 void GraphicsLayer::resetTrackedPaintInvalidations() |
502 { | 498 { |
503 paintInvalidationTrackingMap().remove(this); | 499 paintInvalidationTrackingMap().remove(this); |
504 } | 500 } |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 return json; | 760 return json; |
765 } | 761 } |
766 | 762 |
767 String GraphicsLayer::layerTreeAsText(LayerTreeFlags flags) const | 763 String GraphicsLayer::layerTreeAsText(LayerTreeFlags flags) const |
768 { | 764 { |
769 RenderingContextMap renderingContextMap; | 765 RenderingContextMap renderingContextMap; |
770 RefPtr<JSONObject> json = layerTreeAsJSON(flags, renderingContextMap); | 766 RefPtr<JSONObject> json = layerTreeAsJSON(flags, renderingContextMap); |
771 return json->toPrettyJSONString(); | 767 return json->toPrettyJSONString(); |
772 } | 768 } |
773 | 769 |
774 String GraphicsLayer::debugName(WebLayer* webLayer) const | 770 static const cc::Layer* ccLayerForWebLayer(const WebLayer* webLayer) |
| 771 { |
| 772 return webLayer ? webLayer->ccLayer() : nullptr; |
| 773 } |
| 774 |
| 775 String GraphicsLayer::debugName(cc::Layer* layer) const |
775 { | 776 { |
776 String name; | 777 String name; |
777 if (!m_client) | 778 if (!m_client) |
778 return name; | 779 return name; |
779 | 780 |
780 String highlightDebugName; | 781 String highlightDebugName; |
781 for (size_t i = 0; i < m_linkHighlights.size(); ++i) { | 782 for (size_t i = 0; i < m_linkHighlights.size(); ++i) { |
782 if (webLayer == m_linkHighlights[i]->layer()) { | 783 if (layer == ccLayerForWebLayer(m_linkHighlights[i]->layer())) { |
783 highlightDebugName = "LinkHighlight[" + String::number(i) + "] for "
+ m_client->debugName(this); | 784 highlightDebugName = "LinkHighlight[" + String::number(i) + "] for "
+ m_client->debugName(this); |
784 break; | 785 break; |
785 } | 786 } |
786 } | 787 } |
787 | 788 |
788 if (webLayer == m_contentsLayer) { | 789 if (layer->id() == m_contentsLayerId) { |
789 name = "ContentsLayer for " + m_client->debugName(this); | 790 name = "ContentsLayer for " + m_client->debugName(this); |
790 } else if (!highlightDebugName.isEmpty()) { | 791 } else if (!highlightDebugName.isEmpty()) { |
791 name = highlightDebugName; | 792 name = highlightDebugName; |
792 } else if (webLayer == m_layer->layer()) { | 793 } else if (layer == ccLayerForWebLayer(m_layer->layer())) { |
793 name = m_client->debugName(this); | 794 name = m_client->debugName(this); |
794 } else { | 795 } else { |
795 ASSERT_NOT_REACHED(); | 796 ASSERT_NOT_REACHED(); |
796 } | 797 } |
797 return name; | 798 return name; |
798 } | 799 } |
799 | 800 |
800 void GraphicsLayer::setCompositingReasons(CompositingReasons reasons) | 801 void GraphicsLayer::setCompositingReasons(CompositingReasons reasons) |
801 { | 802 { |
802 m_debugInfo.setCompositingReasons(reasons); | 803 m_debugInfo.setCompositingReasons(reasons); |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1136 if (m_paintingPhase == phase) | 1137 if (m_paintingPhase == phase) |
1137 return; | 1138 return; |
1138 m_paintingPhase = phase; | 1139 m_paintingPhase = phase; |
1139 setNeedsDisplay(); | 1140 setNeedsDisplay(); |
1140 } | 1141 } |
1141 | 1142 |
1142 void GraphicsLayer::addLinkHighlight(LinkHighlight* linkHighlight) | 1143 void GraphicsLayer::addLinkHighlight(LinkHighlight* linkHighlight) |
1143 { | 1144 { |
1144 ASSERT(linkHighlight && !m_linkHighlights.contains(linkHighlight)); | 1145 ASSERT(linkHighlight && !m_linkHighlights.contains(linkHighlight)); |
1145 m_linkHighlights.append(linkHighlight); | 1146 m_linkHighlights.append(linkHighlight); |
1146 linkHighlight->layer()->setWebLayerClient(this); | 1147 linkHighlight->layer()->setLayerClient(this); |
1147 updateChildList(); | 1148 updateChildList(); |
1148 } | 1149 } |
1149 | 1150 |
1150 void GraphicsLayer::removeLinkHighlight(LinkHighlight* linkHighlight) | 1151 void GraphicsLayer::removeLinkHighlight(LinkHighlight* linkHighlight) |
1151 { | 1152 { |
1152 m_linkHighlights.remove(m_linkHighlights.find(linkHighlight)); | 1153 m_linkHighlights.remove(m_linkHighlights.find(linkHighlight)); |
1153 updateChildList(); | 1154 updateChildList(); |
1154 } | 1155 } |
1155 | 1156 |
1156 void GraphicsLayer::setScrollableArea(ScrollableArea* scrollableArea, bool isVie
wport) | 1157 void GraphicsLayer::setScrollableArea(ScrollableArea* scrollableArea, bool isVie
wport) |
(...skipping 27 matching lines...) Expand all Loading... |
1184 { | 1185 { |
1185 if (m_scrollableArea) { | 1186 if (m_scrollableArea) { |
1186 DoublePoint newPosition = m_scrollableArea->minimumScrollPosition() + to
DoubleSize(m_layer->layer()->scrollPositionDouble()); | 1187 DoublePoint newPosition = m_scrollableArea->minimumScrollPosition() + to
DoubleSize(m_layer->layer()->scrollPositionDouble()); |
1187 | 1188 |
1188 // FrameView::setScrollPosition doesn't work for compositor commits (int
eracts poorly with programmatic scroll animations) | 1189 // FrameView::setScrollPosition doesn't work for compositor commits (int
eracts poorly with programmatic scroll animations) |
1189 // so we need to use the ScrollableArea version. The FrameView method sh
ould go away soon anyway. | 1190 // so we need to use the ScrollableArea version. The FrameView method sh
ould go away soon anyway. |
1190 m_scrollableArea->ScrollableArea::setScrollPosition(newPosition, Composi
torScroll); | 1191 m_scrollableArea->ScrollableArea::setScrollPosition(newPosition, Composi
torScroll); |
1191 } | 1192 } |
1192 } | 1193 } |
1193 | 1194 |
| 1195 scoped_refptr<base::trace_event::ConvertableToTraceFormat> GraphicsLayer::TakeDe
bugInfo(cc::Layer* layer) |
| 1196 { |
| 1197 scoped_refptr<base::trace_event::TracedValue> tracedValue = m_debugInfo.asTr
acedValue(); |
| 1198 tracedValue->SetString("layer_name", WTF::StringUTF8Adaptor(debugName(layer)
).asStringPiece()); |
| 1199 return tracedValue; |
| 1200 } |
| 1201 |
1194 PaintController* GraphicsLayer::paintController() | 1202 PaintController* GraphicsLayer::paintController() |
1195 { | 1203 { |
1196 if (!m_paintController) | 1204 if (!m_paintController) |
1197 m_paintController = PaintController::create(); | 1205 m_paintController = PaintController::create(); |
1198 return m_paintController.get(); | 1206 return m_paintController.get(); |
1199 } | 1207 } |
1200 | 1208 |
1201 } // namespace blink | 1209 } // namespace blink |
1202 | 1210 |
1203 #ifndef NDEBUG | 1211 #ifndef NDEBUG |
1204 void showGraphicsLayerTree(const blink::GraphicsLayer* layer) | 1212 void showGraphicsLayerTree(const blink::GraphicsLayer* layer) |
1205 { | 1213 { |
1206 if (!layer) { | 1214 if (!layer) { |
1207 fprintf(stderr, "Cannot showGraphicsLayerTree for (nil).\n"); | 1215 fprintf(stderr, "Cannot showGraphicsLayerTree for (nil).\n"); |
1208 return; | 1216 return; |
1209 } | 1217 } |
1210 | 1218 |
1211 String output = layer->layerTreeAsText(blink::LayerTreeIncludesDebugInfo); | 1219 String output = layer->layerTreeAsText(blink::LayerTreeIncludesDebugInfo); |
1212 fprintf(stderr, "%s\n", output.utf8().data()); | 1220 fprintf(stderr, "%s\n", output.utf8().data()); |
1213 } | 1221 } |
1214 #endif | 1222 #endif |
OLD | NEW |