Bug 1857841 - pt 3. Add a new page kind named "fresh" r=glandium
[gecko.git] / gfx / webrender_bindings / RenderAndroidSurfaceTextureHost.h
blob1a6238a72ff25b74bcb32781984bfd7dda2f01f4
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 MOZILLA_GFX_RENDERANDROIDSURFACETEXTUREHOST_H
8 #define MOZILLA_GFX_RENDERANDROIDSURFACETEXTUREHOST_H
10 #include "mozilla/java/GeckoSurfaceTextureWrappers.h"
11 #include "mozilla/layers/TextureHostOGL.h"
12 #include "RenderTextureHostSWGL.h"
14 namespace mozilla {
16 namespace gfx {
17 class DataSourceSurface;
20 namespace wr {
22 class RenderAndroidSurfaceTextureHost final : public RenderTextureHostSWGL {
23 public:
24 explicit RenderAndroidSurfaceTextureHost(
25 const java::GeckoSurfaceTexture::GlobalRef& aSurfTex, gfx::IntSize aSize,
26 gfx::SurfaceFormat aFormat, bool aContinuousUpdate,
27 Maybe<gfx::Matrix4x4> aTransformOverride, bool aIsRemoteTexture);
29 wr::WrExternalImage Lock(uint8_t aChannelIndex, gl::GLContext* aGL) override;
30 void Unlock() override;
32 size_t Bytes() override {
33 return mSize.width * mSize.height * BytesPerPixel(mFormat);
36 void PrepareForUse() override;
37 void NotifyForUse() override;
38 void NotifyNotUsed() override;
40 // RenderTextureHostSWGL
41 gfx::SurfaceFormat GetFormat() const override;
42 gfx::ColorDepth GetColorDepth() const override {
43 return gfx::ColorDepth::COLOR_8;
45 size_t GetPlaneCount() const override { return 1; }
46 bool MapPlane(RenderCompositor* aCompositor, uint8_t aChannelIndex,
47 PlaneInfo& aPlaneInfo) override;
48 void UnmapPlanes() override;
50 RenderAndroidSurfaceTextureHost* AsRenderAndroidSurfaceTextureHost()
51 override {
52 return this;
55 void UpdateTexImageIfNecessary();
57 mozilla::java::GeckoSurfaceTexture::GlobalRef mSurfTex;
58 const gfx::IntSize mSize;
59 const gfx::SurfaceFormat mFormat;
60 // mContinuousUpdate was used for rendering video in the past.
61 // It is not used on current gecko.
62 const bool mContinuousUpdate;
63 const Maybe<gfx::Matrix4x4> mTransformOverride;
65 private:
66 virtual ~RenderAndroidSurfaceTextureHost();
67 bool EnsureAttachedToGLContext();
69 already_AddRefed<gfx::DataSourceSurface> ReadTexImage();
71 // Returns the UV coordinates to be used when sampling the texture, taking in
72 // to account the SurfaceTexture's transform if applicable.
73 std::pair<gfx::Point, gfx::Point> GetUvCoords(
74 gfx::IntSize aTextureSize) const override;
76 enum PrepareStatus {
77 STATUS_NONE,
78 STATUS_MIGHT_BE_USED_BY_WR,
79 STATUS_UPDATE_TEX_IMAGE_NEEDED,
80 STATUS_PREPARED
83 PrepareStatus mPrepareStatus;
84 bool mAttachedToGLContext;
86 RefPtr<gl::GLContext> mGL;
88 RefPtr<gfx::DataSourceSurface> mReadback;
90 bool mIsRemoteTexture;
93 } // namespace wr
94 } // namespace mozilla
96 #endif // MOZILLA_GFX_RENDERANDROIDSURFACETEXTUREHOST_H