upload android base code part1
This commit is contained in:
parent
e02f198e2d
commit
0a1de6c4b3
48159 changed files with 9071466 additions and 0 deletions
109
android/frameworks/native/opengl/tests/hwc/Android.bp
Normal file
109
android/frameworks/native/opengl/tests/hwc/Android.bp
Normal file
|
@ -0,0 +1,109 @@
|
|||
// Copyright (C) 2010 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
cc_defaults {
|
||||
|
||||
name: "hwc_tests_defaults",
|
||||
cflags: [
|
||||
"-DGL_GLEXT_PROTOTYPES",
|
||||
"-DEGL_EGLEXT_PROTOTYPES",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
],
|
||||
}
|
||||
|
||||
cc_library_static {
|
||||
|
||||
name: "libhwcTest",
|
||||
srcs: ["hwcTestLib.cpp"],
|
||||
|
||||
static_libs: [
|
||||
"libarect",
|
||||
"libglTest",
|
||||
"libtestUtil",
|
||||
],
|
||||
shared_libs: [
|
||||
"libui",
|
||||
"libnativewindow"
|
||||
],
|
||||
defaults: ["hwc_tests_defaults"],
|
||||
}
|
||||
|
||||
cc_defaults {
|
||||
|
||||
name: "hwc_lib_defaults",
|
||||
shared_libs: [
|
||||
"libcutils",
|
||||
"libEGL",
|
||||
"libGLESv2",
|
||||
"libhardware",
|
||||
"liblog",
|
||||
"libui",
|
||||
"libutils",
|
||||
"libnativewindow"
|
||||
],
|
||||
|
||||
gtest: false,
|
||||
|
||||
static_libs: [
|
||||
"libglTest",
|
||||
"libhwcTest",
|
||||
"libtestUtil",
|
||||
],
|
||||
}
|
||||
|
||||
cc_test {
|
||||
|
||||
name: "hwcStress",
|
||||
srcs: ["hwcStress.cpp"],
|
||||
|
||||
defaults: [
|
||||
"hwc_lib_defaults",
|
||||
"hwc_tests_defaults",
|
||||
],
|
||||
}
|
||||
|
||||
cc_test {
|
||||
|
||||
name: "hwcRects",
|
||||
srcs: ["hwcRects.cpp"],
|
||||
|
||||
defaults: [
|
||||
"hwc_lib_defaults",
|
||||
"hwc_tests_defaults",
|
||||
],
|
||||
}
|
||||
|
||||
cc_test {
|
||||
|
||||
name: "hwcColorEquiv",
|
||||
srcs: ["hwcColorEquiv.cpp"],
|
||||
|
||||
defaults: [
|
||||
"hwc_lib_defaults",
|
||||
"hwc_tests_defaults",
|
||||
],
|
||||
}
|
||||
|
||||
cc_test {
|
||||
|
||||
name: "hwcCommit",
|
||||
srcs: ["hwcCommit.cpp"],
|
||||
|
||||
defaults: [
|
||||
"hwc_lib_defaults",
|
||||
"hwc_tests_defaults",
|
||||
],
|
||||
}
|
436
android/frameworks/native/opengl/tests/hwc/hwcColorEquiv.cpp
Normal file
436
android/frameworks/native/opengl/tests/hwc/hwcColorEquiv.cpp
Normal file
|
@ -0,0 +1,436 @@
|
|||
/*
|
||||
* Copyright (C) 2011 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Hardware Composer Color Equivalence
|
||||
*
|
||||
* Synopsis
|
||||
* hwc_colorequiv [options] eFmt
|
||||
*
|
||||
* options:
|
||||
-v - verbose
|
||||
* -s <0.##, 0.##, 0.##> - Start color (default: <0.0, 0.0, 0.0>
|
||||
* -e <0.##, 0.##, 0.##> - Ending color (default: <1.0, 1.0, 1.0>
|
||||
* -r fmt - reference graphic format
|
||||
* -D #.## - End of test delay
|
||||
*
|
||||
* graphic formats:
|
||||
* RGBA8888 (reference frame default)
|
||||
* RGBX8888
|
||||
* RGB888
|
||||
* RGB565
|
||||
* BGRA8888
|
||||
* RGBA5551
|
||||
* RGBA4444
|
||||
* YV12
|
||||
*
|
||||
* Description
|
||||
* Renders a horizontal blend in two frames. The first frame is rendered
|
||||
* in the upper third of the display and is called the reference frame.
|
||||
* The second frame is displayed in the middle third and is called the
|
||||
* equivalence frame. The primary purpose of this utility is to verify
|
||||
* that the colors produced in the reference and equivalence frames are
|
||||
* the same. The colors are the same when the colors are the same
|
||||
* vertically between the reference and equivalence frames.
|
||||
*
|
||||
* By default the reference frame is rendered through the use of the
|
||||
* RGBA8888 graphic format. The -r option can be used to specify a
|
||||
* non-default reference frame graphic format. The graphic format of
|
||||
* the equivalence frame is determined by a single required positional
|
||||
* parameter. Intentionally there is no default for the graphic format
|
||||
* of the equivalence frame.
|
||||
*
|
||||
* The horizontal blend in the reference frame is produced from a linear
|
||||
* interpolation from a start color (default: <0.0, 0.0, 0.0> on the left
|
||||
* side to an end color (default <1.0, 1.0, 1.0> on the right side. Where
|
||||
* possible the equivalence frame is rendered with the equivalent color
|
||||
* from the reference frame. A color of black is used in the equivalence
|
||||
* frame for cases where an equivalent color does not exist.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "hwcColorEquivTest"
|
||||
|
||||
#include <algorithm>
|
||||
#include <assert.h>
|
||||
#include <cerrno>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <libgen.h>
|
||||
#include <sched.h>
|
||||
#include <sstream>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include <EGL/egl.h>
|
||||
#include <EGL/eglext.h>
|
||||
#include <GLES2/gl2.h>
|
||||
#include <GLES2/gl2ext.h>
|
||||
|
||||
#include <ui/GraphicBuffer.h>
|
||||
|
||||
#include <utils/Log.h>
|
||||
#include <testUtil.h>
|
||||
|
||||
#include <hardware/hwcomposer.h>
|
||||
|
||||
#include "hwcTestLib.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace android;
|
||||
|
||||
// Defaults for command-line options
|
||||
const bool defaultVerbose = false;
|
||||
const ColorFract defaultStartColor(0.0, 0.0, 0.0);
|
||||
const ColorFract defaultEndColor(1.0, 1.0, 1.0);
|
||||
const char *defaultRefFormat = "RGBA8888";
|
||||
const float defaultEndDelay = 2.0; // Default delay after rendering graphics
|
||||
|
||||
// Defines
|
||||
#define MAXSTR 100
|
||||
#define MAXCMD 200
|
||||
#define BITSPERBYTE 8 // TODO: Obtain from <values.h>, once
|
||||
// it has been added
|
||||
|
||||
#define CMD_STOP_FRAMEWORK "stop 2>&1"
|
||||
#define CMD_START_FRAMEWORK "start 2>&1"
|
||||
|
||||
// Macros
|
||||
#define NUMA(a) (sizeof(a) / sizeof((a)[0])) // Num elements in an array
|
||||
#define MEMCLR(addr, size) do { \
|
||||
memset((addr), 0, (size)); \
|
||||
} while (0)
|
||||
|
||||
// Globals
|
||||
static const int texUsage = GraphicBuffer::USAGE_HW_TEXTURE |
|
||||
GraphicBuffer::USAGE_SW_WRITE_RARELY;
|
||||
static hwc_composer_device_1_t *hwcDevice;
|
||||
static EGLDisplay dpy;
|
||||
static EGLSurface surface;
|
||||
static EGLint width, height;
|
||||
|
||||
// Functions prototypes
|
||||
void init(void);
|
||||
void printSyntax(const char *cmd);
|
||||
|
||||
// Command-line option settings
|
||||
static bool verbose = defaultVerbose;
|
||||
static ColorFract startRefColor = defaultStartColor;
|
||||
static ColorFract endRefColor = defaultEndColor;
|
||||
static float endDelay = defaultEndDelay;
|
||||
static const struct hwcTestGraphicFormat *refFormat
|
||||
= hwcTestGraphicFormatLookup(defaultRefFormat);
|
||||
static const struct hwcTestGraphicFormat *equivFormat;
|
||||
|
||||
/*
|
||||
* Main
|
||||
*
|
||||
* Performs the following high-level sequence of operations:
|
||||
*
|
||||
* 1. Command-line parsing
|
||||
*
|
||||
* 2. Stop framework
|
||||
*
|
||||
* 3. Initialization
|
||||
*
|
||||
* 4. Create Hardware Composer description of reference and equivalence frames
|
||||
*
|
||||
* 5. Have Hardware Composer render the reference and equivalence frames
|
||||
*
|
||||
* 6. Delay for amount of time given by endDelay
|
||||
*
|
||||
* 7. Start framework
|
||||
*/
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int rv, opt;
|
||||
bool error;
|
||||
char *chptr;
|
||||
char cmd[MAXCMD];
|
||||
string str;
|
||||
|
||||
testSetLogCatTag(LOG_TAG);
|
||||
|
||||
assert(refFormat != NULL);
|
||||
|
||||
testSetLogCatTag(LOG_TAG);
|
||||
|
||||
// Parse command line arguments
|
||||
while ((opt = getopt(argc, argv, "vs:e:r:D:?h")) != -1) {
|
||||
switch (opt) {
|
||||
case 'D': // End of test delay
|
||||
// Delay between completion of final pass and restart
|
||||
// of framework
|
||||
endDelay = strtod(optarg, &chptr);
|
||||
if ((*chptr != '\0') || (endDelay < 0.0)) {
|
||||
testPrintE("Invalid command-line specified end of test delay "
|
||||
"of: %s", optarg);
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
|
||||
case 's': // Starting reference color
|
||||
str = optarg;
|
||||
while (optind < argc) {
|
||||
if (*argv[optind] == '-') { break; }
|
||||
char endChar = (str.length() > 1) ? str[str.length() - 1] : 0;
|
||||
if ((endChar == '>') || (endChar == ']')) { break; }
|
||||
str += " " + string(argv[optind++]);
|
||||
}
|
||||
{
|
||||
istringstream in(str);
|
||||
startRefColor = hwcTestParseColor(in, error);
|
||||
// Any parse error or characters not used by parser
|
||||
if (error
|
||||
|| (((unsigned int) in.tellg() != in.str().length())
|
||||
&& (in.tellg() != (streampos) -1))) {
|
||||
testPrintE("Invalid command-line specified start "
|
||||
"reference color of: %s", str.c_str());
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'e': // Ending reference color
|
||||
str = optarg;
|
||||
while (optind < argc) {
|
||||
if (*argv[optind] == '-') { break; }
|
||||
char endChar = (str.length() > 1) ? str[str.length() - 1] : 0;
|
||||
if ((endChar == '>') || (endChar == ']')) { break; }
|
||||
str += " " + string(argv[optind++]);
|
||||
}
|
||||
{
|
||||
istringstream in(str);
|
||||
endRefColor = hwcTestParseColor(in, error);
|
||||
// Any parse error or characters not used by parser
|
||||
if (error
|
||||
|| (((unsigned int) in.tellg() != in.str().length())
|
||||
&& (in.tellg() != (streampos) -1))) {
|
||||
testPrintE("Invalid command-line specified end "
|
||||
"reference color of: %s", str.c_str());
|
||||
exit(3);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'r': // Reference graphic format
|
||||
refFormat = hwcTestGraphicFormatLookup(optarg);
|
||||
if (refFormat == NULL) {
|
||||
testPrintE("Unkown command-line specified reference graphic "
|
||||
"format of: %s", optarg);
|
||||
printSyntax(basename(argv[0]));
|
||||
exit(4);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'v': // Verbose
|
||||
verbose = true;
|
||||
break;
|
||||
|
||||
case 'h': // Help
|
||||
case '?':
|
||||
default:
|
||||
printSyntax(basename(argv[0]));
|
||||
exit(((optopt == 0) || (optopt == '?')) ? 0 : 5);
|
||||
}
|
||||
}
|
||||
|
||||
// Expect a single positional parameter, which specifies the
|
||||
// equivalence graphic format.
|
||||
if (argc != (optind + 1)) {
|
||||
testPrintE("Expected a single command-line postional parameter");
|
||||
printSyntax(basename(argv[0]));
|
||||
exit(6);
|
||||
}
|
||||
equivFormat = hwcTestGraphicFormatLookup(argv[optind]);
|
||||
if (equivFormat == NULL) {
|
||||
testPrintE("Unkown command-line specified equivalence graphic "
|
||||
"format of: %s", argv[optind]);
|
||||
printSyntax(basename(argv[0]));
|
||||
exit(7);
|
||||
}
|
||||
|
||||
testPrintI("refFormat: %u %s", refFormat->format, refFormat->desc);
|
||||
testPrintI("equivFormat: %u %s", equivFormat->format, equivFormat->desc);
|
||||
testPrintI("startRefColor: %s", ((string) startRefColor).c_str());
|
||||
testPrintI("endRefColor: %s", ((string) endRefColor).c_str());
|
||||
testPrintI("endDelay: %f", endDelay);
|
||||
|
||||
// Stop framework
|
||||
rv = snprintf(cmd, sizeof(cmd), "%s", CMD_STOP_FRAMEWORK);
|
||||
if (rv >= (signed) sizeof(cmd) - 1) {
|
||||
testPrintE("Command too long for: %s", CMD_STOP_FRAMEWORK);
|
||||
exit(8);
|
||||
}
|
||||
testExecCmd(cmd);
|
||||
testDelay(1.0); // TODO - needs means to query whether asynchronous stop
|
||||
// framework operation has completed. For now, just wait
|
||||
// a long time.
|
||||
|
||||
init();
|
||||
|
||||
// Use the upper third of the display for the reference frame and
|
||||
// the middle third for the equivalence frame.
|
||||
unsigned int refHeight = height / 3;
|
||||
unsigned int refPosX = 0; // Reference frame X position
|
||||
unsigned int refWidth = width - refPosX;
|
||||
if ((refWidth & refFormat->wMod) != 0) {
|
||||
refWidth += refFormat->wMod - (refWidth % refFormat->wMod);
|
||||
}
|
||||
unsigned int equivHeight = height / 3;
|
||||
unsigned int equivPosX = 0; // Equivalence frame X position
|
||||
unsigned int equivWidth = width - equivPosX;
|
||||
if ((equivWidth & equivFormat->wMod) != 0) {
|
||||
equivWidth += equivFormat->wMod - (equivWidth % equivFormat->wMod);
|
||||
}
|
||||
|
||||
// Create reference and equivalence graphic buffers
|
||||
const unsigned int numFrames = 2;
|
||||
sp<GraphicBuffer> refFrame;
|
||||
refFrame = new GraphicBuffer(refWidth, refHeight,
|
||||
refFormat->format, texUsage);
|
||||
if ((rv = refFrame->initCheck()) != NO_ERROR) {
|
||||
testPrintE("refFrame initCheck failed, rv: %i", rv);
|
||||
testPrintE(" width %u height: %u format: %u %s", refWidth, refHeight,
|
||||
refFormat->format,
|
||||
hwcTestGraphicFormat2str(refFormat->format));
|
||||
exit(9);
|
||||
}
|
||||
testPrintI("refFrame width: %u height: %u format: %u %s",
|
||||
refWidth, refHeight, refFormat->format,
|
||||
hwcTestGraphicFormat2str(refFormat->format));
|
||||
|
||||
sp<GraphicBuffer> equivFrame;
|
||||
equivFrame = new GraphicBuffer(equivWidth, equivHeight,
|
||||
equivFormat->format, texUsage);
|
||||
if ((rv = refFrame->initCheck()) != NO_ERROR) {
|
||||
testPrintE("refFrame initCheck failed, rv: %i", rv);
|
||||
testPrintE(" width %u height: %u format: %u %s", refWidth, refHeight,
|
||||
refFormat->format,
|
||||
hwcTestGraphicFormat2str(refFormat->format));
|
||||
exit(10);
|
||||
}
|
||||
testPrintI("equivFrame width: %u height: %u format: %u %s",
|
||||
equivWidth, equivHeight, equivFormat->format,
|
||||
hwcTestGraphicFormat2str(equivFormat->format));
|
||||
|
||||
// Fill the frames with a horizontal blend
|
||||
hwcTestFillColorHBlend(refFrame.get(), refFormat->format,
|
||||
startRefColor, endRefColor);
|
||||
hwcTestFillColorHBlend(equivFrame.get(), refFormat->format,
|
||||
startRefColor, endRefColor);
|
||||
|
||||
hwc_display_contents_1_t *list;
|
||||
size_t size = sizeof(hwc_display_contents_1_t) + numFrames * sizeof(hwc_layer_1_t);
|
||||
if ((list = (hwc_display_contents_1_t *) calloc(1, size)) == NULL) {
|
||||
testPrintE("Allocate list failed");
|
||||
exit(11);
|
||||
}
|
||||
list->flags = HWC_GEOMETRY_CHANGED;
|
||||
list->numHwLayers = numFrames;
|
||||
|
||||
hwc_layer_1_t *layer = &list->hwLayers[0];
|
||||
layer->handle = refFrame->handle;
|
||||
layer->blending = HWC_BLENDING_NONE;
|
||||
layer->sourceCrop.left = 0;
|
||||
layer->sourceCrop.top = 0;
|
||||
layer->sourceCrop.right = width;
|
||||
layer->sourceCrop.bottom = refHeight;
|
||||
layer->displayFrame.left = 0;
|
||||
layer->displayFrame.top = 0;
|
||||
layer->displayFrame.right = width;
|
||||
layer->displayFrame.bottom = refHeight;
|
||||
layer->visibleRegionScreen.numRects = 1;
|
||||
layer->visibleRegionScreen.rects = &layer->displayFrame;
|
||||
|
||||
layer++;
|
||||
layer->handle = equivFrame->handle;
|
||||
layer->blending = HWC_BLENDING_NONE;
|
||||
layer->sourceCrop.left = 0;
|
||||
layer->sourceCrop.top = 0;
|
||||
layer->sourceCrop.right = width;
|
||||
layer->sourceCrop.bottom = equivHeight;
|
||||
layer->displayFrame.left = 0;
|
||||
layer->displayFrame.top = refHeight;
|
||||
layer->displayFrame.right = width;
|
||||
layer->displayFrame.bottom = layer->displayFrame.top + equivHeight;
|
||||
layer->visibleRegionScreen.numRects = 1;
|
||||
layer->visibleRegionScreen.rects = &layer->displayFrame;
|
||||
|
||||
// Perform prepare operation
|
||||
if (verbose) { testPrintI("Prepare:"); hwcTestDisplayList(list); }
|
||||
hwcDevice->prepare(hwcDevice, 1, &list);
|
||||
if (verbose) {
|
||||
testPrintI("Post Prepare:");
|
||||
hwcTestDisplayListPrepareModifiable(list);
|
||||
}
|
||||
|
||||
// Turn off the geometry changed flag
|
||||
list->flags &= ~HWC_GEOMETRY_CHANGED;
|
||||
|
||||
if (verbose) {hwcTestDisplayListHandles(list); }
|
||||
list->dpy = dpy;
|
||||
list->sur = surface;
|
||||
hwcDevice->set(hwcDevice, 1, &list);
|
||||
|
||||
testDelay(endDelay);
|
||||
|
||||
// Start framework
|
||||
rv = snprintf(cmd, sizeof(cmd), "%s", CMD_START_FRAMEWORK);
|
||||
if (rv >= (signed) sizeof(cmd) - 1) {
|
||||
testPrintE("Command too long for: %s", CMD_START_FRAMEWORK);
|
||||
exit(12);
|
||||
}
|
||||
testExecCmd(cmd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void init(void)
|
||||
{
|
||||
// Seed pseudo random number generator
|
||||
// Seeding causes fill horizontal blend to fill the pad area with
|
||||
// a deterministic set of values.
|
||||
srand48(0);
|
||||
|
||||
hwcTestInitDisplay(verbose, &dpy, &surface, &width, &height);
|
||||
|
||||
hwcTestOpenHwc(&hwcDevice);
|
||||
}
|
||||
|
||||
void printSyntax(const char *cmd)
|
||||
{
|
||||
testPrintE(" %s [options] graphicFormat", cmd);
|
||||
testPrintE(" options:");
|
||||
testPrintE(" -s <0.##, 0.##, 0.##> - Starting reference color");
|
||||
testPrintE(" -e <0.##, 0.##, 0.##> - Ending reference color");
|
||||
testPrintE(" -r format - Reference graphic format");
|
||||
testPrintE(" -D #.## - End of test delay");
|
||||
testPrintE(" -v Verbose");
|
||||
testPrintE("");
|
||||
testPrintE(" graphic formats:");
|
||||
for (unsigned int n1 = 0; n1 < NUMA(hwcTestGraphicFormat); n1++) {
|
||||
testPrintE(" %s", hwcTestGraphicFormat[n1].desc);
|
||||
}
|
||||
}
|
1558
android/frameworks/native/opengl/tests/hwc/hwcCommit.cpp
Normal file
1558
android/frameworks/native/opengl/tests/hwc/hwcCommit.cpp
Normal file
File diff suppressed because it is too large
Load diff
575
android/frameworks/native/opengl/tests/hwc/hwcRects.cpp
Normal file
575
android/frameworks/native/opengl/tests/hwc/hwcRects.cpp
Normal file
|
@ -0,0 +1,575 @@
|
|||
/*
|
||||
* Copyright (C) 2011 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Hardware Composer Rectangles
|
||||
*
|
||||
* Synopsis
|
||||
* hwcRects [options] (graphicFormat displayFrame [attributes],)...
|
||||
* options:
|
||||
* -D #.## - End of test delay
|
||||
* -v - Verbose
|
||||
*
|
||||
* graphic formats:
|
||||
* RGBA8888 (reference frame default)
|
||||
* RGBX8888
|
||||
* RGB888
|
||||
* RGB565
|
||||
* BGRA8888
|
||||
* RGBA5551
|
||||
* RGBA4444
|
||||
* YV12
|
||||
*
|
||||
* displayFrame
|
||||
* [left, top, right, bottom]
|
||||
*
|
||||
* attributes:
|
||||
* transform: none | fliph | flipv | rot90 | rot180 | rot270
|
||||
* blend: none | premult | coverage
|
||||
* color: [0.##, 0.##, 0.##]
|
||||
* alpha: 0.##
|
||||
* sourceDim: [width, height]
|
||||
* sourceCrop: [left, top, right, bottom]
|
||||
*
|
||||
* Example:
|
||||
* # White YV12 rectangle, with overlapping turquoise
|
||||
* # RGBA8888 rectangle at 30%% (alpha: 0.7) transparency
|
||||
* hwcRects -v -D 30.0 \
|
||||
* YV12 [50, 80, 200, 300] transform: none \
|
||||
* color: [1.0, 0.5, 0.5], \
|
||||
* RGBA8888 [100, 150, 300, 400] blend: coverage \
|
||||
* color: [0.251, 0.878, 0.816] alpha: 0.7 \
|
||||
* sourceDim: [50, 60] sourceCrop: [5, 8, 12, 15]
|
||||
*
|
||||
* Description
|
||||
* Constructs a Hardware Composer (HWC) list of frames from
|
||||
* command-line specified parameters. Then sends it to the HWC
|
||||
* be rendered. The intended purpose of this tool is as a means to
|
||||
* reproduce and succinctly specify an observed HWC operation, with
|
||||
* no need to modify/compile a program.
|
||||
*
|
||||
* The command-line syntax consists of a few standard command-line
|
||||
* options and then a description of one or more frames. The frame
|
||||
* descriptions are separated from one another via a comma. The
|
||||
* beginning of a frame description requires the specification
|
||||
* of the graphic format and then the display frame rectangle where
|
||||
* the frame will be displayed. The display frame rectangle is
|
||||
* specified as follows, with the right and bottom coordinates being
|
||||
* exclusive values:
|
||||
*
|
||||
* [left, top, right, bottom]
|
||||
*
|
||||
* After these two required parameters each frame description can
|
||||
* specify 1 or more optional attributes. The name of each optional
|
||||
* attribute is preceded by a colon. The current implementation
|
||||
* then requires white space after the colon and then the value of
|
||||
* the attribute is specified. See the synopsis section above for
|
||||
* a list of attributes and the format of their expected value.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "hwcRectsTest"
|
||||
|
||||
#include <algorithm>
|
||||
#include <assert.h>
|
||||
#include <cerrno>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <istream>
|
||||
#include <libgen.h>
|
||||
#include <list>
|
||||
#include <sched.h>
|
||||
#include <sstream>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include <EGL/egl.h>
|
||||
#include <EGL/eglext.h>
|
||||
#include <GLES2/gl2.h>
|
||||
#include <GLES2/gl2ext.h>
|
||||
|
||||
#include <ui/GraphicBuffer.h>
|
||||
#include <utils/Log.h>
|
||||
#include <testUtil.h>
|
||||
|
||||
#include <hardware/hwcomposer.h>
|
||||
|
||||
#include <glTestLib.h>
|
||||
#include "hwcTestLib.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace android;
|
||||
|
||||
// Defaults
|
||||
const bool defaultVerbose = false;
|
||||
const float defaultEndDelay = 2.0; // Default delay after rendering graphics
|
||||
|
||||
const uint32_t defaultFormat = HAL_PIXEL_FORMAT_RGBA_8888;
|
||||
const int32_t defaultTransform = 0;
|
||||
const uint32_t defaultBlend = HWC_BLENDING_NONE;
|
||||
const ColorFract defaultColor(0.5, 0.5, 0.5);
|
||||
const float defaultAlpha = 1.0; // Opaque
|
||||
const HwcTestDim defaultSourceDim(1, 1);
|
||||
const struct hwc_rect defaultSourceCrop = {0, 0, 1, 1};
|
||||
const struct hwc_rect defaultDisplayFrame = {0, 0, 100, 100};
|
||||
|
||||
// Defines
|
||||
#define MAXCMD 200
|
||||
#define CMD_STOP_FRAMEWORK "stop 2>&1"
|
||||
#define CMD_START_FRAMEWORK "start 2>&1"
|
||||
|
||||
// Macros
|
||||
#define NUMA(a) (sizeof(a) / sizeof((a)[0])) // Num elements in an array
|
||||
|
||||
// Local types
|
||||
class Rectangle {
|
||||
public:
|
||||
Rectangle() : format(defaultFormat), transform(defaultTransform),
|
||||
blend(defaultBlend), color(defaultColor),
|
||||
alpha(defaultAlpha), sourceDim(defaultSourceDim),
|
||||
sourceCrop(defaultSourceCrop),
|
||||
displayFrame(defaultDisplayFrame) {};
|
||||
|
||||
uint32_t format;
|
||||
uint32_t transform;
|
||||
int32_t blend;
|
||||
ColorFract color;
|
||||
float alpha;
|
||||
HwcTestDim sourceDim;
|
||||
struct hwc_rect sourceCrop;
|
||||
struct hwc_rect displayFrame;
|
||||
|
||||
sp<GraphicBuffer> texture;
|
||||
};
|
||||
|
||||
// Globals
|
||||
list<Rectangle> rectangle;
|
||||
static const int texUsage = GraphicBuffer::USAGE_HW_TEXTURE |
|
||||
GraphicBuffer::USAGE_SW_WRITE_RARELY;
|
||||
static hwc_composer_device_1_t *hwcDevice;
|
||||
static EGLDisplay dpy;
|
||||
static EGLSurface surface;
|
||||
static EGLint width, height;
|
||||
|
||||
// Function prototypes
|
||||
static Rectangle parseRect(string rectStr);
|
||||
void init(void);
|
||||
void printSyntax(const char *cmd);
|
||||
|
||||
// Command-line option settings
|
||||
static bool verbose = defaultVerbose;
|
||||
static float endDelay = defaultEndDelay;
|
||||
|
||||
/*
|
||||
* Main
|
||||
*
|
||||
* Performs the following high-level sequence of operations:
|
||||
*
|
||||
* 1. Parse command-line options
|
||||
*
|
||||
* 2. Stop framework
|
||||
*
|
||||
* 3. Initialization
|
||||
*
|
||||
* 4. Parse frame descriptions
|
||||
*
|
||||
* 5. Create HWC list from frame descriptions
|
||||
*
|
||||
* 6. Have HWC render the list description of the frames
|
||||
*
|
||||
* 7. Delay for amount of time given by endDelay
|
||||
*
|
||||
* 8. Start framework
|
||||
*/
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int rv, opt;
|
||||
char *chptr;
|
||||
string str;
|
||||
char cmd[MAXCMD];
|
||||
|
||||
testSetLogCatTag(LOG_TAG);
|
||||
|
||||
// Parse command line arguments
|
||||
while ((opt = getopt(argc, argv, "D:v?h")) != -1) {
|
||||
switch (opt) {
|
||||
case 'D': // End of test delay
|
||||
endDelay = strtod(optarg, &chptr);
|
||||
if ((*chptr != '\0') || (endDelay < 0.0)) {
|
||||
testPrintE("Invalid command-line specified end of test delay "
|
||||
"of: %s", optarg);
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'v': // Verbose
|
||||
verbose = true;
|
||||
break;
|
||||
|
||||
case 'h': // Help
|
||||
case '?':
|
||||
default:
|
||||
printSyntax(basename(argv[0]));
|
||||
exit(((optopt == 0) || (optopt == '?')) ? 0 : 2);
|
||||
}
|
||||
}
|
||||
|
||||
// Stop framework
|
||||
rv = snprintf(cmd, sizeof(cmd), "%s", CMD_STOP_FRAMEWORK);
|
||||
if (rv >= (signed) sizeof(cmd) - 1) {
|
||||
testPrintE("Command too long for: %s", CMD_STOP_FRAMEWORK);
|
||||
exit(3);
|
||||
}
|
||||
testExecCmd(cmd);
|
||||
testDelay(1.0); // TODO - needs means to query whether asyncronous stop
|
||||
// framework operation has completed. For now, just wait
|
||||
// a long time.
|
||||
|
||||
init();
|
||||
|
||||
// Parse rectangle descriptions
|
||||
int numOpen = 0; // Current number of unmatched <[
|
||||
string rectDesc(""); // String description of a single rectangle
|
||||
while (optind < argc) {
|
||||
string argNext = string(argv[optind++]);
|
||||
|
||||
if (rectDesc.length()) { rectDesc += ' '; }
|
||||
rectDesc += argNext;
|
||||
|
||||
// Count number of opening <[ and matching >]
|
||||
// At this point not worried about an opening character being
|
||||
// matched by it's corresponding closing character. For example,
|
||||
// "<1.0, 2.0]" is incorrect because the opening < should be matched
|
||||
// with a closing >, instead of the closing ]. Such errors are
|
||||
// detected when the actual value is parsed.
|
||||
for (unsigned int n1 = 0; n1 < argNext.length(); n1++) {
|
||||
switch(argNext[n1]) {
|
||||
case '[':
|
||||
case '<':
|
||||
numOpen++;
|
||||
break;
|
||||
|
||||
case ']':
|
||||
case '>':
|
||||
numOpen--;
|
||||
break;
|
||||
}
|
||||
|
||||
// Error anytime there is more closing then opening characters
|
||||
if (numOpen < 0) {
|
||||
testPrintI("Mismatched number of opening <[ with "
|
||||
"closing >] in: %s", rectDesc.c_str());
|
||||
exit(4);
|
||||
}
|
||||
}
|
||||
|
||||
// Description of a rectangle is complete when all opening
|
||||
// <[ are closed with >] and the string ends with a comma or
|
||||
// there are no more args.
|
||||
if ((numOpen == 0) && rectDesc.length()
|
||||
&& ((rectDesc[rectDesc.length() - 1] == ',')
|
||||
|| (optind == argc))) {
|
||||
// Remove trailing comma if it is present
|
||||
if (rectDesc[rectDesc.length() - 1] == ',') {
|
||||
rectDesc.erase(rectDesc.length() - 1);
|
||||
}
|
||||
|
||||
// Parse string description of rectangle
|
||||
Rectangle rect = parseRect(rectDesc);
|
||||
|
||||
// Add to the list of rectangles
|
||||
rectangle.push_back(rect);
|
||||
|
||||
// Prepare for description of another rectangle
|
||||
rectDesc = string("");
|
||||
}
|
||||
}
|
||||
|
||||
// Create list of frames
|
||||
hwc_display_contents_1_t *list;
|
||||
list = hwcTestCreateLayerList(rectangle.size());
|
||||
if (list == NULL) {
|
||||
testPrintE("hwcTestCreateLayerList failed");
|
||||
exit(5);
|
||||
}
|
||||
|
||||
hwc_layer_1_t *layer = &list->hwLayers[0];
|
||||
for (std::list<Rectangle>::iterator it = rectangle.begin();
|
||||
it != rectangle.end(); ++it, ++layer) {
|
||||
layer->handle = it->texture->handle;
|
||||
layer->blending = it->blend;
|
||||
layer->transform = it->transform;
|
||||
layer->sourceCrop = it->sourceCrop;
|
||||
layer->displayFrame = it->displayFrame;
|
||||
|
||||
layer->visibleRegionScreen.numRects = 1;
|
||||
layer->visibleRegionScreen.rects = &layer->displayFrame;
|
||||
}
|
||||
|
||||
// Perform prepare operation
|
||||
if (verbose) { testPrintI("Prepare:"); hwcTestDisplayList(list); }
|
||||
hwcDevice->prepare(hwcDevice, 1, &list);
|
||||
if (verbose) {
|
||||
testPrintI("Post Prepare:");
|
||||
hwcTestDisplayListPrepareModifiable(list);
|
||||
}
|
||||
|
||||
// Turn off the geometry changed flag
|
||||
list->flags &= ~HWC_GEOMETRY_CHANGED;
|
||||
|
||||
// Perform the set operation(s)
|
||||
if (verbose) {testPrintI("Set:"); }
|
||||
if (verbose) { hwcTestDisplayListHandles(list); }
|
||||
list->dpy = dpy;
|
||||
list->sur = surface;
|
||||
hwcDevice->set(hwcDevice, 1, &list);
|
||||
|
||||
testDelay(endDelay);
|
||||
|
||||
// Start framework
|
||||
rv = snprintf(cmd, sizeof(cmd), "%s", CMD_START_FRAMEWORK);
|
||||
if (rv >= (signed) sizeof(cmd) - 1) {
|
||||
testPrintE("Command too long for: %s", CMD_START_FRAMEWORK);
|
||||
exit(6);
|
||||
}
|
||||
testExecCmd(cmd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Parse string description of rectangle and add it to list of rectangles
|
||||
// to be rendered.
|
||||
static Rectangle parseRect(string rectStr)
|
||||
{
|
||||
int rv;
|
||||
string str;
|
||||
bool error;
|
||||
istringstream in(rectStr);
|
||||
const struct hwcTestGraphicFormat *format;
|
||||
Rectangle rect;
|
||||
|
||||
// Graphic Format
|
||||
in >> str;
|
||||
if (!in) {
|
||||
testPrintE("Error parsing format from: %s", rectStr.c_str());
|
||||
exit(20);
|
||||
}
|
||||
format = hwcTestGraphicFormatLookup(str.c_str());
|
||||
if (format == NULL) {
|
||||
testPrintE("Unknown graphic format in: %s", rectStr.c_str());
|
||||
exit(21);
|
||||
}
|
||||
rect.format = format->format;
|
||||
|
||||
// Display Frame
|
||||
rect.displayFrame = hwcTestParseHwcRect(in, error);
|
||||
if (error) {
|
||||
testPrintE("Invalid display frame in: %s", rectStr.c_str());
|
||||
exit(22);
|
||||
}
|
||||
|
||||
// Set default sourceDim and sourceCrop based on size of display frame.
|
||||
// Default is source size equal to the size of the display frame, with
|
||||
// the source crop being the entire size of the source frame.
|
||||
rect.sourceDim = HwcTestDim(rect.displayFrame.right
|
||||
- rect.displayFrame.left,
|
||||
rect.displayFrame.bottom
|
||||
- rect.displayFrame.top);
|
||||
rect.sourceCrop.left = 0;
|
||||
rect.sourceCrop.top = 0;
|
||||
rect.sourceCrop.right = rect.sourceDim.width();
|
||||
rect.sourceCrop.bottom = rect.sourceDim.height();
|
||||
|
||||
// Optional settings
|
||||
while ((in.tellg() < (streampos) in.str().length())
|
||||
&& (in.tellg() != (streampos) -1)) {
|
||||
string attrName;
|
||||
|
||||
in >> attrName;
|
||||
if (in.eof()) { break; }
|
||||
if (!in) {
|
||||
testPrintE("Error reading attribute name in: %s",
|
||||
rectStr.c_str());
|
||||
exit(23);
|
||||
}
|
||||
|
||||
// Transform
|
||||
if (attrName == "transform:") { // Transform
|
||||
string str;
|
||||
|
||||
in >> str;
|
||||
if (str == "none") {
|
||||
rect.transform = 0;
|
||||
} else if (str == "fliph") {
|
||||
rect.transform = HWC_TRANSFORM_FLIP_H;
|
||||
} else if (str == "flipv") {
|
||||
rect.transform = HWC_TRANSFORM_FLIP_V;
|
||||
} else if (str == "rot90") {
|
||||
rect.transform = HWC_TRANSFORM_ROT_90;
|
||||
} else if (str == "rot180") {
|
||||
rect.transform = HWC_TRANSFORM_ROT_180;
|
||||
} else if (str == "rot270") {
|
||||
rect.transform = HWC_TRANSFORM_ROT_270;
|
||||
} else {
|
||||
testPrintE("Unknown transform of \"%s\" in: %s", str.c_str(),
|
||||
rectStr.c_str());
|
||||
exit(24);
|
||||
}
|
||||
} else if (attrName == "blend:") { // Blend
|
||||
string str;
|
||||
|
||||
in >> str;
|
||||
if (str == string("none")) {
|
||||
rect.blend = HWC_BLENDING_NONE;
|
||||
} else if (str == "premult") {
|
||||
rect.blend = HWC_BLENDING_PREMULT;
|
||||
} else if (str == "coverage") {
|
||||
rect.blend = HWC_BLENDING_COVERAGE;
|
||||
} else {
|
||||
testPrintE("Unknown blend of \"%s\" in: %s", str.c_str(),
|
||||
rectStr.c_str());
|
||||
exit(25);
|
||||
}
|
||||
} else if (attrName == "color:") { // Color
|
||||
rect.color = hwcTestParseColor(in, error);
|
||||
if (error) {
|
||||
testPrintE("Error parsing color in: %s", rectStr.c_str());
|
||||
exit(26);
|
||||
}
|
||||
} else if (attrName == "alpha:") { // Alpha
|
||||
in >> rect.alpha;
|
||||
if (!in) {
|
||||
testPrintE("Error parsing value for alpha attribute in: %s",
|
||||
rectStr.c_str());
|
||||
exit(27);
|
||||
}
|
||||
} else if (attrName == "sourceDim:") { // Source Dimension
|
||||
rect.sourceDim = hwcTestParseDim(in, error);
|
||||
if (error) {
|
||||
testPrintE("Error parsing source dimenision in: %s",
|
||||
rectStr.c_str());
|
||||
exit(28);
|
||||
}
|
||||
} else if (attrName == "sourceCrop:") { // Source Crop
|
||||
rect.sourceCrop = hwcTestParseHwcRect(in, error);
|
||||
if (error) {
|
||||
testPrintE("Error parsing source crop in: %s",
|
||||
rectStr.c_str());
|
||||
exit(29);
|
||||
}
|
||||
} else { // Unknown attribute
|
||||
testPrintE("Unknown attribute of \"%s\" in: %s", attrName.c_str(),
|
||||
rectStr.c_str());
|
||||
exit(30);
|
||||
}
|
||||
}
|
||||
|
||||
// Validate
|
||||
if (((uint32_t) rect.sourceCrop.left >= rect.sourceDim.width())
|
||||
|| ((uint32_t) rect.sourceCrop.right > rect.sourceDim.width())
|
||||
|| ((uint32_t) rect.sourceCrop.top >= rect.sourceDim.height())
|
||||
|| ((uint32_t) rect.sourceCrop.bottom > rect.sourceDim.height())) {
|
||||
testPrintE("Invalid source crop in: %s", rectStr.c_str());
|
||||
exit(31);
|
||||
}
|
||||
if ((rect.displayFrame.left >= width)
|
||||
|| (rect.displayFrame.right > width)
|
||||
|| (rect.displayFrame.top >= height)
|
||||
|| (rect.displayFrame.bottom > height)) {
|
||||
testPrintE("Invalid display frame in: %s", rectStr.c_str());
|
||||
exit(32);
|
||||
}
|
||||
if ((rect.alpha < 0.0) || (rect.alpha > 1.0)) {
|
||||
testPrintE("Invalid alpha in: %s", rectStr.c_str());
|
||||
exit(33);
|
||||
}
|
||||
|
||||
// Create source texture
|
||||
rect.texture = new GraphicBuffer(rect.sourceDim.width(),
|
||||
rect.sourceDim.height(),
|
||||
rect.format, texUsage);
|
||||
if ((rv = rect.texture->initCheck()) != NO_ERROR) {
|
||||
testPrintE("source texture initCheck failed, rv: %i", rv);
|
||||
testPrintE(" %s", rectStr.c_str());
|
||||
|
||||
}
|
||||
|
||||
// Fill with uniform color
|
||||
hwcTestFillColor(rect.texture.get(), rect.color, rect.alpha);
|
||||
if (verbose) {
|
||||
testPrintI(" buf: %p handle: %p format: %s width: %u height: %u "
|
||||
"color: %s alpha: %f",
|
||||
rect.texture.get(), rect.texture->handle, format->desc,
|
||||
rect.sourceDim.width(), rect.sourceDim.height(),
|
||||
string(rect.color).c_str(), rect.alpha);
|
||||
}
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
||||
void init(void)
|
||||
{
|
||||
// Seed pseudo random number generator
|
||||
// Needed so that the pad areas of frames are filled with a deterministic
|
||||
// pseudo random value.
|
||||
srand48(0);
|
||||
|
||||
hwcTestInitDisplay(verbose, &dpy, &surface, &width, &height);
|
||||
|
||||
hwcTestOpenHwc(&hwcDevice);
|
||||
}
|
||||
|
||||
void printSyntax(const char *cmd)
|
||||
{
|
||||
testPrintE(" %s [options] (graphicFormat displayFrame [attributes],)...",
|
||||
cmd);
|
||||
testPrintE(" options:");
|
||||
testPrintE(" -D End of test delay");
|
||||
testPrintE(" -v Verbose");
|
||||
testPrintE("");
|
||||
testPrintE(" graphic formats:");
|
||||
for (unsigned int n1 = 0; n1 < NUMA(hwcTestGraphicFormat); n1++) {
|
||||
testPrintE(" %s", hwcTestGraphicFormat[n1].desc);
|
||||
}
|
||||
testPrintE("");
|
||||
testPrintE(" displayFrame");
|
||||
testPrintE(" [left, top, right, bottom]");
|
||||
testPrintE("");
|
||||
testPrintE(" attributes:");
|
||||
testPrintE(" transform: none | fliph | flipv | rot90 | rot180 "
|
||||
" | rot270");
|
||||
testPrintE(" blend: none | premult | coverage");
|
||||
testPrintE(" color: [0.##, 0.##, 0.##]");
|
||||
testPrintE(" alpha: 0.##");
|
||||
testPrintE(" sourceDim: [width, height]");
|
||||
testPrintE(" sourceCrop: [left, top, right, bottom]");
|
||||
testPrintE("");
|
||||
testPrintE(" Example:");
|
||||
testPrintE(" # White YV12 rectangle, with overlapping turquoise ");
|
||||
testPrintE(" # RGBA8888 rectangle at 30%% (alpha: 0.7) transparency");
|
||||
testPrintE(" %s -v -D 30.0 \\", cmd);
|
||||
testPrintE(" YV12 [50, 80, 200, 300] transform: none \\");
|
||||
testPrintE(" color: [1.0, 0.5, 0.5], \\");
|
||||
testPrintE(" RGBA8888 [100, 150, 300, 400] blend: coverage \\");
|
||||
testPrintE(" color: [0.251, 0.878, 0.816] alpha: 0.7 \\");
|
||||
testPrintE(" sourceDim: [50, 60] sourceCrop: [5, 8, 12, 15]");
|
||||
}
|
646
android/frameworks/native/opengl/tests/hwc/hwcStress.cpp
Normal file
646
android/frameworks/native/opengl/tests/hwc/hwcStress.cpp
Normal file
|
@ -0,0 +1,646 @@
|
|||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Hardware Composer stress test
|
||||
*
|
||||
* Performs a pseudo-random (prandom) sequence of operations to the
|
||||
* Hardware Composer (HWC), for a specified number of passes or for
|
||||
* a specified period of time. By default the period of time is FLT_MAX,
|
||||
* so that the number of passes will take precedence.
|
||||
*
|
||||
* The passes are grouped together, where (pass / passesPerGroup) specifies
|
||||
* which group a particular pass is in. This causes every passesPerGroup
|
||||
* worth of sequential passes to be within the same group. Computationally
|
||||
* intensive operations are performed just once at the beginning of a group
|
||||
* of passes and then used by all the passes in that group. This is done
|
||||
* so as to increase both the average and peak rate of graphic operations,
|
||||
* by moving computationally intensive operations to the beginning of a group.
|
||||
* In particular, at the start of each group of passes a set of
|
||||
* graphic buffers are created, then used by the first and remaining
|
||||
* passes of that group of passes.
|
||||
*
|
||||
* The per-group initialization of the graphic buffers is performed
|
||||
* by a function called initFrames. This function creates an array
|
||||
* of smart pointers to the graphic buffers, in the form of a vector
|
||||
* of vectors. The array is accessed in row major order, so each
|
||||
* row is a vector of smart pointers. All the pointers of a single
|
||||
* row point to graphic buffers which use the same pixel format and
|
||||
* have the same dimension, although it is likely that each one is
|
||||
* filled with a different color. This is done so that after doing
|
||||
* the first HWC prepare then set call, subsequent set calls can
|
||||
* be made with each of the layer handles changed to a different
|
||||
* graphic buffer within the same row. Since the graphic buffers
|
||||
* in a particular row have the same pixel format and dimension,
|
||||
* additional HWC set calls can be made, without having to perform
|
||||
* an HWC prepare call.
|
||||
*
|
||||
* This test supports the following command-line options:
|
||||
*
|
||||
* -v Verbose
|
||||
* -s num Starting pass
|
||||
* -e num Ending pass
|
||||
* -p num Execute the single pass specified by num
|
||||
* -n num Number of set operations to perform after each prepare operation
|
||||
* -t float Maximum time in seconds to execute the test
|
||||
* -d float Delay in seconds performed after each set operation
|
||||
* -D float Delay in seconds performed after the last pass is executed
|
||||
*
|
||||
* Typically the test is executed for a large range of passes. By default
|
||||
* passes 0 through 99999 (100,000 passes) are executed. Although this test
|
||||
* does not validate the generated image, at times it is useful to reexecute
|
||||
* a particular pass and leave the displayed image on the screen for an
|
||||
* extended period of time. This can be done either by setting the -s
|
||||
* and -e options to the desired pass, along with a large value for -D.
|
||||
* This can also be done via the -p option, again with a large value for
|
||||
* the -D options.
|
||||
*
|
||||
* So far this test only contains code to create graphic buffers with
|
||||
* a continuous solid color. Although this test is unable to validate the
|
||||
* image produced, any image that contains other than rectangles of a solid
|
||||
* color are incorrect. Note that the rectangles may use a transparent
|
||||
* color and have a blending operation that causes the color in overlapping
|
||||
* rectangles to be mixed. In such cases the overlapping portions may have
|
||||
* a different color from the rest of the rectangle.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "hwcStressTest"
|
||||
|
||||
#include <algorithm>
|
||||
#include <assert.h>
|
||||
#include <cerrno>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <libgen.h>
|
||||
#include <sched.h>
|
||||
#include <sstream>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include <EGL/egl.h>
|
||||
#include <EGL/eglext.h>
|
||||
#include <GLES2/gl2.h>
|
||||
#include <GLES2/gl2ext.h>
|
||||
|
||||
#include <ui/GraphicBuffer.h>
|
||||
|
||||
#include <utils/Log.h>
|
||||
#include <testUtil.h>
|
||||
|
||||
#include <hardware/hwcomposer.h>
|
||||
|
||||
#include <glTestLib.h>
|
||||
#include "hwcTestLib.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace android;
|
||||
|
||||
const float maxSizeRatio = 1.3; // Graphic buffers can be upto this munch
|
||||
// larger than the default screen size
|
||||
const unsigned int passesPerGroup = 10; // A group of passes all use the same
|
||||
// graphic buffers
|
||||
|
||||
// Ratios at which rare and frequent conditions should be produced
|
||||
const float rareRatio = 0.1;
|
||||
const float freqRatio = 0.9;
|
||||
|
||||
// Defaults for command-line options
|
||||
const bool defaultVerbose = false;
|
||||
const unsigned int defaultStartPass = 0;
|
||||
const unsigned int defaultEndPass = 99999;
|
||||
const unsigned int defaultPerPassNumSet = 10;
|
||||
const float defaultPerSetDelay = 0.0; // Default delay after each set
|
||||
// operation. Default delay of
|
||||
// zero used so as to perform the
|
||||
// the set operations as quickly
|
||||
// as possible.
|
||||
const float defaultEndDelay = 2.0; // Default delay between completion of
|
||||
// final pass and restart of framework
|
||||
const float defaultDuration = FLT_MAX; // A fairly long time, so that
|
||||
// range of passes will have
|
||||
// precedence
|
||||
|
||||
// Command-line option settings
|
||||
static bool verbose = defaultVerbose;
|
||||
static unsigned int startPass = defaultStartPass;
|
||||
static unsigned int endPass = defaultEndPass;
|
||||
static unsigned int numSet = defaultPerPassNumSet;
|
||||
static float perSetDelay = defaultPerSetDelay;
|
||||
static float endDelay = defaultEndDelay;
|
||||
static float duration = defaultDuration;
|
||||
|
||||
// Command-line mutual exclusion detection flags.
|
||||
// Corresponding flag set true once an option is used.
|
||||
bool eFlag, sFlag, pFlag;
|
||||
|
||||
#define MAXSTR 100
|
||||
#define MAXCMD 200
|
||||
#define BITSPERBYTE 8 // TODO: Obtain from <values.h>, once
|
||||
// it has been added
|
||||
|
||||
#define CMD_STOP_FRAMEWORK "stop 2>&1"
|
||||
#define CMD_START_FRAMEWORK "start 2>&1"
|
||||
|
||||
#define NUMA(a) (sizeof(a) / sizeof((a)[0]))
|
||||
#define MEMCLR(addr, size) do { \
|
||||
memset((addr), 0, (size)); \
|
||||
} while (0)
|
||||
|
||||
// File scope constants
|
||||
const unsigned int blendingOps[] = {
|
||||
HWC_BLENDING_NONE,
|
||||
HWC_BLENDING_PREMULT,
|
||||
HWC_BLENDING_COVERAGE,
|
||||
};
|
||||
const unsigned int layerFlags[] = {
|
||||
HWC_SKIP_LAYER,
|
||||
};
|
||||
const vector<unsigned int> vecLayerFlags(layerFlags,
|
||||
layerFlags + NUMA(layerFlags));
|
||||
|
||||
const unsigned int transformFlags[] = {
|
||||
HWC_TRANSFORM_FLIP_H,
|
||||
HWC_TRANSFORM_FLIP_V,
|
||||
HWC_TRANSFORM_ROT_90,
|
||||
// ROT_180 & ROT_270 intentionally not listed, because they
|
||||
// they are formed from combinations of the flags already listed.
|
||||
};
|
||||
const vector<unsigned int> vecTransformFlags(transformFlags,
|
||||
transformFlags + NUMA(transformFlags));
|
||||
|
||||
// File scope globals
|
||||
static const int texUsage = GraphicBuffer::USAGE_HW_TEXTURE |
|
||||
GraphicBuffer::USAGE_SW_WRITE_RARELY;
|
||||
static hwc_composer_device_1_t *hwcDevice;
|
||||
static EGLDisplay dpy;
|
||||
static EGLSurface surface;
|
||||
static EGLint width, height;
|
||||
static vector <vector <sp<GraphicBuffer> > > frames;
|
||||
|
||||
// File scope prototypes
|
||||
void init(void);
|
||||
void initFrames(unsigned int seed);
|
||||
template <class T> vector<T> vectorRandSelect(const vector<T>& vec, size_t num);
|
||||
template <class T> T vectorOr(const vector<T>& vec);
|
||||
|
||||
/*
|
||||
* Main
|
||||
*
|
||||
* Performs the following high-level sequence of operations:
|
||||
*
|
||||
* 1. Command-line parsing
|
||||
*
|
||||
* 2. Initialization
|
||||
*
|
||||
* 3. For each pass:
|
||||
*
|
||||
* a. If pass is first pass or in a different group from the
|
||||
* previous pass, initialize the array of graphic buffers.
|
||||
*
|
||||
* b. Create a HWC list with room to specify a prandomly
|
||||
* selected number of layers.
|
||||
*
|
||||
* c. Select a subset of the rows from the graphic buffer array,
|
||||
* such that there is a unique row to be used for each
|
||||
* of the layers in the HWC list.
|
||||
*
|
||||
* d. Prandomly fill in the HWC list with handles
|
||||
* selected from any of the columns of the selected row.
|
||||
*
|
||||
* e. Pass the populated list to the HWC prepare call.
|
||||
*
|
||||
* f. Pass the populated list to the HWC set call.
|
||||
*
|
||||
* g. If additional set calls are to be made, then for each
|
||||
* additional set call, select a new set of handles and
|
||||
* perform the set call.
|
||||
*/
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int rv, opt;
|
||||
char *chptr;
|
||||
unsigned int pass;
|
||||
char cmd[MAXCMD];
|
||||
struct timeval startTime, currentTime, delta;
|
||||
|
||||
testSetLogCatTag(LOG_TAG);
|
||||
|
||||
// Parse command line arguments
|
||||
while ((opt = getopt(argc, argv, "vp:d:D:n:s:e:t:?h")) != -1) {
|
||||
switch (opt) {
|
||||
case 'd': // Delay after each set operation
|
||||
perSetDelay = strtod(optarg, &chptr);
|
||||
if ((*chptr != '\0') || (perSetDelay < 0.0)) {
|
||||
testPrintE("Invalid command-line specified per pass delay of: "
|
||||
"%s", optarg);
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'D': // End of test delay
|
||||
// Delay between completion of final pass and restart
|
||||
// of framework
|
||||
endDelay = strtod(optarg, &chptr);
|
||||
if ((*chptr != '\0') || (endDelay < 0.0)) {
|
||||
testPrintE("Invalid command-line specified end of test delay "
|
||||
"of: %s", optarg);
|
||||
exit(2);
|
||||
}
|
||||
break;
|
||||
|
||||
case 't': // Duration
|
||||
duration = strtod(optarg, &chptr);
|
||||
if ((*chptr != '\0') || (duration < 0.0)) {
|
||||
testPrintE("Invalid command-line specified duration of: %s",
|
||||
optarg);
|
||||
exit(3);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'n': // Num set operations per pass
|
||||
numSet = strtoul(optarg, &chptr, 10);
|
||||
if (*chptr != '\0') {
|
||||
testPrintE("Invalid command-line specified num set per pass "
|
||||
"of: %s", optarg);
|
||||
exit(4);
|
||||
}
|
||||
break;
|
||||
|
||||
case 's': // Starting Pass
|
||||
sFlag = true;
|
||||
if (pFlag) {
|
||||
testPrintE("Invalid combination of command-line options.");
|
||||
testPrintE(" The -p option is mutually exclusive from the");
|
||||
testPrintE(" -s and -e options.");
|
||||
exit(5);
|
||||
}
|
||||
startPass = strtoul(optarg, &chptr, 10);
|
||||
if (*chptr != '\0') {
|
||||
testPrintE("Invalid command-line specified starting pass "
|
||||
"of: %s", optarg);
|
||||
exit(6);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'e': // Ending Pass
|
||||
eFlag = true;
|
||||
if (pFlag) {
|
||||
testPrintE("Invalid combination of command-line options.");
|
||||
testPrintE(" The -p option is mutually exclusive from the");
|
||||
testPrintE(" -s and -e options.");
|
||||
exit(7);
|
||||
}
|
||||
endPass = strtoul(optarg, &chptr, 10);
|
||||
if (*chptr != '\0') {
|
||||
testPrintE("Invalid command-line specified ending pass "
|
||||
"of: %s", optarg);
|
||||
exit(8);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'p': // Run a single specified pass
|
||||
pFlag = true;
|
||||
if (sFlag || eFlag) {
|
||||
testPrintE("Invalid combination of command-line options.");
|
||||
testPrintE(" The -p option is mutually exclusive from the");
|
||||
testPrintE(" -s and -e options.");
|
||||
exit(9);
|
||||
}
|
||||
startPass = endPass = strtoul(optarg, &chptr, 10);
|
||||
if (*chptr != '\0') {
|
||||
testPrintE("Invalid command-line specified pass of: %s",
|
||||
optarg);
|
||||
exit(10);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'v': // Verbose
|
||||
verbose = true;
|
||||
break;
|
||||
|
||||
case 'h': // Help
|
||||
case '?':
|
||||
default:
|
||||
testPrintE(" %s [options]", basename(argv[0]));
|
||||
testPrintE(" options:");
|
||||
testPrintE(" -p Execute specified pass");
|
||||
testPrintE(" -s Starting pass");
|
||||
testPrintE(" -e Ending pass");
|
||||
testPrintE(" -t Duration");
|
||||
testPrintE(" -d Delay after each set operation");
|
||||
testPrintE(" -D End of test delay");
|
||||
testPrintE(" -n Num set operations per pass");
|
||||
testPrintE(" -v Verbose");
|
||||
exit(((optopt == 0) || (optopt == '?')) ? 0 : 11);
|
||||
}
|
||||
}
|
||||
if (endPass < startPass) {
|
||||
testPrintE("Unexpected ending pass before starting pass");
|
||||
testPrintE(" startPass: %u endPass: %u", startPass, endPass);
|
||||
exit(12);
|
||||
}
|
||||
if (argc != optind) {
|
||||
testPrintE("Unexpected command-line postional argument");
|
||||
testPrintE(" %s [-s start_pass] [-e end_pass] [-t duration]",
|
||||
basename(argv[0]));
|
||||
exit(13);
|
||||
}
|
||||
testPrintI("duration: %g", duration);
|
||||
testPrintI("startPass: %u", startPass);
|
||||
testPrintI("endPass: %u", endPass);
|
||||
testPrintI("numSet: %u", numSet);
|
||||
|
||||
// Stop framework
|
||||
rv = snprintf(cmd, sizeof(cmd), "%s", CMD_STOP_FRAMEWORK);
|
||||
if (rv >= (signed) sizeof(cmd) - 1) {
|
||||
testPrintE("Command too long for: %s", CMD_STOP_FRAMEWORK);
|
||||
exit(14);
|
||||
}
|
||||
testExecCmd(cmd);
|
||||
testDelay(1.0); // TODO - need means to query whether asyncronous stop
|
||||
// framework operation has completed. For now, just wait
|
||||
// a long time.
|
||||
|
||||
init();
|
||||
|
||||
// For each pass
|
||||
gettimeofday(&startTime, NULL);
|
||||
for (pass = startPass; pass <= endPass; pass++) {
|
||||
// Stop if duration of work has already been performed
|
||||
gettimeofday(¤tTime, NULL);
|
||||
delta = tvDelta(&startTime, ¤tTime);
|
||||
if (tv2double(&delta) > duration) { break; }
|
||||
|
||||
// Regenerate a new set of test frames when this pass is
|
||||
// either the first pass or is in a different group then
|
||||
// the previous pass. A group of passes are passes that
|
||||
// all have the same quotient when their pass number is
|
||||
// divided by passesPerGroup.
|
||||
if ((pass == startPass)
|
||||
|| ((pass / passesPerGroup) != ((pass - 1) / passesPerGroup))) {
|
||||
initFrames(pass / passesPerGroup);
|
||||
}
|
||||
|
||||
testPrintI("==== Starting pass: %u", pass);
|
||||
|
||||
// Cause deterministic sequence of prandom numbers to be
|
||||
// generated for this pass.
|
||||
srand48(pass);
|
||||
|
||||
hwc_display_contents_1_t *list;
|
||||
list = hwcTestCreateLayerList(testRandMod(frames.size()) + 1);
|
||||
if (list == NULL) {
|
||||
testPrintE("hwcTestCreateLayerList failed");
|
||||
exit(20);
|
||||
}
|
||||
|
||||
// Prandomly select a subset of frames to be used by this pass.
|
||||
vector <vector <sp<GraphicBuffer> > > selectedFrames;
|
||||
selectedFrames = vectorRandSelect(frames, list->numHwLayers);
|
||||
|
||||
// Any transform tends to create a layer that the hardware
|
||||
// composer is unable to support and thus has to leave for
|
||||
// SurfaceFlinger. Place heavy bias on specifying no transforms.
|
||||
bool noTransform = testRandFract() > rareRatio;
|
||||
|
||||
for (unsigned int n1 = 0; n1 < list->numHwLayers; n1++) {
|
||||
unsigned int idx = testRandMod(selectedFrames[n1].size());
|
||||
sp<GraphicBuffer> gBuf = selectedFrames[n1][idx];
|
||||
hwc_layer_1_t *layer = &list->hwLayers[n1];
|
||||
layer->handle = gBuf->handle;
|
||||
|
||||
layer->blending = blendingOps[testRandMod(NUMA(blendingOps))];
|
||||
layer->flags = (testRandFract() > rareRatio) ? 0
|
||||
: vectorOr(vectorRandSelect(vecLayerFlags,
|
||||
testRandMod(vecLayerFlags.size() + 1)));
|
||||
layer->transform = (noTransform || testRandFract() > rareRatio) ? 0
|
||||
: vectorOr(vectorRandSelect(vecTransformFlags,
|
||||
testRandMod(vecTransformFlags.size() + 1)));
|
||||
layer->sourceCrop.left = testRandMod(gBuf->getWidth());
|
||||
layer->sourceCrop.top = testRandMod(gBuf->getHeight());
|
||||
layer->sourceCrop.right = layer->sourceCrop.left
|
||||
+ testRandMod(gBuf->getWidth() - layer->sourceCrop.left) + 1;
|
||||
layer->sourceCrop.bottom = layer->sourceCrop.top
|
||||
+ testRandMod(gBuf->getHeight() - layer->sourceCrop.top) + 1;
|
||||
layer->displayFrame.left = testRandMod(width);
|
||||
layer->displayFrame.top = testRandMod(height);
|
||||
layer->displayFrame.right = layer->displayFrame.left
|
||||
+ testRandMod(width - layer->displayFrame.left) + 1;
|
||||
layer->displayFrame.bottom = layer->displayFrame.top
|
||||
+ testRandMod(height - layer->displayFrame.top) + 1;
|
||||
|
||||
// Increase the frequency that a scale factor of 1.0 from
|
||||
// the sourceCrop to displayFrame occurs. This is the
|
||||
// most common scale factor used by applications and would
|
||||
// be rarely produced by this stress test without this
|
||||
// logic.
|
||||
if (testRandFract() <= freqRatio) {
|
||||
// Only change to scale factor to 1.0 if both the
|
||||
// width and height will fit.
|
||||
int sourceWidth = layer->sourceCrop.right
|
||||
- layer->sourceCrop.left;
|
||||
int sourceHeight = layer->sourceCrop.bottom
|
||||
- layer->sourceCrop.top;
|
||||
if (((layer->displayFrame.left + sourceWidth) <= width)
|
||||
&& ((layer->displayFrame.top + sourceHeight) <= height)) {
|
||||
layer->displayFrame.right = layer->displayFrame.left
|
||||
+ sourceWidth;
|
||||
layer->displayFrame.bottom = layer->displayFrame.top
|
||||
+ sourceHeight;
|
||||
}
|
||||
}
|
||||
|
||||
layer->visibleRegionScreen.numRects = 1;
|
||||
layer->visibleRegionScreen.rects = &layer->displayFrame;
|
||||
}
|
||||
|
||||
// Perform prepare operation
|
||||
if (verbose) { testPrintI("Prepare:"); hwcTestDisplayList(list); }
|
||||
hwcDevice->prepare(hwcDevice, 1, &list);
|
||||
if (verbose) {
|
||||
testPrintI("Post Prepare:");
|
||||
hwcTestDisplayListPrepareModifiable(list);
|
||||
}
|
||||
|
||||
// Turn off the geometry changed flag
|
||||
list->flags &= ~HWC_GEOMETRY_CHANGED;
|
||||
|
||||
// Perform the set operation(s)
|
||||
if (verbose) {testPrintI("Set:"); }
|
||||
for (unsigned int n1 = 0; n1 < numSet; n1++) {
|
||||
if (verbose) { hwcTestDisplayListHandles(list); }
|
||||
list->dpy = dpy;
|
||||
list->sur = surface;
|
||||
hwcDevice->set(hwcDevice, 1, &list);
|
||||
|
||||
// Prandomly select a new set of handles
|
||||
for (unsigned int n1 = 0; n1 < list->numHwLayers; n1++) {
|
||||
unsigned int idx = testRandMod(selectedFrames[n1].size());
|
||||
sp<GraphicBuffer> gBuf = selectedFrames[n1][idx];
|
||||
hwc_layer_1_t *layer = &list->hwLayers[n1];
|
||||
layer->handle = (native_handle_t *) gBuf->handle;
|
||||
}
|
||||
|
||||
testDelay(perSetDelay);
|
||||
}
|
||||
|
||||
hwcTestFreeLayerList(list);
|
||||
testPrintI("==== Completed pass: %u", pass);
|
||||
}
|
||||
|
||||
testDelay(endDelay);
|
||||
|
||||
// Start framework
|
||||
rv = snprintf(cmd, sizeof(cmd), "%s", CMD_START_FRAMEWORK);
|
||||
if (rv >= (signed) sizeof(cmd) - 1) {
|
||||
testPrintE("Command too long for: %s", CMD_START_FRAMEWORK);
|
||||
exit(21);
|
||||
}
|
||||
testExecCmd(cmd);
|
||||
|
||||
testPrintI("Successfully completed %u passes", pass - startPass);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void init(void)
|
||||
{
|
||||
srand48(0); // Defensively set pseudo random number generator.
|
||||
// Should not need to set this, because a stress test
|
||||
// sets the seed on each pass. Defensively set it here
|
||||
// so that future code that uses pseudo random numbers
|
||||
// before the first pass will be deterministic.
|
||||
|
||||
hwcTestInitDisplay(verbose, &dpy, &surface, &width, &height);
|
||||
|
||||
hwcTestOpenHwc(&hwcDevice);
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize Frames
|
||||
*
|
||||
* Creates an array of graphic buffers, within the global variable
|
||||
* named frames. The graphic buffers are contained within a vector of
|
||||
* vectors. All the graphic buffers in a particular row are of the same
|
||||
* format and dimension. Each graphic buffer is uniformly filled with a
|
||||
* prandomly selected color. It is likely that each buffer, even
|
||||
* in the same row, will be filled with a unique color.
|
||||
*/
|
||||
void initFrames(unsigned int seed)
|
||||
{
|
||||
int rv;
|
||||
const size_t maxRows = 5;
|
||||
const size_t minCols = 2; // Need at least double buffering
|
||||
const size_t maxCols = 4; // One more than triple buffering
|
||||
|
||||
if (verbose) { testPrintI("initFrames seed: %u", seed); }
|
||||
srand48(seed);
|
||||
size_t rows = testRandMod(maxRows) + 1;
|
||||
|
||||
frames.clear();
|
||||
frames.resize(rows);
|
||||
|
||||
for (unsigned int row = 0; row < rows; row++) {
|
||||
// All frames within a row have to have the same format and
|
||||
// dimensions. Width and height need to be >= 1.
|
||||
unsigned int formatIdx = testRandMod(NUMA(hwcTestGraphicFormat));
|
||||
const struct hwcTestGraphicFormat *formatPtr
|
||||
= &hwcTestGraphicFormat[formatIdx];
|
||||
int format = formatPtr->format;
|
||||
|
||||
// Pick width and height, which must be >= 1 and the size
|
||||
// mod the wMod/hMod value must be equal to 0.
|
||||
size_t w = (width * maxSizeRatio) * testRandFract();
|
||||
size_t h = (height * maxSizeRatio) * testRandFract();
|
||||
w = max(size_t(1u), w);
|
||||
h = max(size_t(1u), h);
|
||||
if ((w % formatPtr->wMod) != 0) {
|
||||
w += formatPtr->wMod - (w % formatPtr->wMod);
|
||||
}
|
||||
if ((h % formatPtr->hMod) != 0) {
|
||||
h += formatPtr->hMod - (h % formatPtr->hMod);
|
||||
}
|
||||
if (verbose) {
|
||||
testPrintI(" frame %u width: %u height: %u format: %u %s",
|
||||
row, w, h, format, hwcTestGraphicFormat2str(format));
|
||||
}
|
||||
|
||||
size_t cols = testRandMod((maxCols + 1) - minCols) + minCols;
|
||||
frames[row].resize(cols);
|
||||
for (unsigned int col = 0; col < cols; col++) {
|
||||
ColorFract color(testRandFract(), testRandFract(), testRandFract());
|
||||
float alpha = testRandFract();
|
||||
|
||||
frames[row][col] = new GraphicBuffer(w, h, format, texUsage);
|
||||
if ((rv = frames[row][col]->initCheck()) != NO_ERROR) {
|
||||
testPrintE("GraphicBuffer initCheck failed, rv: %i", rv);
|
||||
testPrintE(" frame %u width: %u height: %u format: %u %s",
|
||||
row, w, h, format, hwcTestGraphicFormat2str(format));
|
||||
exit(80);
|
||||
}
|
||||
|
||||
hwcTestFillColor(frames[row][col].get(), color, alpha);
|
||||
if (verbose) {
|
||||
testPrintI(" buf: %p handle: %p color: %s alpha: %f",
|
||||
frames[row][col].get(), frames[row][col]->handle,
|
||||
string(color).c_str(), alpha);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Vector Random Select
|
||||
*
|
||||
* Prandomly selects and returns num elements from vec.
|
||||
*/
|
||||
template <class T>
|
||||
vector<T> vectorRandSelect(const vector<T>& vec, size_t num)
|
||||
{
|
||||
vector<T> rv = vec;
|
||||
|
||||
while (rv.size() > num) {
|
||||
rv.erase(rv.begin() + testRandMod(rv.size()));
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
/*
|
||||
* Vector Or
|
||||
*
|
||||
* Or's togethen the values of each element of vec and returns the result.
|
||||
*/
|
||||
template <class T>
|
||||
T vectorOr(const vector<T>& vec)
|
||||
{
|
||||
T rv = 0;
|
||||
|
||||
for (size_t n1 = 0; n1 < vec.size(); n1++) {
|
||||
rv |= vec[n1];
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
1015
android/frameworks/native/opengl/tests/hwc/hwcTestLib.cpp
Normal file
1015
android/frameworks/native/opengl/tests/hwc/hwcTestLib.cpp
Normal file
File diff suppressed because it is too large
Load diff
131
android/frameworks/native/opengl/tests/hwc/hwcTestLib.h
Normal file
131
android/frameworks/native/opengl/tests/hwc/hwcTestLib.h
Normal file
|
@ -0,0 +1,131 @@
|
|||
/*
|
||||
* Copyright (C) 2011 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Hardware Composer Test Library Header
|
||||
*/
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include <EGL/egl.h>
|
||||
#include <EGL/eglext.h>
|
||||
#include <GLES2/gl2.h>
|
||||
#include <GLES2/gl2ext.h>
|
||||
|
||||
#include <ui/GraphicBuffer.h>
|
||||
|
||||
#include <utils/Log.h>
|
||||
#include <testUtil.h>
|
||||
|
||||
#include <hardware/hwcomposer.h>
|
||||
|
||||
// Characteristics of known graphic formats
|
||||
const struct hwcTestGraphicFormat {
|
||||
uint32_t format;
|
||||
const char *desc;
|
||||
uint32_t wMod, hMod; // Width/height mod this value must equal zero
|
||||
} hwcTestGraphicFormat[] = {
|
||||
{HAL_PIXEL_FORMAT_RGBA_8888, "RGBA8888", 1, 1},
|
||||
{HAL_PIXEL_FORMAT_RGBX_8888, "RGBX8888", 1, 1},
|
||||
{HAL_PIXEL_FORMAT_RGB_888, "RGB888", 1, 1},
|
||||
{HAL_PIXEL_FORMAT_RGB_565, "RGB565", 1, 1},
|
||||
{HAL_PIXEL_FORMAT_BGRA_8888, "BGRA8888", 1, 1},
|
||||
{HAL_PIXEL_FORMAT_YV12, "YV12", 2, 2},
|
||||
};
|
||||
|
||||
// Represent RGB color as fraction of color components.
|
||||
// Each of the color components are expected in the range [0.0, 1.0]
|
||||
class ColorFract {
|
||||
public:
|
||||
ColorFract(): _c1(0.0), _c2(0.0), _c3(0.0) {};
|
||||
ColorFract(float c1, float c2, float c3): _c1(c1), _c2(c2), _c3(c3) {};
|
||||
float c1(void) const { return _c1; }
|
||||
float c2(void) const { return _c2; }
|
||||
float c3(void) const { return _c3; }
|
||||
|
||||
operator std::string();
|
||||
|
||||
private:
|
||||
float _c1;
|
||||
float _c2;
|
||||
float _c3;
|
||||
};
|
||||
|
||||
// Represent RGB color as fraction of color components.
|
||||
// Each of the color components are expected in the range [0.0, 1.0]
|
||||
class ColorRGB {
|
||||
public:
|
||||
ColorRGB(): _r(0.0), _g(0.0), _b(0.0) {};
|
||||
ColorRGB(float f): _r(f), _g(f), _b(f) {}; // Gray, NOLINT(implicit)
|
||||
ColorRGB(float r, float g, float b): _r(r), _g(g), _b(b) {};
|
||||
float r(void) const { return _r; }
|
||||
float g(void) const { return _g; }
|
||||
float b(void) const { return _b; }
|
||||
|
||||
private:
|
||||
float _r;
|
||||
float _g;
|
||||
float _b;
|
||||
};
|
||||
|
||||
// Dimension - width and height of a rectanguler area
|
||||
class HwcTestDim {
|
||||
public:
|
||||
HwcTestDim(): _w(0), _h(0) {};
|
||||
HwcTestDim(uint32_t w, uint32_t h) : _w(w), _h(h) {}
|
||||
uint32_t width(void) const { return _w; }
|
||||
uint32_t height(void) const { return _h; }
|
||||
void setWidth(uint32_t w) { _w = w; }
|
||||
void setHeight(uint32_t h) { _h = h; }
|
||||
|
||||
operator std::string();
|
||||
operator hwc_rect() const;
|
||||
|
||||
private:
|
||||
uint32_t _w;
|
||||
uint32_t _h;
|
||||
};
|
||||
|
||||
// Function Prototypes
|
||||
void hwcTestInitDisplay(bool verbose, EGLDisplay *dpy, EGLSurface *surface,
|
||||
EGLint *width, EGLint *height);
|
||||
void hwcTestOpenHwc(hwc_composer_device_1_t **hwcDevicePtr);
|
||||
const struct hwcTestGraphicFormat *hwcTestGraphicFormatLookup(const char *desc);
|
||||
const struct hwcTestGraphicFormat *hwcTestGraphicFormatLookup(uint32_t id);
|
||||
const char *hwcTestGraphicFormat2str(uint32_t format);
|
||||
std::string hwcTestRect2str(const struct hwc_rect& rect);
|
||||
|
||||
hwc_display_contents_1_t *hwcTestCreateLayerList(size_t numLayers);
|
||||
void hwcTestFreeLayerList(hwc_display_contents_1_t *list);
|
||||
void hwcTestDisplayList(hwc_display_contents_1_t *list);
|
||||
void hwcTestDisplayListPrepareModifiable(hwc_display_contents_1_t *list);
|
||||
void hwcTestDisplayListHandles(hwc_display_contents_1_t *list);
|
||||
|
||||
uint32_t hwcTestColor2Pixel(uint32_t format, ColorFract color, float alpha);
|
||||
void hwcTestColorConvert(uint32_t fromFormat, uint32_t toFormat,
|
||||
ColorFract& color);
|
||||
void hwcTestSetPixel(android::GraphicBuffer *gBuf, unsigned char *buf,
|
||||
uint32_t x, uint32_t y, uint32_t pixel);
|
||||
void hwcTestFillColor(android::GraphicBuffer *gBuf, ColorFract color,
|
||||
float alpha);
|
||||
void hwcTestFillColorHBlend(android::GraphicBuffer *gBuf,
|
||||
uint32_t colorFormat,
|
||||
ColorFract startColor, ColorFract endColor);
|
||||
ColorFract hwcTestParseColor(std::istringstream& in, bool& error);
|
||||
struct hwc_rect hwcTestParseHwcRect(std::istringstream& in, bool& error);
|
||||
HwcTestDim hwcTestParseDim(std::istringstream& in, bool& error);
|
Loading…
Add table
Add a link
Reference in a new issue