1 // Copyright (C) 2011 The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #pragma version(1) 16 17 #pragma rs java_package_name(com.android.perftest) 18 19 #include "rs_graphics.rsh" 20 #include "subtest_def.rsh" 21 22 rs_font gFontSans; 23 rs_font gFontSerif; 24 25 typedef struct TextTestData_s { 26 int fillNum; 27 } TextTestData; 28 TextTestData *gData; 29 30 void init() { 31 } 32 33 static int gRenderSurfaceW = 1280; 34 static int gRenderSurfaceH = 720; 35 36 static const char *sampleText = "This is a sample of small text for performace"; 37 // Offsets for multiple layer of text 38 static int textOffsets[] = { 0, 0, -5, -5, 5, 5, -8, -8, 8, 8}; 39 static float textColors[] = {1.0f, 1.0f, 1.0f, 1.0f, 40 0.5f, 0.7f, 0.5f, 1.0f, 41 0.7f, 0.5f, 0.5f, 1.0f, 42 0.5f, 0.5f, 0.7f, 1.0f, 43 0.5f, 0.6f, 0.7f, 1.0f, 44 }; 45 46 static void displayFontSamples(int fillNum) { 47 48 rs_font fonts[5]; 49 fonts[0] = gFontSans; 50 fonts[1] = gFontSerif; 51 fonts[2] = gFontSans; 52 fonts[3] = gFontSerif; 53 fonts[4] = gFontSans; 54 55 uint width = gRenderSurfaceW; 56 uint height = gRenderSurfaceH; 57 int left = 0, right = 0, top = 0, bottom = 0; 58 rsgMeasureText(sampleText, &left, &right, &top, &bottom); 59 60 int textHeight = top - bottom; 61 int textWidth = right - left; 62 int numVerticalLines = height / textHeight; 63 int yPos = top; 64 65 int xOffset = 0, yOffset = 0; 66 for(int fillI = 0; fillI < fillNum; fillI ++) { 67 rsgBindFont(fonts[fillI]); 68 xOffset = textOffsets[fillI * 2]; 69 yOffset = textOffsets[fillI * 2 + 1]; 70 float *colPtr = textColors + fillI * 4; 71 rsgFontColor(colPtr[0], colPtr[1], colPtr[2], colPtr[3]); 72 for (int h = 0; h < 4; h ++) { 73 yPos = top + yOffset; 74 for (int v = 0; v < numVerticalLines; v ++) { 75 rsgDrawText(sampleText, xOffset + textWidth * h, yPos); 76 yPos += textHeight; 77 } 78 } 79 } 80 } 81 82 void root(const void *v_in, void *v_out, const void *usrData, uint32_t x, uint32_t y) { 83 TestData *testData = (TestData*)usrData; 84 gRenderSurfaceW = testData->renderSurfaceW; 85 gRenderSurfaceH = testData->renderSurfaceH; 86 87 gData = (TextTestData*)v_in; 88 89 displayFontSamples(gData->fillNum); 90 } 91