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