Bumping manifests a=b2g-bump
[gecko.git] / gfx / layers / GrallocImages.h
blob103c11e5a610f6d8b06dd37a7d5e0075c1776932
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
47 , public ISharedImage
49 typedef PlanarYCbCrData Data;
50 static uint32_t sColorIdMap[];
51 public:
52 struct GrallocData {
53 nsRefPtr<TextureClient> mGraphicBuffer;
54 gfx::IntSize mPicSize;
57 GrallocImage();
59 virtual ~GrallocImage();
61 /**
62 * This makes a copy of the data buffers, in order to support functioning
63 * in all different layer managers.
65 virtual void SetData(const Data& aData);
67 /**
68 * Share the SurfaceDescriptor without making the copy, in order
69 * to support functioning in all different layer managers.
71 virtual void SetData(const GrallocData& aData);
73 // From [android 4.0.4]/hardware/msm7k/libgralloc-qsd8k/gralloc_priv.h
74 enum {
75 /* OEM specific HAL formats */
76 HAL_PIXEL_FORMAT_YCbCr_422_P = 0x102,
77 HAL_PIXEL_FORMAT_YCbCr_420_P = 0x103,
78 HAL_PIXEL_FORMAT_YCbCr_420_SP = 0x109,
79 HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO = 0x10A,
80 HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED = 0x7FA30C03,
81 HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS = 0x7FA30C04,
84 enum {
85 GRALLOC_SW_UAGE = android::GraphicBuffer::USAGE_SOFTWARE_MASK,
88 virtual TemporaryRef<gfx::SourceSurface> GetAsSourceSurface() MOZ_OVERRIDE;
90 android::sp<android::GraphicBuffer> GetGraphicBuffer() const;
92 void* GetNativeBuffer();
94 virtual bool IsValid() { return !!mTextureClient; }
96 virtual ISharedImage* AsSharedImage() MOZ_OVERRIDE { return this; }
98 virtual TextureClient* GetTextureClient(CompositableClient* aClient) MOZ_OVERRIDE;
100 virtual uint8_t* GetBuffer()
102 return static_cast<uint8_t*>(GetNativeBuffer());
105 int GetUsage()
107 return (static_cast<ANativeWindowBuffer*>(GetNativeBuffer()))->usage;
110 static int GetOmxFormat(int aFormat)
112 uint32_t omxFormat = 0;
114 for (int i = 0; sColorIdMap[i]; i += 2) {
115 if (sColorIdMap[i] == aFormat) {
116 omxFormat = sColorIdMap[i + 1];
117 break;
121 return omxFormat;
124 private:
125 RefPtr<GrallocTextureClientOGL> mTextureClient;
128 } // namespace layers
129 } // namespace mozilla
130 #endif
132 #endif /* GRALLOCIMAGES_H */