TextureClientOGL.h (5036B)
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_TEXTURECLIENTOGL_H 8 #define MOZILLA_GFX_TEXTURECLIENTOGL_H 9 10 #include "GLContextTypes.h" // for SharedTextureHandle, etc 11 #include "GLImages.h" 12 #include "gfxTypes.h" 13 #include "mozilla/gfx/Point.h" // for IntSize 14 #include "mozilla/gfx/Types.h" // for SurfaceFormat 15 #include "mozilla/layers/CompositorTypes.h" 16 #include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor 17 #include "mozilla/layers/TextureClient.h" // for TextureClient, etc 18 #ifdef MOZ_WIDGET_ANDROID 19 # include "AndroidSurfaceTexture.h" 20 # include "AndroidNativeWindow.h" 21 # include "mozilla/java/GeckoSurfaceWrappers.h" 22 # include "mozilla/layers/AndroidHardwareBuffer.h" 23 #endif 24 25 namespace mozilla { 26 27 namespace gfx { 28 29 class DrawTarget; 30 31 } // namespace gfx 32 33 namespace layers { 34 35 #ifdef MOZ_WIDGET_ANDROID 36 37 class AndroidHardwareBuffer; 38 39 class AndroidSurfaceTextureData : public TextureData { 40 public: 41 static already_AddRefed<TextureClient> CreateTextureClient( 42 AndroidSurfaceTextureHandle aHandle, gfx::IntSize aSize, bool aContinuous, 43 gl::OriginPos aOriginPos, bool aHasAlpha, bool aForceBT709ColorSpace, 44 Maybe<gfx::Matrix4x4> aTransformOverride, LayersIPCChannel* aAllocator, 45 TextureFlags aFlags); 46 47 virtual ~AndroidSurfaceTextureData(); 48 49 void FillInfo(TextureData::Info& aInfo) const override; 50 51 bool Serialize(SurfaceDescriptor& aOutDescriptor) override; 52 53 // Useless functions. 54 bool Lock(OpenMode) override { return true; } 55 56 void Unlock() override {} 57 58 // Our data is always owned externally. 59 void Deallocate(LayersIPCChannel*) override {} 60 61 protected: 62 AndroidSurfaceTextureData(AndroidSurfaceTextureHandle aHandle, 63 gfx::IntSize aSize, bool aContinuous, 64 bool aHasAlpha, bool aForceBT709ColorSpace, 65 Maybe<gfx::Matrix4x4> aTransformOverride); 66 67 const AndroidSurfaceTextureHandle mHandle; 68 const gfx::IntSize mSize; 69 const bool mContinuous; 70 const bool mHasAlpha; 71 const bool mForceBT709ColorSpace; 72 const Maybe<gfx::Matrix4x4> mTransformOverride; 73 }; 74 75 class AndroidNativeWindowTextureData : public TextureData { 76 public: 77 static AndroidNativeWindowTextureData* Create(gfx::IntSize aSize, 78 gfx::SurfaceFormat aFormat); 79 80 TextureType GetTextureType() const override { 81 return TextureType::AndroidNativeWindow; 82 } 83 84 void FillInfo(TextureData::Info& aInfo) const override; 85 86 bool Serialize(SurfaceDescriptor& aOutDescriptor) override; 87 88 bool Lock(OpenMode) override; 89 void Unlock() override; 90 91 void Forget(LayersIPCChannel*) override; 92 void Deallocate(LayersIPCChannel*) override {} 93 94 already_AddRefed<gfx::DrawTarget> BorrowDrawTarget() override; 95 96 void OnForwardedToHost() override; 97 98 protected: 99 AndroidNativeWindowTextureData(java::GeckoSurface::Param aSurface, 100 gfx::IntSize aSize, 101 gfx::SurfaceFormat aFormat); 102 103 private: 104 java::GeckoSurface::GlobalRef mSurface; 105 ANativeWindow* mNativeWindow; 106 ANativeWindow_Buffer mBuffer; 107 // Keeps track of whether the underlying NativeWindow is actually locked. 108 bool mIsLocked; 109 110 const gfx::IntSize mSize; 111 const gfx::SurfaceFormat mFormat; 112 }; 113 114 class AndroidHardwareBufferTextureData : public TextureData { 115 public: 116 static AndroidHardwareBufferTextureData* Create(gfx::IntSize aSize, 117 gfx::SurfaceFormat aFormat); 118 119 virtual ~AndroidHardwareBufferTextureData(); 120 121 void FillInfo(TextureData::Info& aInfo) const override; 122 123 bool Serialize(SurfaceDescriptor& aOutDescriptor) override; 124 125 bool Lock(OpenMode aMode) override; 126 void Unlock() override; 127 128 void Forget(LayersIPCChannel*) override; 129 void Deallocate(LayersIPCChannel*) override {} 130 131 already_AddRefed<gfx::DrawTarget> BorrowDrawTarget() override; 132 133 void OnForwardedToHost() override; 134 135 TextureFlags GetTextureFlags() const override; 136 137 Maybe<uint64_t> GetBufferId() const override; 138 139 UniqueFileHandle GetAcquireFence() override; 140 141 AndroidHardwareBufferTextureData* AsAndroidHardwareBufferTextureData() 142 override { 143 return this; 144 } 145 146 AndroidHardwareBuffer* GetBuffer() { return mAndroidHardwareBuffer; } 147 148 protected: 149 AndroidHardwareBufferTextureData( 150 AndroidHardwareBuffer* aAndroidHardwareBuffer, gfx::IntSize aSize, 151 gfx::SurfaceFormat aFormat); 152 153 RefPtr<AndroidHardwareBuffer> mAndroidHardwareBuffer; 154 const gfx::IntSize mSize; 155 const gfx::SurfaceFormat mFormat; 156 157 void* mAddress; 158 159 // Keeps track of whether the underlying NativeWindow is actually locked. 160 bool mIsLocked; 161 }; 162 163 #endif // MOZ_WIDGET_ANDROID 164 165 } // namespace layers 166 } // namespace mozilla 167 168 #endif