blob: cab0e540c82cc93e753d9dd1b4fb6bd4c0953ae1 [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 Guy5341cea2013-01-09 14:15:58 -080048 Patch(const uint32_t xCount, const uint32_t yCount, const int8_t emptyQuads);
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);
Romain Guy5341cea2013-01-09 14:15:58 -080056 bool matches(const int32_t* xDivs, const int32_t* yDivs,
57 const uint32_t colorKey, const int8_t emptyQuads);
Romain Guyf7f93552010-07-08 19:17:03 -070058
Romain Guy03750a02010-10-18 14:06:08 -070059 GLuint meshBuffer;
Romain Guyf7f93552010-07-08 19:17:03 -070060 uint32_t verticesCount;
Romain Guy5b3b3522010-10-27 18:57:51 -070061 bool hasEmptyQuads;
Romain Guya5ef39a2010-12-03 16:48:20 -080062 Vector<Rect> quads;
Romain Guyfb5e23c2010-07-09 13:52:56 -070063
64private:
Romain Guy03750a02010-10-18 14:06:08 -070065 TextureVertex* mVertices;
Romain Guy5341cea2013-01-09 14:15:58 -080066 uint32_t mAllocatedVerticesCount;
Romain Guy6f72beb2010-11-30 12:04:14 -080067
Romain Guy6f72beb2010-11-30 12:04:14 -080068 int32_t* mXDivs;
Romain Guy6f72beb2010-11-30 12:04:14 -080069 int32_t* mYDivs;
70 uint32_t mColorKey;
71
Romain Guya5ef39a2010-12-03 16:48:20 -080072 uint32_t mXCount;
73 uint32_t mYCount;
74 int8_t mEmptyQuads;
75
Romain Guy5b3b3522010-10-27 18:57:51 -070076 void generateRow(TextureVertex*& vertex, float y1, float y2,
Romain Guy41d35ae2012-10-10 16:06:04 -070077 float v1, float v2, float stretchX, float rescaleX,
78 float width, float bitmapWidth, uint32_t& quadCount);
Romain Guy7444da52011-01-17 10:53:31 -080079 void generateQuad(TextureVertex*& vertex,
Romain Guy759ea802010-09-16 20:49:46 -070080 float x1, float y1, float x2, float y2,
Romain Guy4bb94202010-10-12 15:59:26 -070081 float u1, float v1, float u2, float v2,
Romain Guyeb6a4a12011-01-18 14:02:16 -080082 uint32_t& quadCount);
Romain Guyf7f93552010-07-08 19:17:03 -070083}; // struct Patch
84
85}; // namespace uirenderer
86}; // namespace android
87
Romain Guy5b3b3522010-10-27 18:57:51 -070088#endif // ANDROID_HWUI_PATCH_H