/src/mozilla-central/gfx/layers/composite/CanvasLayerComposite.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 "CanvasLayerComposite.h" |
8 | | #include "composite/CompositableHost.h" // for CompositableHost |
9 | | #include "gfx2DGlue.h" // for ToFilter |
10 | | #include "gfxEnv.h" // for gfxEnv, etc |
11 | | #include "mozilla/gfx/Matrix.h" // for Matrix4x4 |
12 | | #include "mozilla/gfx/Point.h" // for Point |
13 | | #include "mozilla/gfx/Rect.h" // for Rect |
14 | | #include "mozilla/layers/Compositor.h" // for Compositor |
15 | | #include "mozilla/layers/Effects.h" // for EffectChain |
16 | | #include "mozilla/mozalloc.h" // for operator delete |
17 | | #include "nsAString.h" |
18 | | #include "mozilla/RefPtr.h" // for nsRefPtr |
19 | | #include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, etc |
20 | | #include "nsString.h" // for nsAutoCString |
21 | | |
22 | | namespace mozilla { |
23 | | namespace layers { |
24 | | |
25 | | using namespace mozilla::gfx; |
26 | | |
27 | | CanvasLayerComposite::CanvasLayerComposite(LayerManagerComposite* aManager) |
28 | | : CanvasLayer(aManager, nullptr) |
29 | | , LayerComposite(aManager) |
30 | | , mCompositableHost(nullptr) |
31 | 0 | { |
32 | 0 | MOZ_COUNT_CTOR(CanvasLayerComposite); |
33 | 0 | mImplData = static_cast<LayerComposite*>(this); |
34 | 0 | } |
35 | | |
36 | | CanvasLayerComposite::~CanvasLayerComposite() |
37 | 0 | { |
38 | 0 | MOZ_COUNT_DTOR(CanvasLayerComposite); |
39 | 0 |
|
40 | 0 | CleanupResources(); |
41 | 0 | } |
42 | | |
43 | | bool |
44 | | CanvasLayerComposite::SetCompositableHost(CompositableHost* aHost) |
45 | | { |
46 | | switch (aHost->GetType()) { |
47 | | case CompositableType::IMAGE: |
48 | | mCompositableHost = aHost; |
49 | | return true; |
50 | | default: |
51 | | return false; |
52 | | } |
53 | | |
54 | | } |
55 | | |
56 | | Layer* |
57 | | CanvasLayerComposite::GetLayer() |
58 | 0 | { |
59 | 0 | return this; |
60 | 0 | } |
61 | | |
62 | | void |
63 | | CanvasLayerComposite::SetLayerManager(HostLayerManager* aManager) |
64 | 0 | { |
65 | 0 | LayerComposite::SetLayerManager(aManager); |
66 | 0 | mManager = aManager; |
67 | 0 | if (mCompositableHost && mCompositor) { |
68 | 0 | mCompositableHost->SetTextureSourceProvider(mCompositor); |
69 | 0 | } |
70 | 0 | } |
71 | | |
72 | | void |
73 | | CanvasLayerComposite::RenderLayer(const IntRect& aClipRect, |
74 | | const Maybe<gfx::Polygon>& aGeometry) |
75 | 0 | { |
76 | 0 | if (!mCompositableHost || !mCompositableHost->IsAttached()) { |
77 | 0 | return; |
78 | 0 | } |
79 | 0 | |
80 | 0 | mCompositor->MakeCurrent(); |
81 | 0 |
|
82 | | #ifdef MOZ_DUMP_PAINTING |
83 | | if (gfxEnv::DumpCompositorTextures()) { |
84 | | RefPtr<gfx::DataSourceSurface> surf = mCompositableHost->GetAsSurface(); |
85 | | if (surf) { |
86 | | WriteSnapshotToDumpFile(this, surf); |
87 | | } |
88 | | } |
89 | | #endif |
90 | |
|
91 | 0 | RenderWithAllMasks(this, mCompositor, aClipRect, |
92 | 0 | [&](EffectChain& effectChain, const IntRect& clipRect) { |
93 | 0 | mCompositableHost->Composite(mCompositor, this, effectChain, |
94 | 0 | GetEffectiveOpacity(), |
95 | 0 | GetEffectiveTransform(), |
96 | 0 | GetSamplingFilter(), |
97 | 0 | clipRect); |
98 | 0 | }); |
99 | 0 |
|
100 | 0 | mCompositableHost->BumpFlashCounter(); |
101 | 0 | } |
102 | | |
103 | | CompositableHost* |
104 | | CanvasLayerComposite::GetCompositableHost() |
105 | 0 | { |
106 | 0 | if (mCompositableHost && mCompositableHost->IsAttached()) { |
107 | 0 | return mCompositableHost.get(); |
108 | 0 | } |
109 | 0 | |
110 | 0 | return nullptr; |
111 | 0 | } |
112 | | |
113 | | void |
114 | | CanvasLayerComposite::CleanupResources() |
115 | 0 | { |
116 | 0 | if (mCompositableHost) { |
117 | 0 | mCompositableHost->Detach(this); |
118 | 0 | } |
119 | 0 | mCompositableHost = nullptr; |
120 | 0 | } |
121 | | |
122 | | gfx::SamplingFilter |
123 | | CanvasLayerComposite::GetSamplingFilter() |
124 | 0 | { |
125 | 0 | gfx::SamplingFilter filter = mSamplingFilter; |
126 | | #ifdef ANDROID |
127 | | // Bug 691354 |
128 | | // Using the LINEAR filter we get unexplained artifacts. |
129 | | // Use NEAREST when no scaling is required. |
130 | | Matrix matrix; |
131 | | bool is2D = GetEffectiveTransform().Is2D(&matrix); |
132 | | if (is2D && !ThebesMatrix(matrix).HasNonTranslationOrFlip()) { |
133 | | filter = SamplingFilter::POINT; |
134 | | } |
135 | | #endif |
136 | | return filter; |
137 | 0 | } |
138 | | |
139 | | void |
140 | | CanvasLayerComposite::GenEffectChain(EffectChain& aEffect) |
141 | 0 | { |
142 | 0 | aEffect.mLayerRef = this; |
143 | 0 | aEffect.mPrimaryEffect = mCompositableHost->GenEffect(GetSamplingFilter()); |
144 | 0 | } |
145 | | |
146 | | void |
147 | | CanvasLayerComposite::PrintInfo(std::stringstream& aStream, const char* aPrefix) |
148 | 0 | { |
149 | 0 | CanvasLayer::PrintInfo(aStream, aPrefix); |
150 | 0 | aStream << "\n"; |
151 | 0 | if (mCompositableHost && mCompositableHost->IsAttached()) { |
152 | 0 | nsAutoCString pfx(aPrefix); |
153 | 0 | pfx += " "; |
154 | 0 | mCompositableHost->PrintInfo(aStream, pfx.get()); |
155 | 0 | } |
156 | 0 | } |
157 | | |
158 | | } // namespace layers |
159 | | } // namespace mozilla |