Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 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 | |
Romain Guy | 03750a0 | 2010-10-18 14:06:08 -0700 | [diff] [blame] | 22 | #include <GLES2/gl2.h> |
| 23 | |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 24 | #include "Vertex.h" |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 25 | #include "utils/Compare.h" |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 26 | |
| 27 | namespace android { |
| 28 | namespace uirenderer { |
| 29 | |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 30 | /////////////////////////////////////////////////////////////////////////////// |
| 31 | // 9-patch structures |
| 32 | /////////////////////////////////////////////////////////////////////////////// |
| 33 | |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 34 | /** |
| 35 | * Description of a patch. |
| 36 | */ |
| 37 | struct PatchDescription { |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 38 | PatchDescription(): bitmapWidth(0), bitmapHeight(0), pixelWidth(0), pixelHeight(0), |
| 39 | xCount(0), yCount(0), emptyCount(0), colorKey(0) { } |
Romain Guy | 2728f96 | 2010-10-08 18:36:15 -0700 | [diff] [blame] | 40 | PatchDescription(const float bitmapWidth, const float bitmapHeight, |
| 41 | const float pixelWidth, const float pixelHeight, |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 42 | const uint32_t xCount, const uint32_t yCount, |
| 43 | const int8_t emptyCount, const uint32_t colorKey): |
Romain Guy | 2728f96 | 2010-10-08 18:36:15 -0700 | [diff] [blame] | 44 | bitmapWidth(bitmapWidth), bitmapHeight(bitmapHeight), |
| 45 | pixelWidth(pixelWidth), pixelHeight(pixelHeight), |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 46 | xCount(xCount), yCount(yCount), |
| 47 | emptyCount(emptyCount), colorKey(colorKey) { } |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 48 | PatchDescription(const PatchDescription& description): |
Romain Guy | 2728f96 | 2010-10-08 18:36:15 -0700 | [diff] [blame] | 49 | bitmapWidth(description.bitmapWidth), bitmapHeight(description.bitmapHeight), |
| 50 | pixelWidth(description.pixelWidth), pixelHeight(description.pixelHeight), |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 51 | xCount(description.xCount), yCount(description.yCount), |
| 52 | emptyCount(description.emptyCount), colorKey(description.colorKey) { } |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 53 | |
Romain Guy | 2728f96 | 2010-10-08 18:36:15 -0700 | [diff] [blame] | 54 | float bitmapWidth; |
| 55 | float bitmapHeight; |
| 56 | float pixelWidth; |
| 57 | float pixelHeight; |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 58 | uint32_t xCount; |
| 59 | uint32_t yCount; |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 60 | int8_t emptyCount; |
| 61 | uint32_t colorKey; |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 62 | |
| 63 | bool operator<(const PatchDescription& rhs) const { |
Romain Guy | 2665b85 | 2010-10-18 15:11:50 -0700 | [diff] [blame^] | 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; |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 72 | } |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | return false; |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 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 | */ |
| 87 | struct Patch { |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 88 | Patch(const uint32_t xCount, const uint32_t yCount, const int8_t emptyQuads = 0); |
Romain Guy | fb5e23c | 2010-07-09 13:52:56 -0700 | [diff] [blame] | 89 | ~Patch(); |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 90 | |
Romain Guy | 759ea80 | 2010-09-16 20:49:46 -0700 | [diff] [blame] | 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, |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 94 | const uint32_t width, const uint32_t height, |
| 95 | const uint32_t colorKey = 0); |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 96 | |
Romain Guy | 03750a0 | 2010-10-18 14:06:08 -0700 | [diff] [blame] | 97 | GLuint meshBuffer; |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 98 | uint32_t verticesCount; |
Romain Guy | fb5e23c | 2010-07-09 13:52:56 -0700 | [diff] [blame] | 99 | |
| 100 | private: |
Romain Guy | 03750a0 | 2010-10-18 14:06:08 -0700 | [diff] [blame] | 101 | TextureVertex* mVertices; |
| 102 | |
Romain Guy | 6820ac8 | 2010-09-15 18:11:50 -0700 | [diff] [blame] | 103 | static inline void generateRow(TextureVertex*& vertex, float y1, float y2, |
| 104 | float v1, float v2, const int32_t xDivs[], uint32_t xCount, |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 105 | float stretchX, float width, float bitmapWidth, |
| 106 | uint32_t& quadCount, const uint32_t colorKey); |
Romain Guy | 759ea80 | 2010-09-16 20:49:46 -0700 | [diff] [blame] | 107 | static inline void generateQuad(TextureVertex*& vertex, |
| 108 | float x1, float y1, float x2, float y2, |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 109 | float u1, float v1, float u2, float v2, |
| 110 | uint32_t& quadCount, const uint32_t colorKey); |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 111 | }; // struct Patch |
| 112 | |
| 113 | }; // namespace uirenderer |
| 114 | }; // namespace android |
| 115 | |
| 116 | #endif // ANDROID_UI_PATCH_H |