|
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #include "ThebesLayerComposite.h" |
|
7 #include "CompositableHost.h" // for TiledLayerProperties, etc |
|
8 #include "FrameMetrics.h" // for FrameMetrics |
|
9 #include "Units.h" // for CSSRect, LayerPixel, etc |
|
10 #include "gfx2DGlue.h" // for ToMatrix4x4 |
|
11 #include "gfxUtils.h" // for gfxUtils, etc |
|
12 #include "mozilla/Assertions.h" // for MOZ_ASSERT, etc |
|
13 #include "mozilla/gfx/Matrix.h" // for Matrix4x4 |
|
14 #include "mozilla/gfx/Point.h" // for Point |
|
15 #include "mozilla/gfx/Rect.h" // for RoundedToInt, Rect |
|
16 #include "mozilla/gfx/Types.h" // for Filter::Filter::LINEAR |
|
17 #include "mozilla/layers/Compositor.h" // for Compositor |
|
18 #include "mozilla/layers/ContentHost.h" // for ContentHost |
|
19 #include "mozilla/layers/Effects.h" // for EffectChain |
|
20 #include "mozilla/mozalloc.h" // for operator delete |
|
21 #include "nsAString.h" |
|
22 #include "nsAutoPtr.h" // for nsRefPtr |
|
23 #include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, etc |
|
24 #include "nsMathUtils.h" // for NS_lround |
|
25 #include "nsPoint.h" // for nsIntPoint |
|
26 #include "nsRect.h" // for nsIntRect |
|
27 #include "nsSize.h" // for nsIntSize |
|
28 #include "nsString.h" // for nsAutoCString |
|
29 #include "TextRenderer.h" |
|
30 #include "GeckoProfiler.h" |
|
31 |
|
32 namespace mozilla { |
|
33 namespace layers { |
|
34 |
|
35 class TiledLayerComposer; |
|
36 |
|
37 ThebesLayerComposite::ThebesLayerComposite(LayerManagerComposite *aManager) |
|
38 : ThebesLayer(aManager, nullptr) |
|
39 , LayerComposite(aManager) |
|
40 , mBuffer(nullptr) |
|
41 , mRequiresTiledProperties(false) |
|
42 { |
|
43 MOZ_COUNT_CTOR(ThebesLayerComposite); |
|
44 mImplData = static_cast<LayerComposite*>(this); |
|
45 } |
|
46 |
|
47 ThebesLayerComposite::~ThebesLayerComposite() |
|
48 { |
|
49 MOZ_COUNT_DTOR(ThebesLayerComposite); |
|
50 CleanupResources(); |
|
51 } |
|
52 |
|
53 bool |
|
54 ThebesLayerComposite::SetCompositableHost(CompositableHost* aHost) |
|
55 { |
|
56 switch (aHost->GetType()) { |
|
57 case BUFFER_CONTENT_INC: |
|
58 case BUFFER_TILED: |
|
59 case COMPOSITABLE_CONTENT_SINGLE: |
|
60 case COMPOSITABLE_CONTENT_DOUBLE: |
|
61 mBuffer = static_cast<ContentHost*>(aHost); |
|
62 return true; |
|
63 default: |
|
64 return false; |
|
65 } |
|
66 } |
|
67 |
|
68 void |
|
69 ThebesLayerComposite::Disconnect() |
|
70 { |
|
71 Destroy(); |
|
72 } |
|
73 |
|
74 void |
|
75 ThebesLayerComposite::Destroy() |
|
76 { |
|
77 if (!mDestroyed) { |
|
78 CleanupResources(); |
|
79 mDestroyed = true; |
|
80 } |
|
81 } |
|
82 |
|
83 Layer* |
|
84 ThebesLayerComposite::GetLayer() |
|
85 { |
|
86 return this; |
|
87 } |
|
88 |
|
89 TiledLayerComposer* |
|
90 ThebesLayerComposite::GetTiledLayerComposer() |
|
91 { |
|
92 if (!mBuffer) { |
|
93 return nullptr; |
|
94 } |
|
95 MOZ_ASSERT(mBuffer->IsAttached()); |
|
96 return mBuffer->AsTiledLayerComposer(); |
|
97 } |
|
98 |
|
99 LayerRenderState |
|
100 ThebesLayerComposite::GetRenderState() |
|
101 { |
|
102 if (!mBuffer || !mBuffer->IsAttached() || mDestroyed) { |
|
103 return LayerRenderState(); |
|
104 } |
|
105 return mBuffer->GetRenderState(); |
|
106 } |
|
107 |
|
108 void |
|
109 ThebesLayerComposite::RenderLayer(const nsIntRect& aClipRect) |
|
110 { |
|
111 if (!mBuffer || !mBuffer->IsAttached()) { |
|
112 return; |
|
113 } |
|
114 PROFILER_LABEL("ThebesLayerComposite", "RenderLayer"); |
|
115 |
|
116 MOZ_ASSERT(mBuffer->GetCompositor() == mCompositeManager->GetCompositor() && |
|
117 mBuffer->GetLayer() == this, |
|
118 "buffer is corrupted"); |
|
119 |
|
120 gfx::Rect clipRect(aClipRect.x, aClipRect.y, aClipRect.width, aClipRect.height); |
|
121 |
|
122 #ifdef MOZ_DUMP_PAINTING |
|
123 if (gfxUtils::sDumpPainting) { |
|
124 RefPtr<gfx::DataSourceSurface> surf = mBuffer->GetAsSurface(); |
|
125 if (surf) { |
|
126 WriteSnapshotToDumpFile(this, surf); |
|
127 } |
|
128 } |
|
129 #endif |
|
130 |
|
131 EffectChain effectChain(this); |
|
132 LayerManagerComposite::AutoAddMaskEffect autoMaskEffect(mMaskLayer, effectChain); |
|
133 |
|
134 nsIntRegion visibleRegion = GetEffectiveVisibleRegion(); |
|
135 |
|
136 TiledLayerProperties tiledLayerProps; |
|
137 if (mRequiresTiledProperties) { |
|
138 tiledLayerProps.mVisibleRegion = visibleRegion; |
|
139 tiledLayerProps.mEffectiveResolution = GetEffectiveResolution(); |
|
140 tiledLayerProps.mValidRegion = mValidRegion; |
|
141 } |
|
142 |
|
143 mBuffer->SetPaintWillResample(MayResample()); |
|
144 |
|
145 mBuffer->Composite(effectChain, |
|
146 GetEffectiveOpacity(), |
|
147 GetEffectiveTransform(), |
|
148 gfx::Filter::LINEAR, |
|
149 clipRect, |
|
150 &visibleRegion, |
|
151 mRequiresTiledProperties ? &tiledLayerProps |
|
152 : nullptr); |
|
153 mBuffer->BumpFlashCounter(); |
|
154 |
|
155 if (mRequiresTiledProperties) { |
|
156 mValidRegion = tiledLayerProps.mValidRegion; |
|
157 } |
|
158 |
|
159 mCompositeManager->GetCompositor()->MakeCurrent(); |
|
160 } |
|
161 |
|
162 CompositableHost* |
|
163 ThebesLayerComposite::GetCompositableHost() |
|
164 { |
|
165 if (mBuffer && mBuffer->IsAttached()) { |
|
166 return mBuffer.get(); |
|
167 } |
|
168 |
|
169 return nullptr; |
|
170 } |
|
171 |
|
172 void |
|
173 ThebesLayerComposite::CleanupResources() |
|
174 { |
|
175 if (mBuffer) { |
|
176 mBuffer->Detach(this); |
|
177 } |
|
178 mBuffer = nullptr; |
|
179 } |
|
180 |
|
181 CSSToScreenScale |
|
182 ThebesLayerComposite::GetEffectiveResolution() |
|
183 { |
|
184 for (ContainerLayer* parent = GetParent(); parent; parent = parent->GetParent()) { |
|
185 const FrameMetrics& metrics = parent->GetFrameMetrics(); |
|
186 if (metrics.GetScrollId() != FrameMetrics::NULL_SCROLL_ID) { |
|
187 return metrics.GetZoom(); |
|
188 } |
|
189 } |
|
190 |
|
191 return CSSToScreenScale(1.0); |
|
192 } |
|
193 |
|
194 nsACString& |
|
195 ThebesLayerComposite::PrintInfo(nsACString& aTo, const char* aPrefix) |
|
196 { |
|
197 ThebesLayer::PrintInfo(aTo, aPrefix); |
|
198 aTo += "\n"; |
|
199 if (mBuffer && mBuffer->IsAttached()) { |
|
200 nsAutoCString pfx(aPrefix); |
|
201 pfx += " "; |
|
202 mBuffer->PrintInfo(aTo, pfx.get()); |
|
203 } |
|
204 return aTo; |
|
205 } |
|
206 |
|
207 } /* layers */ |
|
208 } /* mozilla */ |