1 | /* |
2 | * Copyright (C) 2012 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 | * THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #include "config.h" |
27 | #include "WebRenderLayer.h" |
28 | |
29 | #include "APIArray.h" |
30 | #include "APIString.h" |
31 | #include "WebPage.h" |
32 | #include <WebCore/Frame.h> |
33 | #include <WebCore/FrameLoader.h> |
34 | #include <WebCore/FrameLoaderClient.h> |
35 | #include <WebCore/RenderLayer.h> |
36 | #include <WebCore/RenderLayerBacking.h> |
37 | #include <WebCore/RenderView.h> |
38 | #include <WebCore/RenderWidget.h> |
39 | #include <WebCore/StyledElement.h> |
40 | |
41 | namespace WebKit { |
42 | |
43 | RefPtr<WebRenderLayer> WebRenderLayer::create(WebPage* page) |
44 | { |
45 | WebCore::Frame* mainFrame = page->mainFrame(); |
46 | if (!mainFrame) |
47 | return nullptr; |
48 | |
49 | if (!mainFrame->loader().client().hasHTMLView()) |
50 | return nullptr; |
51 | |
52 | WebCore::RenderView* contentRenderer = mainFrame->contentRenderer(); |
53 | if (!contentRenderer) |
54 | return nullptr; |
55 | |
56 | WebCore::RenderLayer* rootLayer = contentRenderer->layer(); |
57 | if (!rootLayer) |
58 | return nullptr; |
59 | |
60 | return adoptRef(new WebRenderLayer(rootLayer)); |
61 | } |
62 | |
63 | Ref<WebRenderLayer> WebRenderLayer::create(RefPtr<WebRenderObject>&& renderer, bool isReflection, bool isClipping, bool isClipped, CompositingLayerType type, WebCore::IntRect absoluteBoundingBox, double backingStoreMemoryEstimate, RefPtr<API::Array>&& negativeZOrderList, RefPtr<API::Array>&& normalFlowList, RefPtr<API::Array>&& positiveZOrderList, RefPtr<WebRenderLayer>&& frameContentsLayer) |
64 | { |
65 | return adoptRef(*new WebRenderLayer(WTFMove(renderer), isReflection, isClipping, isClipped, type, absoluteBoundingBox, backingStoreMemoryEstimate, WTFMove(negativeZOrderList), WTFMove(normalFlowList), WTFMove(positiveZOrderList), WTFMove(frameContentsLayer))); |
66 | } |
67 | |
68 | WebRenderLayer::WebRenderLayer(WebCore::RenderLayer* layer) |
69 | { |
70 | m_renderer = WebRenderObject::create(&layer->renderer()); |
71 | m_isReflection = layer->isReflection(); |
72 | |
73 | if (layer->isComposited()) { |
74 | WebCore::RenderLayerBacking* backing = layer->backing(); |
75 | m_isClipping = backing->hasClippingLayer(); |
76 | m_isClipped = backing->hasAncestorClippingLayer(); |
77 | switch (backing->compositingLayerType()) { |
78 | case WebCore::NormalCompositingLayer: |
79 | m_compositingLayerType = Normal; |
80 | break; |
81 | case WebCore::TiledCompositingLayer: |
82 | m_compositingLayerType = Tiled; |
83 | break; |
84 | case WebCore::MediaCompositingLayer: |
85 | m_compositingLayerType = Media; |
86 | break; |
87 | case WebCore::ContainerCompositingLayer: |
88 | m_compositingLayerType = Container; |
89 | break; |
90 | } |
91 | |
92 | m_backingStoreMemoryEstimate = backing->backingStoreMemoryEstimate(); |
93 | } else { |
94 | m_isClipping = false; |
95 | m_isClipped = false; |
96 | m_compositingLayerType = None; |
97 | m_backingStoreMemoryEstimate = 0; |
98 | } |
99 | |
100 | m_absoluteBoundingBox = layer->absoluteBoundingBox(); |
101 | |
102 | auto createArrayFromLayerList = [] (WebCore::RenderLayer::LayerList list) -> RefPtr<API::Array> { |
103 | if (!list.size()) |
104 | return nullptr; |
105 | |
106 | Vector<RefPtr<API::Object>> layers; |
107 | layers.reserveInitialCapacity(list.size()); |
108 | |
109 | for (auto* layer : list) |
110 | layers.uncheckedAppend(adoptRef(new WebRenderLayer(layer))); |
111 | |
112 | return API::Array::create(WTFMove(layers)); |
113 | }; |
114 | |
115 | m_negativeZOrderList = createArrayFromLayerList(layer->negativeZOrderLayers()); |
116 | m_normalFlowList = createArrayFromLayerList(layer->normalFlowLayers()); |
117 | m_positiveZOrderList = createArrayFromLayerList(layer->positiveZOrderLayers()); |
118 | |
119 | if (is<WebCore::RenderWidget>(layer->renderer())) { |
120 | if (WebCore::Document* contentDocument = downcast<WebCore::RenderWidget>(layer->renderer()).frameOwnerElement().contentDocument()) { |
121 | if (WebCore::RenderView* view = contentDocument->renderView()) |
122 | m_frameContentsLayer = adoptRef(new WebRenderLayer(view->layer())); |
123 | } |
124 | } |
125 | } |
126 | |
127 | WebRenderLayer::WebRenderLayer(RefPtr<WebRenderObject>&& renderer, bool isReflection, bool isClipping, bool isClipped, CompositingLayerType type, WebCore::IntRect absoluteBoundingBox, double backingStoreMemoryEstimate, RefPtr<API::Array>&& negativeZOrderList, RefPtr<API::Array>&& normalFlowList, RefPtr<API::Array>&& positiveZOrderList, RefPtr<WebRenderLayer>&& frameContentsLayer) |
128 | : m_renderer(WTFMove(renderer)) |
129 | , m_isReflection(isReflection) |
130 | , m_isClipping(isClipping) |
131 | , m_isClipped(isClipped) |
132 | , m_compositingLayerType(type) |
133 | , m_absoluteBoundingBox(absoluteBoundingBox) |
134 | , m_backingStoreMemoryEstimate(backingStoreMemoryEstimate) |
135 | , m_negativeZOrderList(WTFMove(negativeZOrderList)) |
136 | , m_normalFlowList(WTFMove(normalFlowList)) |
137 | , m_positiveZOrderList(WTFMove(positiveZOrderList)) |
138 | , m_frameContentsLayer(WTFMove(frameContentsLayer)) |
139 | { |
140 | } |
141 | |
142 | } // namespace WebKit |
143 | |