gfx/layers/opengl/GrallocTextureHost.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/layers/opengl/GrallocTextureHost.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,144 @@
     1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 +//  * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef MOZILLA_GFX_GRALLOCTEXTUREHOST_H
    1.10 +#define MOZILLA_GFX_GRALLOCTEXTUREHOST_H
    1.11 +#ifdef MOZ_WIDGET_GONK
    1.12 +
    1.13 +#include "mozilla/layers/TextureHostOGL.h"
    1.14 +#include "mozilla/layers/ShadowLayerUtilsGralloc.h"
    1.15 +#include <ui/GraphicBuffer.h>
    1.16 +
    1.17 +namespace mozilla {
    1.18 +namespace layers {
    1.19 +
    1.20 +class GrallocTextureHostOGL;
    1.21 +
    1.22 +class GrallocTextureSourceOGL : public NewTextureSource
    1.23 +                              , public TextureSourceOGL
    1.24 +{
    1.25 +public:
    1.26 +  friend class GrallocTextureHostOGL;
    1.27 +
    1.28 +  GrallocTextureSourceOGL(CompositorOGL* aCompositor,
    1.29 +                          android::GraphicBuffer* aGraphicBuffer,
    1.30 +                          gfx::SurfaceFormat aFormat);
    1.31 +
    1.32 +  virtual ~GrallocTextureSourceOGL();
    1.33 +
    1.34 +  virtual bool IsValid() const MOZ_OVERRIDE;
    1.35 +
    1.36 +  virtual void BindTexture(GLenum aTextureUnit, gfx::Filter aFilter) MOZ_OVERRIDE;
    1.37 +
    1.38 +  virtual gfx::IntSize GetSize() const MOZ_OVERRIDE;
    1.39 +
    1.40 +  virtual TextureSourceOGL* AsSourceOGL() MOZ_OVERRIDE { return this; }
    1.41 +
    1.42 +  virtual GLenum GetTextureTarget() const MOZ_OVERRIDE;
    1.43 +
    1.44 +  virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE { return mFormat; }
    1.45 +
    1.46 +  virtual GLenum GetWrapMode() const MOZ_OVERRIDE
    1.47 +  {
    1.48 +    return LOCAL_GL_CLAMP_TO_EDGE;
    1.49 +  }
    1.50 +
    1.51 +  virtual void SetCompositableBackendSpecificData(CompositableBackendSpecificData* aBackendData) MOZ_OVERRIDE;
    1.52 +
    1.53 +  void DeallocateDeviceData();
    1.54 +
    1.55 +  gl::GLContext* gl() const;
    1.56 +
    1.57 +  virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
    1.58 +
    1.59 +  void ForgetBuffer()
    1.60 +  {
    1.61 +    mGraphicBuffer = nullptr;
    1.62 +  }
    1.63 +
    1.64 +  TemporaryRef<gfx::DataSourceSurface> GetAsSurface();
    1.65 +
    1.66 +  GLuint GetGLTexture();
    1.67 +
    1.68 +  void Lock();
    1.69 +
    1.70 +protected:
    1.71 +  CompositorOGL* mCompositor;
    1.72 +  android::sp<android::GraphicBuffer> mGraphicBuffer;
    1.73 +  EGLImage mEGLImage;
    1.74 +  GLuint mTexture;
    1.75 +  gfx::SurfaceFormat mFormat;
    1.76 +  bool mNeedsReset;
    1.77 +};
    1.78 +
    1.79 +class GrallocTextureHostOGL : public TextureHost
    1.80 +#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
    1.81 +                            , public TextureHostOGL
    1.82 +#endif
    1.83 +{
    1.84 +  friend class GrallocBufferActor;
    1.85 +public:
    1.86 +  GrallocTextureHostOGL(TextureFlags aFlags,
    1.87 +                        const NewSurfaceDescriptorGralloc& aDescriptor);
    1.88 +
    1.89 +  virtual ~GrallocTextureHostOGL();
    1.90 +
    1.91 +  virtual void Updated(const nsIntRegion* aRegion) MOZ_OVERRIDE {}
    1.92 +
    1.93 +  virtual bool Lock() MOZ_OVERRIDE;
    1.94 +
    1.95 +  virtual void Unlock() MOZ_OVERRIDE;
    1.96 +
    1.97 +  virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
    1.98 +
    1.99 +  virtual void DeallocateSharedData() MOZ_OVERRIDE;
   1.100 +
   1.101 +  virtual void ForgetSharedData() MOZ_OVERRIDE;
   1.102 +
   1.103 +  virtual void DeallocateDeviceData() MOZ_OVERRIDE;
   1.104 +
   1.105 +  virtual gfx::SurfaceFormat GetFormat() const;
   1.106 +
   1.107 +  virtual gfx::IntSize GetSize() const MOZ_OVERRIDE { return mSize; }
   1.108 +
   1.109 +  virtual LayerRenderState GetRenderState() MOZ_OVERRIDE;
   1.110 +
   1.111 +  virtual NewTextureSource* GetTextureSources() MOZ_OVERRIDE
   1.112 +  {
   1.113 +    return mTextureSource;
   1.114 +  }
   1.115 +
   1.116 +#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
   1.117 +  virtual TextureHostOGL* AsHostOGL() MOZ_OVERRIDE
   1.118 +  {
   1.119 +    return this;
   1.120 +  }
   1.121 +#endif
   1.122 +
   1.123 +  virtual TemporaryRef<gfx::DataSourceSurface> GetAsSurface() MOZ_OVERRIDE;
   1.124 +
   1.125 +  virtual void SetCompositableBackendSpecificData(CompositableBackendSpecificData* aBackendData) MOZ_OVERRIDE;
   1.126 +
   1.127 +  bool IsValid() const;
   1.128 +
   1.129 +  virtual const char* Name() MOZ_OVERRIDE { return "GrallocTextureHostOGL"; }
   1.130 +
   1.131 +  // Forget buffer actor. Used only for hacky fix for bug 966446. 
   1.132 +  virtual void ForgetBufferActor()
   1.133 +  {
   1.134 +    mGrallocActor = nullptr;
   1.135 +  }
   1.136 +
   1.137 +private:
   1.138 +  GrallocBufferActor* mGrallocActor;
   1.139 +  RefPtr<GrallocTextureSourceOGL> mTextureSource;
   1.140 +  gfx::IntSize mSize; // See comment in textureClientOGL.h
   1.141 +};
   1.142 +
   1.143 +} // namespace layers
   1.144 +} // namespace mozilla
   1.145 +
   1.146 +#endif
   1.147 +#endif

mercurial