Update configs. IGNORE BROKEN CHANGESETS CLOSED TREE NO BUG a=release ba=release
[gecko.git] / gfx / webrender_bindings / RenderExternalTextureHost.h
blobc3b13250c114ecc00d1c1209127e1f0d17952a84
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_RENDEREXTERNALTEXTUREHOST_H
8 #define MOZILLA_GFX_RENDEREXTERNALTEXTUREHOST_H
10 #include "mozilla/layers/TextureHostOGL.h"
11 #include "RenderTextureHostSWGL.h"
13 namespace mozilla {
14 namespace wr {
16 /**
17 * RenderExternalTextureHost manages external textures used by WebRender on Mac.
18 * The motivation for this is to be able to use Apple Client Storage OpenGL
19 * extension, which makes it possible to avoid some copies during texture
20 * upload. This is especially helpful for high resolution video.
22 class RenderExternalTextureHost final : public RenderTextureHostSWGL {
23 public:
24 RenderExternalTextureHost(uint8_t* aBuffer,
25 const layers::BufferDescriptor& aDescriptor);
27 wr::WrExternalImage Lock(uint8_t aChannelIndex, gl::GLContext* aGL) override;
28 void Unlock() override;
29 void PrepareForUse() override;
30 size_t Bytes() override {
31 return mSize.width * mSize.height * BytesPerPixel(mFormat);
34 // RenderTextureHostSWGL
35 size_t GetPlaneCount() const override;
37 gfx::SurfaceFormat GetFormat() const override;
39 gfx::ColorDepth GetColorDepth() const override;
41 gfx::YUVRangedColorSpace GetYUVColorSpace() const override;
43 bool MapPlane(RenderCompositor* aCompositor, uint8_t aChannelIndex,
44 PlaneInfo& aPlaneInfo) override;
46 void UnmapPlanes() override;
48 private:
49 ~RenderExternalTextureHost();
51 bool CreateSurfaces();
52 void DeleteSurfaces();
53 void DeleteTextures();
55 uint8_t* GetBuffer() const { return mBuffer; }
56 bool InitializeIfNeeded();
57 bool IsReadyForDeletion();
58 bool IsYUV() const { return mFormat == gfx::SurfaceFormat::YUV; }
59 size_t PlaneCount() const { return IsYUV() ? 3 : 1; }
60 void UpdateTexture(size_t aIndex);
61 void UpdateTextures();
63 uint8_t* mBuffer;
64 layers::BufferDescriptor mDescriptor;
66 bool mInitialized;
67 bool mTextureUpdateNeeded;
69 gfx::IntSize mSize;
70 gfx::SurfaceFormat mFormat;
72 RefPtr<gl::GLContext> mGL;
73 RefPtr<gfx::DataSourceSurface> mSurfaces[3];
74 RefPtr<layers::DirectMapTextureSource> mTextureSources[3];
75 wr::WrExternalImage mImages[3];
78 } // namespace wr
79 } // namespace mozilla
81 #endif // MOZILLA_GFX_RENDEREXTERNALTEXTUREHOST_H