Line data Source code
1 : /* -*- Mode: C++; tab-width: 20; 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/. */
5 :
6 : #include "GPUVideoTextureHost.h"
7 : #include "mozilla/dom/VideoDecoderManagerParent.h"
8 : #include "ImageContainer.h"
9 : #include "mozilla/layers/VideoBridgeParent.h"
10 :
11 : namespace mozilla {
12 : namespace layers {
13 :
14 0 : GPUVideoTextureHost::GPUVideoTextureHost(TextureFlags aFlags,
15 0 : const SurfaceDescriptorGPUVideo& aDescriptor)
16 0 : : TextureHost(aFlags)
17 : {
18 0 : MOZ_COUNT_CTOR(GPUVideoTextureHost);
19 0 : mWrappedTextureHost = VideoBridgeParent::GetSingleton()->LookupTexture(aDescriptor.handle());
20 0 : }
21 :
22 0 : GPUVideoTextureHost::~GPUVideoTextureHost()
23 : {
24 0 : MOZ_COUNT_DTOR(GPUVideoTextureHost);
25 0 : }
26 :
27 : bool
28 0 : GPUVideoTextureHost::Lock()
29 : {
30 0 : if (!mWrappedTextureHost) {
31 0 : return false;
32 : }
33 0 : return mWrappedTextureHost->Lock();
34 : }
35 :
36 : void
37 0 : GPUVideoTextureHost::Unlock()
38 : {
39 0 : if (!mWrappedTextureHost) {
40 0 : return;
41 : }
42 0 : mWrappedTextureHost->Unlock();
43 : }
44 :
45 : bool
46 0 : GPUVideoTextureHost::BindTextureSource(CompositableTextureSourceRef& aTexture)
47 : {
48 0 : if (!mWrappedTextureHost) {
49 0 : return false;
50 : }
51 0 : return mWrappedTextureHost->BindTextureSource(aTexture);
52 : }
53 :
54 : bool
55 0 : GPUVideoTextureHost::AcquireTextureSource(CompositableTextureSourceRef& aTexture)
56 : {
57 0 : if (!mWrappedTextureHost) {
58 0 : return false;
59 : }
60 0 : return mWrappedTextureHost->AcquireTextureSource(aTexture);
61 : }
62 :
63 : void
64 0 : GPUVideoTextureHost::SetTextureSourceProvider(TextureSourceProvider* aProvider)
65 : {
66 0 : if (mWrappedTextureHost) {
67 0 : mWrappedTextureHost->SetTextureSourceProvider(aProvider);
68 : }
69 0 : }
70 :
71 : YUVColorSpace
72 0 : GPUVideoTextureHost::GetYUVColorSpace() const
73 : {
74 0 : if (mWrappedTextureHost) {
75 0 : return mWrappedTextureHost->GetYUVColorSpace();
76 : }
77 0 : return YUVColorSpace::UNKNOWN;
78 : }
79 :
80 : gfx::IntSize
81 0 : GPUVideoTextureHost::GetSize() const
82 : {
83 0 : if (!mWrappedTextureHost) {
84 0 : return gfx::IntSize();
85 : }
86 0 : return mWrappedTextureHost->GetSize();
87 : }
88 :
89 : gfx::SurfaceFormat
90 0 : GPUVideoTextureHost::GetFormat() const
91 : {
92 0 : if (!mWrappedTextureHost) {
93 0 : return gfx::SurfaceFormat::UNKNOWN;
94 : }
95 0 : return mWrappedTextureHost->GetFormat();
96 : }
97 :
98 : bool
99 0 : GPUVideoTextureHost::HasIntermediateBuffer() const
100 : {
101 0 : MOZ_ASSERT(mWrappedTextureHost);
102 :
103 0 : return mWrappedTextureHost->HasIntermediateBuffer();
104 : }
105 :
106 : void
107 0 : GPUVideoTextureHost::CreateRenderTexture(const wr::ExternalImageId& aExternalImageId)
108 : {
109 0 : MOZ_ASSERT(mWrappedTextureHost);
110 :
111 0 : mWrappedTextureHost->CreateRenderTexture(aExternalImageId);
112 0 : }
113 :
114 : void
115 0 : GPUVideoTextureHost::GetWRImageKeys(nsTArray<wr::ImageKey>& aImageKeys,
116 : const std::function<wr::ImageKey()>& aImageKeyAllocator)
117 : {
118 0 : MOZ_ASSERT(mWrappedTextureHost);
119 0 : MOZ_ASSERT(aImageKeys.IsEmpty());
120 :
121 0 : mWrappedTextureHost->GetWRImageKeys(aImageKeys, aImageKeyAllocator);
122 0 : }
123 :
124 : void
125 0 : GPUVideoTextureHost::AddWRImage(wr::WebRenderAPI* aAPI,
126 : Range<const wr::ImageKey>& aImageKeys,
127 : const wr::ExternalImageId& aExtID)
128 : {
129 0 : MOZ_ASSERT(mWrappedTextureHost);
130 :
131 0 : mWrappedTextureHost->AddWRImage(aAPI, aImageKeys, aExtID);
132 0 : }
133 :
134 : void
135 0 : GPUVideoTextureHost::PushExternalImage(wr::DisplayListBuilder& aBuilder,
136 : const WrRect& aBounds,
137 : const WrRect& aClip,
138 : wr::ImageRendering aFilter,
139 : Range<const wr::ImageKey>& aImageKeys)
140 : {
141 0 : MOZ_ASSERT(mWrappedTextureHost);
142 0 : MOZ_ASSERT(aImageKeys.length() > 0);
143 :
144 0 : mWrappedTextureHost->PushExternalImage(aBuilder,
145 : aBounds,
146 : aClip,
147 : aFilter,
148 0 : aImageKeys);
149 0 : }
150 :
151 : } // namespace layers
152 : } // namespace mozilla
|