blob: 2cb8ecbc21f00bdd35d5c9ed6f5098419a1fa805 [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/**
Romain Guyf7f93552010-07-08 19:17:03 -070038 * An OpenGL patch. This contains an array of vertices and an array of
39 * indices to render the vertices.
40 */
41struct Patch {
Romain Guy4bb94202010-10-12 15:59:26 -070042 Patch(const uint32_t xCount, const uint32_t yCount, const int8_t emptyQuads = 0);
Romain Guyfb5e23c2010-07-09 13:52:56 -070043 ~Patch();
Romain Guyf7f93552010-07-08 19:17:03 -070044
Romain Guy759ea802010-09-16 20:49:46 -070045 void updateVertices(const float bitmapWidth, const float bitmapHeight,
Romain Guy6f72beb2010-11-30 12:04:14 -080046 float left, float top, float right, float bottom);
47
48 void updateColorKey(const uint32_t colorKey);
49 void copy(const int32_t* xDivs, const int32_t* yDivs);
50 bool matches(const int32_t* xDivs, const int32_t* yDivs, const uint32_t colorKey);
Romain Guyf7f93552010-07-08 19:17:03 -070051
Romain Guy03750a02010-10-18 14:06:08 -070052 GLuint meshBuffer;
Romain Guyf7f93552010-07-08 19:17:03 -070053 uint32_t verticesCount;
Romain Guy5b3b3522010-10-27 18:57:51 -070054 Vector<Rect> quads;
55 bool hasEmptyQuads;
Romain Guyfb5e23c2010-07-09 13:52:56 -070056
57private:
Romain Guy03750a02010-10-18 14:06:08 -070058 TextureVertex* mVertices;
Romain Guy6f72beb2010-11-30 12:04:14 -080059 bool mUploaded;
60
61 uint32_t mXCount;
62 int32_t* mXDivs;
63 uint32_t mYCount;
64 int32_t* mYDivs;
65 uint32_t mColorKey;
66
67 void copy(const int32_t* yDivs);
Romain Guy03750a02010-10-18 14:06:08 -070068
Romain Guy5b3b3522010-10-27 18:57:51 -070069 void generateRow(TextureVertex*& vertex, float y1, float y2,
Romain Guy6f72beb2010-11-30 12:04:14 -080070 float v1, float v2, float stretchX, float width, float bitmapWidth,
71 uint32_t& quadCount);
Romain Guy5b3b3522010-10-27 18:57:51 -070072 void generateQuad(TextureVertex*& vertex,
Romain Guy759ea802010-09-16 20:49:46 -070073 float x1, float y1, float x2, float y2,
Romain Guy4bb94202010-10-12 15:59:26 -070074 float u1, float v1, float u2, float v2,
Romain Guy6f72beb2010-11-30 12:04:14 -080075 uint32_t& quadCount);
Romain Guyf7f93552010-07-08 19:17:03 -070076}; // struct Patch
77
78}; // namespace uirenderer
79}; // namespace android
80
Romain Guy5b3b3522010-10-27 18:57:51 -070081#endif // ANDROID_HWUI_PATCH_H