gfx/layers/client/CanvasClient.h

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:d35f6f0c7010
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_CANVASCLIENT_H
7 #define MOZILLA_GFX_CANVASCLIENT_H
8
9 #include "mozilla/Assertions.h" // for MOZ_ASSERT, etc
10 #include "mozilla/Attributes.h" // for MOZ_OVERRIDE
11 #include "mozilla/RefPtr.h" // for RefPtr, TemporaryRef
12 #include "mozilla/layers/CompositableClient.h" // for CompositableClient
13 #include "mozilla/layers/CompositorTypes.h" // for TextureInfo, etc
14 #include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor
15 #include "mozilla/layers/TextureClient.h" // for TextureClient, etc
16 #include "mozilla/mozalloc.h" // for operator delete
17
18 #include "mozilla/gfx/Point.h" // for IntSize
19 #include "mozilla/gfx/Types.h" // for SurfaceFormat
20
21 namespace mozilla {
22 namespace gfx {
23 class SharedSurface;
24 }
25 }
26
27 namespace mozilla {
28 namespace layers {
29
30 class ClientCanvasLayer;
31 class CompositableForwarder;
32
33 /**
34 * Compositable client for 2d and webgl canvas.
35 */
36 class CanvasClient : public CompositableClient
37 {
38 public:
39 /**
40 * Creates, configures, and returns a new canvas client. If necessary, a
41 * message will be sent to the compositor to create a corresponding image
42 * host.
43 */
44 enum CanvasClientType {
45 CanvasClientSurface,
46 CanvasClientGLContext,
47 };
48 static TemporaryRef<CanvasClient> CreateCanvasClient(CanvasClientType aType,
49 CompositableForwarder* aFwd,
50 TextureFlags aFlags);
51
52 CanvasClient(CompositableForwarder* aFwd, TextureFlags aFlags)
53 : CompositableClient(aFwd, aFlags)
54 {
55 mTextureInfo.mTextureFlags = aFlags;
56 }
57
58 virtual ~CanvasClient() {}
59
60 virtual void Clear() {};
61
62 virtual void Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer) = 0;
63
64 virtual void Updated() { }
65
66 protected:
67 TextureInfo mTextureInfo;
68 };
69
70 // Used for 2D canvases and WebGL canvas on non-GL systems where readback is requried.
71 class CanvasClient2D : public CanvasClient
72 {
73 public:
74 CanvasClient2D(CompositableForwarder* aLayerForwarder,
75 TextureFlags aFlags)
76 : CanvasClient(aLayerForwarder, aFlags)
77 {
78 }
79
80 TextureInfo GetTextureInfo() const
81 {
82 return TextureInfo(COMPOSITABLE_IMAGE);
83 }
84
85 virtual void Clear() MOZ_OVERRIDE
86 {
87 mBuffer = nullptr;
88 }
89
90 virtual void Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer) MOZ_OVERRIDE;
91
92 virtual bool AddTextureClient(TextureClient* aTexture) MOZ_OVERRIDE
93 {
94 MOZ_ASSERT((mTextureInfo.mTextureFlags & aTexture->GetFlags()) == mTextureInfo.mTextureFlags);
95 return CompositableClient::AddTextureClient(aTexture);
96 }
97
98 virtual void OnDetach() MOZ_OVERRIDE
99 {
100 mBuffer = nullptr;
101 }
102
103 private:
104 RefPtr<TextureClient> mBuffer;
105 };
106
107 // Used for GL canvases where we don't need to do any readback, i.e., with a
108 // GL backend.
109 class CanvasClientSurfaceStream : public CanvasClient
110 {
111 public:
112 CanvasClientSurfaceStream(CompositableForwarder* aLayerForwarder, TextureFlags aFlags);
113
114 TextureInfo GetTextureInfo() const
115 {
116 return TextureInfo(COMPOSITABLE_IMAGE);
117 }
118
119 virtual void Clear() MOZ_OVERRIDE
120 {
121 mBuffer = nullptr;
122 }
123
124 virtual void Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer) MOZ_OVERRIDE;
125
126 virtual void OnDetach() MOZ_OVERRIDE
127 {
128 mBuffer = nullptr;
129 }
130
131 private:
132 RefPtr<TextureClient> mBuffer;
133 };
134
135 }
136 }
137
138 #endif

mercurial