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_MACIOSURFACETEXTUREHOSTOGL_H 8 #define MOZILLA_GFX_MACIOSURFACETEXTUREHOSTOGL_H 9 10 #include "MacIOSurfaceHelpers.h" 11 #include "mozilla/gfx/2D.h" 12 #include "mozilla/layers/CompositorOGL.h" 13 #include "mozilla/layers/TextureHostOGL.h" 14 15 class MacIOSurface; 16 17 namespace mozilla { 18 namespace layers { 19 20 /** 21 * A TextureHost for shared MacIOSurface 22 * 23 * Most of the logic actually happens in MacIOSurfaceTextureSourceOGL. 24 */ 25 class MacIOSurfaceTextureHostOGL : public TextureHost { 26 public: 27 MacIOSurfaceTextureHostOGL(TextureFlags aFlags, 28 const SurfaceDescriptorMacIOSurface& aDescriptor); 29 virtual ~MacIOSurfaceTextureHostOGL(); 30 31 // MacIOSurfaceTextureSourceOGL doesn't own any GL texture DeallocateDeviceData()32 void DeallocateDeviceData() override {} 33 34 void SetTextureSourceProvider(TextureSourceProvider* aProvider) override; 35 36 bool Lock() override; 37 38 gfx::SurfaceFormat GetFormat() const override; 39 gfx::SurfaceFormat GetReadFormat() const override; 40 BindTextureSource(CompositableTextureSourceRef & aTexture)41 bool BindTextureSource(CompositableTextureSourceRef& aTexture) override { 42 aTexture = mTextureSource; 43 return !!aTexture; 44 } 45 GetAsSurface()46 already_AddRefed<gfx::DataSourceSurface> GetAsSurface() override { 47 RefPtr<gfx::SourceSurface> surf = 48 CreateSourceSurfaceFromMacIOSurface(GetMacIOSurface()); 49 return surf->GetDataSurface(); 50 } 51 52 gl::GLContext* gl() const; 53 54 gfx::IntSize GetSize() const override; 55 56 #ifdef MOZ_LAYERS_HAVE_LOG Name()57 const char* Name() override { return "MacIOSurfaceTextureHostOGL"; } 58 #endif 59 AsMacIOSurfaceTextureHost()60 MacIOSurfaceTextureHostOGL* AsMacIOSurfaceTextureHost() override { 61 return this; 62 } 63 GetMacIOSurface()64 MacIOSurface* GetMacIOSurface() override { return mSurface; } 65 66 void CreateRenderTexture( 67 const wr::ExternalImageId& aExternalImageId) override; 68 69 uint32_t NumSubTextures() override; 70 71 void PushResourceUpdates(wr::TransactionBuilder& aResources, 72 ResourceUpdateOp aOp, 73 const Range<wr::ImageKey>& aImageKeys, 74 const wr::ExternalImageId& aExtID) override; 75 76 void PushDisplayItems(wr::DisplayListBuilder& aBuilder, 77 const wr::LayoutRect& aBounds, 78 const wr::LayoutRect& aClip, wr::ImageRendering aFilter, 79 const Range<wr::ImageKey>& aImageKeys, 80 PushDisplayItemFlagSet aFlags) override; 81 82 gfx::YUVColorSpace GetYUVColorSpace() const override; 83 gfx::ColorRange GetColorRange() const override; 84 85 protected: 86 GLTextureSource* CreateTextureSourceForPlane(size_t aPlane); 87 88 RefPtr<GLTextureSource> mTextureSource; 89 RefPtr<MacIOSurface> mSurface; 90 }; 91 92 } // namespace layers 93 } // namespace mozilla 94 95 #endif // MOZILLA_GFX_MACIOSURFACETEXTUREHOSTOGL_H 96