blob: 54c9d6cca7e455f8b33f26b3b489cc1bd7b4cf79 [file] [log] [blame]
Romain Guyf7f93552010-07-08 19:17:03 -07001/*
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 Guyf7f93552010-07-08 19:17:03 -070022#include "Vertex.h"
Romain Guy4bb94202010-10-12 15:59:26 -070023#include "utils/Compare.h"
Romain Guyf7f93552010-07-08 19:17:03 -070024
25namespace android {
26namespace uirenderer {
27
Romain Guy4bb94202010-10-12 15:59:26 -070028///////////////////////////////////////////////////////////////////////////////
29// 9-patch structures
30///////////////////////////////////////////////////////////////////////////////
31
Romain Guyf7f93552010-07-08 19:17:03 -070032/**
33 * Description of a patch.
34 */
35struct PatchDescription {
Romain Guy4bb94202010-10-12 15:59:26 -070036 PatchDescription(): bitmapWidth(0), bitmapHeight(0), pixelWidth(0), pixelHeight(0),
37 xCount(0), yCount(0), emptyCount(0), colorKey(0) { }
Romain Guy2728f962010-10-08 18:36:15 -070038 PatchDescription(const float bitmapWidth, const float bitmapHeight,
39 const float pixelWidth, const float pixelHeight,
Romain Guy4bb94202010-10-12 15:59:26 -070040 const uint32_t xCount, const uint32_t yCount,
41 const int8_t emptyCount, const uint32_t colorKey):
Romain Guy2728f962010-10-08 18:36:15 -070042 bitmapWidth(bitmapWidth), bitmapHeight(bitmapHeight),
43 pixelWidth(pixelWidth), pixelHeight(pixelHeight),
Romain Guy4bb94202010-10-12 15:59:26 -070044 xCount(xCount), yCount(yCount),
45 emptyCount(emptyCount), colorKey(colorKey) { }
Romain Guyf7f93552010-07-08 19:17:03 -070046 PatchDescription(const PatchDescription& description):
Romain Guy2728f962010-10-08 18:36:15 -070047 bitmapWidth(description.bitmapWidth), bitmapHeight(description.bitmapHeight),
48 pixelWidth(description.pixelWidth), pixelHeight(description.pixelHeight),
Romain Guy4bb94202010-10-12 15:59:26 -070049 xCount(description.xCount), yCount(description.yCount),
50 emptyCount(description.emptyCount), colorKey(description.colorKey) { }
Romain Guyf7f93552010-07-08 19:17:03 -070051
Romain Guy2728f962010-10-08 18:36:15 -070052 float bitmapWidth;
53 float bitmapHeight;
54 float pixelWidth;
55 float pixelHeight;
Romain Guyf7f93552010-07-08 19:17:03 -070056 uint32_t xCount;
57 uint32_t yCount;
Romain Guy4bb94202010-10-12 15:59:26 -070058 int8_t emptyCount;
59 uint32_t colorKey;
Romain Guyf7f93552010-07-08 19:17:03 -070060
61 bool operator<(const PatchDescription& rhs) const {
Romain Guy4bb94202010-10-12 15:59:26 -070062 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 Guyf7f93552010-07-08 19:17:03 -070078 }
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 */
85struct Patch {
Romain Guy4bb94202010-10-12 15:59:26 -070086 Patch(const uint32_t xCount, const uint32_t yCount, const int8_t emptyQuads = 0);
Romain Guyfb5e23c2010-07-09 13:52:56 -070087 ~Patch();
Romain Guyf7f93552010-07-08 19:17:03 -070088
Romain Guy759ea802010-09-16 20:49:46 -070089 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 Guy4bb94202010-10-12 15:59:26 -070092 const uint32_t width, const uint32_t height,
93 const uint32_t colorKey = 0);
Romain Guyf7f93552010-07-08 19:17:03 -070094
95 TextureVertex* vertices;
96 uint32_t verticesCount;
Romain Guyfb5e23c2010-07-09 13:52:56 -070097
98private:
Romain Guy6820ac82010-09-15 18:11:50 -070099 static inline void generateRow(TextureVertex*& vertex, float y1, float y2,
100 float v1, float v2, const int32_t xDivs[], uint32_t xCount,
Romain Guy4bb94202010-10-12 15:59:26 -0700101 float stretchX, float width, float bitmapWidth,
102 uint32_t& quadCount, const uint32_t colorKey);
Romain Guy759ea802010-09-16 20:49:46 -0700103 static inline void generateQuad(TextureVertex*& vertex,
104 float x1, float y1, float x2, float y2,
Romain Guy4bb94202010-10-12 15:59:26 -0700105 float u1, float v1, float u2, float v2,
106 uint32_t& quadCount, const uint32_t colorKey);
Romain Guyf7f93552010-07-08 19:17:03 -0700107}; // struct Patch
108
109}; // namespace uirenderer
110}; // namespace android
111
112#endif // ANDROID_UI_PATCH_H