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