blob: ee7bf700c3556d03cd8de57745a48b4665b0dbb4 [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"
28
29namespace android {
30namespace uirenderer {
31
Romain Guy4bb94202010-10-12 15:59:26 -070032///////////////////////////////////////////////////////////////////////////////
Romain Guyf504a2f2011-05-26 16:40:55 -070033// Defines
34///////////////////////////////////////////////////////////////////////////////
35
36#define EXPLODE_GAP 4
37
38///////////////////////////////////////////////////////////////////////////////
Romain Guy4bb94202010-10-12 15:59:26 -070039// 9-patch structures
40///////////////////////////////////////////////////////////////////////////////
41
Romain Guyf7f93552010-07-08 19:17:03 -070042/**
Romain Guyf7f93552010-07-08 19:17:03 -070043 * An OpenGL patch. This contains an array of vertices and an array of
44 * indices to render the vertices.
45 */
46struct Patch {
Romain Guy5341cea2013-01-09 14:15:58 -080047 Patch(const uint32_t xCount, const uint32_t yCount, const int8_t emptyQuads);
Romain Guyfb5e23c2010-07-09 13:52:56 -070048 ~Patch();
Romain Guyf7f93552010-07-08 19:17:03 -070049
Romain Guy759ea802010-09-16 20:49:46 -070050 void updateVertices(const float bitmapWidth, const float bitmapHeight,
Romain Guy6f72beb2010-11-30 12:04:14 -080051 float left, float top, float right, float bottom);
52
53 void updateColorKey(const uint32_t colorKey);
54 void copy(const int32_t* xDivs, const int32_t* yDivs);
Romain Guy5341cea2013-01-09 14:15:58 -080055 bool matches(const int32_t* xDivs, const int32_t* yDivs,
56 const uint32_t colorKey, const int8_t emptyQuads);
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 Guy5341cea2013-01-09 14:15:58 -080065 uint32_t mAllocatedVerticesCount;
Romain Guy6f72beb2010-11-30 12:04:14 -080066
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 Guy5b3b3522010-10-27 18:57:51 -070075 void generateRow(TextureVertex*& vertex, float y1, float y2,
Romain Guy41d35ae2012-10-10 16:06:04 -070076 float v1, float v2, float stretchX, float rescaleX,
77 float width, float bitmapWidth, uint32_t& quadCount);
Romain Guy7444da52011-01-17 10:53:31 -080078 void generateQuad(TextureVertex*& vertex,
Romain Guy759ea802010-09-16 20:49:46 -070079 float x1, float y1, float x2, float y2,
Romain Guy4bb94202010-10-12 15:59:26 -070080 float u1, float v1, float u2, float v2,
Romain Guyeb6a4a12011-01-18 14:02:16 -080081 uint32_t& quadCount);
Romain Guyf7f93552010-07-08 19:17:03 -070082}; // struct Patch
83
84}; // namespace uirenderer
85}; // namespace android
86
Romain Guy5b3b3522010-10-27 18:57:51 -070087#endif // ANDROID_HWUI_PATCH_H