1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "TexturedLayerMLGPU.h"
8 #include "LayerManagerMLGPU.h"
9 #include "RenderViewMLGPU.h"
10 #include "FrameBuilder.h"
11 #include "mozilla/gfx/Types.h"
12 #include "mozilla/layers/ImageHost.h"
13 #include "UnitTransforms.h"
20 TexturedLayerMLGPU::TexturedLayerMLGPU(LayerManagerMLGPU
* aManager
)
21 : LayerMLGPU(aManager
) {}
23 TexturedLayerMLGPU::~TexturedLayerMLGPU() {
24 // Note: we have to cleanup resources in derived classes, since we can't
25 // easily tell in our destructor if we have a TempImageLayerMLGPU, which
26 // should not have its compositable detached, and we can't call GetLayer
30 bool TexturedLayerMLGPU::SetCompositableHost(CompositableHost
* aHost
) {
31 switch (aHost
->GetType()) {
32 case CompositableType::IMAGE
:
33 mHost
= aHost
->AsImageHost();
40 CompositableHost
* TexturedLayerMLGPU::GetCompositableHost() {
41 if (mHost
&& mHost
->IsAttached()) {
47 RefPtr
<TextureSource
> TexturedLayerMLGPU::BindAndGetTexture() {
52 LayerManagerMLGPU
* lm
= GetLayerManager()->AsLayerManagerMLGPU();
54 // Note: we don't call FinishRendering since mask layers do not need
55 // composite notifications or bias updates. (This function should
56 // not be called for non-mask-layers).
57 ImageHost::RenderInfo info
;
58 if (!mHost
->PrepareToRender(lm
->GetTextureSourceProvider(), &info
)) {
62 RefPtr
<TextureSource
> source
= mHost
->AcquireTextureSource(info
);
71 bool TexturedLayerMLGPU::OnPrepareToRender(FrameBuilder
* aBuilder
) {
76 LayerManagerMLGPU
* lm
= GetLayerManager()->AsLayerManagerMLGPU();
78 ImageHost::RenderInfo info
;
79 if (!mHost
->PrepareToRender(lm
->GetTextureSourceProvider(), &info
)) {
83 RefPtr
<TextureSource
> source
= mHost
->AcquireTextureSource(info
);
88 if (source
->AsBigImageIterator()) {
89 mBigImageTexture
= source
;
95 mPictureRect
= IntRect(0, 0, info
.img
->mPictureRect
.Width(),
96 info
.img
->mPictureRect
.Height());
98 mHost
->FinishRendering(info
);
102 void TexturedLayerMLGPU::AssignToView(FrameBuilder
* aBuilder
,
103 RenderViewMLGPU
* aView
,
104 Maybe
<Polygon
>&& aGeometry
) {
105 if (mBigImageTexture
) {
106 BigImageIterator
* iter
= mBigImageTexture
->AsBigImageIterator();
107 iter
->BeginBigImageIteration();
108 AssignBigImage(aBuilder
, aView
, iter
, aGeometry
);
109 iter
->EndBigImageIteration();
111 LayerMLGPU::AssignToView(aBuilder
, aView
, std::move(aGeometry
));
115 void TexturedLayerMLGPU::AssignBigImage(FrameBuilder
* aBuilder
,
116 RenderViewMLGPU
* aView
,
117 BigImageIterator
* aIter
,
118 const Maybe
<Polygon
>& aGeometry
) {
119 const Matrix4x4
& transform
= GetLayer()->GetEffectiveTransformForBuffer();
121 // Note that we don't need to assign these in any particular order, since
122 // they do not overlap.
124 IntRect tileRect
= aIter
->GetTileRect();
125 IntRect rect
= tileRect
.Intersect(mPictureRect
);
126 if (rect
.IsEmpty()) {
131 Rect screenRect
= transform
.TransformBounds(Rect(rect
));
132 screenRect
.MoveBy(-aView
->GetTargetOffset());
134 screenRect
.Intersect(Rect(mComputedClipRect
.ToUnknownRect()));
135 if (screenRect
.IsEmpty()) {
136 // This tile is not in the clip region, so skip it.
141 RefPtr
<TextureSource
> tile
= mBigImageTexture
->ExtractCurrentTile();
146 // Create a temporary item.
147 RefPtr
<TempImageLayerMLGPU
> item
=
148 new TempImageLayerMLGPU(aBuilder
->GetManager());
149 item
->Init(this, tile
, rect
);
151 Maybe
<Polygon
> geometry
= aGeometry
;
152 item
->AddBoundsToView(aBuilder
, aView
, std::move(geometry
));
154 // Since the layer tree is not holding this alive, we have to ask the
155 // FrameBuilder to do it for us.
156 aBuilder
->RetainTemporaryLayer(item
);
157 } while (aIter
->NextTile());
160 TempImageLayerMLGPU::TempImageLayerMLGPU(LayerManagerMLGPU
* aManager
)
161 : ImageLayer(aManager
, static_cast<HostLayer
*>(this)),
162 TexturedLayerMLGPU(aManager
),
163 mFilter(gfx::SamplingFilter::GOOD
),
166 TempImageLayerMLGPU::~TempImageLayerMLGPU() = default;
168 void TempImageLayerMLGPU::Init(TexturedLayerMLGPU
* aSource
,
169 const RefPtr
<TextureSource
>& aTexture
,
170 const gfx::IntRect
& aPictureRect
) {
171 // ImageLayer properties.
172 mEffectiveTransform
= aSource
->GetLayer()->GetEffectiveTransform();
173 mEffectiveTransformForBuffer
=
174 aSource
->GetLayer()->GetEffectiveTransformForBuffer();
176 // Base LayerMLGPU properties.
177 mComputedClipRect
= aSource
->GetComputedClipRect();
178 mMask
= aSource
->GetMask();
179 mComputedOpacity
= aSource
->GetComputedOpacity();
181 // TexturedLayerMLGPU properties.
182 mHost
= aSource
->GetImageHost();
184 mPictureRect
= aPictureRect
;
187 mFilter
= aSource
->GetSamplingFilter();
188 mShadowVisibleRegion
= aSource
->GetShadowVisibleRegion();
189 mIsOpaque
= aSource
->IsContentOpaque();
191 // Set this layer to prepared so IsPrepared() assertions don't fire.
195 } // namespace layers
196 } // namespace mozilla