gfx/layers/client/ImageClient.h

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:c3d2432b7d67
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 MOZ_OVERRIDE
12 #include "mozilla/RefPtr.h" // for RefPtr, TemporaryRef
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 nsIntRect
21
22 namespace mozilla {
23 namespace layers {
24
25 class CompositableForwarder;
26 class Image;
27 class ImageContainer;
28 class ShadowableLayer;
29
30 /**
31 * Image clients are used by basic image layers on the content thread, they
32 * always match with an ImageHost on the compositor thread. See
33 * CompositableClient.h for information on connecting clients to hosts.
34 */
35 class ImageClient : public CompositableClient
36 {
37 public:
38 /**
39 * Creates, configures, and returns a new image client. If necessary, a
40 * message will be sent to the compositor to create a corresponding image
41 * host.
42 */
43 static TemporaryRef<ImageClient> CreateImageClient(CompositableType aImageHostType,
44 CompositableForwarder* aFwd,
45 TextureFlags aFlags);
46
47 virtual ~ImageClient() {}
48
49 /**
50 * Update this ImageClient from aContainer in aLayer
51 * returns false if this is the wrong kind of ImageClient for aContainer.
52 * Note that returning true does not necessarily imply success
53 */
54 virtual bool UpdateImage(ImageContainer* aContainer, uint32_t aContentFlags) = 0;
55
56 /**
57 * The picture rect is the area of the texture which makes up the image. That
58 * is, the area that should be composited. In texture space.
59 */
60 virtual void UpdatePictureRect(nsIntRect aPictureRect);
61
62 virtual already_AddRefed<Image> CreateImage(ImageFormat aFormat) = 0;
63
64 /**
65 * Synchronously remove all the textures used by the image client.
66 */
67 virtual void FlushAllImages(bool aExceptFront) {}
68
69 protected:
70 ImageClient(CompositableForwarder* aFwd, TextureFlags aFlags,
71 CompositableType aType);
72
73 CompositableType mType;
74 int32_t mLastPaintedImageSerial;
75 nsIntRect mPictureRect;
76 };
77
78 /**
79 * An image client which uses a single texture client.
80 */
81 class ImageClientSingle : public ImageClient
82 {
83 public:
84 ImageClientSingle(CompositableForwarder* aFwd,
85 TextureFlags aFlags,
86 CompositableType aType);
87
88 virtual bool UpdateImage(ImageContainer* aContainer, uint32_t aContentFlags);
89
90 virtual void OnDetach() MOZ_OVERRIDE;
91
92 virtual bool AddTextureClient(TextureClient* aTexture) MOZ_OVERRIDE;
93
94 virtual TextureInfo GetTextureInfo() const MOZ_OVERRIDE;
95
96 virtual already_AddRefed<Image> CreateImage(ImageFormat aFormat) MOZ_OVERRIDE;
97
98 virtual void FlushAllImages(bool aExceptFront) MOZ_OVERRIDE;
99
100 protected:
101 virtual bool UpdateImageInternal(ImageContainer* aContainer, uint32_t aContentFlags, bool* aIsSwapped);
102
103 protected:
104 RefPtr<TextureClient> mFrontBuffer;
105 };
106
107 /**
108 * An image client which uses two texture clients.
109 */
110 class ImageClientBuffered : public ImageClientSingle
111 {
112 public:
113 ImageClientBuffered(CompositableForwarder* aFwd,
114 TextureFlags aFlags,
115 CompositableType aType);
116
117 virtual bool UpdateImage(ImageContainer* aContainer, uint32_t aContentFlags);
118
119 virtual void OnDetach() MOZ_OVERRIDE;
120
121 virtual void FlushAllImages(bool aExceptFront) MOZ_OVERRIDE;
122
123 protected:
124 RefPtr<TextureClient> mBackBuffer;
125 };
126
127 /**
128 * Image class to be used for async image uploads using the image bridge
129 * protocol.
130 * We store the ImageBridge id in the TextureClientIdentifier.
131 */
132 class ImageClientBridge : public ImageClient
133 {
134 public:
135 ImageClientBridge(CompositableForwarder* aFwd,
136 TextureFlags aFlags);
137
138 virtual bool UpdateImage(ImageContainer* aContainer, uint32_t aContentFlags);
139 virtual bool Connect() { return false; }
140 virtual void Updated() {}
141 void SetLayer(ShadowableLayer* aLayer)
142 {
143 mLayer = aLayer;
144 }
145
146 virtual TextureInfo GetTextureInfo() const MOZ_OVERRIDE
147 {
148 return TextureInfo(mType);
149 }
150
151 virtual void SetIPDLActor(CompositableChild* aChild) MOZ_OVERRIDE
152 {
153 MOZ_ASSERT(!aChild, "ImageClientBridge should not have IPDL actor");
154 }
155
156 virtual already_AddRefed<Image> CreateImage(ImageFormat aFormat) MOZ_OVERRIDE
157 {
158 NS_WARNING("Should not create an image through an ImageClientBridge");
159 return nullptr;
160 }
161
162 protected:
163 uint64_t mAsyncContainerID;
164 ShadowableLayer* mLayer;
165 };
166
167 }
168 }
169
170 #endif

mercurial