blob: 0f0ffa22594e71e552716d72440b43653ad3ca26 [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 bool hasEmptyQuads;
Romain Guya5ef39a2010-12-03 16:48:20 -080055 Vector<Rect> quads;
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
Romain Guy6f72beb2010-11-30 12:04:14 -080061 int32_t* mXDivs;
Romain Guy6f72beb2010-11-30 12:04:14 -080062 int32_t* mYDivs;
63 uint32_t mColorKey;
64
Romain Guya5ef39a2010-12-03 16:48:20 -080065 uint32_t mXCount;
66 uint32_t mYCount;
67 int8_t mEmptyQuads;
68
Romain Guy6f72beb2010-11-30 12:04:14 -080069 void copy(const int32_t* yDivs);
Romain Guy03750a02010-10-18 14:06:08 -070070
Romain Guy5b3b3522010-10-27 18:57:51 -070071 void generateRow(TextureVertex*& vertex, float y1, float y2,
Romain Guy6f72beb2010-11-30 12:04:14 -080072 float v1, float v2, float stretchX, float width, float bitmapWidth,
Romain Guyeb6a4a12011-01-18 14:02:16 -080073 uint32_t& quadCount);
Romain Guy7444da52011-01-17 10:53:31 -080074 void generateQuad(TextureVertex*& vertex,
Romain Guy759ea802010-09-16 20:49:46 -070075 float x1, float y1, float x2, float y2,
Romain Guy4bb94202010-10-12 15:59:26 -070076 float u1, float v1, float u2, float v2,
Romain Guyeb6a4a12011-01-18 14:02:16 -080077 uint32_t& quadCount);
Romain Guyf7f93552010-07-08 19:17:03 -070078}; // struct Patch
79
80}; // namespace uirenderer
81}; // namespace android
82
Romain Guy5b3b3522010-10-27 18:57:51 -070083#endif // ANDROID_HWUI_PATCH_H