Line data Source code
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 "TexturedLayerMLGPU.h"
7 : #include "LayerManagerMLGPU.h"
8 : #include "RenderViewMLGPU.h"
9 : #include "FrameBuilder.h"
10 : #include "mozilla/gfx/Types.h"
11 : #include "mozilla/layers/ImageHost.h"
12 : #include "UnitTransforms.h"
13 :
14 : namespace mozilla {
15 : namespace layers {
16 :
17 : using namespace gfx;
18 :
19 0 : TexturedLayerMLGPU::TexturedLayerMLGPU(LayerManagerMLGPU* aManager)
20 0 : : LayerMLGPU(aManager)
21 : {
22 0 : }
23 :
24 0 : TexturedLayerMLGPU::~TexturedLayerMLGPU()
25 : {
26 : // Note: we have to cleanup resources in derived classes, since we can't
27 : // easily tell in our destructor if we have a TempImageLayerMLGPU, which
28 : // should not have its compositable detached, and we can't call GetLayer
29 : // here.
30 0 : }
31 :
32 : bool
33 0 : TexturedLayerMLGPU::SetCompositableHost(CompositableHost* aHost)
34 : {
35 0 : switch (aHost->GetType()) {
36 : case CompositableType::IMAGE:
37 0 : mHost = aHost->AsImageHost();
38 0 : return true;
39 : default:
40 0 : return false;
41 : }
42 : }
43 :
44 : CompositableHost*
45 0 : TexturedLayerMLGPU::GetCompositableHost()
46 : {
47 0 : if (mHost && mHost->IsAttached()) {
48 0 : return mHost.get();
49 : }
50 0 : return nullptr;
51 : }
52 :
53 : RefPtr<TextureSource>
54 0 : TexturedLayerMLGPU::BindAndGetTexture()
55 : {
56 0 : if (!mHost) {
57 0 : return nullptr;
58 : }
59 :
60 0 : LayerManagerMLGPU* lm = GetLayerManager()->AsLayerManagerMLGPU();
61 :
62 : // Note: we don't call FinishRendering since mask layers do not need
63 : // composite notifications or bias updates. (This function should
64 : // not be called for non-mask-layers).
65 0 : ImageHost::RenderInfo info;
66 0 : if (!mHost->PrepareToRender(lm->GetTextureSourceProvider(), &info)) {
67 0 : return nullptr;
68 : }
69 :
70 0 : RefPtr<TextureSource> source = mHost->AcquireTextureSource(info);
71 0 : if (!source) {
72 0 : return nullptr;
73 : }
74 :
75 0 : mTexture = source;
76 0 : return source;
77 : }
78 :
79 : bool
80 0 : TexturedLayerMLGPU::OnPrepareToRender(FrameBuilder* aBuilder)
81 : {
82 0 : if (!mHost) {
83 0 : return false;
84 : }
85 :
86 0 : LayerManagerMLGPU* lm = GetLayerManager()->AsLayerManagerMLGPU();
87 :
88 0 : ImageHost::RenderInfo info;
89 0 : if (!mHost->PrepareToRender(lm->GetTextureSourceProvider(), &info)) {
90 0 : return false;
91 : }
92 :
93 0 : RefPtr<TextureSource> source = mHost->AcquireTextureSource(info);
94 0 : if (!source) {
95 0 : return false;
96 : }
97 :
98 0 : if (source->AsBigImageIterator()) {
99 0 : mBigImageTexture = source;
100 0 : mTexture = nullptr;
101 : } else {
102 0 : mTexture = source;
103 : }
104 :
105 0 : mPictureRect = IntRect(0, 0, info.img->mPictureRect.width, info.img->mPictureRect.height);
106 :
107 0 : mHost->FinishRendering(info);
108 0 : return true;
109 : }
110 :
111 : void
112 0 : TexturedLayerMLGPU::AssignToView(FrameBuilder* aBuilder,
113 : RenderViewMLGPU* aView,
114 : Maybe<Polygon>&& aGeometry)
115 : {
116 0 : if (mBigImageTexture) {
117 0 : BigImageIterator* iter = mBigImageTexture->AsBigImageIterator();
118 0 : iter->BeginBigImageIteration();
119 0 : AssignBigImage(aBuilder, aView, iter, aGeometry);
120 0 : iter->EndBigImageIteration();
121 : } else {
122 0 : LayerMLGPU::AssignToView(aBuilder, aView, Move(aGeometry));
123 : }
124 0 : }
125 :
126 : void
127 0 : TexturedLayerMLGPU::AssignBigImage(FrameBuilder* aBuilder,
128 : RenderViewMLGPU* aView,
129 : BigImageIterator* aIter,
130 : const Maybe<Polygon>& aGeometry)
131 : {
132 0 : const Matrix4x4& transform = GetLayer()->GetEffectiveTransformForBuffer();
133 :
134 : // Note that we don't need to assign these in any particular order, since
135 : // they do not overlap.
136 0 : do {
137 0 : IntRect tileRect = aIter->GetTileRect();
138 0 : IntRect rect = tileRect.Intersect(mPictureRect);
139 0 : if (rect.IsEmpty()) {
140 0 : continue;
141 : }
142 :
143 : {
144 0 : Rect screenRect = transform.TransformBounds(Rect(rect));
145 0 : screenRect.MoveBy(-aView->GetTargetOffset());
146 0 : screenRect = screenRect.Intersect(Rect(mComputedClipRect.ToUnknownRect()));
147 0 : if (screenRect.IsEmpty()) {
148 : // This tile is not in the clip region, so skip it.
149 0 : continue;
150 : }
151 : }
152 :
153 0 : RefPtr<TextureSource> tile = mBigImageTexture->ExtractCurrentTile();
154 0 : if (!tile) {
155 0 : continue;
156 : }
157 :
158 : // Create a temporary item.
159 0 : RefPtr<TempImageLayerMLGPU> item = new TempImageLayerMLGPU(aBuilder->GetManager());
160 0 : item->Init(this, tile, rect);
161 :
162 0 : Maybe<Polygon> geometry = aGeometry;
163 0 : item->AddBoundsToView(aBuilder, aView, Move(geometry));
164 :
165 : // Since the layer tree is not holding this alive, we have to ask the
166 : // FrameBuilder to do it for us.
167 0 : aBuilder->RetainTemporaryLayer(item);
168 0 : } while (aIter->NextTile());
169 0 : }
170 :
171 0 : TempImageLayerMLGPU::TempImageLayerMLGPU(LayerManagerMLGPU* aManager)
172 : : ImageLayer(aManager, static_cast<HostLayer*>(this)),
173 0 : TexturedLayerMLGPU(aManager)
174 : {
175 0 : }
176 :
177 0 : TempImageLayerMLGPU::~TempImageLayerMLGPU()
178 : {
179 0 : }
180 :
181 : void
182 0 : TempImageLayerMLGPU::Init(TexturedLayerMLGPU* aSource,
183 : const RefPtr<TextureSource>& aTexture,
184 : const gfx::IntRect& aPictureRect)
185 : {
186 : // ImageLayer properties.
187 0 : mEffectiveTransform = aSource->GetLayer()->GetEffectiveTransform();
188 0 : mEffectiveTransformForBuffer = aSource->GetLayer()->GetEffectiveTransformForBuffer();
189 :
190 : // Base LayerMLGPU properties.
191 0 : mComputedClipRect = aSource->GetComputedClipRect();
192 0 : mMask = aSource->GetMask();
193 0 : mComputedOpacity = aSource->GetComputedOpacity();
194 :
195 : // TexturedLayerMLGPU properties.
196 0 : mHost = aSource->GetImageHost();
197 0 : mTexture = aTexture;
198 0 : mPictureRect = aPictureRect;
199 :
200 : // Local properties.
201 0 : mFilter = aSource->GetSamplingFilter();
202 0 : mShadowVisibleRegion = aSource->GetShadowVisibleRegion();
203 0 : mIsOpaque = aSource->IsContentOpaque();
204 :
205 : // Set this layer to prepared so IsPrepared() assertions don't fire.
206 0 : MarkPrepared();
207 0 : }
208 :
209 : } // namespace layers
210 : } // namespace mozilla
|