1734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller/* 2734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller * Copyright (C) 2011 The Android Open Source Project 3734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller * 4734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller * Licensed under the Apache License, Version 2.0 (the "License"); 5734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller * you may not use this file except in compliance with the License. 6734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller * You may obtain a copy of the License at 7734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller * 8734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller * http://www.apache.org/licenses/LICENSE-2.0 9734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller * 10734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller * Unless required by applicable law or agreed to in writing, software 11734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller * distributed under the License is distributed on an "AS IS" BASIS, 12734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller * See the License for the specific language governing permissions and 14734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller * limitations under the License. 15734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller * 16734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller */ 17734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller 18734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller/* 19734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller * Hardware Composer Test Library Header 20734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller */ 21734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller 22734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller#include <sstream> 23734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller#include <string> 24734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller 25734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller#include <EGL/egl.h> 26734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller#include <EGL/eglext.h> 27734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller#include <GLES2/gl2.h> 28734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller#include <GLES2/gl2ext.h> 29734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller 30734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller#include <ui/GraphicBuffer.h> 31734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller 32734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller#include <utils/Log.h> 33734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller#include <testUtil.h> 34734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller 35734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller#include <hardware/hwcomposer.h> 36734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller 37734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller// Characteristics of known graphic formats 38734d8d898c6b0b315e431b231cc6759514da361bLouis Huemillerconst struct hwcTestGraphicFormat { 39734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller uint32_t format; 40734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller const char *desc; 41734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller uint32_t wMod, hMod; // Width/height mod this value must equal zero 42734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller} hwcTestGraphicFormat[] = { 43734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller {HAL_PIXEL_FORMAT_RGBA_8888, "RGBA8888", 1, 1}, 44734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller {HAL_PIXEL_FORMAT_RGBX_8888, "RGBX8888", 1, 1}, 45734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller {HAL_PIXEL_FORMAT_RGB_888, "RGB888", 1, 1}, 46734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller {HAL_PIXEL_FORMAT_RGB_565, "RGB565", 1, 1}, 47734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller {HAL_PIXEL_FORMAT_BGRA_8888, "BGRA8888", 1, 1}, 48734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller {HAL_PIXEL_FORMAT_YV12, "YV12", 2, 2}, 49734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller}; 50734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller 51734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller// Represent RGB color as fraction of color components. 52734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller// Each of the color components are expected in the range [0.0, 1.0] 53734d8d898c6b0b315e431b231cc6759514da361bLouis Huemillerclass ColorFract { 54734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller public: 55734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller ColorFract(): _c1(0.0), _c2(0.0), _c3(0.0) {}; 56734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller ColorFract(float c1, float c2, float c3): _c1(c1), _c2(c2), _c3(c3) {}; 57734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller float c1(void) const { return _c1; } 58734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller float c2(void) const { return _c2; } 59734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller float c3(void) const { return _c3; } 60734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller 61734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller operator std::string(); 62734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller 63734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller private: 64734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller float _c1; 65734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller float _c2; 66734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller float _c3; 67734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller}; 68734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller 69734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller// Represent RGB color as fraction of color components. 70734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller// Each of the color components are expected in the range [0.0, 1.0] 71734d8d898c6b0b315e431b231cc6759514da361bLouis Huemillerclass ColorRGB { 72734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller public: 73734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller ColorRGB(): _r(0.0), _g(0.0), _b(0.0) {}; 74734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller ColorRGB(float f): _r(f), _g(f), _b(f) {}; // Gray 75734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller ColorRGB(float r, float g, float b): _r(r), _g(g), _b(b) {}; 76734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller float r(void) const { return _r; } 77734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller float g(void) const { return _g; } 78734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller float b(void) const { return _b; } 79734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller 80734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller private: 81734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller float _r; 82734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller float _g; 83734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller float _b; 84734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller}; 85734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller 86734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller// Dimension - width and height of a rectanguler area 87734d8d898c6b0b315e431b231cc6759514da361bLouis Huemillerclass HwcTestDim { 88734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller public: 89734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller HwcTestDim(): _w(0), _h(0) {}; 90734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller HwcTestDim(uint32_t w, uint32_t h) : _w(w), _h(h) {} 91734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller uint32_t width(void) const { return _w; } 92734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller uint32_t height(void) const { return _h; } 93734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller void setWidth(uint32_t w) { _w = w; } 94734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller void setHeight(uint32_t h) { _h = h; } 95734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller 96734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller operator std::string(); 97653f81087920d479d8916a6ae6d2575dd80ed665Louis Huemiller operator hwc_rect() const; 98734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller 99734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller private: 100734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller uint32_t _w; 101734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller uint32_t _h; 102734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller}; 103734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller 104734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller// Function Prototypes 105734d8d898c6b0b315e431b231cc6759514da361bLouis Huemillervoid hwcTestInitDisplay(bool verbose, EGLDisplay *dpy, EGLSurface *surface, 106734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller EGLint *width, EGLint *height); 1075880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hallvoid hwcTestOpenHwc(hwc_composer_device_1_t **hwcDevicePtr); 108734d8d898c6b0b315e431b231cc6759514da361bLouis Huemillerconst struct hwcTestGraphicFormat *hwcTestGraphicFormatLookup(const char *desc); 109653f81087920d479d8916a6ae6d2575dd80ed665Louis Huemillerconst struct hwcTestGraphicFormat *hwcTestGraphicFormatLookup(uint32_t id); 110734d8d898c6b0b315e431b231cc6759514da361bLouis Huemillerconst char *hwcTestGraphicFormat2str(uint32_t format); 111734d8d898c6b0b315e431b231cc6759514da361bLouis Huemillerstd::string hwcTestRect2str(const struct hwc_rect& rect); 112734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller 113b685c542836b93c99cd85053e07696406ea37adbJesse Hallhwc_display_contents_1_t *hwcTestCreateLayerList(size_t numLayers); 114b685c542836b93c99cd85053e07696406ea37adbJesse Hallvoid hwcTestFreeLayerList(hwc_display_contents_1_t *list); 115b685c542836b93c99cd85053e07696406ea37adbJesse Hallvoid hwcTestDisplayList(hwc_display_contents_1_t *list); 116b685c542836b93c99cd85053e07696406ea37adbJesse Hallvoid hwcTestDisplayListPrepareModifiable(hwc_display_contents_1_t *list); 117b685c542836b93c99cd85053e07696406ea37adbJesse Hallvoid hwcTestDisplayListHandles(hwc_display_contents_1_t *list); 118734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller 119734d8d898c6b0b315e431b231cc6759514da361bLouis Huemilleruint32_t hwcTestColor2Pixel(uint32_t format, ColorFract color, float alpha); 120734d8d898c6b0b315e431b231cc6759514da361bLouis Huemillervoid hwcTestColorConvert(uint32_t fromFormat, uint32_t toFormat, 121734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller ColorFract& color); 122734d8d898c6b0b315e431b231cc6759514da361bLouis Huemillervoid hwcTestSetPixel(android::GraphicBuffer *gBuf, unsigned char *buf, 123734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller uint32_t x, uint32_t y, uint32_t pixel); 124734d8d898c6b0b315e431b231cc6759514da361bLouis Huemillervoid hwcTestFillColor(android::GraphicBuffer *gBuf, ColorFract color, 125734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller float alpha); 126734d8d898c6b0b315e431b231cc6759514da361bLouis Huemillervoid hwcTestFillColorHBlend(android::GraphicBuffer *gBuf, 127734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller uint32_t colorFormat, 128734d8d898c6b0b315e431b231cc6759514da361bLouis Huemiller ColorFract startColor, ColorFract endColor); 129734d8d898c6b0b315e431b231cc6759514da361bLouis HuemillerColorFract hwcTestParseColor(std::istringstream& in, bool& error); 130734d8d898c6b0b315e431b231cc6759514da361bLouis Huemillerstruct hwc_rect hwcTestParseHwcRect(std::istringstream& in, bool& error); 131734d8d898c6b0b315e431b231cc6759514da361bLouis HuemillerHwcTestDim hwcTestParseDim(std::istringstream& in, bool& error); 132