gfx/layers/opengl/GrallocTextureHost.h

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:bbfb6718d7a8
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_GRALLOCTEXTUREHOST_H
7 #define MOZILLA_GFX_GRALLOCTEXTUREHOST_H
8 #ifdef MOZ_WIDGET_GONK
9
10 #include "mozilla/layers/TextureHostOGL.h"
11 #include "mozilla/layers/ShadowLayerUtilsGralloc.h"
12 #include <ui/GraphicBuffer.h>
13
14 namespace mozilla {
15 namespace layers {
16
17 class GrallocTextureHostOGL;
18
19 class GrallocTextureSourceOGL : public NewTextureSource
20 , public TextureSourceOGL
21 {
22 public:
23 friend class GrallocTextureHostOGL;
24
25 GrallocTextureSourceOGL(CompositorOGL* aCompositor,
26 android::GraphicBuffer* aGraphicBuffer,
27 gfx::SurfaceFormat aFormat);
28
29 virtual ~GrallocTextureSourceOGL();
30
31 virtual bool IsValid() const MOZ_OVERRIDE;
32
33 virtual void BindTexture(GLenum aTextureUnit, gfx::Filter aFilter) MOZ_OVERRIDE;
34
35 virtual gfx::IntSize GetSize() const MOZ_OVERRIDE;
36
37 virtual TextureSourceOGL* AsSourceOGL() MOZ_OVERRIDE { return this; }
38
39 virtual GLenum GetTextureTarget() const MOZ_OVERRIDE;
40
41 virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE { return mFormat; }
42
43 virtual GLenum GetWrapMode() const MOZ_OVERRIDE
44 {
45 return LOCAL_GL_CLAMP_TO_EDGE;
46 }
47
48 virtual void SetCompositableBackendSpecificData(CompositableBackendSpecificData* aBackendData) MOZ_OVERRIDE;
49
50 void DeallocateDeviceData();
51
52 gl::GLContext* gl() const;
53
54 virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
55
56 void ForgetBuffer()
57 {
58 mGraphicBuffer = nullptr;
59 }
60
61 TemporaryRef<gfx::DataSourceSurface> GetAsSurface();
62
63 GLuint GetGLTexture();
64
65 void Lock();
66
67 protected:
68 CompositorOGL* mCompositor;
69 android::sp<android::GraphicBuffer> mGraphicBuffer;
70 EGLImage mEGLImage;
71 GLuint mTexture;
72 gfx::SurfaceFormat mFormat;
73 bool mNeedsReset;
74 };
75
76 class GrallocTextureHostOGL : public TextureHost
77 #if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
78 , public TextureHostOGL
79 #endif
80 {
81 friend class GrallocBufferActor;
82 public:
83 GrallocTextureHostOGL(TextureFlags aFlags,
84 const NewSurfaceDescriptorGralloc& aDescriptor);
85
86 virtual ~GrallocTextureHostOGL();
87
88 virtual void Updated(const nsIntRegion* aRegion) MOZ_OVERRIDE {}
89
90 virtual bool Lock() MOZ_OVERRIDE;
91
92 virtual void Unlock() MOZ_OVERRIDE;
93
94 virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
95
96 virtual void DeallocateSharedData() MOZ_OVERRIDE;
97
98 virtual void ForgetSharedData() MOZ_OVERRIDE;
99
100 virtual void DeallocateDeviceData() MOZ_OVERRIDE;
101
102 virtual gfx::SurfaceFormat GetFormat() const;
103
104 virtual gfx::IntSize GetSize() const MOZ_OVERRIDE { return mSize; }
105
106 virtual LayerRenderState GetRenderState() MOZ_OVERRIDE;
107
108 virtual NewTextureSource* GetTextureSources() MOZ_OVERRIDE
109 {
110 return mTextureSource;
111 }
112
113 #if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
114 virtual TextureHostOGL* AsHostOGL() MOZ_OVERRIDE
115 {
116 return this;
117 }
118 #endif
119
120 virtual TemporaryRef<gfx::DataSourceSurface> GetAsSurface() MOZ_OVERRIDE;
121
122 virtual void SetCompositableBackendSpecificData(CompositableBackendSpecificData* aBackendData) MOZ_OVERRIDE;
123
124 bool IsValid() const;
125
126 virtual const char* Name() MOZ_OVERRIDE { return "GrallocTextureHostOGL"; }
127
128 // Forget buffer actor. Used only for hacky fix for bug 966446.
129 virtual void ForgetBufferActor()
130 {
131 mGrallocActor = nullptr;
132 }
133
134 private:
135 GrallocBufferActor* mGrallocActor;
136 RefPtr<GrallocTextureSourceOGL> mTextureSource;
137 gfx::IntSize mSize; // See comment in textureClientOGL.h
138 };
139
140 } // namespace layers
141 } // namespace mozilla
142
143 #endif
144 #endif

mercurial