blob: 1e78b2fcd4ea62a3b49927055d8a74c6f3d624e7 [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
Romain Guy5b3b3522010-10-27 18:57:51 -070017#ifndef ANDROID_HWUI_PATCH_H
18#define ANDROID_HWUI_PATCH_H
Romain Guyf7f93552010-07-08 19:17:03 -070019
20#include <sys/types.h>
21
Romain Guy03750a02010-10-18 14:06:08 -070022#include <GLES2/gl2.h>
23
Romain Guy5b3b3522010-10-27 18:57:51 -070024#include <utils/Vector.h>
25
26#include "Rect.h"
Romain Guyf7f93552010-07-08 19:17:03 -070027#include "Vertex.h"
Romain Guy4bb94202010-10-12 15:59:26 -070028#include "utils/Compare.h"
Romain Guyf7f93552010-07-08 19:17:03 -070029
30namespace android {
31namespace uirenderer {
32
Romain Guy4bb94202010-10-12 15:59:26 -070033///////////////////////////////////////////////////////////////////////////////
34// 9-patch structures
35///////////////////////////////////////////////////////////////////////////////
36
Romain Guyf7f93552010-07-08 19:17:03 -070037/**
38 * Description of a patch.
39 */
40struct PatchDescription {
Romain Guy4bb94202010-10-12 15:59:26 -070041 PatchDescription(): bitmapWidth(0), bitmapHeight(0), pixelWidth(0), pixelHeight(0),
42 xCount(0), yCount(0), emptyCount(0), colorKey(0) { }
Romain Guy2728f962010-10-08 18:36:15 -070043 PatchDescription(const float bitmapWidth, const float bitmapHeight,
44 const float pixelWidth, const float pixelHeight,
Romain Guy4bb94202010-10-12 15:59:26 -070045 const uint32_t xCount, const uint32_t yCount,
46 const int8_t emptyCount, const uint32_t colorKey):
Romain Guy2728f962010-10-08 18:36:15 -070047 bitmapWidth(bitmapWidth), bitmapHeight(bitmapHeight),
48 pixelWidth(pixelWidth), pixelHeight(pixelHeight),
Romain Guy4bb94202010-10-12 15:59:26 -070049 xCount(xCount), yCount(yCount),
50 emptyCount(emptyCount), colorKey(colorKey) { }
Romain Guyf7f93552010-07-08 19:17:03 -070051 PatchDescription(const PatchDescription& description):
Romain Guy2728f962010-10-08 18:36:15 -070052 bitmapWidth(description.bitmapWidth), bitmapHeight(description.bitmapHeight),
53 pixelWidth(description.pixelWidth), pixelHeight(description.pixelHeight),
Romain Guy4bb94202010-10-12 15:59:26 -070054 xCount(description.xCount), yCount(description.yCount),
55 emptyCount(description.emptyCount), colorKey(description.colorKey) { }
Romain Guyf7f93552010-07-08 19:17:03 -070056
Romain Guy2728f962010-10-08 18:36:15 -070057 float bitmapWidth;
58 float bitmapHeight;
59 float pixelWidth;
60 float pixelHeight;
Romain Guyf7f93552010-07-08 19:17:03 -070061 uint32_t xCount;
62 uint32_t yCount;
Romain Guy4bb94202010-10-12 15:59:26 -070063 int8_t emptyCount;
64 uint32_t colorKey;
Romain Guyf7f93552010-07-08 19:17:03 -070065
66 bool operator<(const PatchDescription& rhs) const {
Romain Guy2665b852010-10-18 15:11:50 -070067 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 Guy4bb94202010-10-12 15:59:26 -070075 }
76 }
77 }
78 }
79 }
80 }
81 }
82 return false;
Romain Guyf7f93552010-07-08 19:17:03 -070083 }
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 */
90struct Patch {
Romain Guy4bb94202010-10-12 15:59:26 -070091 Patch(const uint32_t xCount, const uint32_t yCount, const int8_t emptyQuads = 0);
Romain Guyfb5e23c2010-07-09 13:52:56 -070092 ~Patch();
Romain Guyf7f93552010-07-08 19:17:03 -070093
Romain Guy759ea802010-09-16 20:49:46 -070094 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 Guy4bb94202010-10-12 15:59:26 -070097 const uint32_t width, const uint32_t height,
98 const uint32_t colorKey = 0);
Romain Guyf7f93552010-07-08 19:17:03 -070099
Romain Guy03750a02010-10-18 14:06:08 -0700100 GLuint meshBuffer;
Romain Guyf7f93552010-07-08 19:17:03 -0700101 uint32_t verticesCount;
Romain Guy5b3b3522010-10-27 18:57:51 -0700102 Vector<Rect> quads;
103 bool hasEmptyQuads;
Romain Guyfb5e23c2010-07-09 13:52:56 -0700104
105private:
Romain Guy03750a02010-10-18 14:06:08 -0700106 TextureVertex* mVertices;
107
Romain Guy5b3b3522010-10-27 18:57:51 -0700108 void generateRow(TextureVertex*& vertex, float y1, float y2,
Romain Guy6820ac82010-09-15 18:11:50 -0700109 float v1, float v2, const int32_t xDivs[], uint32_t xCount,
Romain Guy4bb94202010-10-12 15:59:26 -0700110 float stretchX, float width, float bitmapWidth,
111 uint32_t& quadCount, const uint32_t colorKey);
Romain Guy5b3b3522010-10-27 18:57:51 -0700112 void generateQuad(TextureVertex*& vertex,
Romain Guy759ea802010-09-16 20:49:46 -0700113 float x1, float y1, float x2, float y2,
Romain Guy4bb94202010-10-12 15:59:26 -0700114 float u1, float v1, float u2, float v2,
115 uint32_t& quadCount, const uint32_t colorKey);
Romain Guyf7f93552010-07-08 19:17:03 -0700116}; // struct Patch
117
118}; // namespace uirenderer
119}; // namespace android
120
Romain Guy5b3b3522010-10-27 18:57:51 -0700121#endif // ANDROID_HWUI_PATCH_H