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