Bumping manifests a=b2g-bump
[gecko.git] / gfx / layers / GrallocImages.h
blobee151ecadaeba3054e97a3c4ab742a5225663df4
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 "ImageLayers.h"
12 #include "ImageContainer.h"
13 #include "mozilla/gfx/Point.h"
14 #include "mozilla/layers/AtomicRefCountedWithFinalize.h"
15 #include "mozilla/layers/FenceUtils.h"
16 #include "mozilla/layers/LayersSurfaces.h"
18 #include <ui/GraphicBuffer.h>
20 namespace mozilla {
21 namespace layers {
23 class GrallocTextureClientOGL;
25 /**
26 * The YUV format supported by Android HAL
28 * 4:2:0 - CbCr width and height is half that of Y.
30 * This format assumes
31 * - an even width
32 * - an even height
33 * - a horizontal stride multiple of 16 pixels
34 * - a vertical stride equal to the height
36 * y_size = stride * height
37 * c_size = ALIGN(stride/2, 16) * height/2
38 * size = y_size + c_size * 2
39 * cr_offset = y_size
40 * cb_offset = y_size + c_size
42 * The Image that is rendered is the picture region defined by
43 * mPicX, mPicY and mPicSize. The size of the rendered image is
44 * mPicSize, not mYSize or mCbCrSize.
46 class GrallocImage : public PlanarYCbCrImage
48 typedef PlanarYCbCrData Data;
49 static int32_t sColorIdMap[];
50 public:
51 struct GrallocData {
52 nsRefPtr<TextureClient> mGraphicBuffer;
53 gfx::IntSize mPicSize;
56 GrallocImage();
58 virtual ~GrallocImage();
60 /**
61 * This makes a copy of the data buffers, in order to support functioning
62 * in all different layer managers.
64 virtual void SetData(const Data& aData);
66 /**
67 * Share the SurfaceDescriptor without making the copy, in order
68 * to support functioning in all different layer managers.
70 virtual void SetData(const GrallocData& aData);
72 // From [android 4.0.4]/hardware/msm7k/libgralloc-qsd8k/gralloc_priv.h
73 enum {
74 /* OEM specific HAL formats */
75 HAL_PIXEL_FORMAT_YCbCr_422_P = 0x102,
76 HAL_PIXEL_FORMAT_YCbCr_420_P = 0x103,
77 HAL_PIXEL_FORMAT_YCbCr_420_SP = 0x109,
78 HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO = 0x10A,
79 HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED = 0x7FA30C03,
80 HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS = 0x7FA30C04,
83 enum {
84 GRALLOC_SW_UAGE = android::GraphicBuffer::USAGE_SOFTWARE_MASK,
87 virtual TemporaryRef<gfx::SourceSurface> GetAsSourceSurface() MOZ_OVERRIDE;
89 android::sp<android::GraphicBuffer> GetGraphicBuffer() const;
91 void* GetNativeBuffer();
93 virtual bool IsValid() { return !!mTextureClient; }
95 virtual TextureClient* GetTextureClient(CompositableClient* aClient) MOZ_OVERRIDE;
97 virtual GrallocImage* AsGrallocImage() MOZ_OVERRIDE
99 return this;
102 virtual uint8_t* GetBuffer()
104 return static_cast<uint8_t*>(GetNativeBuffer());
107 int GetUsage()
109 return (static_cast<ANativeWindowBuffer*>(GetNativeBuffer()))->usage;
112 static int GetOmxFormat(int aFormat)
114 uint32_t omxFormat = 0;
116 for (int i = 0; sColorIdMap[i]; i += 2) {
117 if (sColorIdMap[i] == aFormat) {
118 omxFormat = sColorIdMap[i + 1];
119 break;
123 return omxFormat;
126 private:
127 RefPtr<GrallocTextureClientOGL> mTextureClient;
130 } // namespace layers
131 } // namespace mozilla
132 #endif
134 #endif /* GRALLOCIMAGES_H */