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_X11TEXTUREHOST__H
8 #define MOZILLA_GFX_X11TEXTUREHOST__H
9 
10 #include "mozilla/layers/TextureHost.h"
11 #include "mozilla/layers/LayersSurfaces.h"
12 #include "mozilla/gfx/Types.h"
13 
14 #include "gfxXlibSurface.h"
15 
16 namespace mozilla {
17 namespace layers {
18 
19 class X11TextureSource : public TextureSource {
20  public:
21   // Called when the underlying X surface has been changed.
22   // Useful for determining whether to rebind a GLXPixmap to a texture.
23   virtual void Updated() = 0;
24 
Name()25   const char* Name() const override { return "X11TextureSource"; }
26 };
27 
28 // TextureHost for Xlib-backed TextureSources.
29 class X11TextureHost : public TextureHost {
30  public:
31   X11TextureHost(TextureFlags aFlags, const SurfaceDescriptorX11& aDescriptor);
32 
33   void SetTextureSourceProvider(TextureSourceProvider* aProvider) override;
34 
35   bool Lock() override;
36 
37   gfx::SurfaceFormat GetFormat() const override;
38 
39   gfx::IntSize GetSize() const override;
40 
BindTextureSource(CompositableTextureSourceRef & aTexture)41   bool BindTextureSource(CompositableTextureSourceRef& aTexture) override {
42     aTexture = mTextureSource;
43     return !!aTexture;
44   }
45 
46   already_AddRefed<gfx::DataSourceSurface> GetAsSurface() override;
47 
48 #ifdef MOZ_LAYERS_HAVE_LOG
Name()49   const char* Name() override { return "X11TextureHost"; }
50 #endif
51 
52  protected:
UpdatedInternal(const nsIntRegion *)53   void UpdatedInternal(const nsIntRegion*) override {
54     if (mTextureSource) mTextureSource->Updated();
55   }
56 
57   RefPtr<Compositor> mCompositor;
58   RefPtr<X11TextureSource> mTextureSource;
59   RefPtr<gfxXlibSurface> mSurface;
60 };
61 
62 }  // namespace layers
63 }  // namespace mozilla
64 
65 #endif  // MOZILLA_GFX_X11TEXTUREHOST__H
66