71ca038077dc0f484209a2344ac3e32c8dabf6b9
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_GRALLOCTEXTURECLIENT_H
7 #define MOZILLA_GFX_GRALLOCTEXTURECLIENT_H
10 #include "mozilla/layers/TextureClient.h"
11 #include "ISurfaceAllocator.h" // For IsSurfaceDescriptorValid
12 #include "mozilla/layers/ShadowLayerUtilsGralloc.h"
13 #include <ui/GraphicBuffer.h>
19 * A TextureClient implementation based on android::GraphicBuffer (also referred to
22 * Gralloc lets us map texture data in memory (accessible through pointers)
23 * and also use it directly as an OpenGL texture without the cost of texture
25 * Gralloc buffers can also be shared accros processes.
27 * More info about Gralloc here: https://wiki.mozilla.org/Platform/GFX/Gralloc
29 * This is only used in Firefox OS
31 class GrallocTextureClientOGL
: public BufferTextureClient
34 GrallocTextureClientOGL(GrallocBufferActor
* aActor
,
36 TextureFlags aFlags
= TEXTURE_FLAGS_DEFAULT
);
37 GrallocTextureClientOGL(CompositableClient
* aCompositable
,
38 gfx::SurfaceFormat aFormat
,
39 TextureFlags aFlags
= TEXTURE_FLAGS_DEFAULT
);
41 ~GrallocTextureClientOGL();
43 virtual bool Lock(OpenMode aMode
) MOZ_OVERRIDE
;
45 virtual void Unlock() MOZ_OVERRIDE
;
47 virtual bool ImplementsLocking() const MOZ_OVERRIDE
{ return true; }
49 virtual bool IsAllocated() const MOZ_OVERRIDE
;
51 virtual bool ToSurfaceDescriptor(SurfaceDescriptor
& aOutDescriptor
) MOZ_OVERRIDE
;
53 void InitWith(GrallocBufferActor
* aActor
, gfx::IntSize aSize
);
55 gfx::IntSize
GetSize() const MOZ_OVERRIDE
{ return mSize
; }
57 android::GraphicBuffer
* GetGraphicBuffer()
59 return mGraphicBuffer
.get();
62 android::PixelFormat
GetPixelFormat()
64 return mGraphicBuffer
->getPixelFormat();
68 * These flags are important for performances because they'll let the driver
69 * optimize for the right usage.
70 * Be sure to specify them before calling Lock.
72 void SetGrallocOpenFlags(uint32_t aFlags
)
74 mGrallocFlags
= aFlags
;
77 virtual uint8_t* GetBuffer() const MOZ_OVERRIDE
;
79 virtual bool AllocateForSurface(gfx::IntSize aSize
) MOZ_OVERRIDE
;
81 virtual bool AllocateForYCbCr(gfx::IntSize aYSize
,
82 gfx::IntSize aCbCrSize
,
83 StereoMode aStereoMode
) MOZ_OVERRIDE
;
85 bool AllocateGralloc(gfx::IntSize aYSize
, uint32_t aAndroidFormat
, uint32_t aUsage
);
87 virtual bool Allocate(uint32_t aSize
) MOZ_OVERRIDE
;
89 virtual size_t GetBufferSize() const MOZ_OVERRIDE
;
94 * Unfortunately, until bug 879681 is fixed we need to use a GrallocBufferActor.
96 GrallocBufferActor
* mGrallocActor
;
98 android::sp
<android::GraphicBuffer
> mGraphicBuffer
;
101 * Flags that are used when locking the gralloc buffer
103 uint32_t mGrallocFlags
;
105 * Points to a mapped gralloc buffer between calls to lock and unlock.
106 * Should be null outside of the lock-unlock pair.
108 uint8_t* mMappedBuffer
;
110 * android::GraphicBuffer has a size information. But there are cases
111 * that GraphicBuffer's size and actual video's size are different.
112 * Extra size member is necessary. See Bug 850566.
117 } // namespace layers
118 } // namespace mozilla
120 #endif // MOZ_WIDGET_GONK