• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 /*
19  * Hardware Composer Test Library Header
20  */
21 
22 #include <sstream>
23 #include <string>
24 
25 #include <EGL/egl.h>
26 #include <EGL/eglext.h>
27 #include <GLES2/gl2.h>
28 #include <GLES2/gl2ext.h>
29 
30 #include <ui/GraphicBuffer.h>
31 
32 #include <utils/Log.h>
33 #include <testUtil.h>
34 
35 #include <hardware/hwcomposer.h>
36 
37 // Characteristics of known graphic formats
38 const struct hwcTestGraphicFormat {
39     uint32_t format;
40     const char *desc;
41     uint32_t wMod, hMod; // Width/height mod this value must equal zero
42 } hwcTestGraphicFormat[] = {
43     {HAL_PIXEL_FORMAT_RGBA_8888, "RGBA8888", 1, 1},
44     {HAL_PIXEL_FORMAT_RGBX_8888, "RGBX8888", 1, 1},
45     {HAL_PIXEL_FORMAT_RGB_888,   "RGB888",   1, 1},
46     {HAL_PIXEL_FORMAT_RGB_565,   "RGB565",   1, 1},
47     {HAL_PIXEL_FORMAT_BGRA_8888, "BGRA8888", 1, 1},
48     {HAL_PIXEL_FORMAT_YV12,      "YV12",     2, 2},
49 };
50 
51 // Represent RGB color as fraction of color components.
52 // Each of the color components are expected in the range [0.0, 1.0]
53 class ColorFract {
54   public:
ColorFract()55     ColorFract(): _c1(0.0), _c2(0.0), _c3(0.0) {};
ColorFract(float c1,float c2,float c3)56     ColorFract(float c1, float c2, float c3): _c1(c1), _c2(c2), _c3(c3) {};
c1(void)57     float c1(void) const { return _c1; }
c2(void)58     float c2(void) const { return _c2; }
c3(void)59     float c3(void) const { return _c3; }
60 
61     operator std::string();
62 
63   private:
64     float _c1;
65     float _c2;
66     float _c3;
67 };
68 
69 // Represent RGB color as fraction of color components.
70 // Each of the color components are expected in the range [0.0, 1.0]
71 class ColorRGB {
72   public:
ColorRGB()73     ColorRGB(): _r(0.0), _g(0.0), _b(0.0) {};
ColorRGB(float f)74     ColorRGB(float f): _r(f), _g(f), _b(f) {}; // Gray, NOLINT(implicit)
ColorRGB(float r,float g,float b)75     ColorRGB(float r, float g, float b): _r(r), _g(g), _b(b) {};
r(void)76     float r(void) const { return _r; }
g(void)77     float g(void) const { return _g; }
b(void)78     float b(void) const { return _b; }
79 
80   private:
81     float _r;
82     float _g;
83     float _b;
84 };
85 
86 // Dimension - width and height of a rectanguler area
87 class HwcTestDim {
88   public:
HwcTestDim()89     HwcTestDim(): _w(0), _h(0) {};
HwcTestDim(uint32_t w,uint32_t h)90     HwcTestDim(uint32_t w, uint32_t h) : _w(w), _h(h) {}
width(void)91     uint32_t width(void) const { return _w; }
height(void)92     uint32_t height(void) const { return _h; }
setWidth(uint32_t w)93     void setWidth(uint32_t w) { _w = w; }
setHeight(uint32_t h)94     void setHeight(uint32_t h) { _h = h; }
95 
96     operator std::string();
97     operator hwc_rect() const;
98 
99   private:
100     uint32_t _w;
101     uint32_t _h;
102 };
103 
104 // Function Prototypes
105 void hwcTestInitDisplay(bool verbose, EGLDisplay *dpy, EGLSurface *surface,
106     EGLint *width, EGLint *height);
107 void hwcTestOpenHwc(hwc_composer_device_1_t **hwcDevicePtr);
108 const struct hwcTestGraphicFormat *hwcTestGraphicFormatLookup(const char *desc);
109 const struct hwcTestGraphicFormat *hwcTestGraphicFormatLookup(uint32_t id);
110 const char *hwcTestGraphicFormat2str(uint32_t format);
111 std::string hwcTestRect2str(const struct hwc_rect& rect);
112 
113 hwc_display_contents_1_t *hwcTestCreateLayerList(size_t numLayers);
114 void hwcTestFreeLayerList(hwc_display_contents_1_t *list);
115 void hwcTestDisplayList(hwc_display_contents_1_t *list);
116 void hwcTestDisplayListPrepareModifiable(hwc_display_contents_1_t *list);
117 void hwcTestDisplayListHandles(hwc_display_contents_1_t *list);
118 
119 uint32_t hwcTestColor2Pixel(uint32_t format, ColorFract color, float alpha);
120 void hwcTestColorConvert(uint32_t fromFormat, uint32_t toFormat,
121                   ColorFract& color);
122 void hwcTestSetPixel(android::GraphicBuffer *gBuf, unsigned char *buf,
123                      uint32_t x, uint32_t y, uint32_t pixel);
124 void hwcTestFillColor(android::GraphicBuffer *gBuf, ColorFract color,
125                       float alpha);
126 void hwcTestFillColorHBlend(android::GraphicBuffer *gBuf,
127                             uint32_t colorFormat,
128                             ColorFract startColor, ColorFract endColor);
129 ColorFract hwcTestParseColor(std::istringstream& in, bool& error);
130 struct hwc_rect hwcTestParseHwcRect(std::istringstream& in, bool& error);
131 HwcTestDim hwcTestParseDim(std::istringstream& in, bool& error);
132