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> |
Romain Guy | 2728f96 | 2010-10-08 18:36:15 -0700 | [diff] [blame] | 21 | #include <cstring> |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 22 | |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 23 | #include "Vertex.h" |
| 24 | |
| 25 | namespace android { |
| 26 | namespace uirenderer { |
| 27 | |
| 28 | /** |
| 29 | * Description of a patch. |
| 30 | */ |
| 31 | struct PatchDescription { |
Romain Guy | 2728f96 | 2010-10-08 18:36:15 -0700 | [diff] [blame] | 32 | PatchDescription(): bitmapWidth(0), bitmapHeight(0), |
| 33 | pixelWidth(0), pixelHeight(0), xCount(0), yCount(0) { } |
| 34 | PatchDescription(const float bitmapWidth, const float bitmapHeight, |
| 35 | const float pixelWidth, const float pixelHeight, |
| 36 | const uint32_t xCount, const uint32_t yCount): |
| 37 | bitmapWidth(bitmapWidth), bitmapHeight(bitmapHeight), |
| 38 | pixelWidth(pixelWidth), pixelHeight(pixelHeight), |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 39 | xCount(xCount), yCount(yCount) { } |
| 40 | PatchDescription(const PatchDescription& description): |
Romain Guy | 2728f96 | 2010-10-08 18:36:15 -0700 | [diff] [blame] | 41 | bitmapWidth(description.bitmapWidth), bitmapHeight(description.bitmapHeight), |
| 42 | pixelWidth(description.pixelWidth), pixelHeight(description.pixelHeight), |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 43 | xCount(description.xCount), yCount(description.yCount) { } |
| 44 | |
Romain Guy | 2728f96 | 2010-10-08 18:36:15 -0700 | [diff] [blame] | 45 | float bitmapWidth; |
| 46 | float bitmapHeight; |
| 47 | float pixelWidth; |
| 48 | float pixelHeight; |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 49 | uint32_t xCount; |
| 50 | uint32_t yCount; |
| 51 | |
| 52 | bool operator<(const PatchDescription& rhs) const { |
Romain Guy | 2728f96 | 2010-10-08 18:36:15 -0700 | [diff] [blame] | 53 | return memcmp(this, &rhs, sizeof(PatchDescription)) < 0; |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 54 | } |
| 55 | }; // struct PatchDescription |
| 56 | |
| 57 | /** |
| 58 | * An OpenGL patch. This contains an array of vertices and an array of |
| 59 | * indices to render the vertices. |
| 60 | */ |
| 61 | struct Patch { |
Romain Guy | fb5e23c | 2010-07-09 13:52:56 -0700 | [diff] [blame] | 62 | Patch(const uint32_t xCount, const uint32_t yCount); |
| 63 | ~Patch(); |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 64 | |
Romain Guy | 759ea80 | 2010-09-16 20:49:46 -0700 | [diff] [blame] | 65 | void updateVertices(const float bitmapWidth, const float bitmapHeight, |
| 66 | float left, float top, float right, float bottom, |
| 67 | const int32_t* xDivs, const int32_t* yDivs, |
Romain Guy | fb5e23c | 2010-07-09 13:52:56 -0700 | [diff] [blame] | 68 | const uint32_t width, const uint32_t height); |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 69 | |
| 70 | TextureVertex* vertices; |
| 71 | uint32_t verticesCount; |
Romain Guy | fb5e23c | 2010-07-09 13:52:56 -0700 | [diff] [blame] | 72 | |
| 73 | private: |
Romain Guy | 6820ac8 | 2010-09-15 18:11:50 -0700 | [diff] [blame] | 74 | static inline void generateRow(TextureVertex*& vertex, float y1, float y2, |
| 75 | float v1, float v2, const int32_t xDivs[], uint32_t xCount, |
| 76 | float stretchX, float width, float bitmapWidth); |
Romain Guy | 759ea80 | 2010-09-16 20:49:46 -0700 | [diff] [blame] | 77 | static inline void generateQuad(TextureVertex*& vertex, |
| 78 | float x1, float y1, float x2, float y2, |
Romain Guy | 6820ac8 | 2010-09-15 18:11:50 -0700 | [diff] [blame] | 79 | float u1, float v1, float u2, float v2); |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 80 | }; // struct Patch |
| 81 | |
| 82 | }; // namespace uirenderer |
| 83 | }; // namespace android |
| 84 | |
| 85 | #endif // ANDROID_UI_PATCH_H |