Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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/. */
6 #ifndef MOZILLA_GFX_GRALLOCTEXTUREHOST_H
7 #define MOZILLA_GFX_GRALLOCTEXTUREHOST_H
8 #ifdef MOZ_WIDGET_GONK
10 #include "mozilla/layers/TextureHostOGL.h"
11 #include "mozilla/layers/ShadowLayerUtilsGralloc.h"
12 #include <ui/GraphicBuffer.h>
14 namespace mozilla {
15 namespace layers {
17 class GrallocTextureHostOGL;
19 class GrallocTextureSourceOGL : public NewTextureSource
20 , public TextureSourceOGL
21 {
22 public:
23 friend class GrallocTextureHostOGL;
25 GrallocTextureSourceOGL(CompositorOGL* aCompositor,
26 android::GraphicBuffer* aGraphicBuffer,
27 gfx::SurfaceFormat aFormat);
29 virtual ~GrallocTextureSourceOGL();
31 virtual bool IsValid() const MOZ_OVERRIDE;
33 virtual void BindTexture(GLenum aTextureUnit, gfx::Filter aFilter) MOZ_OVERRIDE;
35 virtual gfx::IntSize GetSize() const MOZ_OVERRIDE;
37 virtual TextureSourceOGL* AsSourceOGL() MOZ_OVERRIDE { return this; }
39 virtual GLenum GetTextureTarget() const MOZ_OVERRIDE;
41 virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE { return mFormat; }
43 virtual GLenum GetWrapMode() const MOZ_OVERRIDE
44 {
45 return LOCAL_GL_CLAMP_TO_EDGE;
46 }
48 virtual void SetCompositableBackendSpecificData(CompositableBackendSpecificData* aBackendData) MOZ_OVERRIDE;
50 void DeallocateDeviceData();
52 gl::GLContext* gl() const;
54 virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
56 void ForgetBuffer()
57 {
58 mGraphicBuffer = nullptr;
59 }
61 TemporaryRef<gfx::DataSourceSurface> GetAsSurface();
63 GLuint GetGLTexture();
65 void Lock();
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 };
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);
86 virtual ~GrallocTextureHostOGL();
88 virtual void Updated(const nsIntRegion* aRegion) MOZ_OVERRIDE {}
90 virtual bool Lock() MOZ_OVERRIDE;
92 virtual void Unlock() MOZ_OVERRIDE;
94 virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
96 virtual void DeallocateSharedData() MOZ_OVERRIDE;
98 virtual void ForgetSharedData() MOZ_OVERRIDE;
100 virtual void DeallocateDeviceData() MOZ_OVERRIDE;
102 virtual gfx::SurfaceFormat GetFormat() const;
104 virtual gfx::IntSize GetSize() const MOZ_OVERRIDE { return mSize; }
106 virtual LayerRenderState GetRenderState() MOZ_OVERRIDE;
108 virtual NewTextureSource* GetTextureSources() MOZ_OVERRIDE
109 {
110 return mTextureSource;
111 }
113 #if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
114 virtual TextureHostOGL* AsHostOGL() MOZ_OVERRIDE
115 {
116 return this;
117 }
118 #endif
120 virtual TemporaryRef<gfx::DataSourceSurface> GetAsSurface() MOZ_OVERRIDE;
122 virtual void SetCompositableBackendSpecificData(CompositableBackendSpecificData* aBackendData) MOZ_OVERRIDE;
124 bool IsValid() const;
126 virtual const char* Name() MOZ_OVERRIDE { return "GrallocTextureHostOGL"; }
128 // Forget buffer actor. Used only for hacky fix for bug 966446.
129 virtual void ForgetBufferActor()
130 {
131 mGrallocActor = nullptr;
132 }
134 private:
135 GrallocBufferActor* mGrallocActor;
136 RefPtr<GrallocTextureSourceOGL> mTextureSource;
137 gfx::IntSize mSize; // See comment in textureClientOGL.h
138 };
140 } // namespace layers
141 } // namespace mozilla
143 #endif
144 #endif