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