Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/gfx/layers/mlgpu/ImageLayerMLGPU.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 "ImageLayerMLGPU.h"
8
#include "LayerManagerMLGPU.h"
9
10
namespace mozilla {
11
12
using namespace gfx;
13
14
namespace layers {
15
16
ImageLayerMLGPU::ImageLayerMLGPU(LayerManagerMLGPU* aManager)
17
  : ImageLayer(aManager, static_cast<HostLayer*>(this))
18
  , TexturedLayerMLGPU(aManager)
19
0
{
20
0
}
21
22
ImageLayerMLGPU::~ImageLayerMLGPU()
23
0
{
24
0
  CleanupResources();
25
0
}
26
27
void
28
ImageLayerMLGPU::ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface)
29
0
{
30
0
  Matrix4x4 local = GetLocalTransform();
31
0
32
0
  // Snap image edges to pixel boundaries.
33
0
  gfxRect sourceRect(0, 0, 0, 0);
34
0
  if (mHost && mHost->IsAttached()) {
35
0
    IntSize size = mHost->GetImageSize();
36
0
    sourceRect.SizeTo(size.width, size.height);
37
0
  }
38
0
39
0
  // Snap our local transform first, and snap the inherited transform as well.
40
0
  // This makes our snapping equivalent to what would happen if our content
41
0
  // was drawn into a PaintedLayer (gfxContext would snap using the local
42
0
  // transform, then we'd snap again when compositing the PaintedLayer).
43
0
  mEffectiveTransform =
44
0
      SnapTransform(local, sourceRect, nullptr) *
45
0
      SnapTransformTranslation(aTransformToSurface, nullptr);
46
0
  mEffectiveTransformForBuffer = mEffectiveTransform;
47
0
48
0
  if (mScaleMode == ScaleMode::STRETCH &&
49
0
      mScaleToSize.width != 0.0 &&
50
0
      mScaleToSize.height != 0.0)
51
0
  {
52
0
    Size scale(sourceRect.Width() / mScaleToSize.width,
53
0
               sourceRect.Height() / mScaleToSize.height);
54
0
    mScale = Some(scale);
55
0
  }
56
0
57
0
  ComputeEffectiveTransformForMaskLayers(aTransformToSurface);
58
0
}
59
60
gfx::SamplingFilter
61
ImageLayerMLGPU::GetSamplingFilter()
62
0
{
63
0
  return ImageLayer::GetSamplingFilter();
64
0
}
65
66
bool
67
ImageLayerMLGPU::IsContentOpaque()
68
0
{
69
0
  if (mPictureRect.Width() == 0 || mPictureRect.Height() == 0) {
70
0
    return false;
71
0
  }
72
0
  if (mScaleMode == ScaleMode::STRETCH) {
73
0
    return gfx::IsOpaque(mHost->CurrentTextureHost()->GetFormat());
74
0
  }
75
0
  return false;
76
0
}
77
78
void
79
ImageLayerMLGPU::SetRenderRegion(LayerIntRegion&& aRegion)
80
0
{
81
0
  switch (mScaleMode) {
82
0
  case ScaleMode::STRETCH:
83
0
    // See bug 1264142.
84
0
    aRegion.AndWith(LayerIntRect(0, 0, mScaleToSize.width, mScaleToSize.height));
85
0
    break;
86
0
  default:
87
0
    // Clamp the visible region to the texture size. (see bug 1396507)
88
0
    MOZ_ASSERT(mScaleMode == ScaleMode::SCALE_NONE);
89
0
    aRegion.AndWith(LayerIntRect(0, 0, mPictureRect.Width(), mPictureRect.Height()));
90
0
    break;
91
0
  }
92
0
  LayerMLGPU::SetRenderRegion(std::move(aRegion));
93
0
}
94
95
void
96
ImageLayerMLGPU::CleanupResources()
97
0
{
98
0
  if (mHost) {
99
0
    mHost->CleanupResources();
100
0
    mHost->Detach(this);
101
0
  }
102
0
  mTexture = nullptr;
103
0
  mBigImageTexture = nullptr;
104
0
  mHost = nullptr;
105
0
}
106
107
void
108
ImageLayerMLGPU::PrintInfo(std::stringstream& aStream, const char* aPrefix)
109
0
{
110
0
  ImageLayer::PrintInfo(aStream, aPrefix);
111
0
  if (mHost && mHost->IsAttached()) {
112
0
    aStream << "\n";
113
0
    nsAutoCString pfx(aPrefix);
114
0
    pfx += "  ";
115
0
    mHost->PrintInfo(aStream, pfx.get());
116
0
  }
117
0
}
118
119
void
120
ImageLayerMLGPU::Disconnect()
121
0
{
122
0
  CleanupResources();
123
0
}
124
125
void
126
ImageLayerMLGPU::ClearCachedResources()
127
0
{
128
0
  CleanupResources();
129
0
}
130
131
} // namespace layers
132
} // namespace mozilla