hwcTestLib.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. * Hardware Composer Test Library Header
  19. */
  20. #include <sstream>
  21. #include <string>
  22. #include <EGL/egl.h>
  23. #include <EGL/eglext.h>
  24. #include <GLES2/gl2.h>
  25. #include <GLES2/gl2ext.h>
  26. #include <ui/GraphicBuffer.h>
  27. #include <utils/Log.h>
  28. #include <testUtil.h>
  29. #include <hardware/hwcomposer.h>
  30. // Characteristics of known graphic formats
  31. const struct hwcTestGraphicFormat {
  32. uint32_t format;
  33. const char *desc;
  34. uint32_t wMod, hMod; // Width/height mod this value must equal zero
  35. } hwcTestGraphicFormat[] = {
  36. {HAL_PIXEL_FORMAT_RGBA_8888, "RGBA8888", 1, 1},
  37. {HAL_PIXEL_FORMAT_RGBX_8888, "RGBX8888", 1, 1},
  38. {HAL_PIXEL_FORMAT_RGB_888, "RGB888", 1, 1},
  39. {HAL_PIXEL_FORMAT_RGB_565, "RGB565", 1, 1},
  40. {HAL_PIXEL_FORMAT_BGRA_8888, "BGRA8888", 1, 1},
  41. {HAL_PIXEL_FORMAT_YV12, "YV12", 2, 2},
  42. };
  43. // Represent RGB color as fraction of color components.
  44. // Each of the color components are expected in the range [0.0, 1.0]
  45. class ColorFract {
  46. public:
  47. ColorFract(): _c1(0.0), _c2(0.0), _c3(0.0) {};
  48. ColorFract(float c1, float c2, float c3): _c1(c1), _c2(c2), _c3(c3) {};
  49. float c1(void) const { return _c1; }
  50. float c2(void) const { return _c2; }
  51. float c3(void) const { return _c3; }
  52. operator std::string();
  53. private:
  54. float _c1;
  55. float _c2;
  56. float _c3;
  57. };
  58. // Represent RGB color as fraction of color components.
  59. // Each of the color components are expected in the range [0.0, 1.0]
  60. class ColorRGB {
  61. public:
  62. ColorRGB(): _r(0.0), _g(0.0), _b(0.0) {};
  63. ColorRGB(float f): _r(f), _g(f), _b(f) {}; // Gray
  64. ColorRGB(float r, float g, float b): _r(r), _g(g), _b(b) {};
  65. float r(void) const { return _r; }
  66. float g(void) const { return _g; }
  67. float b(void) const { return _b; }
  68. private:
  69. float _r;
  70. float _g;
  71. float _b;
  72. };
  73. // Dimension - width and height of a rectanguler area
  74. class HwcTestDim {
  75. public:
  76. HwcTestDim(): _w(0), _h(0) {};
  77. HwcTestDim(uint32_t w, uint32_t h) : _w(w), _h(h) {}
  78. uint32_t width(void) const { return _w; }
  79. uint32_t height(void) const { return _h; }
  80. void setWidth(uint32_t w) { _w = w; }
  81. void setHeight(uint32_t h) { _h = h; }
  82. operator std::string();
  83. operator hwc_rect() const;
  84. private:
  85. uint32_t _w;
  86. uint32_t _h;
  87. };
  88. // Function Prototypes
  89. void hwcTestInitDisplay(bool verbose, EGLDisplay *dpy, EGLSurface *surface,
  90. EGLint *width, EGLint *height);
  91. void hwcTestOpenHwc(hwc_composer_device_1_t **hwcDevicePtr);
  92. const struct hwcTestGraphicFormat *hwcTestGraphicFormatLookup(const char *desc);
  93. const struct hwcTestGraphicFormat *hwcTestGraphicFormatLookup(uint32_t id);
  94. const char *hwcTestGraphicFormat2str(uint32_t format);
  95. std::string hwcTestRect2str(const struct hwc_rect& rect);
  96. hwc_display_contents_1_t *hwcTestCreateLayerList(size_t numLayers);
  97. void hwcTestFreeLayerList(hwc_display_contents_1_t *list);
  98. void hwcTestDisplayList(hwc_display_contents_1_t *list);
  99. void hwcTestDisplayListPrepareModifiable(hwc_display_contents_1_t *list);
  100. void hwcTestDisplayListHandles(hwc_display_contents_1_t *list);
  101. uint32_t hwcTestColor2Pixel(uint32_t format, ColorFract color, float alpha);
  102. void hwcTestColorConvert(uint32_t fromFormat, uint32_t toFormat,
  103. ColorFract& color);
  104. void hwcTestSetPixel(android::GraphicBuffer *gBuf, unsigned char *buf,
  105. uint32_t x, uint32_t y, uint32_t pixel);
  106. void hwcTestFillColor(android::GraphicBuffer *gBuf, ColorFract color,
  107. float alpha);
  108. void hwcTestFillColorHBlend(android::GraphicBuffer *gBuf,
  109. uint32_t colorFormat,
  110. ColorFract startColor, ColorFract endColor);
  111. ColorFract hwcTestParseColor(std::istringstream& in, bool& error);
  112. struct hwc_rect hwcTestParseHwcRect(std::istringstream& in, bool& error);
  113. HwcTestDim hwcTestParseDim(std::istringstream& in, bool& error);