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/. */
10 #include "AndroidSurfaceTexture.h"
11 #include "GLContextTypes.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
21 class GLImage
: public Image
{
23 explicit GLImage(ImageFormat aFormat
) : Image(nullptr, aFormat
) {}
25 already_AddRefed
<gfx::SourceSurface
> GetAsSourceSurface() override
;
27 GLImage
* AsGLImage() override
{ return this; }
30 #ifdef MOZ_WIDGET_ANDROID
32 class SurfaceTextureImage
: public GLImage
{
34 class SetCurrentCallback
{
36 virtual void operator()(void) = 0;
37 virtual ~SetCurrentCallback() {}
40 SurfaceTextureImage(AndroidSurfaceTextureHandle aHandle
,
41 const gfx::IntSize
& aSize
, bool aContinuous
,
42 gl::OriginPos aOriginPos
, bool aHasAlpha
= true);
44 gfx::IntSize
GetSize() const override
{ return mSize
; }
45 AndroidSurfaceTextureHandle
GetHandle() const { return mHandle
; }
46 bool GetContinuous() const { return mContinuous
; }
47 gl::OriginPos
GetOriginPos() const { return mOriginPos
; }
48 bool GetHasAlpha() const { return mHasAlpha
; }
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
57 SurfaceTextureImage
* AsSurfaceTextureImage() override
{ return this; }
59 void RegisterSetCurrentCallback(UniquePtr
<SetCurrentCallback
> aCallback
) {
60 mSetCurrentCallback
= std::move(aCallback
);
64 if (mSetCurrentCallback
) {
65 (*mSetCurrentCallback
)();
66 mSetCurrentCallback
.reset();
71 AndroidSurfaceTextureHandle mHandle
;
74 gl::OriginPos mOriginPos
;
76 UniquePtr
<SetCurrentCallback
> mSetCurrentCallback
;
79 #endif // MOZ_WIDGET_ANDROID
82 } // namespace mozilla
84 #endif // GFX_GLIMAGES_H