1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef GFX_LAYER_DCOMP_SURFACE_IMAGE_H
7 #define GFX_LAYER_DCOMP_SURFACE_IMAGE_H
9 #include "ImageContainer.h"
10 #include "mozilla/layers/TextureClient.h"
11 #include "mozilla/layers/TextureHost.h"
13 namespace mozilla::wr
{
14 class DisplayListBuilder
;
15 class TransactionBuilder
;
16 } // namespace mozilla::wr
18 namespace mozilla::layers
{
20 already_AddRefed
<TextureHost
> CreateTextureHostDcompSurface(
21 const SurfaceDescriptor
& aDesc
, ISurfaceAllocator
* aDeallocator
,
22 LayersBackend aBackend
, TextureFlags aFlags
);
25 * A texture data wrapping a dcomp surface handle, which is provided by the
26 * media foundation media engine. We won't be able to control real texture data
27 * because that is protected by the media engine.
29 class DcompSurfaceTexture final
: public TextureData
{
31 static already_AddRefed
<TextureClient
> CreateTextureClient(
32 HANDLE aHandle
, gfx::IntSize aSize
, gfx::SurfaceFormat aFormat
,
33 KnowsCompositor
* aKnowsCompositor
);
35 ~DcompSurfaceTexture();
37 bool Serialize(SurfaceDescriptor
& aOutDescriptor
) override
;
38 void GetSubDescriptor(RemoteDecoderVideoSubDescriptor
* aOutDesc
) override
;
39 void FillInfo(TextureData::Info
& aInfo
) const {
41 aInfo
.supportsMoz2D
= false;
42 aInfo
.canExposeMappedData
= false;
43 aInfo
.hasSynchronization
= false;
45 bool Lock(OpenMode
) override
{ return true; }
46 void Unlock() override
{}
47 void Deallocate(LayersIPCChannel
* aAllocator
) override
{}
50 DcompSurfaceTexture(HANDLE aHandle
, gfx::IntSize aSize
,
51 gfx::SurfaceFormat aFormat
)
52 : mHandle(aHandle
), mSize(aSize
), mFormat(aFormat
) {}
55 const gfx::IntSize mSize
;
56 const gfx::SurfaceFormat mFormat
;
60 * A image data which holds a dcomp texture which is provided by the media
61 * foundation media engine. As the real texture is protected, it does not
62 * support being accessed as a source surface.
64 class DcompSurfaceImage
: public Image
{
66 DcompSurfaceImage(HANDLE aHandle
, gfx::IntSize aSize
,
67 gfx::SurfaceFormat aFormat
,
68 KnowsCompositor
* aKnowsCompositor
);
69 virtual ~DcompSurfaceImage() = default;
71 already_AddRefed
<gfx::SourceSurface
> GetAsSourceSurface() override
{
75 gfx::IntSize
GetSize() const { return mTextureClient
->GetSize(); };
77 TextureClient
* GetTextureClient(KnowsCompositor
* aKnowsCompositor
) override
;
80 RefPtr
<TextureClient
> mTextureClient
;
84 * A Texture host living in GPU process which owns a dcomp surface handle which
85 * is provided by the media foundation media engine.
87 class DcompSurfaceHandleHost
: public TextureHost
{
89 DcompSurfaceHandleHost(TextureFlags aFlags
,
90 const SurfaceDescriptorDcompSurface
& aDescriptor
);
92 gfx::SurfaceFormat
GetFormat() const override
{ return mFormat
; }
94 gfx::IntSize
GetSize() const override
{ return mSize
; }
96 const char* Name() override
{ return "DcompSurfaceHandleHost"; }
98 already_AddRefed
<gfx::DataSourceSurface
> GetAsSurface() override
{
102 void CreateRenderTexture(
103 const wr::ExternalImageId
& aExternalImageId
) override
;
105 void PushResourceUpdates(
106 wr::TransactionBuilder
& aResources
, ResourceUpdateOp aOp
,
107 const Range
<wr::ImageKey
>& aImageKeys
,
108 const wr::ExternalImageId
& aExternalImageId
) override
;
110 void PushDisplayItems(wr::DisplayListBuilder
& aBuilder
,
111 const wr::LayoutRect
& aBounds
,
112 const wr::LayoutRect
& aClip
, wr::ImageRendering aFilter
,
113 const Range
<wr::ImageKey
>& aImageKeys
,
114 PushDisplayItemFlagSet aFlags
) override
;
116 bool SupportsExternalCompositing(WebRenderBackend aBackend
) override
{
121 ~DcompSurfaceHandleHost();
123 // Handle will be closed automatically when `UniqueFileHandle` gets destroyed.
124 const mozilla::UniqueFileHandle mHandle
;
125 const gfx::IntSize mSize
;
126 const gfx::SurfaceFormat mFormat
;
129 } // namespace mozilla::layers
131 #endif // GFX_LAYER_DCOMP_SURFACE_IMAGE_H