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 GFX_GLIMAGES_H 8 #define GFX_GLIMAGES_H 9 10 #include "AndroidSurfaceTexture.h" 11 #include "GLContextTypes.h" 12 #include "GLTypes.h" 13 #include "ImageContainer.h" // for Image 14 #include "ImageTypes.h" // for ImageFormat::SHARED_GLTEXTURE 15 #include "nsCOMPtr.h" // for already_AddRefed 16 #include "mozilla/gfx/Point.h" // for IntSize 17 18 namespace mozilla { 19 namespace layers { 20 21 class GLImage : public Image { 22 public: GLImage(ImageFormat aFormat)23 explicit GLImage(ImageFormat aFormat) : Image(nullptr, aFormat) {} 24 25 already_AddRefed<gfx::SourceSurface> GetAsSourceSurface() override; 26 AsGLImage()27 GLImage* AsGLImage() override { return this; } 28 }; 29 30 #ifdef MOZ_WIDGET_ANDROID 31 32 class SurfaceTextureImage : public GLImage { 33 public: 34 class SetCurrentCallback { 35 public: 36 virtual void operator()(void) = 0; ~SetCurrentCallback()37 virtual ~SetCurrentCallback() {} 38 }; 39 40 SurfaceTextureImage(AndroidSurfaceTextureHandle aHandle, 41 const gfx::IntSize& aSize, bool aContinuous, 42 gl::OriginPos aOriginPos, bool aHasAlpha = true); 43 GetSize()44 gfx::IntSize GetSize() const override { return mSize; } GetHandle()45 AndroidSurfaceTextureHandle GetHandle() const { return mHandle; } GetContinuous()46 bool GetContinuous() const { return mContinuous; } GetOriginPos()47 gl::OriginPos GetOriginPos() const { return mOriginPos; } GetHasAlpha()48 bool GetHasAlpha() const { return mHasAlpha; } 49 GetAsSourceSurface()50 already_AddRefed<gfx::SourceSurface> GetAsSourceSurface() override { 51 // We can implement this, but currently don't want to because it will cause 52 // the SurfaceTexture to be permanently bound to the snapshot readback 53 // context. 54 return nullptr; 55 } 56 AsSurfaceTextureImage()57 SurfaceTextureImage* AsSurfaceTextureImage() override { return this; } 58 RegisterSetCurrentCallback(UniquePtr<SetCurrentCallback> aCallback)59 void RegisterSetCurrentCallback(UniquePtr<SetCurrentCallback> aCallback) { 60 mSetCurrentCallback = std::move(aCallback); 61 } 62 OnSetCurrent()63 void OnSetCurrent() { 64 if (mSetCurrentCallback) { 65 (*mSetCurrentCallback)(); 66 mSetCurrentCallback.reset(); 67 } 68 } 69 70 private: 71 AndroidSurfaceTextureHandle mHandle; 72 gfx::IntSize mSize; 73 bool mContinuous; 74 gl::OriginPos mOriginPos; 75 const bool mHasAlpha; 76 UniquePtr<SetCurrentCallback> mSetCurrentCallback; 77 }; 78 79 #endif // MOZ_WIDGET_ANDROID 80 81 } // namespace layers 82 } // namespace mozilla 83 84 #endif // GFX_GLIMAGES_H 85