backout 29799f914cab, Bug 917642 - [Helix] Please update the helix blobs
[gecko.git] / gfx / layers / GrallocImages.h
blob816e3442b52030b6b97082895c4aa7b6694afe6e
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
9 #ifdef MOZ_WIDGET_GONK
11 #include "mozilla/layers/LayersSurfaces.h"
12 #include "ImageLayers.h"
13 #include "ImageContainer.h"
15 #include <ui/GraphicBuffer.h>
17 namespace mozilla {
18 namespace layers {
20 class GrallocTextureClientOGL;
22 /**
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)
34 public:
35 GraphicBufferLocked(SurfaceDescriptor aGraphicBuffer)
36 : mSurfaceDescriptor(aGraphicBuffer)
39 virtual ~GraphicBufferLocked() {}
41 virtual void Unlock() {}
43 SurfaceDescriptor GetSurfaceDescriptor()
45 return mSurfaceDescriptor;
48 protected:
49 SurfaceDescriptor mSurfaceDescriptor;
52 /**
53 * The YUV format supported by Android HAL
55 * 4:2:0 - CbCr width and height is half that of Y.
57 * This format assumes
58 * - an even width
59 * - an even height
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
66 * cr_offset = y_size
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
74 , public ISharedImage
76 typedef PlanarYCbCrData Data;
77 static uint32_t sColorIdMap[];
78 public:
79 struct GrallocData {
80 nsRefPtr<GraphicBufferLocked> mGraphicBuffer;
81 gfxIntSize mPicSize;
84 GrallocImage();
86 virtual ~GrallocImage();
88 /**
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);
94 /**
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
101 enum {
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()
115 if (IsValid()) {
116 return GrallocBufferActor::GetFrom(GetSurfaceDescriptor())->getNativeBuffer();
117 } else {
118 return nullptr;
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());
140 private:
141 bool mBufferAllocated;
142 nsRefPtr<GraphicBufferLocked> mGraphicBuffer;
143 RefPtr<GrallocTextureClientOGL> mTextureClient;
146 } // namespace layers
147 } // namespace mozilla
148 #endif
150 #endif /* GRALLOCIMAGES_H */