gfx/layers/GrallocImages.h

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:f638f716e140
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/. */
5
6 #ifndef GRALLOCIMAGES_H
7 #define GRALLOCIMAGES_H
8
9 #ifdef MOZ_WIDGET_GONK
10
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"
17
18 #include <ui/GraphicBuffer.h>
19
20 namespace mozilla {
21 namespace layers {
22
23 class GrallocTextureClientOGL;
24
25 /**
26 * The YUV format supported by Android HAL
27 *
28 * 4:2:0 - CbCr width and height is half that of Y.
29 *
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
35 *
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
41 *
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.
45 */
46 class GrallocImage : public PlanarYCbCrImage
47 , public ISharedImage
48 {
49 typedef PlanarYCbCrData Data;
50 static uint32_t sColorIdMap[];
51 public:
52 struct GrallocData {
53 nsRefPtr<TextureClient> mGraphicBuffer;
54 gfx::IntSize mPicSize;
55 };
56
57 GrallocImage();
58
59 virtual ~GrallocImage();
60
61 /**
62 * This makes a copy of the data buffers, in order to support functioning
63 * in all different layer managers.
64 */
65 virtual void SetData(const Data& aData);
66
67 /**
68 * Share the SurfaceDescriptor without making the copy, in order
69 * to support functioning in all different layer managers.
70 */
71 virtual void SetData(const GrallocData& aData);
72
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,
82 };
83
84 virtual TemporaryRef<gfx::SourceSurface> GetAsSourceSurface() MOZ_OVERRIDE;
85
86 android::sp<android::GraphicBuffer> GetGraphicBuffer() const;
87
88 void* GetNativeBuffer();
89
90 virtual bool IsValid() { return !!mTextureClient; }
91
92 virtual ISharedImage* AsSharedImage() MOZ_OVERRIDE { return this; }
93
94 virtual TextureClient* GetTextureClient(CompositableClient* aClient) MOZ_OVERRIDE;
95
96 virtual uint8_t* GetBuffer()
97 {
98 return static_cast<uint8_t*>(GetNativeBuffer());
99 }
100
101 private:
102 RefPtr<GrallocTextureClientOGL> mTextureClient;
103 };
104
105 } // namespace layers
106 } // namespace mozilla
107 #endif
108
109 #endif /* GRALLOCIMAGES_H */

mercurial