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 GRALLOCIMAGES_H
7 #define GRALLOCIMAGES_H
11 #include "mozilla/layers/LayersSurfaces.h"
12 #include "ImageLayers.h"
13 #include "ImageContainer.h"
15 #include <ui/GraphicBuffer.h>
20 class GrallocTextureClientOGL
;
23 * The gralloc buffer maintained by android GraphicBuffer can be
24 * shared between the compositor thread and the producer thread. The
25 * mGraphicBuffer is owned by the producer thread, but when it is
26 * wrapped by GraphicBufferLocked and passed to the compositor, the
27 * buffer content is guaranteed to not change until Unlock() is
28 * called. Each producer must maintain their own buffer queue and
29 * implement the GraphicBufferLocked::Unlock() interface.
31 class GraphicBufferLocked
{
32 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GraphicBufferLocked
)
35 GraphicBufferLocked(SurfaceDescriptor aGraphicBuffer
)
36 : mSurfaceDescriptor(aGraphicBuffer
)
39 virtual ~GraphicBufferLocked() {}
41 virtual void Unlock() {}
43 SurfaceDescriptor
GetSurfaceDescriptor()
45 return mSurfaceDescriptor
;
49 SurfaceDescriptor mSurfaceDescriptor
;
53 * The YUV format supported by Android HAL
55 * 4:2:0 - CbCr width and height is half that of Y.
60 * - a horizontal stride multiple of 16 pixels
61 * - a vertical stride equal to the height
63 * y_size = stride * height
64 * c_size = ALIGN(stride/2, 16) * height/2
65 * size = y_size + c_size * 2
67 * cb_offset = y_size + c_size
69 * The Image that is rendered is the picture region defined by
70 * mPicX, mPicY and mPicSize. The size of the rendered image is
71 * mPicSize, not mYSize or mCbCrSize.
73 class GrallocImage
: public PlanarYCbCrImage
76 typedef PlanarYCbCrData Data
;
77 static uint32_t sColorIdMap
[];
80 nsRefPtr
<GraphicBufferLocked
> mGraphicBuffer
;
86 virtual ~GrallocImage();
89 * This makes a copy of the data buffers, in order to support functioning
90 * in all different layer managers.
92 virtual void SetData(const Data
& aData
);
95 * Share the SurfaceDescriptor without making the copy, in order
96 * to support functioning in all different layer managers.
98 virtual void SetData(const GrallocData
& aData
);
100 // From [android 4.0.4]/hardware/msm7k/libgralloc-qsd8k/gralloc_priv.h
102 /* OEM specific HAL formats */
103 HAL_PIXEL_FORMAT_YCbCr_422_P
= 0x102,
104 HAL_PIXEL_FORMAT_YCbCr_420_P
= 0x103,
105 HAL_PIXEL_FORMAT_YCbCr_420_SP
= 0x109,
106 HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO
= 0x10A,
107 HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED
= 0x7FA30C03,
108 HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS
= 0x7FA30C04,
111 virtual already_AddRefed
<gfxASurface
> GetAsSurface();
113 void* GetNativeBuffer()
116 return GrallocBufferActor::GetFrom(GetSurfaceDescriptor())->getNativeBuffer();
122 virtual bool IsValid() { return GetSurfaceDescriptor().type() != SurfaceDescriptor::T__None
; }
124 SurfaceDescriptor
GetSurfaceDescriptor() {
125 if (mGraphicBuffer
.get()) {
126 return mGraphicBuffer
->GetSurfaceDescriptor();
128 return SurfaceDescriptor();
131 virtual ISharedImage
* AsSharedImage() MOZ_OVERRIDE
{ return this; }
133 virtual TextureClient
* GetTextureClient() MOZ_OVERRIDE
;
135 virtual uint8_t* GetBuffer()
137 return static_cast<uint8_t*>(GetNativeBuffer());
141 bool mBufferAllocated
;
142 nsRefPtr
<GraphicBufferLocked
> mGraphicBuffer
;
143 RefPtr
<GrallocTextureClientOGL
> mTextureClient
;
146 } // namespace layers
147 } // namespace mozilla
150 #endif /* GRALLOCIMAGES_H */