blob: 869b3bfdc4cb715a870547051e440f8f522fbecd [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 Guy03750a02010-10-18 14:06:08 -070022#include <GLES2/gl2.h>
23
Romain Guyf7f93552010-07-08 19:17:03 -070024#include "Vertex.h"
Romain Guy4bb94202010-10-12 15:59:26 -070025#include "utils/Compare.h"
Romain Guyf7f93552010-07-08 19:17:03 -070026
27namespace android {
28namespace uirenderer {
29
Romain Guy4bb94202010-10-12 15:59:26 -070030///////////////////////////////////////////////////////////////////////////////
31// 9-patch structures
32///////////////////////////////////////////////////////////////////////////////
33
Romain Guyf7f93552010-07-08 19:17:03 -070034/**
35 * Description of a patch.
36 */
37struct PatchDescription {
Romain Guy4bb94202010-10-12 15:59:26 -070038 PatchDescription(): bitmapWidth(0), bitmapHeight(0), pixelWidth(0), pixelHeight(0),
39 xCount(0), yCount(0), emptyCount(0), colorKey(0) { }
Romain Guy2728f962010-10-08 18:36:15 -070040 PatchDescription(const float bitmapWidth, const float bitmapHeight,
41 const float pixelWidth, const float pixelHeight,
Romain Guy4bb94202010-10-12 15:59:26 -070042 const uint32_t xCount, const uint32_t yCount,
43 const int8_t emptyCount, const uint32_t colorKey):
Romain Guy2728f962010-10-08 18:36:15 -070044 bitmapWidth(bitmapWidth), bitmapHeight(bitmapHeight),
45 pixelWidth(pixelWidth), pixelHeight(pixelHeight),
Romain Guy4bb94202010-10-12 15:59:26 -070046 xCount(xCount), yCount(yCount),
47 emptyCount(emptyCount), colorKey(colorKey) { }
Romain Guyf7f93552010-07-08 19:17:03 -070048 PatchDescription(const PatchDescription& description):
Romain Guy2728f962010-10-08 18:36:15 -070049 bitmapWidth(description.bitmapWidth), bitmapHeight(description.bitmapHeight),
50 pixelWidth(description.pixelWidth), pixelHeight(description.pixelHeight),
Romain Guy4bb94202010-10-12 15:59:26 -070051 xCount(description.xCount), yCount(description.yCount),
52 emptyCount(description.emptyCount), colorKey(description.colorKey) { }
Romain Guyf7f93552010-07-08 19:17:03 -070053
Romain Guy2728f962010-10-08 18:36:15 -070054 float bitmapWidth;
55 float bitmapHeight;
56 float pixelWidth;
57 float pixelHeight;
Romain Guyf7f93552010-07-08 19:17:03 -070058 uint32_t xCount;
59 uint32_t yCount;
Romain Guy4bb94202010-10-12 15:59:26 -070060 int8_t emptyCount;
61 uint32_t colorKey;
Romain Guyf7f93552010-07-08 19:17:03 -070062
63 bool operator<(const PatchDescription& rhs) const {
Romain Guy03750a02010-10-18 14:06:08 -070064 FLOAT_COMPARE(bitmapWidth) {
65 FLOAT_COMPARE(bitmapHeight) {
66 FLOAT_COMPARE(pixelWidth) {
67 FLOAT_COMPARE(pixelHeight) {
68 INT_COMPARE(xCount) {
69 INT_COMPARE(yCount) {
70 INT_COMPARE(emptyCount) {
71 INT_COMPARE(colorKey) return false;
Romain Guy4bb94202010-10-12 15:59:26 -070072 }
73 }
74 }
75 }
76 }
77 }
78 }
79 return false;
Romain Guyf7f93552010-07-08 19:17:03 -070080 }
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 */
87struct Patch {
Romain Guy4bb94202010-10-12 15:59:26 -070088 Patch(const uint32_t xCount, const uint32_t yCount, const int8_t emptyQuads = 0);
Romain Guyfb5e23c2010-07-09 13:52:56 -070089 ~Patch();
Romain Guyf7f93552010-07-08 19:17:03 -070090
Romain Guy759ea802010-09-16 20:49:46 -070091 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 Guy4bb94202010-10-12 15:59:26 -070094 const uint32_t width, const uint32_t height,
95 const uint32_t colorKey = 0);
Romain Guyf7f93552010-07-08 19:17:03 -070096
Romain Guy03750a02010-10-18 14:06:08 -070097 GLuint meshBuffer;
Romain Guyf7f93552010-07-08 19:17:03 -070098 uint32_t verticesCount;
Romain Guyfb5e23c2010-07-09 13:52:56 -070099
100private:
Romain Guy03750a02010-10-18 14:06:08 -0700101 TextureVertex* mVertices;
102
Romain Guy6820ac82010-09-15 18:11:50 -0700103 static inline void generateRow(TextureVertex*& vertex, float y1, float y2,
104 float v1, float v2, const int32_t xDivs[], uint32_t xCount,
Romain Guy4bb94202010-10-12 15:59:26 -0700105 float stretchX, float width, float bitmapWidth,
106 uint32_t& quadCount, const uint32_t colorKey);
Romain Guy759ea802010-09-16 20:49:46 -0700107 static inline void generateQuad(TextureVertex*& vertex,
108 float x1, float y1, float x2, float y2,
Romain Guy4bb94202010-10-12 15:59:26 -0700109 float u1, float v1, float u2, float v2,
110 uint32_t& quadCount, const uint32_t colorKey);
Romain Guyf7f93552010-07-08 19:17:03 -0700111}; // struct Patch
112
113}; // namespace uirenderer
114}; // namespace android
115
116#endif // ANDROID_UI_PATCH_H