1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef MOZILLA_GFX_TEXTUREOGL_H
7 #define MOZILLA_GFX_TEXTUREOGL_H
9 #include <stddef.h> // for size_t
10 #include <stdint.h> // for uint64_t
11 #include "GLContextTypes.h" // for GLContext
12 #include "GLDefs.h" // for GLenum, LOCAL_GL_CLAMP_TO_EDGE, etc
13 #include "GLTextureImage.h" // for TextureImage
14 #include "gfx3DMatrix.h" // for gfx3DMatrix
15 #include "gfxASurface.h" // for gfxASurface, etc
16 #include "mozilla/GfxMessageUtils.h" // for gfxContentType
17 #include "mozilla/Assertions.h" // for MOZ_ASSERT, etc
18 #include "mozilla/Attributes.h" // for MOZ_OVERRIDE
19 #include "mozilla/RefPtr.h" // for RefPtr
20 #include "mozilla/gfx/Point.h" // for IntSize, IntPoint
21 #include "mozilla/gfx/Types.h" // for SurfaceFormat, etc
22 #include "mozilla/layers/CompositorTypes.h" // for TextureFlags
23 #include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor
24 #include "mozilla/layers/LayersTypes.h" // for MOZ_LAYERS_HAVE_LOG
25 #include "mozilla/layers/TextureHost.h" // for DeprecatedTextureHost, etc
26 #include "mozilla/mozalloc.h" // for operator delete, etc
27 #include "nsAutoPtr.h" // for nsRefPtr
28 #include "nsCOMPtr.h" // for already_AddRefed
29 #include "nsDebug.h" // for NS_WARNING
30 #include "nsISupportsImpl.h" // for TextureImage::Release, etc
31 #include "nsTraceRefcnt.h" // for MOZ_COUNT_CTOR, etc
32 #include "LayerManagerOGLProgram.h" // for ShaderProgramType, etc
33 #ifdef MOZ_WIDGET_GONK
34 #include <ui/GraphicBuffer.h>
37 class gfxImageSurface
;
38 class gfxReusableSurfaceWrapper
;
46 class DataSourceSurface
;
54 class TextureImageDeprecatedTextureHostOGL
;
57 * TextureHost implementations for the OpenGL backend.
59 * Note that it is important to be careful about the ownership model with
60 * the OpenGL backend, due to some widget limitation on Linux: before
61 * the nsBaseWidget associated with our OpenGL context has been completely
62 * deleted, every resource belonging to the OpenGL context MUST have been
63 * released. At the moment the teardown sequence happens in the middle of
64 * the nsBaseWidget's destructor, meaning that at a given moment we must be
65 * able to easily find and release all the GL resources.
66 * The point is: be careful about the ownership model and limit the number
67 * of objects sharing references to GL resources to make the tear down
68 * sequence as simple as possible.
71 inline ShaderProgramType
72 GetProgramTypeForSurfaceFormat(gfx::SurfaceFormat aFormat
)
75 case gfx::FORMAT_B8G8R8A8
:
76 return BGRALayerProgramType
;;
77 case gfx::FORMAT_B8G8R8X8
:
78 return BGRXLayerProgramType
;;
79 case gfx::FORMAT_R8G8B8X8
:
80 return RGBXLayerProgramType
;;
81 case gfx::FORMAT_R8G8B8A8
:
82 return RGBALayerProgramType
;;
84 MOZ_CRASH("unhandled program type");
88 inline ShaderProgramType
89 GetProgramTypeForTexture(const DeprecatedTextureHost
*aDeprecatedTextureHost
)
91 return GetProgramTypeForSurfaceFormat(aDeprecatedTextureHost
->GetFormat());
95 * TextureSourceOGL provides the necessary API for CompositorOGL to composite
98 class TextureSourceOGL
101 virtual bool IsValid() const = 0;
103 virtual void BindTexture(GLenum aTextureUnit
) = 0;
105 virtual void UnbindTexture() = 0;
107 virtual gfx::IntSize
GetSize() const = 0;
109 virtual GLenum
GetTextureTarget() const { return LOCAL_GL_TEXTURE_2D
; }
111 virtual gfx::SurfaceFormat
GetFormat() const = 0;
113 virtual GLenum
GetWrapMode() const = 0;
115 virtual gfx3DMatrix
GetTextureTransform() { return gfx3DMatrix(); }
117 virtual TextureImageDeprecatedTextureHostOGL
* AsTextureImageDeprecatedTextureHost() { return nullptr; }
121 * A TextureSource backed by a TextureImage.
123 * Depending on the underlying TextureImage, may support texture tiling, so
124 * make sure to check AsTileIterator() and use the texture accordingly.
126 * This TextureSource can be used without a TextureHost and manage it's own
129 class TextureImageTextureSourceOGL
: public DataTextureSource
130 , public TextureSourceOGL
131 , public TileIterator
134 TextureImageTextureSourceOGL(gl::GLContext
* aGL
, bool aAllowBiImage
= true)
136 , mAllowBigImage(aAllowBiImage
)
142 virtual bool Update(gfx::DataSourceSurface
* aSurface
,
144 nsIntRegion
* aDestRegion
= nullptr,
145 gfx::IntPoint
* aSrcOffset
= nullptr) MOZ_OVERRIDE
;
149 virtual void DeallocateDeviceData() MOZ_OVERRIDE
155 virtual TextureSourceOGL
* AsSourceOGL() MOZ_OVERRIDE
{ return this; }
157 virtual void BindTexture(GLenum aTextureUnit
) MOZ_OVERRIDE
;
159 virtual gfx::IntSize
GetSize() const MOZ_OVERRIDE
;
161 virtual gfx::SurfaceFormat
GetFormat() const MOZ_OVERRIDE
;
163 virtual bool IsValid() const MOZ_OVERRIDE
{ return !!mTexImage
; }
165 virtual void UnbindTexture() MOZ_OVERRIDE
167 mTexImage
->ReleaseTexture();
170 virtual GLenum
GetWrapMode() const MOZ_OVERRIDE
172 return mTexImage
->GetWrapMode();
177 virtual TileIterator
* AsTileIterator() MOZ_OVERRIDE
{ return this; }
179 virtual void BeginTileIteration() MOZ_OVERRIDE
181 mTexImage
->BeginTileIteration();
185 virtual void EndTileIteration() MOZ_OVERRIDE
190 virtual nsIntRect
GetTileRect() MOZ_OVERRIDE
;
192 virtual size_t GetTileCount() MOZ_OVERRIDE
194 return mTexImage
->GetTileCount();
197 virtual bool NextTile() MOZ_OVERRIDE
199 return mTexImage
->NextTile();
203 nsRefPtr
<gl::TextureImage
> mTexImage
;
210 * A texture source meant for use with SharedTextureHostOGL.
212 * It does not own any GL texture, and attaches its shared handle to one of
213 * the compositor's temporary textures when binding.
215 * The shared texture handle is owned by the TextureHost.
217 class SharedTextureSourceOGL
: public NewTextureSource
218 , public TextureSourceOGL
221 typedef gl::SharedTextureShareType SharedTextureShareType
;
223 SharedTextureSourceOGL(CompositorOGL
* aCompositor
,
224 gl::SharedTextureHandle aHandle
,
225 gfx::SurfaceFormat aFormat
,
228 SharedTextureShareType aShareType
,
230 const gfx3DMatrix
& aTexTransform
);
232 virtual TextureSourceOGL
* AsSourceOGL() { return this; }
234 virtual void BindTexture(GLenum activetex
) MOZ_OVERRIDE
;
236 virtual bool IsValid() const MOZ_OVERRIDE
;
238 virtual gfx::IntSize
GetSize() const MOZ_OVERRIDE
{ return mSize
; }
240 virtual gfx::SurfaceFormat
GetFormat() const MOZ_OVERRIDE
{ return mFormat
; }
242 virtual gfx3DMatrix
GetTextureTransform() MOZ_OVERRIDE
{ return mTextureTransform
; }
244 virtual GLenum
GetTextureTarget() const { return mTextureTarget
; }
246 virtual GLenum
GetWrapMode() const MOZ_OVERRIDE
{ return mWrapMode
; }
248 virtual void UnbindTexture() MOZ_OVERRIDE
{}
250 // SharedTextureSource doesn't own any gl texture
251 virtual void DeallocateDeviceData() {}
253 void DetachSharedHandle();
255 void SetCompositor(CompositorOGL
* aCompositor
);
257 gl::GLContext
* gl() const;
260 gfx3DMatrix mTextureTransform
;
262 CompositorOGL
* mCompositor
;
263 gl::SharedTextureHandle mSharedHandle
;
264 gfx::SurfaceFormat mFormat
;
265 SharedTextureShareType mShareType
;
266 GLenum mTextureTarget
;
271 * A TextureHost for shared GL Textures
273 * Most of the logic actually happens in SharedTextureSourceOGL.
275 class SharedTextureHostOGL
: public TextureHost
278 SharedTextureHostOGL(uint64_t aID
,
280 gl::SharedTextureShareType aShareType
,
281 gl::SharedTextureHandle aSharedhandle
,
285 virtual ~SharedTextureHostOGL();
287 // SharedTextureHostOGL doesn't own any GL texture
288 virtual void DeallocateDeviceData() MOZ_OVERRIDE
{}
290 virtual void SetCompositor(Compositor
* aCompositor
) MOZ_OVERRIDE
;
292 virtual bool Lock() MOZ_OVERRIDE
;
294 virtual void Unlock() MOZ_OVERRIDE
;
296 virtual gfx::SurfaceFormat
GetFormat() const MOZ_OVERRIDE
;
298 virtual NewTextureSource
* GetTextureSources() MOZ_OVERRIDE
300 return mTextureSource
;
303 virtual already_AddRefed
<gfxImageSurface
> GetAsSurface() MOZ_OVERRIDE
305 return nullptr; // XXX - implement this (for MOZ_DUMP_PAINTING)
308 gl::GLContext
* gl() const;
310 virtual gfx::IntSize
GetSize() const MOZ_OVERRIDE
{ return mSize
; }
312 #ifdef MOZ_LAYERS_HAVE_LOG
313 virtual const char* Name() { return "SharedTextureHostOGL"; }
318 CompositorOGL
* mCompositor
;
319 gl::SharedTextureHandle mSharedHandle
;
320 gl::SharedTextureShareType mShareType
;
322 RefPtr
<SharedTextureSourceOGL
> mTextureSource
;
326 * DeprecatedTextureHost implementation using a TextureImage as the underlying texture.
328 class TextureImageDeprecatedTextureHostOGL
: public DeprecatedTextureHost
329 , public TextureSourceOGL
330 , public TileIterator
333 TextureImageDeprecatedTextureHostOGL(gl::TextureImage
* aTexImage
= nullptr)
334 : mTexture(aTexImage
)
338 MOZ_COUNT_CTOR(TextureImageDeprecatedTextureHostOGL
);
341 ~TextureImageDeprecatedTextureHostOGL();
343 TextureSourceOGL
* AsSourceOGL() MOZ_OVERRIDE
348 virtual TextureImageDeprecatedTextureHostOGL
* AsTextureImageDeprecatedTextureHost() MOZ_OVERRIDE
353 // This is a hack that is here to not break on-main-thread ThebesLayerBuffer
354 // please do not use it anywhere else, use SetCompositor instead.
355 void SetGLContext(gl::GLContext
* aGL
)
360 // DeprecatedTextureHost
362 void UpdateImpl(const SurfaceDescriptor
& aImage
,
363 nsIntRegion
* aRegion
= nullptr,
364 nsIntPoint
* aOffset
= nullptr) MOZ_OVERRIDE
;
366 virtual void SetCompositor(Compositor
* aCompositor
) MOZ_OVERRIDE
;
368 virtual void EnsureBuffer(const nsIntSize
& aSize
, gfxContentType aType
) MOZ_OVERRIDE
;
370 virtual void CopyTo(const nsIntRect
& aSourceRect
,
371 DeprecatedTextureHost
*aDest
,
372 const nsIntRect
& aDestRect
) MOZ_OVERRIDE
;
374 bool IsValid() const MOZ_OVERRIDE
379 virtual bool Lock() MOZ_OVERRIDE
;
381 virtual already_AddRefed
<gfxImageSurface
> GetAsSurface() MOZ_OVERRIDE
;
384 void BindTexture(GLenum aTextureUnit
) MOZ_OVERRIDE
386 mTexture
->BindTexture(aTextureUnit
);
389 void UnbindTexture() MOZ_OVERRIDE
391 mTexture
->ReleaseTexture();
394 gfx::IntSize
GetSize() const MOZ_OVERRIDE
;
396 GLenum
GetWrapMode() const MOZ_OVERRIDE
398 return mTexture
->GetWrapMode();
401 gl::TextureImage
* GetTextureImage()
406 void SetTextureImage(gl::TextureImage
* aImage
)
413 TileIterator
* AsTileIterator() MOZ_OVERRIDE
418 void BeginTileIteration() MOZ_OVERRIDE
420 mTexture
->BeginTileIteration();
424 void EndTileIteration() MOZ_OVERRIDE
429 nsIntRect
GetTileRect() MOZ_OVERRIDE
;
431 size_t GetTileCount() MOZ_OVERRIDE
433 return mTexture
->GetTileCount();
436 bool NextTile() MOZ_OVERRIDE
438 return mTexture
->NextTile();
441 virtual gfx::SurfaceFormat
GetFormat() const MOZ_OVERRIDE
443 return DeprecatedTextureHost::GetFormat();
446 #ifdef MOZ_LAYERS_HAVE_LOG
447 virtual const char* Name() { return "TextureImageDeprecatedTextureHostOGL"; }
451 nsRefPtr
<gl::TextureImage
> mTexture
;
457 * DeprecatedTextureHost implementation for YCbCr images in the OpenGL backend.
459 * This DeprecatedTextureHost is a little bit particular in that it implements
460 * the TextureSource interface, as it is required that a DeprecatedTextureHost
461 * provides access to a TextureSource, but does not implement the
462 * DeprecatedTextureHostOGL interface. Instead it contains 3 channels (one per
463 * plane) that implement the TextureSourceOGL interface, and
464 * YCbCrDeprecatedTextureHostOGL's TextureSource implementation provide access
465 * to these channels with the GetSubSource method.
467 class YCbCrDeprecatedTextureHostOGL
: public DeprecatedTextureHost
470 YCbCrDeprecatedTextureHostOGL()
473 MOZ_COUNT_CTOR(YCbCrDeprecatedTextureHostOGL
);
474 mYTexture
= new Channel
;
475 mCbTexture
= new Channel
;
476 mCrTexture
= new Channel
;
477 mFormat
= gfx::FORMAT_YUV
;
480 ~YCbCrDeprecatedTextureHostOGL()
482 MOZ_COUNT_DTOR(YCbCrDeprecatedTextureHostOGL
);
485 virtual void SetCompositor(Compositor
* aCompositor
) MOZ_OVERRIDE
;
487 virtual void UpdateImpl(const SurfaceDescriptor
& aImage
,
488 nsIntRegion
* aRegion
= nullptr,
489 nsIntPoint
* aOffset
= nullptr) MOZ_OVERRIDE
;
491 virtual bool Lock() MOZ_OVERRIDE
;
493 virtual bool IsValid() const MOZ_OVERRIDE
495 return mYTexture
->IsValid()
496 && mCbTexture
->IsValid()
497 && mCrTexture
->IsValid();
500 struct Channel
: public TextureSourceOGL
501 , public TextureSource
503 TextureSourceOGL
* AsSourceOGL() MOZ_OVERRIDE
507 nsRefPtr
<gl::TextureImage
> mTexImage
;
509 void BindTexture(GLenum aUnit
) MOZ_OVERRIDE
511 mTexImage
->BindTexture(aUnit
);
513 void UnbindTexture() MOZ_OVERRIDE
515 mTexImage
->ReleaseTexture();
517 virtual bool IsValid() const MOZ_OVERRIDE
521 virtual gfx::IntSize
GetSize() const MOZ_OVERRIDE
523 return gfx::IntSize(mTexImage
->GetSize().width
, mTexImage
->GetSize().height
);
525 virtual GLenum
GetWrapMode() const MOZ_OVERRIDE
527 return mTexImage
->GetWrapMode();
529 virtual gfx::SurfaceFormat
GetFormat() const MOZ_OVERRIDE
531 return gfx::FORMAT_A8
;
535 // TextureSource implementation
537 TextureSource
* GetSubSource(int index
) MOZ_OVERRIDE
540 case 0 : return mYTexture
.get();
541 case 1 : return mCbTexture
.get();
542 case 2 : return mCrTexture
.get();
547 gfx::IntSize
GetSize() const MOZ_OVERRIDE
549 if (!mYTexture
->mTexImage
) {
550 NS_WARNING("YCbCrDeprecatedTextureHost::GetSize called but no data has been set yet");
551 return gfx::IntSize(0,0);
553 return mYTexture
->GetSize();
556 virtual already_AddRefed
<gfxImageSurface
> GetAsSurface() MOZ_OVERRIDE
;
558 #ifdef MOZ_LAYERS_HAVE_LOG
559 virtual const char* Name() { return "YCbCrDeprecatedTextureHostOGL"; }
563 RefPtr
<Channel
> mYTexture
;
564 RefPtr
<Channel
> mCbTexture
;
565 RefPtr
<Channel
> mCrTexture
;
570 class SharedDeprecatedTextureHostOGL
: public DeprecatedTextureHost
571 , public TextureSourceOGL
574 typedef gfxASurface::gfxContentType ContentType
;
575 typedef mozilla::gl::GLContext GLContext
;
576 typedef mozilla::gl::TextureImage TextureImage
;
578 SharedDeprecatedTextureHostOGL()
581 , mWrapMode(LOCAL_GL_CLAMP_TO_EDGE
)
583 , mShareType(gl::SameProcess
)
586 virtual void SetCompositor(Compositor
* aCompositor
) MOZ_OVERRIDE
;
588 virtual ~SharedDeprecatedTextureHostOGL()
590 if (mSharedHandle
|| mTextureHandle
) {
595 virtual GLuint
GetTextureHandle()
597 return mTextureHandle
;
600 virtual gfx::SurfaceFormat
GetFormat() const MOZ_OVERRIDE
602 return DeprecatedTextureHost::GetFormat();
605 virtual TextureSourceOGL
* AsSourceOGL() MOZ_OVERRIDE
{ return this; }
607 bool IsValid() const MOZ_OVERRIDE
{ return !!mSharedHandle
; }
609 // override from DeprecatedTextureHost, we support both buffered
610 // and unbuffered operation.
611 virtual void UpdateImpl(const SurfaceDescriptor
& aImage
,
612 nsIntRegion
* aRegion
= nullptr,
613 nsIntPoint
* aOffset
= nullptr) MOZ_OVERRIDE
;
614 virtual void SwapTexturesImpl(const SurfaceDescriptor
& aImage
,
615 nsIntRegion
* aRegion
= nullptr) MOZ_OVERRIDE
;
616 virtual bool Lock() MOZ_OVERRIDE
;
617 virtual void Unlock() MOZ_OVERRIDE
;
619 virtual GLenum
GetWrapMode() const MOZ_OVERRIDE
{ return mWrapMode
; }
620 virtual void SetWrapMode(GLenum aMode
) { mWrapMode
= aMode
; }
622 virtual GLenum
GetTextureTarget() const MOZ_OVERRIDE
624 return mTextureTarget
;
627 gfx::IntSize
GetSize() const MOZ_OVERRIDE
{
631 void BindTexture(GLenum activetex
) MOZ_OVERRIDE
634 // Lock already bound us!
635 MOZ_ASSERT(activetex
== LOCAL_GL_TEXTURE0
);
637 void UnbindTexture() MOZ_OVERRIDE
{}
638 GLuint
GetTextureID() { return mTextureHandle
; }
639 ContentType
GetContentType()
641 return (mFormat
== gfx::FORMAT_B8G8R8A8
) ?
642 gfxASurface::CONTENT_COLOR_ALPHA
:
643 gfxASurface::CONTENT_COLOR
;
646 virtual gfx3DMatrix
GetTextureTransform() MOZ_OVERRIDE
;
648 virtual already_AddRefed
<gfxImageSurface
> GetAsSurface() MOZ_OVERRIDE
;
650 #ifdef MOZ_LAYERS_HAVE_LOG
651 virtual const char* Name() { return "SharedDeprecatedTextureHostOGL"; }
655 void DeleteTextures();
658 nsRefPtr
<gl::GLContext
> mGL
;
659 GLuint mTextureHandle
;
661 GLenum mTextureTarget
;
662 gl::SharedTextureHandle mSharedHandle
;
663 gl::SharedTextureShareType mShareType
;
666 class SurfaceStreamHostOGL
: public DeprecatedTextureHost
667 , public TextureSourceOGL
670 typedef gfxASurface::gfxContentType ContentType
;
671 typedef mozilla::gl::GLContext GLContext
;
672 typedef mozilla::gl::TextureImage TextureImage
;
674 virtual ~SurfaceStreamHostOGL()
679 virtual void SetCompositor(Compositor
* aCompositor
) MOZ_OVERRIDE
;
681 virtual GLuint
GetTextureHandle()
683 return mTextureHandle
;
686 virtual gfx::SurfaceFormat
GetFormat() const MOZ_OVERRIDE
688 return DeprecatedTextureHost::GetFormat();
691 virtual TextureSourceOGL
* AsSourceOGL() MOZ_OVERRIDE
{ return this; }
693 bool IsValid() const MOZ_OVERRIDE
{ return true; }
695 // override from DeprecatedTextureHost
696 virtual void UpdateImpl(const SurfaceDescriptor
& aImage
,
697 nsIntRegion
* aRegion
,
698 nsIntPoint
* aOffset
);
699 virtual bool Lock() MOZ_OVERRIDE
;
700 virtual void Unlock() MOZ_OVERRIDE
;
702 virtual GLenum
GetWrapMode() const MOZ_OVERRIDE
{
705 virtual void SetWrapMode(GLenum aMode
) {
709 gfx::IntSize
GetSize() const MOZ_OVERRIDE
{
713 virtual GLenum
GetTextureTarget() const MOZ_OVERRIDE
715 return mTextureTarget
;
718 void BindTexture(GLenum activetex
) MOZ_OVERRIDE
;
720 void UnbindTexture() MOZ_OVERRIDE
{}
722 GLuint
GetTextureID() { return mTextureHandle
; }
723 ContentType
GetContentType() {
724 return (mFormat
== gfx::FORMAT_B8G8R8A8
) ?
725 gfxASurface::CONTENT_COLOR_ALPHA
:
726 gfxASurface::CONTENT_COLOR
;
729 virtual already_AddRefed
<gfxImageSurface
> GetAsSurface() MOZ_OVERRIDE
;
731 #ifdef MOZ_LAYERS_HAVE_LOG
732 virtual const char* Name() { return "SurfaceStreamHostOGL"; }
735 SurfaceStreamHostOGL()
738 , mTextureTarget(LOCAL_GL_TEXTURE_2D
)
740 , mWrapMode(LOCAL_GL_CLAMP_TO_EDGE
)
745 void DeleteTextures();
748 nsRefPtr
<GLContext
> mGL
;
749 GLuint mTextureHandle
;
750 GLenum mTextureTarget
;
751 GLuint mUploadTexture
;
753 nsRefPtr
<GLContext
> mStreamGL
;
754 gfx::SurfaceStream
*mStream
;
757 class TiledDeprecatedTextureHostOGL
: public DeprecatedTextureHost
758 , public TextureSourceOGL
761 TiledDeprecatedTextureHostOGL()
765 ~TiledDeprecatedTextureHostOGL();
767 virtual void SetCompositor(Compositor
* aCompositor
);
769 // have to pass the size in here (every time) because of DrawQuad API :-(
770 virtual void Update(gfxReusableSurfaceWrapper
* aReusableSurface
, TextureFlags aFlags
, const gfx::IntSize
& aSize
) MOZ_OVERRIDE
;
771 virtual bool Lock() MOZ_OVERRIDE
;
772 virtual void Unlock() MOZ_OVERRIDE
{}
774 virtual gfx::SurfaceFormat
GetFormat() const MOZ_OVERRIDE
776 return DeprecatedTextureHost::GetFormat();
779 virtual TextureSourceOGL
* AsSourceOGL() MOZ_OVERRIDE
{ return this; }
780 virtual bool IsValid() const MOZ_OVERRIDE
{ return true; }
781 virtual GLenum
GetWrapMode() const MOZ_OVERRIDE
{ return LOCAL_GL_CLAMP_TO_EDGE
; }
782 virtual void BindTexture(GLenum aTextureUnit
);
783 virtual void UnbindTexture() MOZ_OVERRIDE
{}
784 virtual gfx::IntSize
GetSize() const MOZ_OVERRIDE
789 virtual void SwapTexturesImpl(const SurfaceDescriptor
& aImage
,
790 nsIntRegion
* aRegion
= nullptr)
791 { MOZ_ASSERT(false, "Tiles should not use this path"); }
793 virtual already_AddRefed
<gfxImageSurface
> GetAsSurface() MOZ_OVERRIDE
;
795 #ifdef MOZ_LAYERS_HAVE_LOG
796 virtual const char* Name() { return "TiledDeprecatedTextureHostOGL"; }
800 void DeleteTextures();
802 virtual uint64_t GetIdentifier() const MOZ_OVERRIDE
{
803 return static_cast<uint64_t>(mTextureHandle
);
809 // Deduce the type that was assigned in GetFormatAndTileForImageFormat
810 return mGLFormat
== LOCAL_GL_RGB
? LOCAL_GL_UNSIGNED_SHORT_5_6_5
: LOCAL_GL_UNSIGNED_BYTE
;
814 GLuint mTextureHandle
;
816 nsRefPtr
<gl::GLContext
> mGL
;
819 #ifdef MOZ_WIDGET_GONK
821 // For direct texturing with gralloc buffers. The corresponding DeprecatedTextureClient is DeprecatedTextureClientShmem,
822 // which automatically gets gralloc when it can, in which case the compositor sees that the
823 // SurfaceDescriptor is gralloc, and decides to use a GrallocDeprecatedTextureHostOGL to do direct texturing,
824 // saving the cost of a texture upload.
825 class GrallocDeprecatedTextureHostOGL
826 : public DeprecatedTextureHost
827 , public TextureSourceOGL
830 GrallocDeprecatedTextureHostOGL();
832 ~GrallocDeprecatedTextureHostOGL();
834 virtual void SetCompositor(Compositor
* aCompositor
) MOZ_OVERRIDE
;
836 virtual void UpdateImpl(const SurfaceDescriptor
& aImage
,
837 nsIntRegion
* aRegion
= nullptr,
838 nsIntPoint
* aOffset
= nullptr) MOZ_OVERRIDE
;
839 virtual void SwapTexturesImpl(const SurfaceDescriptor
& aImage
,
840 nsIntRegion
* aRegion
= nullptr) MOZ_OVERRIDE
;
841 virtual bool Lock() MOZ_OVERRIDE
;
842 virtual void Unlock() MOZ_OVERRIDE
;
844 virtual gfx::IntSize
GetSize() const MOZ_OVERRIDE
846 return mGraphicBuffer
.get() ? gfx::IntSize(mGraphicBuffer
->getWidth(), mGraphicBuffer
->getHeight()) : gfx::IntSize(0, 0);
849 virtual gfx::SurfaceFormat
GetFormat() const MOZ_OVERRIDE
;
851 GLenum
GetWrapMode() const MOZ_OVERRIDE
853 return LOCAL_GL_CLAMP_TO_EDGE
;
856 virtual GLenum
GetTextureTarget() const MOZ_OVERRIDE
858 return mTextureTarget
;
861 bool IsValid() const MOZ_OVERRIDE
;
863 virtual already_AddRefed
<gfxImageSurface
> GetAsSurface() MOZ_OVERRIDE
;
865 #ifdef MOZ_LAYERS_HAVE_LOG
866 virtual const char* Name() { return "GrallocDeprecatedTextureHostOGL"; }
869 void BindTexture(GLenum aTextureUnit
) MOZ_OVERRIDE
;
870 void UnbindTexture() MOZ_OVERRIDE
{}
872 virtual TextureSourceOGL
* AsSourceOGL() MOZ_OVERRIDE
877 // only overridden for hacky fix in gecko 23 for bug 862324
878 // see bug 865908 about fixing this.
879 virtual void SetBuffer(SurfaceDescriptor
* aBuffer
, ISurfaceAllocator
* aAllocator
) MOZ_OVERRIDE
;
881 // used only for hacky fix in gecko 23 for bug 862324
882 virtual void ForgetBuffer()
885 // Intentionally don't destroy the actor held by mBuffer here.
886 // The point is that this is only called from GrallocBufferActor::ActorDestroy
887 // where we know that the actor is already being deleted.
888 // See bug 862324 comment 39.
893 mGraphicBuffer
= nullptr;
897 virtual LayerRenderState
GetRenderState() MOZ_OVERRIDE
;
900 gl::GLContext
* gl() const;
902 void DeleteTextures();
904 RefPtr
<CompositorOGL
> mCompositor
;
905 android::sp
<android::GraphicBuffer
> mGraphicBuffer
;
906 GLenum mTextureTarget
;
908 //Set when the composer needs to swap RB pixels of gralloc buffer
916 #endif /* MOZILLA_GFX_TEXTUREOGL_H */