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 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 17 | #ifndef ANDROID_HWUI_PATCH_H |
| 18 | #define ANDROID_HWUI_PATCH_H |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 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 | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 24 | #include <utils/Vector.h> |
| 25 | |
| 26 | #include "Rect.h" |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 27 | #include "Vertex.h" |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 28 | #include "utils/Compare.h" |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 29 | |
| 30 | namespace android { |
| 31 | namespace uirenderer { |
| 32 | |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 33 | /////////////////////////////////////////////////////////////////////////////// |
| 34 | // 9-patch structures |
| 35 | /////////////////////////////////////////////////////////////////////////////// |
| 36 | |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 37 | /** |
| 38 | * Description of a patch. |
| 39 | */ |
| 40 | struct PatchDescription { |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 41 | PatchDescription(): bitmapWidth(0), bitmapHeight(0), pixelWidth(0), pixelHeight(0), |
| 42 | xCount(0), yCount(0), emptyCount(0), colorKey(0) { } |
Romain Guy | 2728f96 | 2010-10-08 18:36:15 -0700 | [diff] [blame] | 43 | PatchDescription(const float bitmapWidth, const float bitmapHeight, |
| 44 | const float pixelWidth, const float pixelHeight, |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 45 | const uint32_t xCount, const uint32_t yCount, |
| 46 | const int8_t emptyCount, const uint32_t colorKey): |
Romain Guy | 2728f96 | 2010-10-08 18:36:15 -0700 | [diff] [blame] | 47 | bitmapWidth(bitmapWidth), bitmapHeight(bitmapHeight), |
| 48 | pixelWidth(pixelWidth), pixelHeight(pixelHeight), |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 49 | xCount(xCount), yCount(yCount), |
| 50 | emptyCount(emptyCount), colorKey(colorKey) { } |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 51 | PatchDescription(const PatchDescription& description): |
Romain Guy | 2728f96 | 2010-10-08 18:36:15 -0700 | [diff] [blame] | 52 | bitmapWidth(description.bitmapWidth), bitmapHeight(description.bitmapHeight), |
| 53 | pixelWidth(description.pixelWidth), pixelHeight(description.pixelHeight), |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 54 | xCount(description.xCount), yCount(description.yCount), |
| 55 | emptyCount(description.emptyCount), colorKey(description.colorKey) { } |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 56 | |
Romain Guy | 2728f96 | 2010-10-08 18:36:15 -0700 | [diff] [blame] | 57 | float bitmapWidth; |
| 58 | float bitmapHeight; |
| 59 | float pixelWidth; |
| 60 | float pixelHeight; |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 61 | uint32_t xCount; |
| 62 | uint32_t yCount; |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 63 | int8_t emptyCount; |
| 64 | uint32_t colorKey; |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 65 | |
| 66 | bool operator<(const PatchDescription& rhs) const { |
Romain Guy | 2665b85 | 2010-10-18 15:11:50 -0700 | [diff] [blame] | 67 | LTE_FLOAT(bitmapWidth) { |
| 68 | LTE_FLOAT(bitmapHeight) { |
| 69 | LTE_FLOAT(pixelWidth) { |
| 70 | LTE_FLOAT(pixelHeight) { |
| 71 | LTE_INT(xCount) { |
| 72 | LTE_INT(yCount) { |
| 73 | LTE_INT(emptyCount) { |
| 74 | LTE_INT(colorKey) return false; |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | return false; |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 83 | } |
| 84 | }; // struct PatchDescription |
| 85 | |
| 86 | /** |
| 87 | * An OpenGL patch. This contains an array of vertices and an array of |
| 88 | * indices to render the vertices. |
| 89 | */ |
| 90 | struct Patch { |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 91 | 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] | 92 | ~Patch(); |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 93 | |
Romain Guy | 759ea80 | 2010-09-16 20:49:46 -0700 | [diff] [blame] | 94 | void updateVertices(const float bitmapWidth, const float bitmapHeight, |
| 95 | float left, float top, float right, float bottom, |
| 96 | const int32_t* xDivs, const int32_t* yDivs, |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 97 | const uint32_t width, const uint32_t height, |
| 98 | const uint32_t colorKey = 0); |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 99 | |
Romain Guy | 03750a0 | 2010-10-18 14:06:08 -0700 | [diff] [blame] | 100 | GLuint meshBuffer; |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 101 | uint32_t verticesCount; |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 102 | Vector<Rect> quads; |
| 103 | bool hasEmptyQuads; |
Romain Guy | fb5e23c | 2010-07-09 13:52:56 -0700 | [diff] [blame] | 104 | |
| 105 | private: |
Romain Guy | 03750a0 | 2010-10-18 14:06:08 -0700 | [diff] [blame] | 106 | TextureVertex* mVertices; |
| 107 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 108 | void generateRow(TextureVertex*& vertex, float y1, float y2, |
Romain Guy | 6820ac8 | 2010-09-15 18:11:50 -0700 | [diff] [blame] | 109 | float v1, float v2, const int32_t xDivs[], uint32_t xCount, |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 110 | float stretchX, float width, float bitmapWidth, |
| 111 | uint32_t& quadCount, const uint32_t colorKey); |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 112 | void generateQuad(TextureVertex*& vertex, |
Romain Guy | 759ea80 | 2010-09-16 20:49:46 -0700 | [diff] [blame] | 113 | float x1, float y1, float x2, float y2, |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 114 | float u1, float v1, float u2, float v2, |
| 115 | uint32_t& quadCount, const uint32_t colorKey); |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 116 | }; // struct Patch |
| 117 | |
| 118 | }; // namespace uirenderer |
| 119 | }; // namespace android |
| 120 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 121 | #endif // ANDROID_HWUI_PATCH_H |