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"
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
{
24 RenderExternalTextureHost(uint8_t* aBuffer
,
25 const layers::BufferDescriptor
& aDescriptor
);
27 wr::WrExternalImage
Lock(uint8_t aChannelIndex
, gl::GLContext
* aGL
,
28 wr::ImageRendering aRendering
) override
;
29 void Unlock() override
;
30 void PrepareForUse() override
;
31 size_t Bytes() override
{
32 return mSize
.width
* mSize
.height
* BytesPerPixel(mFormat
);
35 // RenderTextureHostSWGL
36 size_t GetPlaneCount() const override
;
38 gfx::SurfaceFormat
GetFormat() const override
;
40 gfx::ColorDepth
GetColorDepth() const override
;
42 gfx::YUVColorSpace
GetYUVColorSpace() const override
;
44 bool MapPlane(RenderCompositor
* aCompositor
, uint8_t aChannelIndex
,
45 PlaneInfo
& aPlaneInfo
) override
;
47 void UnmapPlanes() override
;
50 ~RenderExternalTextureHost();
52 bool CreateSurfaces();
53 void DeleteSurfaces();
54 void DeleteTextures();
56 uint8_t* GetBuffer() const { return mBuffer
; }
57 bool InitializeIfNeeded();
58 bool IsReadyForDeletion();
59 bool IsYUV() const { return mFormat
== gfx::SurfaceFormat::YUV
; }
60 size_t PlaneCount() const { return IsYUV() ? 3 : 1; }
61 void UpdateTexture(size_t aIndex
);
62 void UpdateTextures(wr::ImageRendering aRendering
);
65 layers::BufferDescriptor mDescriptor
;
68 bool mTextureUpdateNeeded
;
71 gfx::SurfaceFormat mFormat
;
73 RefPtr
<gl::GLContext
> mGL
;
74 RefPtr
<gfx::DataSourceSurface
> mSurfaces
[3];
75 RefPtr
<layers::DirectMapTextureSource
> mTextureSources
[3];
76 wr::WrExternalImage mImages
[3];
80 } // namespace mozilla
82 #endif // MOZILLA_GFX_RENDEREXTERNALTEXTUREHOST_H