/work/obj-fuzz/dist/include/GPUVideoImage.h
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #ifndef GFX_GPU_VIDEO_IMAGE_H |
8 | | #define GFX_GPU_VIDEO_IMAGE_H |
9 | | |
10 | | #include "mozilla/RefPtr.h" |
11 | | #include "ImageContainer.h" |
12 | | #include "mozilla/layers/GPUVideoTextureClient.h" |
13 | | #include "mozilla/layers/CompositableClient.h" |
14 | | #include "mozilla/layers/ImageBridgeChild.h" |
15 | | |
16 | | namespace mozilla { |
17 | | namespace dom { |
18 | | class VideoDecoderManagerChild; |
19 | | } |
20 | | namespace gl { |
21 | | class GLBlitHelper; |
22 | | } |
23 | | namespace layers { |
24 | | |
25 | | // Image class that refers to a decoded video frame within |
26 | | // the GPU process. |
27 | | class GPUVideoImage final : public Image |
28 | | { |
29 | | friend class gl::GLBlitHelper; |
30 | | public: |
31 | | GPUVideoImage(dom::VideoDecoderManagerChild* aManager, |
32 | | const SurfaceDescriptorGPUVideo& aSD, |
33 | | const gfx::IntSize& aSize) |
34 | | : Image(nullptr, ImageFormat::GPU_VIDEO) |
35 | | , mSize(aSize) |
36 | 0 | { |
37 | 0 | // Create the TextureClient immediately since the GPUVideoTextureData |
38 | 0 | // is responsible for deallocating the SurfaceDescriptor. |
39 | 0 | // |
40 | 0 | // Use the RECYCLE texture flag, since it's likely that our 'real' |
41 | 0 | // TextureData (in the decoder thread of the GPU process) is using |
42 | 0 | // it too, and we want to make sure we don't send the delete message |
43 | 0 | // until we've stopped being used on the compositor. |
44 | 0 | mTextureClient = |
45 | 0 | TextureClient::CreateWithData(new GPUVideoTextureData(aManager, aSD, aSize), |
46 | 0 | TextureFlags::RECYCLE, |
47 | 0 | ImageBridgeChild::GetSingleton().get()); |
48 | 0 | } |
49 | | |
50 | 0 | virtual ~GPUVideoImage() {} |
51 | | |
52 | 0 | gfx::IntSize GetSize() const override { return mSize; } |
53 | | |
54 | | private: |
55 | | GPUVideoTextureData* GetData() const |
56 | 0 | { |
57 | 0 | if (!mTextureClient) { |
58 | 0 | return nullptr; |
59 | 0 | } |
60 | 0 | TextureData* data = mTextureClient->GetInternalData(); |
61 | 0 | if (!data) { |
62 | 0 | return nullptr; |
63 | 0 | } |
64 | 0 | return data->AsGPUVideoTextureData(); |
65 | 0 | } |
66 | | |
67 | | public: |
68 | | already_AddRefed<gfx::SourceSurface> GetAsSourceSurface() override |
69 | 0 | { |
70 | 0 | GPUVideoTextureData* data = GetData(); |
71 | 0 | if (!data) { |
72 | 0 | return nullptr; |
73 | 0 | } |
74 | 0 | return data->GetAsSourceSurface(); |
75 | 0 | } |
76 | | |
77 | | TextureClient* GetTextureClient(KnowsCompositor* aForwarder) override |
78 | 0 | { |
79 | 0 | MOZ_ASSERT(aForwarder == ImageBridgeChild::GetSingleton(), "Must only use GPUVideo on ImageBridge"); |
80 | 0 | return mTextureClient; |
81 | 0 | } |
82 | | |
83 | | private: |
84 | | gfx::IntSize mSize; |
85 | | RefPtr<TextureClient> mTextureClient; |
86 | | }; |
87 | | |
88 | | } // namepace layers |
89 | | } // namespace mozilla |
90 | | |
91 | | #endif // GFX_GPU_VIDEO_IMAGE_H |