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_IMAGECLIENT_H
7 : #define MOZILLA_GFX_IMAGECLIENT_H
8 :
9 : #include <stdint.h> // for uint32_t, uint64_t
10 : #include <sys/types.h> // for int32_t
11 : #include "mozilla/Attributes.h" // for override
12 : #include "mozilla/RefPtr.h" // for RefPtr, already_AddRefed
13 : #include "mozilla/gfx/Types.h" // for SurfaceFormat
14 : #include "mozilla/layers/CompositableClient.h" // for CompositableClient
15 : #include "mozilla/layers/CompositorTypes.h" // for CompositableType, etc
16 : #include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor
17 : #include "mozilla/layers/TextureClient.h" // for TextureClient, etc
18 : #include "mozilla/mozalloc.h" // for operator delete
19 : #include "nsCOMPtr.h" // for already_AddRefed
20 : #include "nsRect.h" // for mozilla::gfx::IntRect
21 :
22 : namespace mozilla {
23 : namespace layers {
24 :
25 : class ClientLayer;
26 : class CompositableForwarder;
27 : class Image;
28 : class ImageContainer;
29 : class ShadowableLayer;
30 : class ImageClientSingle;
31 :
32 : /**
33 : * Image clients are used by basic image layers on the content thread, they
34 : * always match with an ImageHost on the compositor thread. See
35 : * CompositableClient.h for information on connecting clients to hosts.
36 : */
37 : class ImageClient : public CompositableClient
38 : {
39 : public:
40 : /**
41 : * Creates, configures, and returns a new image client. If necessary, a
42 : * message will be sent to the compositor to create a corresponding image
43 : * host.
44 : */
45 : static already_AddRefed<ImageClient> CreateImageClient(CompositableType aImageHostType,
46 : CompositableForwarder* aFwd,
47 : TextureFlags aFlags);
48 :
49 0 : virtual ~ImageClient() {}
50 :
51 : /**
52 : * Update this ImageClient from aContainer in aLayer
53 : * returns false if this is the wrong kind of ImageClient for aContainer.
54 : * Note that returning true does not necessarily imply success
55 : */
56 : virtual bool UpdateImage(ImageContainer* aContainer, uint32_t aContentFlags) = 0;
57 :
58 0 : void SetLayer(ClientLayer* aLayer) { mLayer = aLayer; }
59 : ClientLayer* GetLayer() const { return mLayer; }
60 :
61 : /**
62 : * asynchronously remove all the textures used by the image client.
63 : *
64 : */
65 0 : virtual void FlushAllImages() {}
66 :
67 : virtual void RemoveTexture(TextureClient* aTexture) override;
68 :
69 0 : virtual ImageClientSingle* AsImageClientSingle() { return nullptr; }
70 :
71 : static already_AddRefed<TextureClient> CreateTextureClientForImage(Image* aImage, KnowsCompositor* aForwarder);
72 :
73 0 : uint32_t GetLastUpdateGenerationCounter() { return mLastUpdateGenerationCounter; }
74 :
75 : protected:
76 : ImageClient(CompositableForwarder* aFwd, TextureFlags aFlags,
77 : CompositableType aType);
78 :
79 : ClientLayer* mLayer;
80 : CompositableType mType;
81 : uint32_t mLastUpdateGenerationCounter;
82 : };
83 :
84 : /**
85 : * An image client which uses a single texture client.
86 : */
87 0 : class ImageClientSingle : public ImageClient
88 : {
89 : public:
90 : ImageClientSingle(CompositableForwarder* aFwd,
91 : TextureFlags aFlags,
92 : CompositableType aType);
93 :
94 : virtual bool UpdateImage(ImageContainer* aContainer, uint32_t aContentFlags) override;
95 :
96 : virtual void OnDetach() override;
97 :
98 : virtual bool AddTextureClient(TextureClient* aTexture) override;
99 :
100 : virtual TextureInfo GetTextureInfo() const override;
101 :
102 : virtual void FlushAllImages() override;
103 :
104 0 : ImageClientSingle* AsImageClientSingle() override { return this; }
105 :
106 0 : bool IsEmpty() { return mBuffers.IsEmpty(); }
107 :
108 : protected:
109 0 : struct Buffer {
110 : RefPtr<TextureClient> mTextureClient;
111 : int32_t mImageSerial;
112 : };
113 : nsTArray<Buffer> mBuffers;
114 : };
115 :
116 : /**
117 : * Image class to be used for async image uploads using the image bridge
118 : * protocol.
119 : * We store the ImageBridge id in the TextureClientIdentifier.
120 : */
121 0 : class ImageClientBridge : public ImageClient
122 : {
123 : public:
124 : ImageClientBridge(CompositableForwarder* aFwd,
125 : TextureFlags aFlags);
126 :
127 : virtual bool UpdateImage(ImageContainer* aContainer, uint32_t aContentFlags) override;
128 0 : virtual bool Connect(ImageContainer* aImageContainer) override { return false; }
129 :
130 0 : virtual TextureInfo GetTextureInfo() const override
131 : {
132 0 : return TextureInfo(mType);
133 : }
134 :
135 : protected:
136 : CompositableHandle mAsyncContainerHandle;
137 : };
138 :
139 : } // namespace layers
140 : } // namespace mozilla
141 :
142 : #endif
|