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