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 
GPUVideoTextureHost(TextureFlags aFlags,const SurfaceDescriptorGPUVideo & aDescriptor)14 GPUVideoTextureHost::GPUVideoTextureHost(TextureFlags aFlags,
15                                          const SurfaceDescriptorGPUVideo& aDescriptor)
16   : TextureHost(aFlags)
17 {
18   MOZ_COUNT_CTOR(GPUVideoTextureHost);
19   mWrappedTextureHost = VideoBridgeParent::GetSingleton()->LookupTexture(aDescriptor.handle());
20 }
21 
~GPUVideoTextureHost()22 GPUVideoTextureHost::~GPUVideoTextureHost()
23 {
24   MOZ_COUNT_DTOR(GPUVideoTextureHost);
25 }
26 
27 bool
Lock()28 GPUVideoTextureHost::Lock()
29 {
30   if (!mWrappedTextureHost) {
31     return false;
32   }
33   return mWrappedTextureHost->Lock();
34 }
35 
36 bool
BindTextureSource(CompositableTextureSourceRef & aTexture)37 GPUVideoTextureHost::BindTextureSource(CompositableTextureSourceRef& aTexture)
38 {
39   if (!mWrappedTextureHost) {
40     return false;
41   }
42   return mWrappedTextureHost->BindTextureSource(aTexture);
43 }
44 
45 Compositor*
GetCompositor()46 GPUVideoTextureHost::GetCompositor()
47 {
48   if (!mWrappedTextureHost) {
49     return nullptr;
50   }
51   return mWrappedTextureHost->GetCompositor();
52 }
53 
54 void
SetCompositor(Compositor * aCompositor)55 GPUVideoTextureHost::SetCompositor(Compositor* aCompositor)
56 {
57   if (mWrappedTextureHost) {
58     mWrappedTextureHost->SetCompositor(aCompositor);
59   }
60 }
61 
62 YUVColorSpace
GetYUVColorSpace() const63 GPUVideoTextureHost::GetYUVColorSpace() const
64 {
65   if (mWrappedTextureHost) {
66     return mWrappedTextureHost->GetYUVColorSpace();
67   }
68   return YUVColorSpace::UNKNOWN;
69 }
70 
71 gfx::IntSize
GetSize() const72 GPUVideoTextureHost::GetSize() const
73 {
74   if (!mWrappedTextureHost) {
75     return gfx::IntSize();
76   }
77   return mWrappedTextureHost->GetSize();
78 }
79 
80 gfx::SurfaceFormat
GetFormat() const81 GPUVideoTextureHost::GetFormat() const
82 {
83   if (!mWrappedTextureHost) {
84     return gfx::SurfaceFormat::UNKNOWN;
85   }
86   return mWrappedTextureHost->GetFormat();
87 }
88 
89 } // namespace layers
90 } // namespace mozilla
91