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_D3D11_YCBCR_IMAGE_H
8 #define GFX_D3D11_YCBCR_IMAGE_H
9 
10 #include "d3d11.h"
11 #include "mozilla/layers/TextureClientRecycleAllocator.h"
12 #include "mozilla/Maybe.h"
13 #include "ImageContainer.h"
14 
15 namespace mozilla {
16 namespace gl {
17 class GLBlitHelper;
18 }
19 namespace layers {
20 
21 class ImageContainer;
22 class DXGIYCbCrTextureClient;
23 class DXGIYCbCrTextureData;
24 
25 class MOZ_RAII DXGIYCbCrTextureAllocationHelper
26     : public ITextureClientAllocationHelper {
27  public:
28   DXGIYCbCrTextureAllocationHelper(const PlanarYCbCrData& aData,
29                                    TextureFlags aTextureFlags,
30                                    ID3D11Device* aDevice);
31 
32   bool IsCompatible(TextureClient* aTextureClient) override;
33 
34   already_AddRefed<TextureClient> Allocate(
35       KnowsCompositor* aAllocator) override;
36 
37  protected:
38   const PlanarYCbCrData& mData;
39   RefPtr<ID3D11Device> mDevice;
40 };
41 
42 class D3D11YCbCrRecycleAllocator : public TextureClientRecycleAllocator {
43  public:
D3D11YCbCrRecycleAllocator(KnowsCompositor * aKnowsCompositor)44   explicit D3D11YCbCrRecycleAllocator(KnowsCompositor* aKnowsCompositor)
45       : TextureClientRecycleAllocator(aKnowsCompositor) {}
46 
47  protected:
48   already_AddRefed<TextureClient> Allocate(
49       gfx::SurfaceFormat aFormat, gfx::IntSize aSize, BackendSelector aSelector,
50       TextureFlags aTextureFlags, TextureAllocationFlags aAllocFlags) override;
51 };
52 
53 class D3D11YCbCrImage : public Image {
54   friend class gl::GLBlitHelper;
55 
56  public:
57   D3D11YCbCrImage();
58   virtual ~D3D11YCbCrImage();
59 
60   // Copies the surface into a sharable texture's surface, and initializes
61   // the image.
62   bool SetData(KnowsCompositor* aAllocator, ImageContainer* aContainer,
63                const PlanarYCbCrData& aData);
64 
65   gfx::IntSize GetSize() const override;
66 
67   already_AddRefed<gfx::SourceSurface> GetAsSourceSurface() override;
68 
69   TextureClient* GetTextureClient(KnowsCompositor* aKnowsCompositor) override;
70 
GetPictureRect()71   gfx::IntRect GetPictureRect() const override { return mPictureRect; }
72 
73  private:
74   const DXGIYCbCrTextureData* GetData() const;
75 
76   gfx::IntSize mYSize;
77   gfx::IntSize mCbCrSize;
78   gfx::IntRect mPictureRect;
79   gfx::ColorDepth mColorDepth;
80   gfx::YUVColorSpace mColorSpace;
81   gfx::ColorRange mColorRange;
82   RefPtr<TextureClient> mTextureClient;
83 };
84 
85 }  // namespace layers
86 }  // namespace mozilla
87 
88 #endif  // GFX_D3D11_YCBCR_IMAGE_H
89