blob: d7d5837ba9344d1960a224105391539a248bf9c0 [file] [log] [blame]
Louis Huemiller734d8d82011-01-05 18:53:47 -08001/*
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/FramebufferNativeWindow.h>
31#include <ui/GraphicBuffer.h>
Louis Huemiller734d8d82011-01-05 18:53:47 -080032
33#include <utils/Log.h>
34#include <testUtil.h>
35
36#include <hardware/hwcomposer.h>
37
38// Characteristics of known graphic formats
39const struct hwcTestGraphicFormat {
40 uint32_t format;
41 const char *desc;
42 uint32_t wMod, hMod; // Width/height mod this value must equal zero
43} hwcTestGraphicFormat[] = {
44 {HAL_PIXEL_FORMAT_RGBA_8888, "RGBA8888", 1, 1},
45 {HAL_PIXEL_FORMAT_RGBX_8888, "RGBX8888", 1, 1},
46 {HAL_PIXEL_FORMAT_RGB_888, "RGB888", 1, 1},
47 {HAL_PIXEL_FORMAT_RGB_565, "RGB565", 1, 1},
48 {HAL_PIXEL_FORMAT_BGRA_8888, "BGRA8888", 1, 1},
49 {HAL_PIXEL_FORMAT_RGBA_5551, "RGBA5551", 1, 1},
50 {HAL_PIXEL_FORMAT_RGBA_4444, "RGBA4444", 1, 1},
51 {HAL_PIXEL_FORMAT_YV12, "YV12", 2, 2},
52};
53
54// Represent RGB color as fraction of color components.
55// Each of the color components are expected in the range [0.0, 1.0]
56class ColorFract {
57 public:
58 ColorFract(): _c1(0.0), _c2(0.0), _c3(0.0) {};
59 ColorFract(float c1, float c2, float c3): _c1(c1), _c2(c2), _c3(c3) {};
60 float c1(void) const { return _c1; }
61 float c2(void) const { return _c2; }
62 float c3(void) const { return _c3; }
63
64 operator std::string();
65
66 private:
67 float _c1;
68 float _c2;
69 float _c3;
70};
71
72// Represent RGB color as fraction of color components.
73// Each of the color components are expected in the range [0.0, 1.0]
74class ColorRGB {
75 public:
76 ColorRGB(): _r(0.0), _g(0.0), _b(0.0) {};
77 ColorRGB(float f): _r(f), _g(f), _b(f) {}; // Gray
78 ColorRGB(float r, float g, float b): _r(r), _g(g), _b(b) {};
79 float r(void) const { return _r; }
80 float g(void) const { return _g; }
81 float b(void) const { return _b; }
82
83 private:
84 float _r;
85 float _g;
86 float _b;
87};
88
89// Dimension - width and height of a rectanguler area
90class HwcTestDim {
91 public:
92 HwcTestDim(): _w(0), _h(0) {};
93 HwcTestDim(uint32_t w, uint32_t h) : _w(w), _h(h) {}
94 uint32_t width(void) const { return _w; }
95 uint32_t height(void) const { return _h; }
96 void setWidth(uint32_t w) { _w = w; }
97 void setHeight(uint32_t h) { _h = h; }
98
99 operator std::string();
Louis Huemiller653f8102011-01-09 10:59:31 -0800100 operator hwc_rect() const;
Louis Huemiller734d8d82011-01-05 18:53:47 -0800101
102 private:
103 uint32_t _w;
104 uint32_t _h;
105};
106
107// Function Prototypes
108void hwcTestInitDisplay(bool verbose, EGLDisplay *dpy, EGLSurface *surface,
109 EGLint *width, EGLint *height);
Jesse Hall5880cc52012-06-05 23:40:32 -0700110void hwcTestOpenHwc(hwc_composer_device_1_t **hwcDevicePtr);
Louis Huemiller734d8d82011-01-05 18:53:47 -0800111const struct hwcTestGraphicFormat *hwcTestGraphicFormatLookup(const char *desc);
Louis Huemiller653f8102011-01-09 10:59:31 -0800112const struct hwcTestGraphicFormat *hwcTestGraphicFormatLookup(uint32_t id);
Louis Huemiller734d8d82011-01-05 18:53:47 -0800113const char *hwcTestGraphicFormat2str(uint32_t format);
114std::string hwcTestRect2str(const struct hwc_rect& rect);
115
Jesse Hallb685c542012-07-31 14:32:56 -0700116hwc_display_contents_1_t *hwcTestCreateLayerList(size_t numLayers);
117void hwcTestFreeLayerList(hwc_display_contents_1_t *list);
118void hwcTestDisplayList(hwc_display_contents_1_t *list);
119void hwcTestDisplayListPrepareModifiable(hwc_display_contents_1_t *list);
120void hwcTestDisplayListHandles(hwc_display_contents_1_t *list);
Louis Huemiller734d8d82011-01-05 18:53:47 -0800121
122uint32_t hwcTestColor2Pixel(uint32_t format, ColorFract color, float alpha);
123void hwcTestColorConvert(uint32_t fromFormat, uint32_t toFormat,
124 ColorFract& color);
125void hwcTestSetPixel(android::GraphicBuffer *gBuf, unsigned char *buf,
126 uint32_t x, uint32_t y, uint32_t pixel);
127void hwcTestFillColor(android::GraphicBuffer *gBuf, ColorFract color,
128 float alpha);
129void hwcTestFillColorHBlend(android::GraphicBuffer *gBuf,
130 uint32_t colorFormat,
131 ColorFract startColor, ColorFract endColor);
132ColorFract hwcTestParseColor(std::istringstream& in, bool& error);
133struct hwc_rect hwcTestParseHwcRect(std::istringstream& in, bool& error);
134HwcTestDim hwcTestParseDim(std::istringstream& in, bool& error);