Bug 1764201 Part 3: Remove screen info stuff from gfxPlatform. r=jgilbert,geckoview...
[gecko.git] / gfx / layers / GLImages.h
blob7e31fdec4434de9f1df691f85f10cb07b189a182
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 nsresult BuildSurfaceDescriptorBuffer(
33 SurfaceDescriptorBuffer& aSdBuffer, BuildSdbFlags aFlags,
34 const std::function<MemoryOrShmem(uint32_t)>& aAllocate) override;
36 GLImage* AsGLImage() override { return this; }
38 protected:
39 nsresult ReadIntoBuffer(uint8_t* aData, int32_t aStride,
40 const gfx::IntSize& aSize,
41 gfx::SurfaceFormat aFormat);
44 #ifdef MOZ_WIDGET_ANDROID
46 class SurfaceTextureImage final : public GLImage {
47 public:
48 class SetCurrentCallback {
49 public:
50 virtual void operator()(void) = 0;
51 virtual ~SetCurrentCallback() {}
54 SurfaceTextureImage(AndroidSurfaceTextureHandle aHandle,
55 const gfx::IntSize& aSize, bool aContinuous,
56 gl::OriginPos aOriginPos, bool aHasAlpha,
57 bool aForceBT709ColorSpace,
58 Maybe<gfx::Matrix4x4> aTransformOverride);
60 gfx::IntSize GetSize() const override { return mSize; }
61 AndroidSurfaceTextureHandle GetHandle() const { return mHandle; }
62 bool GetContinuous() const { return mContinuous; }
63 gl::OriginPos GetOriginPos() const { return mOriginPos; }
64 bool GetHasAlpha() const { return mHasAlpha; }
65 bool GetForceBT709ColorSpace() const { return mForceBT709ColorSpace; }
66 const Maybe<gfx::Matrix4x4>& GetTransformOverride() const {
67 return mTransformOverride;
70 already_AddRefed<gfx::SourceSurface> GetAsSourceSurface() override {
71 // We can implement this, but currently don't want to because it will cause
72 // the SurfaceTexture to be permanently bound to the snapshot readback
73 // context.
74 return nullptr;
77 nsresult BuildSurfaceDescriptorBuffer(
78 SurfaceDescriptorBuffer& aSdBuffer, BuildSdbFlags aFlags,
79 const std::function<MemoryOrShmem(uint32_t)>& aAllocate) override {
80 // We can implement this, but currently don't want to because it will cause
81 // the SurfaceTexture to be permanently bound to the snapshot readback
82 // context.
83 return NS_ERROR_NOT_IMPLEMENTED;
86 SurfaceTextureImage* AsSurfaceTextureImage() override { return this; }
88 Maybe<SurfaceDescriptor> GetDesc() override;
90 void RegisterSetCurrentCallback(UniquePtr<SetCurrentCallback> aCallback) {
91 mSetCurrentCallback = std::move(aCallback);
94 void OnSetCurrent() {
95 if (mSetCurrentCallback) {
96 (*mSetCurrentCallback)();
97 mSetCurrentCallback.reset();
101 private:
102 AndroidSurfaceTextureHandle mHandle;
103 gfx::IntSize mSize;
104 bool mContinuous;
105 gl::OriginPos mOriginPos;
106 const bool mHasAlpha;
107 const bool mForceBT709ColorSpace;
108 const Maybe<gfx::Matrix4x4> mTransformOverride;
109 UniquePtr<SetCurrentCallback> mSetCurrentCallback;
112 #endif // MOZ_WIDGET_ANDROID
114 } // namespace layers
115 } // namespace mozilla
117 #endif // GFX_GLIMAGES_H