tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

TextureHostOGL.h (21843B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef MOZILLA_GFX_TEXTUREOGL_H
      8 #define MOZILLA_GFX_TEXTUREOGL_H
      9 
     10 #include <stddef.h>  // for size_t
     11 #include <stdint.h>  // for uint64_t
     12 #include "CompositableHost.h"
     13 #include "GLContextTypes.h"  // for GLContext
     14 #include "GLDefs.h"          // for GLenum, LOCAL_GL_CLAMP_TO_EDGE, etc
     15 #include "GLTextureImage.h"  // for TextureImage
     16 #include "gfxTypes.h"
     17 #include "mozilla/GfxMessageUtils.h"         // for gfxContentType
     18 #include "mozilla/Assertions.h"              // for MOZ_ASSERT, etc
     19 #include "mozilla/RefPtr.h"                  // for RefPtr
     20 #include "mozilla/gfx/Matrix.h"              // for Matrix4x4
     21 #include "mozilla/gfx/Point.h"               // for IntSize, IntPoint
     22 #include "mozilla/gfx/Types.h"               // for SurfaceFormat, etc
     23 #include "mozilla/layers/CompositorOGL.h"    // for CompositorOGL
     24 #include "mozilla/layers/CompositorTypes.h"  // for TextureFlags
     25 #include "mozilla/layers/LayersSurfaces.h"   // for SurfaceDescriptor
     26 #include "mozilla/layers/TextureHost.h"      // for TextureHost, etc
     27 #include "mozilla/mozalloc.h"                // for operator delete, etc
     28 #include "mozilla/webrender/RenderThread.h"
     29 #include "nsCOMPtr.h"         // for already_AddRefed
     30 #include "nsDebug.h"          // for NS_WARNING
     31 #include "nsISupportsImpl.h"  // for TextureImage::Release, etc
     32 #include "nsRegionFwd.h"      // for nsIntRegion
     33 
     34 #ifdef MOZ_WIDGET_ANDROID
     35 #  include "AndroidSurfaceTexture.h"
     36 #  include "mozilla/java/GeckoSurfaceTextureWrappers.h"
     37 #endif
     38 
     39 namespace mozilla {
     40 namespace gfx {
     41 class DataSourceSurface;
     42 }  // namespace gfx
     43 
     44 namespace layers {
     45 
     46 class Compositor;
     47 class CompositorOGL;
     48 class AndroidHardwareBuffer;
     49 class SurfaceDescriptorAndroidHardwareBuffer;
     50 class TextureImageTextureSourceOGL;
     51 class GLTextureSource;
     52 
     53 void ApplySamplingFilterToBoundTexture(gl::GLContext* aGL,
     54                                       gfx::SamplingFilter aSamplingFilter,
     55                                       GLuint aTarget = LOCAL_GL_TEXTURE_2D);
     56 
     57 already_AddRefed<TextureHost> CreateTextureHostOGL(
     58    const SurfaceDescriptor& aDesc, ISurfaceAllocator* aDeallocator,
     59    LayersBackend aBackend, TextureFlags aFlags);
     60 
     61 /*
     62 * TextureHost implementations for the OpenGL backend.
     63 *
     64 * Note that it is important to be careful about the ownership model with
     65 * the OpenGL backend, due to some widget limitation on Linux: before
     66 * the nsIWidget associated with our OpenGL context has been completely
     67 * deleted, every resource belonging to the OpenGL context MUST have been
     68 * released. At the moment the teardown sequence happens in the middle of
     69 * the nsIWidget's destructor, meaning that at a given moment we must be
     70 * able to easily find and release all the GL resources.
     71 * The point is: be careful about the ownership model and limit the number
     72 * of objects sharing references to GL resources to make the tear down
     73 * sequence as simple as possible.
     74 */
     75 
     76 /**
     77 * TextureSourceOGL provides the necessary API for CompositorOGL to composite
     78 * a TextureSource.
     79 */
     80 class TextureSourceOGL {
     81 public:
     82  TextureSourceOGL()
     83      : mCachedSamplingFilter(gfx::SamplingFilter::GOOD),
     84        mHasCachedSamplingFilter(false) {}
     85 
     86  virtual bool IsValid() const = 0;
     87 
     88  virtual void BindTexture(GLenum aTextureUnit,
     89                           gfx::SamplingFilter aSamplingFilter) = 0;
     90 
     91  // To be overridden in textures that need this. This method will be called
     92  // when the compositor has used the texture to draw. This allows us to set
     93  // a fence with glFenceSync which we can wait on later to ensure the GPU
     94  // is done with the draw calls using that texture. We would like to be able
     95  // to simply use glFinishObjectAPPLE, but this returns earlier than
     96  // expected with nvidia drivers.
     97  virtual void MaybeFenceTexture() {}
     98 
     99  virtual gfx::IntSize GetSize() const = 0;
    100 
    101  virtual GLenum GetTextureTarget() const { return LOCAL_GL_TEXTURE_2D; }
    102 
    103  virtual gfx::SurfaceFormat GetFormat() const = 0;
    104 
    105  virtual GLenum GetWrapMode() const = 0;
    106 
    107  virtual gfx::Matrix4x4 GetTextureTransform() { return gfx::Matrix4x4(); }
    108 
    109  virtual TextureImageTextureSourceOGL* AsTextureImageTextureSource() {
    110    return nullptr;
    111  }
    112 
    113  virtual GLTextureSource* AsGLTextureSource() { return nullptr; }
    114 
    115  void SetSamplingFilter(gl::GLContext* aGL,
    116                         gfx::SamplingFilter aSamplingFilter) {
    117    if (mHasCachedSamplingFilter && mCachedSamplingFilter == aSamplingFilter) {
    118      return;
    119    }
    120    mHasCachedSamplingFilter = true;
    121    mCachedSamplingFilter = aSamplingFilter;
    122    ApplySamplingFilterToBoundTexture(aGL, aSamplingFilter, GetTextureTarget());
    123  }
    124 
    125  void ClearCachedFilter() { mHasCachedSamplingFilter = false; }
    126 
    127 private:
    128  gfx::SamplingFilter mCachedSamplingFilter;
    129  bool mHasCachedSamplingFilter;
    130 };
    131 
    132 /**
    133 * A TextureSource backed by a TextureImage.
    134 *
    135 * Depending on the underlying TextureImage, may support texture tiling, so
    136 * make sure to check AsBigImageIterator() and use the texture accordingly.
    137 *
    138 * This TextureSource can be used without a TextureHost and manage it's own
    139 * GL texture(s).
    140 */
    141 class TextureImageTextureSourceOGL final : public DataTextureSource,
    142                                           public TextureSourceOGL,
    143                                           public BigImageIterator {
    144 public:
    145  explicit TextureImageTextureSourceOGL(
    146      CompositorOGL* aCompositor, TextureFlags aFlags = TextureFlags::DEFAULT);
    147 
    148  const char* Name() const override { return "TextureImageTextureSourceOGL"; }
    149  // DataTextureSource
    150 
    151  bool Update(gfx::DataSourceSurface* aSurface,
    152              nsIntRegion* aDestRegion = nullptr,
    153              gfx::IntPoint* aSrcOffset = nullptr,
    154              gfx::IntPoint* aDstOffset = nullptr) override;
    155 
    156  void EnsureBuffer(const gfx::IntSize& aSize, gfxContentType aContentType);
    157 
    158  TextureImageTextureSourceOGL* AsTextureImageTextureSource() override {
    159    return this;
    160  }
    161 
    162  // TextureSource
    163 
    164  void DeallocateDeviceData() override;
    165 
    166  TextureSourceOGL* AsSourceOGL() override { return this; }
    167 
    168  void BindTexture(GLenum aTextureUnit,
    169                   gfx::SamplingFilter aSamplingFilter) override;
    170 
    171  gfx::IntSize GetSize() const override;
    172 
    173  gfx::SurfaceFormat GetFormat() const override;
    174 
    175  bool IsValid() const override { return !!mTexImage; }
    176 
    177  GLenum GetWrapMode() const override { return mTexImage->GetWrapMode(); }
    178 
    179  // BigImageIterator
    180 
    181  BigImageIterator* AsBigImageIterator() override { return this; }
    182 
    183  void BeginBigImageIteration() override {
    184    mTexImage->BeginBigImageIteration();
    185    mIterating = true;
    186  }
    187 
    188  void EndBigImageIteration() override { mIterating = false; }
    189 
    190  gfx::IntRect GetTileRect() override;
    191 
    192  size_t GetTileCount() override { return mTexImage->GetTileCount(); }
    193 
    194  bool NextTile() override { return mTexImage->NextTile(); }
    195 
    196  gl::GLContext* gl() const { return mGL; }
    197 
    198 protected:
    199  ~TextureImageTextureSourceOGL();
    200 
    201  RefPtr<gl::TextureImage> mTexImage;
    202  RefPtr<gl::GLContext> mGL;
    203  RefPtr<CompositorOGL> mCompositor;
    204  TextureFlags mFlags;
    205  bool mIterating;
    206 };
    207 
    208 /**
    209 * A texture source for GL textures.
    210 *
    211 * It does not own any GL texture, and attaches its shared handle to one of
    212 * the compositor's temporary textures when binding.
    213 *
    214 * The shared texture handle is owned by the TextureHost.
    215 */
    216 class GLTextureSource : public DataTextureSource, public TextureSourceOGL {
    217 public:
    218  GLTextureSource(TextureSourceProvider* aProvider, GLuint aTextureHandle,
    219                  GLenum aTarget, gfx::IntSize aSize,
    220                  gfx::SurfaceFormat aFormat);
    221 
    222  GLTextureSource(gl::GLContext* aGL, GLuint aTextureHandle, GLenum aTarget,
    223                  gfx::IntSize aSize, gfx::SurfaceFormat aFormat);
    224 
    225  virtual ~GLTextureSource();
    226 
    227  const char* Name() const override { return "GLTextureSource"; }
    228 
    229  GLTextureSource* AsGLTextureSource() override { return this; }
    230 
    231  TextureSourceOGL* AsSourceOGL() override { return this; }
    232 
    233  void BindTexture(GLenum activetex,
    234                   gfx::SamplingFilter aSamplingFilter) override;
    235 
    236  bool IsValid() const override;
    237 
    238  gfx::IntSize GetSize() const override { return mSize; }
    239 
    240  gfx::SurfaceFormat GetFormat() const override { return mFormat; }
    241 
    242  GLenum GetTextureTarget() const override { return mTextureTarget; }
    243 
    244  GLenum GetWrapMode() const override { return LOCAL_GL_CLAMP_TO_EDGE; }
    245 
    246  void DeallocateDeviceData() override;
    247 
    248  void SetSize(gfx::IntSize aSize) { mSize = aSize; }
    249 
    250  void SetFormat(gfx::SurfaceFormat aFormat) { mFormat = aFormat; }
    251 
    252  GLuint GetTextureHandle() const { return mTextureHandle; }
    253 
    254  gl::GLContext* gl() const { return mGL; }
    255 
    256  bool Update(gfx::DataSourceSurface* aSurface,
    257              nsIntRegion* aDestRegion = nullptr,
    258              gfx::IntPoint* aSrcOffset = nullptr,
    259              gfx::IntPoint* aDstOffset = nullptr) override {
    260    return false;
    261  }
    262 
    263 protected:
    264  void DeleteTextureHandle();
    265 
    266  RefPtr<gl::GLContext> mGL;
    267  RefPtr<CompositorOGL> mCompositor;
    268  GLuint mTextureHandle;
    269  GLenum mTextureTarget;
    270  gfx::IntSize mSize;
    271  gfx::SurfaceFormat mFormat;
    272 };
    273 
    274 // This texture source try to wrap "aSurface" in ctor for compositor direct
    275 // access. Since we can't know the timing for gpu buffer access, the surface
    276 // should be alive until the ~ClientStorageTextureSource(). And if we try to
    277 // update the surface we mapped before, we need to call Sync() to make sure
    278 // the surface is not used by compositor.
    279 class DirectMapTextureSource : public GLTextureSource {
    280 public:
    281  DirectMapTextureSource(gl::GLContext* aContext,
    282                         gfx::DataSourceSurface* aSurface);
    283  DirectMapTextureSource(TextureSourceProvider* aProvider,
    284                         gfx::DataSourceSurface* aSurface);
    285  ~DirectMapTextureSource();
    286 
    287  bool Update(gfx::DataSourceSurface* aSurface,
    288              nsIntRegion* aDestRegion = nullptr,
    289              gfx::IntPoint* aSrcOffset = nullptr,
    290              gfx::IntPoint* aDstOffset = nullptr) override;
    291 
    292  // If aBlocking is false, check if this texture is no longer being used
    293  // by the GPU - if aBlocking is true, this will block until the GPU is
    294  // done with it.
    295  bool Sync(bool aBlocking) override;
    296 
    297  void MaybeFenceTexture() override;
    298 
    299 private:
    300  bool UpdateInternal(gfx::DataSourceSurface* aSurface,
    301                      nsIntRegion* aDestRegion, gfx::IntPoint* aSrcOffset,
    302                      bool aInit);
    303 
    304  GLsync mSync;
    305 };
    306 
    307 class GLTextureHost : public TextureHost {
    308 public:
    309  GLTextureHost(TextureFlags aFlags, GLuint aTextureHandle, GLenum aTarget,
    310                GLsync aSync, gfx::IntSize aSize, bool aHasAlpha);
    311 
    312  virtual ~GLTextureHost();
    313 
    314  // We don't own anything.
    315  void DeallocateDeviceData() override {}
    316 
    317  gfx::SurfaceFormat GetFormat() const override;
    318 
    319  already_AddRefed<gfx::DataSourceSurface> GetAsSurface(
    320      gfx::DataSourceSurface* aSurface) override {
    321    return nullptr;  // XXX - implement this (for MOZ_DUMP_PAINTING)
    322  }
    323 
    324  gl::GLContext* gl() const;
    325 
    326  gfx::IntSize GetSize() const override { return mSize; }
    327 
    328  const char* Name() override { return "GLTextureHost"; }
    329 
    330 protected:
    331  const GLuint mTexture;
    332  const GLenum mTarget;
    333  GLsync mSync;
    334  const gfx::IntSize mSize;
    335  const bool mHasAlpha;
    336  RefPtr<GLTextureSource> mTextureSource;
    337 };
    338 
    339 ////////////////////////////////////////////////////////////////////////
    340 // SurfaceTexture
    341 
    342 #ifdef MOZ_WIDGET_ANDROID
    343 
    344 class SurfaceTextureSource : public TextureSource, public TextureSourceOGL {
    345 public:
    346  SurfaceTextureSource(TextureSourceProvider* aProvider,
    347                       java::GeckoSurfaceTexture::Ref& aSurfTex,
    348                       gfx::SurfaceFormat aFormat, GLenum aTarget,
    349                       GLenum aWrapMode, gfx::IntSize aSize,
    350                       Maybe<gfx::Matrix4x4> aTransformOverride);
    351 
    352  const char* Name() const override { return "SurfaceTextureSource"; }
    353 
    354  TextureSourceOGL* AsSourceOGL() override { return this; }
    355 
    356  void BindTexture(GLenum activetex,
    357                   gfx::SamplingFilter aSamplingFilter) override;
    358 
    359  bool IsValid() const override;
    360 
    361  gfx::IntSize GetSize() const override { return mSize; }
    362 
    363  gfx::SurfaceFormat GetFormat() const override { return mFormat; }
    364 
    365  gfx::Matrix4x4 GetTextureTransform() override;
    366 
    367  GLenum GetTextureTarget() const override { return mTextureTarget; }
    368 
    369  GLenum GetWrapMode() const override { return mWrapMode; }
    370 
    371  void DeallocateDeviceData() override;
    372 
    373  gl::GLContext* gl() const { return mGL; }
    374 
    375 protected:
    376  RefPtr<gl::GLContext> mGL;
    377  mozilla::java::GeckoSurfaceTexture::GlobalRef mSurfTex;
    378  const gfx::SurfaceFormat mFormat;
    379  const GLenum mTextureTarget;
    380  const GLenum mWrapMode;
    381  const gfx::IntSize mSize;
    382  const Maybe<gfx::Matrix4x4> mTransformOverride;
    383 };
    384 
    385 class SurfaceTextureHost : public TextureHost {
    386 public:
    387  SurfaceTextureHost(TextureFlags aFlags,
    388                     mozilla::java::GeckoSurfaceTexture::Ref& aSurfTex,
    389                     gfx::IntSize aSize, gfx::SurfaceFormat aFormat,
    390                     bool aContinuousUpdate, bool aForceBT709ColorSpace,
    391                     Maybe<gfx::Matrix4x4> aTransformOverride);
    392 
    393  virtual ~SurfaceTextureHost();
    394 
    395  void DeallocateDeviceData() override;
    396 
    397  gfx::SurfaceFormat GetFormat() const override;
    398 
    399  already_AddRefed<gfx::DataSourceSurface> GetAsSurface(
    400      gfx::DataSourceSurface* aSurface) override {
    401    return nullptr;  // XXX - implement this (for MOZ_DUMP_PAINTING)
    402  }
    403 
    404  gl::GLContext* gl() const;
    405 
    406  gfx::IntSize GetSize() const override { return mSize; }
    407 
    408  const char* Name() override { return "SurfaceTextureHost"; }
    409 
    410  SurfaceTextureHost* AsSurfaceTextureHost() override { return this; }
    411 
    412  bool IsWrappingSurfaceTextureHost() override { return true; }
    413 
    414  void CreateRenderTexture(
    415      const wr::ExternalImageId& aExternalImageId) override;
    416 
    417  uint32_t NumSubTextures() override;
    418 
    419  void PushResourceUpdates(wr::TransactionBuilder& aResources,
    420                           ResourceUpdateOp aOp,
    421                           const Range<wr::ImageKey>& aImageKeys,
    422                           const wr::ExternalImageId& aExtID) override;
    423 
    424  void PushDisplayItems(wr::DisplayListBuilder& aBuilder,
    425                        const wr::LayoutRect& aBounds,
    426                        const wr::LayoutRect& aClip, wr::ImageRendering aFilter,
    427                        const Range<wr::ImageKey>& aImageKeys,
    428                        PushDisplayItemFlagSet aFlags) override;
    429 
    430  bool SupportsExternalCompositing(WebRenderBackend aBackend) override;
    431 
    432  // gecko does not need deferred deletion with WebRender
    433  // GPU/hardware task end could be checked by android fence.
    434  // SurfaceTexture uses android fence internally,
    435  bool NeedsDeferredDeletion() const override { return false; }
    436 
    437 protected:
    438  mozilla::java::GeckoSurfaceTexture::GlobalRef mSurfTex;
    439  const gfx::IntSize mSize;
    440  const gfx::SurfaceFormat mFormat;
    441  bool mContinuousUpdate;
    442  const bool mForceBT709ColorSpace;
    443  const Maybe<gfx::Matrix4x4> mTransformOverride;
    444  RefPtr<CompositorOGL> mCompositor;
    445  RefPtr<SurfaceTextureSource> mTextureSource;
    446 };
    447 
    448 class AndroidHardwareBufferTextureSource : public TextureSource,
    449                                           public TextureSourceOGL {
    450 public:
    451  AndroidHardwareBufferTextureSource(
    452      TextureSourceProvider* aProvider,
    453      AndroidHardwareBuffer* aAndroidHardwareBuffer, gfx::SurfaceFormat aFormat,
    454      GLenum aTarget, GLenum aWrapMode, gfx::IntSize aSize);
    455 
    456  const char* Name() const override { return "SurfaceTextureSource"; }
    457 
    458  TextureSourceOGL* AsSourceOGL() override { return this; }
    459 
    460  void BindTexture(GLenum activetex,
    461                   gfx::SamplingFilter aSamplingFilter) override;
    462 
    463  bool IsValid() const override;
    464 
    465  gfx::IntSize GetSize() const override { return mSize; }
    466 
    467  gfx::SurfaceFormat GetFormat() const override { return mFormat; }
    468 
    469  GLenum GetTextureTarget() const override { return mTextureTarget; }
    470 
    471  GLenum GetWrapMode() const override { return mWrapMode; }
    472 
    473  void DeallocateDeviceData() override;
    474 
    475  gl::GLContext* gl() const { return mGL; }
    476 
    477 protected:
    478  virtual ~AndroidHardwareBufferTextureSource();
    479 
    480  bool EnsureEGLImage();
    481  void DestroyEGLImage();
    482  void DeleteTextureHandle();
    483 
    484  RefPtr<gl::GLContext> mGL;
    485  RefPtr<AndroidHardwareBuffer> mAndroidHardwareBuffer;
    486  const gfx::SurfaceFormat mFormat;
    487  const GLenum mTextureTarget;
    488  const GLenum mWrapMode;
    489  const gfx::IntSize mSize;
    490 
    491  EGLImage mEGLImage;
    492  GLuint mTextureHandle;
    493 };
    494 
    495 class AndroidHardwareBufferTextureHost : public TextureHost {
    496 public:
    497  static already_AddRefed<AndroidHardwareBufferTextureHost> Create(
    498      TextureFlags aFlags, const SurfaceDescriptorAndroidHardwareBuffer& aDesc);
    499 
    500  AndroidHardwareBufferTextureHost(
    501      TextureFlags aFlags, AndroidHardwareBuffer* aAndroidHardwareBuffer);
    502 
    503  virtual ~AndroidHardwareBufferTextureHost();
    504 
    505  void DeallocateDeviceData() override;
    506 
    507  gfx::SurfaceFormat GetFormat() const override;
    508 
    509  gfx::IntSize GetSize() const override;
    510 
    511  void NotifyNotUsed() override;
    512 
    513  already_AddRefed<gfx::DataSourceSurface> GetAsSurface(
    514      gfx::DataSourceSurface* aSurface) override {
    515    return nullptr;  // XXX - implement this (for MOZ_DUMP_PAINTING)
    516  }
    517 
    518  gl::GLContext* gl() const;
    519 
    520  const char* Name() override { return "AndroidHardwareBufferTextureHost"; }
    521 
    522  AndroidHardwareBufferTextureHost* AsAndroidHardwareBufferTextureHost()
    523      override {
    524    return this;
    525  }
    526 
    527  void CreateRenderTexture(
    528      const wr::ExternalImageId& aExternalImageId) override;
    529 
    530  uint32_t NumSubTextures() override;
    531 
    532  void PushResourceUpdates(wr::TransactionBuilder& aResources,
    533                           ResourceUpdateOp aOp,
    534                           const Range<wr::ImageKey>& aImageKeys,
    535                           const wr::ExternalImageId& aExtID) override;
    536 
    537  void PushDisplayItems(wr::DisplayListBuilder& aBuilder,
    538                        const wr::LayoutRect& aBounds,
    539                        const wr::LayoutRect& aClip, wr::ImageRendering aFilter,
    540                        const Range<wr::ImageKey>& aImageKeys,
    541                        PushDisplayItemFlagSet aFlags) override;
    542 
    543  void SetReadFence(Fence* aReadFence) override;
    544 
    545  AndroidHardwareBuffer* GetAndroidHardwareBuffer() const override {
    546    return mAndroidHardwareBuffer;
    547  }
    548 
    549  bool SupportsExternalCompositing(WebRenderBackend aBackend) override;
    550 
    551  // gecko does not need deferred deletion with WebRender
    552  // GPU/hardware task end could be checked by android fence.
    553  bool NeedsDeferredDeletion() const override { return false; }
    554 
    555 protected:
    556  RefPtr<AndroidHardwareBuffer> mAndroidHardwareBuffer;
    557 };
    558 
    559 #endif  // MOZ_WIDGET_ANDROID
    560 
    561 ////////////////////////////////////////////////////////////////////////
    562 // EGLImage
    563 
    564 class EGLImageTextureSource : public TextureSource, public TextureSourceOGL {
    565 public:
    566  EGLImageTextureSource(TextureSourceProvider* aProvider, EGLImage aImage,
    567                        gfx::SurfaceFormat aFormat, GLenum aTarget,
    568                        GLenum aWrapMode, gfx::IntSize aSize);
    569 
    570  const char* Name() const override { return "EGLImageTextureSource"; }
    571 
    572  TextureSourceOGL* AsSourceOGL() override { return this; }
    573 
    574  void BindTexture(GLenum activetex,
    575                   gfx::SamplingFilter aSamplingFilter) override;
    576 
    577  bool IsValid() const override;
    578 
    579  gfx::IntSize GetSize() const override { return mSize; }
    580 
    581  gfx::SurfaceFormat GetFormat() const override { return mFormat; }
    582 
    583  gfx::Matrix4x4 GetTextureTransform() override;
    584 
    585  GLenum GetTextureTarget() const override { return mTextureTarget; }
    586 
    587  GLenum GetWrapMode() const override { return mWrapMode; }
    588 
    589  // We don't own anything.
    590  void DeallocateDeviceData() override {}
    591 
    592  gl::GLContext* gl() const { return mGL; }
    593 
    594 protected:
    595  RefPtr<gl::GLContext> mGL;
    596  RefPtr<CompositorOGL> mCompositor;
    597  const EGLImage mImage;
    598  const gfx::SurfaceFormat mFormat;
    599  const GLenum mTextureTarget;
    600  const GLenum mWrapMode;
    601  const gfx::IntSize mSize;
    602 };
    603 
    604 class EGLImageTextureHost final : public TextureHost {
    605 public:
    606  EGLImageTextureHost(TextureFlags aFlags, EGLImage aImage, EGLSync aSync,
    607                      gfx::IntSize aSize, bool hasAlpha);
    608 
    609  virtual ~EGLImageTextureHost();
    610 
    611  // We don't own anything.
    612  void DeallocateDeviceData() override {}
    613 
    614  gfx::SurfaceFormat GetFormat() const override;
    615 
    616  already_AddRefed<gfx::DataSourceSurface> GetAsSurface(
    617      gfx::DataSourceSurface* aSurface) override {
    618    return nullptr;  // XXX - implement this (for MOZ_DUMP_PAINTING)
    619  }
    620 
    621  gl::GLContext* gl() const;
    622 
    623  gfx::IntSize GetSize() const override { return mSize; }
    624 
    625  const char* Name() override { return "EGLImageTextureHost"; }
    626 
    627  void CreateRenderTexture(
    628      const wr::ExternalImageId& aExternalImageId) override;
    629 
    630  void PushResourceUpdates(wr::TransactionBuilder& aResources,
    631                           ResourceUpdateOp aOp,
    632                           const Range<wr::ImageKey>& aImageKeys,
    633                           const wr::ExternalImageId& aExtID) override;
    634 
    635  void PushDisplayItems(wr::DisplayListBuilder& aBuilder,
    636                        const wr::LayoutRect& aBounds,
    637                        const wr::LayoutRect& aClip, wr::ImageRendering aFilter,
    638                        const Range<wr::ImageKey>& aImageKeys,
    639                        PushDisplayItemFlagSet aFlags) override;
    640 
    641  bool SupportsExternalCompositing(WebRenderBackend aBackend) override;
    642 
    643 protected:
    644  const EGLImage mImage;
    645  const EGLSync mSync;
    646  const gfx::IntSize mSize;
    647  const bool mHasAlpha;
    648  RefPtr<EGLImageTextureSource> mTextureSource;
    649 };
    650 
    651 }  // namespace layers
    652 }  // namespace mozilla
    653 
    654 #endif /* MOZILLA_GFX_TEXTUREOGL_H */