Patch.h revision a5ef39a21683189e5906c9f252b997f0508e350d
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_HWUI_PATCH_H 18#define ANDROID_HWUI_PATCH_H 19 20#include <sys/types.h> 21 22#include <GLES2/gl2.h> 23 24#include <utils/Vector.h> 25 26#include "Rect.h" 27#include "Vertex.h" 28#include "utils/Compare.h" 29 30namespace android { 31namespace uirenderer { 32 33/////////////////////////////////////////////////////////////////////////////// 34// 9-patch structures 35/////////////////////////////////////////////////////////////////////////////// 36 37/** 38 * An OpenGL patch. This contains an array of vertices and an array of 39 * indices to render the vertices. 40 */ 41struct Patch { 42 Patch(const uint32_t xCount, const uint32_t yCount, const int8_t emptyQuads = 0); 43 ~Patch(); 44 45 void updateVertices(const float bitmapWidth, const float bitmapHeight, 46 float left, float top, float right, float bottom); 47 48 void updateColorKey(const uint32_t colorKey); 49 void copy(const int32_t* xDivs, const int32_t* yDivs); 50 bool matches(const int32_t* xDivs, const int32_t* yDivs, const uint32_t colorKey); 51 52 GLuint meshBuffer; 53 uint32_t verticesCount; 54 bool hasEmptyQuads; 55#if RENDER_LAYERS_AS_REGIONS 56 Vector<Rect> quads; 57#endif 58 59private: 60 TextureVertex* mVertices; 61 bool mUploaded; 62 63 int32_t* mXDivs; 64 int32_t* mYDivs; 65 uint32_t mColorKey; 66 67 uint32_t mXCount; 68 uint32_t mYCount; 69 int8_t mEmptyQuads; 70 71 void copy(const int32_t* yDivs); 72 73 void generateRow(TextureVertex*& vertex, float y1, float y2, 74 float v1, float v2, float stretchX, float width, float bitmapWidth, 75 uint32_t& quadCount); 76 void generateQuad(TextureVertex*& vertex, 77 float x1, float y1, float x2, float y2, 78 float u1, float v1, float u2, float v2, 79 uint32_t& quadCount); 80}; // struct Patch 81 82}; // namespace uirenderer 83}; // namespace android 84 85#endif // ANDROID_HWUI_PATCH_H 86