Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef MOZILLA_GFX_TEXTUREOGL_H |
michael@0 | 7 | #define MOZILLA_GFX_TEXTUREOGL_H |
michael@0 | 8 | |
michael@0 | 9 | #include <stddef.h> // for size_t |
michael@0 | 10 | #include <stdint.h> // for uint64_t |
michael@0 | 11 | #include "CompositableHost.h" |
michael@0 | 12 | #include "GLContextTypes.h" // for GLContext |
michael@0 | 13 | #include "GLDefs.h" // for GLenum, LOCAL_GL_CLAMP_TO_EDGE, etc |
michael@0 | 14 | #include "GLTextureImage.h" // for TextureImage |
michael@0 | 15 | #include "gfxTypes.h" |
michael@0 | 16 | #include "mozilla/GfxMessageUtils.h" // for gfxContentType |
michael@0 | 17 | #include "mozilla/Assertions.h" // for MOZ_ASSERT, etc |
michael@0 | 18 | #include "mozilla/Attributes.h" // for MOZ_OVERRIDE |
michael@0 | 19 | #include "mozilla/RefPtr.h" // for RefPtr |
michael@0 | 20 | #include "mozilla/gfx/Matrix.h" // for Matrix4x4 |
michael@0 | 21 | #include "mozilla/gfx/Point.h" // for IntSize, IntPoint |
michael@0 | 22 | #include "mozilla/gfx/Types.h" // for SurfaceFormat, etc |
michael@0 | 23 | #include "mozilla/layers/CompositorTypes.h" // for TextureFlags |
michael@0 | 24 | #include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor |
michael@0 | 25 | #include "mozilla/layers/TextureHost.h" // for TextureHost, etc |
michael@0 | 26 | #include "mozilla/mozalloc.h" // for operator delete, etc |
michael@0 | 27 | #include "nsAutoPtr.h" // for nsRefPtr |
michael@0 | 28 | #include "nsCOMPtr.h" // for already_AddRefed |
michael@0 | 29 | #include "nsDebug.h" // for NS_WARNING |
michael@0 | 30 | #include "nsISupportsImpl.h" // for TextureImage::Release, etc |
michael@0 | 31 | #include "OGLShaderProgram.h" // for ShaderProgramType, etc |
michael@0 | 32 | #ifdef MOZ_WIDGET_GONK |
michael@0 | 33 | #include <ui/GraphicBuffer.h> |
michael@0 | 34 | #if ANDROID_VERSION >= 17 |
michael@0 | 35 | #include <ui/Fence.h> |
michael@0 | 36 | #endif |
michael@0 | 37 | #endif |
michael@0 | 38 | |
michael@0 | 39 | class gfxReusableSurfaceWrapper; |
michael@0 | 40 | class nsIntRegion; |
michael@0 | 41 | struct nsIntPoint; |
michael@0 | 42 | struct nsIntRect; |
michael@0 | 43 | struct nsIntSize; |
michael@0 | 44 | |
michael@0 | 45 | namespace mozilla { |
michael@0 | 46 | namespace gfx { |
michael@0 | 47 | class DataSourceSurface; |
michael@0 | 48 | class SurfaceStream; |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | namespace layers { |
michael@0 | 52 | |
michael@0 | 53 | class Compositor; |
michael@0 | 54 | class CompositorOGL; |
michael@0 | 55 | class TextureImageTextureSourceOGL; |
michael@0 | 56 | |
michael@0 | 57 | /** |
michael@0 | 58 | * CompositableBackendSpecificData implementation for the Gonk OpenGL backend. |
michael@0 | 59 | * Share a same texture between TextureHosts in the same CompositableHost. |
michael@0 | 60 | * By shareing the texture among the TextureHosts, number of texture allocations |
michael@0 | 61 | * can be reduced than texture allocation in every TextureHosts. |
michael@0 | 62 | * From Bug 912134, use only one texture among all TextureHosts degrade |
michael@0 | 63 | * the rendering performance. |
michael@0 | 64 | * CompositableDataGonkOGL chooses in a middile of them. |
michael@0 | 65 | */ |
michael@0 | 66 | class CompositableDataGonkOGL : public CompositableBackendSpecificData |
michael@0 | 67 | { |
michael@0 | 68 | public: |
michael@0 | 69 | CompositableDataGonkOGL(); |
michael@0 | 70 | virtual ~CompositableDataGonkOGL(); |
michael@0 | 71 | |
michael@0 | 72 | virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE; |
michael@0 | 73 | virtual void ClearData() MOZ_OVERRIDE; |
michael@0 | 74 | GLuint GetTexture(); |
michael@0 | 75 | void DeleteTextureIfPresent(); |
michael@0 | 76 | gl::GLContext* gl() const; |
michael@0 | 77 | protected: |
michael@0 | 78 | RefPtr<CompositorOGL> mCompositor; |
michael@0 | 79 | GLuint mTexture; |
michael@0 | 80 | }; |
michael@0 | 81 | |
michael@0 | 82 | inline void ApplyFilterToBoundTexture(gl::GLContext* aGL, |
michael@0 | 83 | gfx::Filter aFilter, |
michael@0 | 84 | GLuint aTarget = LOCAL_GL_TEXTURE_2D) |
michael@0 | 85 | { |
michael@0 | 86 | GLenum filter = |
michael@0 | 87 | (aFilter == gfx::Filter::POINT ? LOCAL_GL_NEAREST : LOCAL_GL_LINEAR); |
michael@0 | 88 | |
michael@0 | 89 | aGL->fTexParameteri(aTarget, LOCAL_GL_TEXTURE_MIN_FILTER, filter); |
michael@0 | 90 | aGL->fTexParameteri(aTarget, LOCAL_GL_TEXTURE_MAG_FILTER, filter); |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | /* |
michael@0 | 94 | * TextureHost implementations for the OpenGL backend. |
michael@0 | 95 | * |
michael@0 | 96 | * Note that it is important to be careful about the ownership model with |
michael@0 | 97 | * the OpenGL backend, due to some widget limitation on Linux: before |
michael@0 | 98 | * the nsBaseWidget associated with our OpenGL context has been completely |
michael@0 | 99 | * deleted, every resource belonging to the OpenGL context MUST have been |
michael@0 | 100 | * released. At the moment the teardown sequence happens in the middle of |
michael@0 | 101 | * the nsBaseWidget's destructor, meaning that at a given moment we must be |
michael@0 | 102 | * able to easily find and release all the GL resources. |
michael@0 | 103 | * The point is: be careful about the ownership model and limit the number |
michael@0 | 104 | * of objects sharing references to GL resources to make the tear down |
michael@0 | 105 | * sequence as simple as possible. |
michael@0 | 106 | */ |
michael@0 | 107 | |
michael@0 | 108 | /** |
michael@0 | 109 | * TextureSourceOGL provides the necessary API for CompositorOGL to composite |
michael@0 | 110 | * a TextureSource. |
michael@0 | 111 | */ |
michael@0 | 112 | class TextureSourceOGL |
michael@0 | 113 | { |
michael@0 | 114 | public: |
michael@0 | 115 | TextureSourceOGL() |
michael@0 | 116 | : mHasCachedFilter(false) |
michael@0 | 117 | {} |
michael@0 | 118 | |
michael@0 | 119 | virtual bool IsValid() const = 0; |
michael@0 | 120 | |
michael@0 | 121 | virtual void BindTexture(GLenum aTextureUnit, gfx::Filter aFilter) = 0; |
michael@0 | 122 | |
michael@0 | 123 | virtual gfx::IntSize GetSize() const = 0; |
michael@0 | 124 | |
michael@0 | 125 | virtual GLenum GetTextureTarget() const { return LOCAL_GL_TEXTURE_2D; } |
michael@0 | 126 | |
michael@0 | 127 | virtual gfx::SurfaceFormat GetFormat() const = 0; |
michael@0 | 128 | |
michael@0 | 129 | virtual GLenum GetWrapMode() const = 0; |
michael@0 | 130 | |
michael@0 | 131 | virtual gfx::Matrix4x4 GetTextureTransform() { return gfx::Matrix4x4(); } |
michael@0 | 132 | |
michael@0 | 133 | virtual TextureImageTextureSourceOGL* AsTextureImageTextureSource() { return nullptr; } |
michael@0 | 134 | |
michael@0 | 135 | void SetFilter(gl::GLContext* aGL, gfx::Filter aFilter) |
michael@0 | 136 | { |
michael@0 | 137 | if (mHasCachedFilter && |
michael@0 | 138 | mCachedFilter == aFilter) { |
michael@0 | 139 | return; |
michael@0 | 140 | } |
michael@0 | 141 | mHasCachedFilter = true; |
michael@0 | 142 | mCachedFilter = aFilter; |
michael@0 | 143 | ApplyFilterToBoundTexture(aGL, aFilter, GetTextureTarget()); |
michael@0 | 144 | } |
michael@0 | 145 | |
michael@0 | 146 | void ClearCachedFilter() { mHasCachedFilter = false; } |
michael@0 | 147 | |
michael@0 | 148 | private: |
michael@0 | 149 | gfx::Filter mCachedFilter; |
michael@0 | 150 | bool mHasCachedFilter; |
michael@0 | 151 | }; |
michael@0 | 152 | |
michael@0 | 153 | /** |
michael@0 | 154 | * TextureHostOGL provides the necessary API for platform specific composition. |
michael@0 | 155 | */ |
michael@0 | 156 | class TextureHostOGL |
michael@0 | 157 | { |
michael@0 | 158 | public: |
michael@0 | 159 | #if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17 |
michael@0 | 160 | |
michael@0 | 161 | /** |
michael@0 | 162 | * Store a fence that will signal when the current buffer is no longer being read. |
michael@0 | 163 | * Similar to android's GLConsumer::setReleaseFence() |
michael@0 | 164 | */ |
michael@0 | 165 | virtual bool SetReleaseFence(const android::sp<android::Fence>& aReleaseFence); |
michael@0 | 166 | |
michael@0 | 167 | /** |
michael@0 | 168 | * Return a releaseFence's Fence and clear a reference to the Fence. |
michael@0 | 169 | */ |
michael@0 | 170 | virtual android::sp<android::Fence> GetAndResetReleaseFence(); |
michael@0 | 171 | |
michael@0 | 172 | protected: |
michael@0 | 173 | android::sp<android::Fence> mReleaseFence; |
michael@0 | 174 | |
michael@0 | 175 | /** |
michael@0 | 176 | * Hold previous ReleaseFence to prevent Fence delivery failure via gecko IPC. |
michael@0 | 177 | * Fence is a kernel object and its lifetime is managed by a reference count. |
michael@0 | 178 | * Until the Fence is delivered to client side, need to hold Fence on host side. |
michael@0 | 179 | */ |
michael@0 | 180 | android::sp<android::Fence> mPrevReleaseFence; |
michael@0 | 181 | #endif |
michael@0 | 182 | }; |
michael@0 | 183 | |
michael@0 | 184 | /** |
michael@0 | 185 | * A TextureSource backed by a TextureImage. |
michael@0 | 186 | * |
michael@0 | 187 | * Depending on the underlying TextureImage, may support texture tiling, so |
michael@0 | 188 | * make sure to check AsTileIterator() and use the texture accordingly. |
michael@0 | 189 | * |
michael@0 | 190 | * This TextureSource can be used without a TextureHost and manage it's own |
michael@0 | 191 | * GL texture(s). |
michael@0 | 192 | */ |
michael@0 | 193 | class TextureImageTextureSourceOGL : public DataTextureSource |
michael@0 | 194 | , public TextureSourceOGL |
michael@0 | 195 | , public TileIterator |
michael@0 | 196 | { |
michael@0 | 197 | public: |
michael@0 | 198 | TextureImageTextureSourceOGL(gl::GLContext* aGL, |
michael@0 | 199 | TextureFlags aFlags = TEXTURE_FLAGS_DEFAULT) |
michael@0 | 200 | : mGL(aGL) |
michael@0 | 201 | , mFlags(aFlags) |
michael@0 | 202 | , mIterating(false) |
michael@0 | 203 | {} |
michael@0 | 204 | |
michael@0 | 205 | // DataTextureSource |
michael@0 | 206 | |
michael@0 | 207 | virtual bool Update(gfx::DataSourceSurface* aSurface, |
michael@0 | 208 | nsIntRegion* aDestRegion = nullptr, |
michael@0 | 209 | gfx::IntPoint* aSrcOffset = nullptr) MOZ_OVERRIDE; |
michael@0 | 210 | |
michael@0 | 211 | void EnsureBuffer(const nsIntSize& aSize, |
michael@0 | 212 | gfxContentType aContentType); |
michael@0 | 213 | |
michael@0 | 214 | void CopyTo(const nsIntRect& aSourceRect, |
michael@0 | 215 | DataTextureSource* aDest, |
michael@0 | 216 | const nsIntRect& aDestRect); |
michael@0 | 217 | |
michael@0 | 218 | virtual TextureImageTextureSourceOGL* AsTextureImageTextureSource() { return this; } |
michael@0 | 219 | |
michael@0 | 220 | // TextureSource |
michael@0 | 221 | |
michael@0 | 222 | virtual void DeallocateDeviceData() MOZ_OVERRIDE |
michael@0 | 223 | { |
michael@0 | 224 | mTexImage = nullptr; |
michael@0 | 225 | SetUpdateSerial(0); |
michael@0 | 226 | } |
michael@0 | 227 | |
michael@0 | 228 | virtual TextureSourceOGL* AsSourceOGL() MOZ_OVERRIDE { return this; } |
michael@0 | 229 | |
michael@0 | 230 | virtual void BindTexture(GLenum aTextureUnit, gfx::Filter aFilter) MOZ_OVERRIDE; |
michael@0 | 231 | |
michael@0 | 232 | virtual gfx::IntSize GetSize() const MOZ_OVERRIDE; |
michael@0 | 233 | |
michael@0 | 234 | virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE; |
michael@0 | 235 | |
michael@0 | 236 | virtual bool IsValid() const MOZ_OVERRIDE { return !!mTexImage; } |
michael@0 | 237 | |
michael@0 | 238 | virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE; |
michael@0 | 239 | |
michael@0 | 240 | virtual GLenum GetWrapMode() const MOZ_OVERRIDE |
michael@0 | 241 | { |
michael@0 | 242 | return mTexImage->GetWrapMode(); |
michael@0 | 243 | } |
michael@0 | 244 | |
michael@0 | 245 | // TileIterator |
michael@0 | 246 | |
michael@0 | 247 | virtual TileIterator* AsTileIterator() MOZ_OVERRIDE { return this; } |
michael@0 | 248 | |
michael@0 | 249 | virtual void BeginTileIteration() MOZ_OVERRIDE |
michael@0 | 250 | { |
michael@0 | 251 | mTexImage->BeginTileIteration(); |
michael@0 | 252 | mIterating = true; |
michael@0 | 253 | } |
michael@0 | 254 | |
michael@0 | 255 | virtual void EndTileIteration() MOZ_OVERRIDE |
michael@0 | 256 | { |
michael@0 | 257 | mIterating = false; |
michael@0 | 258 | } |
michael@0 | 259 | |
michael@0 | 260 | virtual nsIntRect GetTileRect() MOZ_OVERRIDE; |
michael@0 | 261 | |
michael@0 | 262 | virtual size_t GetTileCount() MOZ_OVERRIDE |
michael@0 | 263 | { |
michael@0 | 264 | return mTexImage->GetTileCount(); |
michael@0 | 265 | } |
michael@0 | 266 | |
michael@0 | 267 | virtual bool NextTile() MOZ_OVERRIDE |
michael@0 | 268 | { |
michael@0 | 269 | return mTexImage->NextTile(); |
michael@0 | 270 | } |
michael@0 | 271 | |
michael@0 | 272 | protected: |
michael@0 | 273 | nsRefPtr<gl::TextureImage> mTexImage; |
michael@0 | 274 | gl::GLContext* mGL; |
michael@0 | 275 | TextureFlags mFlags; |
michael@0 | 276 | bool mIterating; |
michael@0 | 277 | }; |
michael@0 | 278 | |
michael@0 | 279 | /** |
michael@0 | 280 | * A texture source meant for use with SharedTextureHostOGL. |
michael@0 | 281 | * |
michael@0 | 282 | * It does not own any GL texture, and attaches its shared handle to one of |
michael@0 | 283 | * the compositor's temporary textures when binding. |
michael@0 | 284 | * |
michael@0 | 285 | * The shared texture handle is owned by the TextureHost. |
michael@0 | 286 | */ |
michael@0 | 287 | class SharedTextureSourceOGL : public NewTextureSource |
michael@0 | 288 | , public TextureSourceOGL |
michael@0 | 289 | { |
michael@0 | 290 | public: |
michael@0 | 291 | typedef gl::SharedTextureShareType SharedTextureShareType; |
michael@0 | 292 | |
michael@0 | 293 | SharedTextureSourceOGL(CompositorOGL* aCompositor, |
michael@0 | 294 | gl::SharedTextureHandle aHandle, |
michael@0 | 295 | gfx::SurfaceFormat aFormat, |
michael@0 | 296 | GLenum aTarget, |
michael@0 | 297 | GLenum aWrapMode, |
michael@0 | 298 | SharedTextureShareType aShareType, |
michael@0 | 299 | gfx::IntSize aSize); |
michael@0 | 300 | |
michael@0 | 301 | virtual TextureSourceOGL* AsSourceOGL() { return this; } |
michael@0 | 302 | |
michael@0 | 303 | virtual void BindTexture(GLenum activetex, gfx::Filter aFilter) MOZ_OVERRIDE; |
michael@0 | 304 | |
michael@0 | 305 | virtual bool IsValid() const MOZ_OVERRIDE; |
michael@0 | 306 | |
michael@0 | 307 | virtual gfx::IntSize GetSize() const MOZ_OVERRIDE { return mSize; } |
michael@0 | 308 | |
michael@0 | 309 | virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE { return mFormat; } |
michael@0 | 310 | |
michael@0 | 311 | virtual gfx::Matrix4x4 GetTextureTransform() MOZ_OVERRIDE; |
michael@0 | 312 | |
michael@0 | 313 | virtual GLenum GetTextureTarget() const { return mTextureTarget; } |
michael@0 | 314 | |
michael@0 | 315 | virtual GLenum GetWrapMode() const MOZ_OVERRIDE { return mWrapMode; } |
michael@0 | 316 | |
michael@0 | 317 | // SharedTextureSource doesn't own any gl texture |
michael@0 | 318 | virtual void DeallocateDeviceData() {} |
michael@0 | 319 | |
michael@0 | 320 | void DetachSharedHandle(); |
michael@0 | 321 | |
michael@0 | 322 | virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE; |
michael@0 | 323 | |
michael@0 | 324 | gl::GLContext* gl() const; |
michael@0 | 325 | |
michael@0 | 326 | protected: |
michael@0 | 327 | gfx::IntSize mSize; |
michael@0 | 328 | CompositorOGL* mCompositor; |
michael@0 | 329 | gl::SharedTextureHandle mSharedHandle; |
michael@0 | 330 | gfx::SurfaceFormat mFormat; |
michael@0 | 331 | SharedTextureShareType mShareType; |
michael@0 | 332 | GLenum mTextureTarget; |
michael@0 | 333 | GLenum mWrapMode; |
michael@0 | 334 | }; |
michael@0 | 335 | |
michael@0 | 336 | /** |
michael@0 | 337 | * A TextureHost for shared GL Textures |
michael@0 | 338 | * |
michael@0 | 339 | * Most of the logic actually happens in SharedTextureSourceOGL. |
michael@0 | 340 | */ |
michael@0 | 341 | class SharedTextureHostOGL : public TextureHost |
michael@0 | 342 | { |
michael@0 | 343 | public: |
michael@0 | 344 | SharedTextureHostOGL(TextureFlags aFlags, |
michael@0 | 345 | gl::SharedTextureShareType aShareType, |
michael@0 | 346 | gl::SharedTextureHandle aSharedhandle, |
michael@0 | 347 | gfx::IntSize aSize, |
michael@0 | 348 | bool inverted); |
michael@0 | 349 | |
michael@0 | 350 | virtual ~SharedTextureHostOGL(); |
michael@0 | 351 | |
michael@0 | 352 | // SharedTextureHostOGL doesn't own any GL texture |
michael@0 | 353 | virtual void DeallocateDeviceData() MOZ_OVERRIDE {} |
michael@0 | 354 | |
michael@0 | 355 | virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE; |
michael@0 | 356 | |
michael@0 | 357 | virtual bool Lock() MOZ_OVERRIDE; |
michael@0 | 358 | |
michael@0 | 359 | virtual void Unlock() MOZ_OVERRIDE; |
michael@0 | 360 | |
michael@0 | 361 | virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE; |
michael@0 | 362 | |
michael@0 | 363 | virtual NewTextureSource* GetTextureSources() MOZ_OVERRIDE |
michael@0 | 364 | { |
michael@0 | 365 | return mTextureSource; |
michael@0 | 366 | } |
michael@0 | 367 | |
michael@0 | 368 | virtual TemporaryRef<gfx::DataSourceSurface> GetAsSurface() MOZ_OVERRIDE |
michael@0 | 369 | { |
michael@0 | 370 | return nullptr; // XXX - implement this (for MOZ_DUMP_PAINTING) |
michael@0 | 371 | } |
michael@0 | 372 | |
michael@0 | 373 | gl::GLContext* gl() const; |
michael@0 | 374 | |
michael@0 | 375 | virtual gfx::IntSize GetSize() const MOZ_OVERRIDE { return mSize; } |
michael@0 | 376 | |
michael@0 | 377 | virtual const char* Name() { return "SharedTextureHostOGL"; } |
michael@0 | 378 | |
michael@0 | 379 | protected: |
michael@0 | 380 | gfx::IntSize mSize; |
michael@0 | 381 | CompositorOGL* mCompositor; |
michael@0 | 382 | gl::SharedTextureHandle mSharedHandle; |
michael@0 | 383 | gl::SharedTextureShareType mShareType; |
michael@0 | 384 | |
michael@0 | 385 | RefPtr<SharedTextureSourceOGL> mTextureSource; |
michael@0 | 386 | }; |
michael@0 | 387 | |
michael@0 | 388 | /** |
michael@0 | 389 | * A texture source meant for use with StreamTextureHostOGL. |
michael@0 | 390 | * |
michael@0 | 391 | * It does not own any texture, we get texture from SurfaceStream. |
michael@0 | 392 | */ |
michael@0 | 393 | class StreamTextureSourceOGL : public NewTextureSource |
michael@0 | 394 | , public TextureSourceOGL |
michael@0 | 395 | { |
michael@0 | 396 | public: |
michael@0 | 397 | StreamTextureSourceOGL(CompositorOGL* aCompositor, |
michael@0 | 398 | gfx::SurfaceStream* aStream) |
michael@0 | 399 | : mCompositor(aCompositor) |
michael@0 | 400 | , mStream(aStream) |
michael@0 | 401 | , mTextureHandle(0) |
michael@0 | 402 | , mTextureTarget(LOCAL_GL_TEXTURE_2D) |
michael@0 | 403 | , mUploadTexture(0) |
michael@0 | 404 | , mFormat(gfx::SurfaceFormat::UNKNOWN) |
michael@0 | 405 | { |
michael@0 | 406 | MOZ_COUNT_CTOR(StreamTextureSourceOGL); |
michael@0 | 407 | } |
michael@0 | 408 | |
michael@0 | 409 | ~StreamTextureSourceOGL() |
michael@0 | 410 | { |
michael@0 | 411 | MOZ_COUNT_DTOR(StreamTextureSourceOGL); |
michael@0 | 412 | } |
michael@0 | 413 | |
michael@0 | 414 | virtual TextureSourceOGL* AsSourceOGL() { return this; } |
michael@0 | 415 | |
michael@0 | 416 | virtual void BindTexture(GLenum activetex, gfx::Filter aFilter) MOZ_OVERRIDE; |
michael@0 | 417 | |
michael@0 | 418 | virtual bool IsValid() const MOZ_OVERRIDE { return !!gl(); } |
michael@0 | 419 | |
michael@0 | 420 | virtual gfx::IntSize GetSize() const MOZ_OVERRIDE { return mSize; } |
michael@0 | 421 | |
michael@0 | 422 | virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE { return mFormat; } |
michael@0 | 423 | |
michael@0 | 424 | virtual GLenum GetTextureTarget() const { return mTextureTarget; } |
michael@0 | 425 | |
michael@0 | 426 | virtual GLenum GetWrapMode() const MOZ_OVERRIDE { return LOCAL_GL_CLAMP_TO_EDGE; } |
michael@0 | 427 | |
michael@0 | 428 | virtual void DeallocateDeviceData(); |
michael@0 | 429 | |
michael@0 | 430 | bool RetrieveTextureFromStream(); |
michael@0 | 431 | |
michael@0 | 432 | virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE; |
michael@0 | 433 | |
michael@0 | 434 | protected: |
michael@0 | 435 | gl::GLContext* gl() const; |
michael@0 | 436 | |
michael@0 | 437 | CompositorOGL* mCompositor; |
michael@0 | 438 | gfx::SurfaceStream* mStream; |
michael@0 | 439 | GLuint mTextureHandle; |
michael@0 | 440 | GLenum mTextureTarget; |
michael@0 | 441 | GLuint mUploadTexture; |
michael@0 | 442 | gfx::IntSize mSize; |
michael@0 | 443 | gfx::SurfaceFormat mFormat; |
michael@0 | 444 | }; |
michael@0 | 445 | |
michael@0 | 446 | /** |
michael@0 | 447 | * A TextureHost for shared SurfaceStream |
michael@0 | 448 | */ |
michael@0 | 449 | class StreamTextureHostOGL : public TextureHost |
michael@0 | 450 | { |
michael@0 | 451 | public: |
michael@0 | 452 | StreamTextureHostOGL(TextureFlags aFlags, |
michael@0 | 453 | const SurfaceStreamDescriptor& aDesc); |
michael@0 | 454 | |
michael@0 | 455 | virtual ~StreamTextureHostOGL(); |
michael@0 | 456 | |
michael@0 | 457 | // SharedTextureHostOGL doesn't own any GL texture |
michael@0 | 458 | virtual void DeallocateDeviceData() MOZ_OVERRIDE {} |
michael@0 | 459 | |
michael@0 | 460 | virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE; |
michael@0 | 461 | |
michael@0 | 462 | virtual bool Lock() MOZ_OVERRIDE; |
michael@0 | 463 | |
michael@0 | 464 | virtual void Unlock() MOZ_OVERRIDE; |
michael@0 | 465 | |
michael@0 | 466 | virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE; |
michael@0 | 467 | |
michael@0 | 468 | virtual NewTextureSource* GetTextureSources() MOZ_OVERRIDE |
michael@0 | 469 | { |
michael@0 | 470 | return mTextureSource; |
michael@0 | 471 | } |
michael@0 | 472 | |
michael@0 | 473 | virtual TemporaryRef<gfx::DataSourceSurface> GetAsSurface() MOZ_OVERRIDE |
michael@0 | 474 | { |
michael@0 | 475 | return nullptr; // XXX - implement this (for MOZ_DUMP_PAINTING) |
michael@0 | 476 | } |
michael@0 | 477 | |
michael@0 | 478 | virtual gfx::IntSize GetSize() const MOZ_OVERRIDE; |
michael@0 | 479 | |
michael@0 | 480 | #ifdef MOZ_LAYERS_HAVE_LOG |
michael@0 | 481 | virtual const char* Name() { return "StreamTextureHostOGL"; } |
michael@0 | 482 | #endif |
michael@0 | 483 | |
michael@0 | 484 | protected: |
michael@0 | 485 | CompositorOGL* mCompositor; |
michael@0 | 486 | gfx::SurfaceStream* mStream; |
michael@0 | 487 | RefPtr<StreamTextureSourceOGL> mTextureSource; |
michael@0 | 488 | }; |
michael@0 | 489 | |
michael@0 | 490 | } // namespace |
michael@0 | 491 | } // namespace |
michael@0 | 492 | |
michael@0 | 493 | #endif /* MOZILLA_GFX_TEXTUREOGL_H */ |