Bug 1839315: part 4) Link from `SheetLoadData::mWasAlternate` to spec. r=emilio DONTBUILD
[gecko.git] / gfx / layers / GLImages.h
blob3bab26216c073613d7d1aaa2b4d5efb7035b676c
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/. */
7 #ifndef GFX_GLIMAGES_H
8 #define GFX_GLIMAGES_H
10 #include "GLContextTypes.h"
11 #include "GLTypes.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"
21 #endif
23 namespace mozilla {
24 namespace layers {
26 class GLImage : public Image {
27 public:
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 {
38 public:
39 class SetCurrentCallback {
40 public:
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
62 // context.
63 return nullptr;
66 SurfaceTextureImage* AsSurfaceTextureImage() override { return this; }
68 Maybe<SurfaceDescriptor> GetDesc() override;
70 void RegisterSetCurrentCallback(UniquePtr<SetCurrentCallback> aCallback) {
71 mSetCurrentCallback = std::move(aCallback);
74 void OnSetCurrent() {
75 if (mSetCurrentCallback) {
76 (*mSetCurrentCallback)();
77 mSetCurrentCallback.reset();
81 private:
82 AndroidSurfaceTextureHandle mHandle;
83 gfx::IntSize mSize;
84 bool mContinuous;
85 gl::OriginPos mOriginPos;
86 const bool mHasAlpha;
87 const Maybe<gfx::Matrix4x4> mTransformOverride;
88 UniquePtr<SetCurrentCallback> mSetCurrentCallback;
91 #endif // MOZ_WIDGET_ANDROID
93 } // namespace layers
94 } // namespace mozilla
96 #endif // GFX_GLIMAGES_H