Bug 1568876 - Make copyRule in the ChangesView fission compatible. r=rcaliman
[gecko.git] / gfx / layers / GLImages.h
blobc01e0ed463f4b583b0ca01a8b11d03b3aeff91eb
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 "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
18 namespace mozilla {
19 namespace layers {
21 class GLImage : public Image {
22 public:
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 {
33 public:
34 class SetCurrentCallback {
35 public:
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
53 // context.
54 return nullptr;
57 SurfaceTextureImage* AsSurfaceTextureImage() override { return this; }
59 void RegisterSetCurrentCallback(UniquePtr<SetCurrentCallback> aCallback) {
60 mSetCurrentCallback = std::move(aCallback);
63 void OnSetCurrent() {
64 if (mSetCurrentCallback) {
65 (*mSetCurrentCallback)();
66 mSetCurrentCallback.reset();
70 private:
71 AndroidSurfaceTextureHandle mHandle;
72 gfx::IntSize mSize;
73 bool mContinuous;
74 gl::OriginPos mOriginPos;
75 const bool mHasAlpha;
76 UniquePtr<SetCurrentCallback> mSetCurrentCallback;
79 #endif // MOZ_WIDGET_ANDROID
81 } // namespace layers
82 } // namespace mozilla
84 #endif // GFX_GLIMAGES_H