blob: 0518d911d7d8a138d791c960683302faa37391f2 [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///////////////////////////////////////////////////////////////////////////////
Romain Guyf504a2f2011-05-26 16:40:55 -070034// Defines
35///////////////////////////////////////////////////////////////////////////////
36
37#define EXPLODE_GAP 4
38
39///////////////////////////////////////////////////////////////////////////////
Romain Guy4bb94202010-10-12 15:59:26 -070040// 9-patch structures
41///////////////////////////////////////////////////////////////////////////////
42
Romain Guyf7f93552010-07-08 19:17:03 -070043/**
Romain Guyf7f93552010-07-08 19:17:03 -070044 * An OpenGL patch. This contains an array of vertices and an array of
45 * indices to render the vertices.
46 */
47struct Patch {
Romain Guy4bb94202010-10-12 15:59:26 -070048 Patch(const uint32_t xCount, const uint32_t yCount, const int8_t emptyQuads = 0);
Romain Guyfb5e23c2010-07-09 13:52:56 -070049 ~Patch();
Romain Guyf7f93552010-07-08 19:17:03 -070050
Romain Guy759ea802010-09-16 20:49:46 -070051 void updateVertices(const float bitmapWidth, const float bitmapHeight,
Romain Guy6f72beb2010-11-30 12:04:14 -080052 float left, float top, float right, float bottom);
53
54 void updateColorKey(const uint32_t colorKey);
55 void copy(const int32_t* xDivs, const int32_t* yDivs);
56 bool matches(const int32_t* xDivs, const int32_t* yDivs, const uint32_t colorKey);
Romain Guyf7f93552010-07-08 19:17:03 -070057
Romain Guy03750a02010-10-18 14:06:08 -070058 GLuint meshBuffer;
Romain Guyf7f93552010-07-08 19:17:03 -070059 uint32_t verticesCount;
Romain Guy5b3b3522010-10-27 18:57:51 -070060 bool hasEmptyQuads;
Romain Guya5ef39a2010-12-03 16:48:20 -080061 Vector<Rect> quads;
Romain Guyfb5e23c2010-07-09 13:52:56 -070062
63private:
Romain Guy03750a02010-10-18 14:06:08 -070064 TextureVertex* mVertices;
Romain Guy6f72beb2010-11-30 12:04:14 -080065 bool mUploaded;
66
Romain Guy6f72beb2010-11-30 12:04:14 -080067 int32_t* mXDivs;
Romain Guy6f72beb2010-11-30 12:04:14 -080068 int32_t* mYDivs;
69 uint32_t mColorKey;
70
Romain Guya5ef39a2010-12-03 16:48:20 -080071 uint32_t mXCount;
72 uint32_t mYCount;
73 int8_t mEmptyQuads;
74
Romain Guy6f72beb2010-11-30 12:04:14 -080075 void copy(const int32_t* yDivs);
Romain Guy03750a02010-10-18 14:06:08 -070076
Romain Guy5b3b3522010-10-27 18:57:51 -070077 void generateRow(TextureVertex*& vertex, float y1, float y2,
Romain Guy41d35ae2012-10-10 16:06:04 -070078 float v1, float v2, float stretchX, float rescaleX,
79 float width, float bitmapWidth, uint32_t& quadCount);
Romain Guy7444da52011-01-17 10:53:31 -080080 void generateQuad(TextureVertex*& vertex,
Romain Guy759ea802010-09-16 20:49:46 -070081 float x1, float y1, float x2, float y2,
Romain Guy4bb94202010-10-12 15:59:26 -070082 float u1, float v1, float u2, float v2,
Romain Guyeb6a4a12011-01-18 14:02:16 -080083 uint32_t& quadCount);
Romain Guyf7f93552010-07-08 19:17:03 -070084}; // struct Patch
85
86}; // namespace uirenderer
87}; // namespace android
88
Romain Guy5b3b3522010-10-27 18:57:51 -070089#endif // ANDROID_HWUI_PATCH_H