Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/gfx/layers/composite/PaintedLayerComposite.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 "PaintedLayerComposite.h"
8
#include "CompositableHost.h"           // for TiledLayerProperties, etc
9
#include "FrameMetrics.h"               // for FrameMetrics
10
#include "Units.h"                      // for CSSRect, LayerPixel, etc
11
#include "gfxEnv.h"                     // for gfxEnv
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/Polygon.h"        // for Polygon
16
#include "mozilla/gfx/Rect.h"           // for RoundedToInt, Rect
17
#include "mozilla/gfx/Types.h"          // for SamplingFilter::LINEAR
18
#include "mozilla/layers/Compositor.h"  // for Compositor
19
#include "mozilla/layers/ContentHost.h"  // for ContentHost
20
#include "mozilla/layers/Effects.h"     // for EffectChain
21
#include "mozilla/mozalloc.h"           // for operator delete
22
#include "nsAString.h"
23
#include "mozilla/RefPtr.h"                   // for nsRefPtr
24
#include "nsISupportsImpl.h"            // for MOZ_COUNT_CTOR, etc
25
#include "nsMathUtils.h"                // for NS_lround
26
#include "nsString.h"                   // for nsAutoCString
27
#include "TextRenderer.h"
28
#include "GeckoProfiler.h"
29
30
namespace mozilla {
31
namespace layers {
32
33
PaintedLayerComposite::PaintedLayerComposite(LayerManagerComposite *aManager)
34
  : PaintedLayer(aManager, nullptr)
35
  , LayerComposite(aManager)
36
  , mBuffer(nullptr)
37
0
{
38
0
  MOZ_COUNT_CTOR(PaintedLayerComposite);
39
0
  mImplData = static_cast<LayerComposite*>(this);
40
0
}
41
42
PaintedLayerComposite::~PaintedLayerComposite()
43
0
{
44
0
  MOZ_COUNT_DTOR(PaintedLayerComposite);
45
0
  CleanupResources();
46
0
}
47
48
bool
49
PaintedLayerComposite::SetCompositableHost(CompositableHost* aHost)
50
{
51
  switch (aHost->GetType()) {
52
    case CompositableType::CONTENT_TILED:
53
    case CompositableType::CONTENT_SINGLE:
54
    case CompositableType::CONTENT_DOUBLE:
55
      mBuffer = static_cast<ContentHost*>(aHost);
56
      return true;
57
    default:
58
      return false;
59
  }
60
}
61
62
void
63
PaintedLayerComposite::Disconnect()
64
0
{
65
0
  Destroy();
66
0
}
67
68
void
69
PaintedLayerComposite::Destroy()
70
0
{
71
0
  if (!mDestroyed) {
72
0
    CleanupResources();
73
0
    mDestroyed = true;
74
0
  }
75
0
}
76
77
Layer*
78
PaintedLayerComposite::GetLayer()
79
0
{
80
0
  return this;
81
0
}
82
83
void
84
PaintedLayerComposite::SetLayerManager(HostLayerManager* aManager)
85
0
{
86
0
  LayerComposite::SetLayerManager(aManager);
87
0
  mManager = aManager;
88
0
  if (mBuffer && mCompositor) {
89
0
    mBuffer->SetTextureSourceProvider(mCompositor);
90
0
  }
91
0
}
92
93
void
94
PaintedLayerComposite::RenderLayer(const gfx::IntRect& aClipRect,
95
                                   const Maybe<gfx::Polygon>& aGeometry)
96
0
{
97
0
  if (!mBuffer || !mBuffer->IsAttached()) {
98
0
    return;
99
0
  }
100
0
  AUTO_PROFILER_LABEL("PaintedLayerComposite::RenderLayer", GRAPHICS);
101
0
102
0
  Compositor* compositor = mCompositeManager->GetCompositor();
103
0
104
0
  MOZ_ASSERT(mBuffer->GetTextureSourceProvider() == compositor &&
105
0
             mBuffer->GetLayer() == this,
106
0
             "buffer is corrupted");
107
0
108
0
  const nsIntRegion visibleRegion = GetLocalVisibleRegion().ToUnknownRegion();
109
0
110
#ifdef MOZ_DUMP_PAINTING
111
  if (gfxEnv::DumpCompositorTextures()) {
112
    RefPtr<gfx::DataSourceSurface> surf = mBuffer->GetAsSurface();
113
    if (surf) {
114
      WriteSnapshotToDumpFile(this, surf);
115
    }
116
  }
117
#endif
118
119
0
  RenderWithAllMasks(this, compositor, aClipRect,
120
0
                     [&](EffectChain& effectChain,
121
0
                     const gfx::IntRect& clipRect) {
122
0
    mBuffer->SetPaintWillResample(MayResample());
123
0
124
0
    mBuffer->Composite(compositor, this, effectChain, GetEffectiveOpacity(),
125
0
                       GetEffectiveTransform(), GetSamplingFilter(),
126
0
                       clipRect, &visibleRegion, aGeometry);
127
0
  });
128
0
129
0
  mBuffer->BumpFlashCounter();
130
0
131
0
  compositor->MakeCurrent();
132
0
}
133
134
CompositableHost*
135
PaintedLayerComposite::GetCompositableHost()
136
0
{
137
0
  if (mBuffer && mBuffer->IsAttached()) {
138
0
    return mBuffer.get();
139
0
  }
140
0
141
0
  return nullptr;
142
0
}
143
144
void
145
PaintedLayerComposite::CleanupResources()
146
0
{
147
0
  if (mBuffer) {
148
0
    mBuffer->Detach(this);
149
0
  }
150
0
  mBuffer = nullptr;
151
0
}
152
153
bool
154
PaintedLayerComposite::IsOpaque()
155
0
{
156
0
  if (!mBuffer || !mBuffer->IsAttached()) {
157
0
    return false;
158
0
  }
159
0
  return PaintedLayer::IsOpaque();
160
0
}
161
162
void
163
PaintedLayerComposite::GenEffectChain(EffectChain& aEffect)
164
0
{
165
0
  aEffect.mLayerRef = this;
166
0
  aEffect.mPrimaryEffect = mBuffer->GenEffect(GetSamplingFilter());
167
0
}
168
169
void
170
PaintedLayerComposite::PrintInfo(std::stringstream& aStream, const char* aPrefix)
171
0
{
172
0
  PaintedLayer::PrintInfo(aStream, aPrefix);
173
0
  if (mBuffer && mBuffer->IsAttached()) {
174
0
    aStream << "\n";
175
0
    nsAutoCString pfx(aPrefix);
176
0
    pfx += "  ";
177
0
    mBuffer->PrintInfo(aStream, pfx.get());
178
0
  }
179
0
}
180
181
const gfx::TiledIntRegion&
182
PaintedLayerComposite::GetInvalidRegion()
183
0
{
184
0
  if (mBuffer) {
185
0
    nsIntRegion region = mInvalidRegion.GetRegion();
186
0
    mBuffer->AddAnimationInvalidation(region);
187
0
  }
188
0
  return mInvalidRegion;
189
0
}
190
191
192
} // namespace layers
193
} // namespace mozilla