Patch.h revision 2665b85b2bd08faabf7c520a622a0e4d3465245f
1/* 2 * Copyright (C) 2010 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#ifndef ANDROID_UI_PATCH_H 18#define ANDROID_UI_PATCH_H 19 20#include <sys/types.h> 21 22#include <GLES2/gl2.h> 23 24#include "Vertex.h" 25#include "utils/Compare.h" 26 27namespace android { 28namespace uirenderer { 29 30/////////////////////////////////////////////////////////////////////////////// 31// 9-patch structures 32/////////////////////////////////////////////////////////////////////////////// 33 34/** 35 * Description of a patch. 36 */ 37struct PatchDescription { 38 PatchDescription(): bitmapWidth(0), bitmapHeight(0), pixelWidth(0), pixelHeight(0), 39 xCount(0), yCount(0), emptyCount(0), colorKey(0) { } 40 PatchDescription(const float bitmapWidth, const float bitmapHeight, 41 const float pixelWidth, const float pixelHeight, 42 const uint32_t xCount, const uint32_t yCount, 43 const int8_t emptyCount, const uint32_t colorKey): 44 bitmapWidth(bitmapWidth), bitmapHeight(bitmapHeight), 45 pixelWidth(pixelWidth), pixelHeight(pixelHeight), 46 xCount(xCount), yCount(yCount), 47 emptyCount(emptyCount), colorKey(colorKey) { } 48 PatchDescription(const PatchDescription& description): 49 bitmapWidth(description.bitmapWidth), bitmapHeight(description.bitmapHeight), 50 pixelWidth(description.pixelWidth), pixelHeight(description.pixelHeight), 51 xCount(description.xCount), yCount(description.yCount), 52 emptyCount(description.emptyCount), colorKey(description.colorKey) { } 53 54 float bitmapWidth; 55 float bitmapHeight; 56 float pixelWidth; 57 float pixelHeight; 58 uint32_t xCount; 59 uint32_t yCount; 60 int8_t emptyCount; 61 uint32_t colorKey; 62 63 bool operator<(const PatchDescription& rhs) const { 64 LTE_FLOAT(bitmapWidth) { 65 LTE_FLOAT(bitmapHeight) { 66 LTE_FLOAT(pixelWidth) { 67 LTE_FLOAT(pixelHeight) { 68 LTE_INT(xCount) { 69 LTE_INT(yCount) { 70 LTE_INT(emptyCount) { 71 LTE_INT(colorKey) return false; 72 } 73 } 74 } 75 } 76 } 77 } 78 } 79 return false; 80 } 81}; // struct PatchDescription 82 83/** 84 * An OpenGL patch. This contains an array of vertices and an array of 85 * indices to render the vertices. 86 */ 87struct Patch { 88 Patch(const uint32_t xCount, const uint32_t yCount, const int8_t emptyQuads = 0); 89 ~Patch(); 90 91 void updateVertices(const float bitmapWidth, const float bitmapHeight, 92 float left, float top, float right, float bottom, 93 const int32_t* xDivs, const int32_t* yDivs, 94 const uint32_t width, const uint32_t height, 95 const uint32_t colorKey = 0); 96 97 GLuint meshBuffer; 98 uint32_t verticesCount; 99 100private: 101 TextureVertex* mVertices; 102 103 static inline void generateRow(TextureVertex*& vertex, float y1, float y2, 104 float v1, float v2, const int32_t xDivs[], uint32_t xCount, 105 float stretchX, float width, float bitmapWidth, 106 uint32_t& quadCount, const uint32_t colorKey); 107 static inline void generateQuad(TextureVertex*& vertex, 108 float x1, float y1, float x2, float y2, 109 float u1, float v1, float u2, float v2, 110 uint32_t& quadCount, const uint32_t colorKey); 111}; // struct Patch 112 113}; // namespace uirenderer 114}; // namespace android 115 116#endif // ANDROID_UI_PATCH_H 117