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 "GLContextTypes.h"
12 #include "ImageContainer.h" // for Image
13 #include "ImageTypes.h" // for ImageFormat::SHARED_GLTEXTURE
14 #include "nsCOMPtr.h" // for already_AddRefed
15 #include "mozilla/Maybe.h" // for Maybe
16 #include "mozilla/gfx/Matrix.h" // for Matrix4x4
17 #include "mozilla/gfx/Point.h" // for IntSize
19 #ifdef MOZ_WIDGET_ANDROID
20 # include "AndroidSurfaceTexture.h"
26 class GLImage
: public Image
{
28 explicit GLImage(ImageFormat aFormat
) : Image(nullptr, aFormat
) {}
30 already_AddRefed
<gfx::SourceSurface
> GetAsSourceSurface() override
;
32 GLImage
* AsGLImage() override
{ return this; }
35 #ifdef MOZ_WIDGET_ANDROID
37 class SurfaceTextureImage
: public GLImage
{
39 class SetCurrentCallback
{
41 virtual void operator()(void) = 0;
42 virtual ~SetCurrentCallback() {}
45 SurfaceTextureImage(AndroidSurfaceTextureHandle aHandle
,
46 const gfx::IntSize
& aSize
, bool aContinuous
,
47 gl::OriginPos aOriginPos
, bool aHasAlpha
,
48 Maybe
<gfx::Matrix4x4
> aTransformOverride
);
50 gfx::IntSize
GetSize() const override
{ return mSize
; }
51 AndroidSurfaceTextureHandle
GetHandle() const { return mHandle
; }
52 bool GetContinuous() const { return mContinuous
; }
53 gl::OriginPos
GetOriginPos() const { return mOriginPos
; }
54 bool GetHasAlpha() const { return mHasAlpha
; }
55 const Maybe
<gfx::Matrix4x4
>& GetTransformOverride() const {
56 return mTransformOverride
;
59 already_AddRefed
<gfx::SourceSurface
> GetAsSourceSurface() override
{
60 // We can implement this, but currently don't want to because it will cause
61 // the SurfaceTexture to be permanently bound to the snapshot readback
66 SurfaceTextureImage
* AsSurfaceTextureImage() override
{ return this; }
68 Maybe
<SurfaceDescriptor
> GetDesc() override
;
70 void RegisterSetCurrentCallback(UniquePtr
<SetCurrentCallback
> aCallback
) {
71 mSetCurrentCallback
= std::move(aCallback
);
75 if (mSetCurrentCallback
) {
76 (*mSetCurrentCallback
)();
77 mSetCurrentCallback
.reset();
82 AndroidSurfaceTextureHandle mHandle
;
85 gl::OriginPos mOriginPos
;
87 const Maybe
<gfx::Matrix4x4
> mTransformOverride
;
88 UniquePtr
<SetCurrentCallback
> mSetCurrentCallback
;
91 #endif // MOZ_WIDGET_ANDROID
94 } // namespace mozilla
96 #endif // GFX_GLIMAGES_H