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 MOZILLA_GFX_WAYLANDDMABUFTEXTUREHOSTOGL_H
8 #define MOZILLA_GFX_WAYLANDDMABUFTEXTUREHOSTOGL_H
9 
10 #include "mozilla/gfx/2D.h"
11 #include "mozilla/layers/CompositorOGL.h"
12 #include "mozilla/layers/TextureHostOGL.h"
13 
14 class WaylandDMABufSurface;
15 
16 namespace mozilla {
17 namespace layers {
18 
19 /**
20  * A TextureHost for shared class WaylandDMABufSurface;
21  */
22 class WaylandDMABUFTextureHostOGL : public TextureHost {
23  public:
24   WaylandDMABUFTextureHostOGL(TextureFlags aFlags,
25                               const SurfaceDescriptor& aDesc);
26   virtual ~WaylandDMABUFTextureHostOGL();
27 
28   void SetTextureSourceProvider(TextureSourceProvider* aProvider) override;
29 
30   bool Lock() override;
31 
32   void Unlock() override;
33 
34   gfx::SurfaceFormat GetFormat() const override;
35 
BindTextureSource(CompositableTextureSourceRef & aTexture)36   bool BindTextureSource(CompositableTextureSourceRef& aTexture) override {
37     aTexture = mTextureSource;
38     return !!aTexture;
39   }
40 
GetAsSurface()41   already_AddRefed<gfx::DataSourceSurface> GetAsSurface() override {
42     return nullptr;  // XXX - implement this (for MOZ_DUMP_PAINTING)
43   }
44 
45   gl::GLContext* gl() const;
46 
47   gfx::IntSize GetSize() const override;
48 
49 #ifdef MOZ_LAYERS_HAVE_LOG
Name()50   const char* Name() override { return "WaylandDMABUFTextureHostOGL"; }
51 #endif
52   uint32_t NumSubTextures() override;
53 
54   gfx::YUVColorSpace GetYUVColorSpace() const override;
55   gfx::ColorRange GetColorRange() const override;
56 
57   void CreateRenderTexture(
58       const wr::ExternalImageId& aExternalImageId) override;
59 
60   void PushResourceUpdates(wr::TransactionBuilder& aResources,
61                            ResourceUpdateOp aOp,
62                            const Range<wr::ImageKey>& aImageKeys,
63                            const wr::ExternalImageId& aExtID) override;
64 
65   void PushDisplayItems(wr::DisplayListBuilder& aBuilder,
66                         const wr::LayoutRect& aBounds,
67                         const wr::LayoutRect& aClip, wr::ImageRendering aFilter,
68                         const Range<wr::ImageKey>& aImageKeys,
69                         const bool aPreferCompositorSurface) override;
70 
71  private:
72   GLTextureSource* CreateTextureSourceForPlane(size_t aPlane);
73 
74  protected:
75   RefPtr<GLTextureSource> mTextureSource;
76   RefPtr<WaylandDMABufSurface> mSurface;
77 };
78 
79 }  // namespace layers
80 }  // namespace mozilla
81 
82 #endif  // MOZILLA_GFX_WAYLANDDMABUFTEXTUREHOSTOGL_H
83