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 : #ifndef MOZILLA_GFX_IMAGEHOST_H
7 : #define MOZILLA_GFX_IMAGEHOST_H
8 :
9 : #include <stdio.h> // for FILE
10 : #include "CompositableHost.h" // for CompositableHost
11 : #include "mozilla/Attributes.h" // for override
12 : #include "mozilla/RefPtr.h" // for RefPtr
13 : #include "mozilla/gfx/MatrixFwd.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 Rect
17 : #include "mozilla/gfx/Types.h" // for SamplingFilter
18 : #include "mozilla/layers/CompositorTypes.h" // for TextureInfo, etc
19 : #include "mozilla/layers/ImageComposite.h" // for ImageComposite
20 : #include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor
21 : #include "mozilla/layers/LayersTypes.h" // for LayerRenderState, etc
22 : #include "mozilla/layers/TextureHost.h" // for TextureHost, etc
23 : #include "mozilla/mozalloc.h" // for operator delete
24 : #include "nsCOMPtr.h" // for already_AddRefed
25 : #include "nsRect.h" // for mozilla::gfx::IntRect
26 : #include "nsRegionFwd.h" // for nsIntRegion
27 : #include "nscore.h" // for nsACString
28 :
29 : namespace mozilla {
30 : namespace layers {
31 :
32 : class Compositor;
33 : struct EffectChain;
34 : class HostLayerManager;
35 :
36 : /**
37 : * ImageHost. Works with ImageClientSingle and ImageClientBuffered
38 : */
39 : class ImageHost : public CompositableHost,
40 : public ImageComposite
41 : {
42 : public:
43 : explicit ImageHost(const TextureInfo& aTextureInfo);
44 : ~ImageHost();
45 :
46 0 : virtual CompositableType GetType() override { return mTextureInfo.mCompositableType; }
47 0 : virtual ImageHost* AsImageHost() override { return this; }
48 :
49 : virtual void Composite(Compositor* aCompositor,
50 : LayerComposite* aLayer,
51 : EffectChain& aEffectChain,
52 : float aOpacity,
53 : const gfx::Matrix4x4& aTransform,
54 : const gfx::SamplingFilter aSamplingFilter,
55 : const gfx::IntRect& aClipRect,
56 : const nsIntRegion* aVisibleRegion = nullptr,
57 : const Maybe<gfx::Polygon>& aGeometry = Nothing()) override;
58 :
59 : virtual void UseTextureHost(const nsTArray<TimedTexture>& aTextures) override;
60 :
61 : virtual void RemoveTextureHost(TextureHost* aTexture) override;
62 :
63 : virtual TextureHost* GetAsTextureHost(gfx::IntRect* aPictureRect = nullptr) override;
64 :
65 : virtual void Attach(Layer* aLayer,
66 : TextureSourceProvider* aProvider,
67 : AttachFlags aFlags = NO_FLAGS) override;
68 :
69 : virtual void SetTextureSourceProvider(TextureSourceProvider* aProvider) override;
70 :
71 : gfx::IntSize GetImageSize() const override;
72 :
73 : virtual void PrintInfo(std::stringstream& aStream, const char* aPrefix) override;
74 :
75 : virtual void Dump(std::stringstream& aStream,
76 : const char* aPrefix = "",
77 : bool aDumpHtml = false) override;
78 :
79 : virtual already_AddRefed<gfx::DataSourceSurface> GetAsSurface() override;
80 :
81 : virtual bool Lock() override;
82 :
83 : virtual void Unlock() override;
84 :
85 : virtual already_AddRefed<TexturedEffect> GenEffect(const gfx::SamplingFilter aSamplingFilter) override;
86 :
87 : void SetCurrentTextureHost(TextureHost* aTexture);
88 :
89 : virtual void CleanupResources() override;
90 :
91 : bool IsOpaque();
92 :
93 0 : struct RenderInfo {
94 : int imageIndex;
95 : TimedImage* img;
96 : RefPtr<TextureHost> host;
97 :
98 0 : RenderInfo() : imageIndex(-1), img(nullptr)
99 0 : {}
100 : };
101 :
102 : // Acquire rendering information for the current frame.
103 : bool PrepareToRender(TextureSourceProvider* aProvider, RenderInfo* aOutInfo);
104 :
105 : // Acquire the TextureSource for the currently prepared frame.
106 : RefPtr<TextureSource> AcquireTextureSource(const RenderInfo& aInfo);
107 :
108 : // Send ImageComposite notifications and update the ChooseImage bias.
109 : void FinishRendering(const RenderInfo& aInfo);
110 :
111 : // This should only be called inside a lock, or during rendering. It is
112 : // infallible to enforce this.
113 0 : TextureHost* CurrentTextureHost() const {
114 0 : MOZ_ASSERT(mCurrentTextureHost);
115 0 : return mCurrentTextureHost;
116 : }
117 :
118 : protected:
119 : // ImageComposite
120 : virtual TimeStamp GetCompositionTime() const override;
121 :
122 : // Use a simple RefPtr because the same texture is already held by a
123 : // a CompositableTextureHostRef in the array of TimedImage.
124 : // See the comment in CompositableTextureRef for more details.
125 : RefPtr<TextureHost> mCurrentTextureHost;
126 : CompositableTextureSourceRef mCurrentTextureSource;
127 : // When doing texture uploads it's best to alternate between two (or three)
128 : // texture sources so that the texture we upload to isn't being used by
129 : // the GPU to composite the previous frame.
130 : RefPtr<TextureSource> mExtraTextureSource;
131 :
132 : bool mLocked;
133 : };
134 :
135 : } // namespace layers
136 : } // namespace mozilla
137 :
138 : #endif
|