Coverage Report

Created: 2018-09-25 14:53

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