blob: 1d08c64fc40291f79fa5d4f4093c07f3f4de1aa7 [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
17#ifndef ANDROID_UI_PATCH_H
18#define ANDROID_UI_PATCH_H
19
20#include <sys/types.h>
21
Romain Guyf7f93552010-07-08 19:17:03 -070022#include "Vertex.h"
23
24namespace android {
25namespace uirenderer {
26
27/**
28 * Description of a patch.
29 */
30struct PatchDescription {
31 PatchDescription(): xCount(0), yCount(0) { }
32 PatchDescription(const uint32_t xCount, const uint32_t yCount):
33 xCount(xCount), yCount(yCount) { }
34 PatchDescription(const PatchDescription& description):
35 xCount(description.xCount), yCount(description.yCount) { }
36
37 uint32_t xCount;
38 uint32_t yCount;
39
40 bool operator<(const PatchDescription& rhs) const {
41 if (xCount == rhs.xCount) {
42 return yCount < rhs.yCount;
43 }
44 return xCount < rhs.xCount;
45 }
46
47 bool operator==(const PatchDescription& rhs) const {
48 return xCount == rhs.xCount && yCount == rhs.yCount;
49 }
50}; // struct PatchDescription
51
52/**
53 * An OpenGL patch. This contains an array of vertices and an array of
54 * indices to render the vertices.
55 */
56struct Patch {
Romain Guyfb5e23c2010-07-09 13:52:56 -070057 Patch(const uint32_t xCount, const uint32_t yCount);
58 ~Patch();
Romain Guyf7f93552010-07-08 19:17:03 -070059
Romain Guy759ea802010-09-16 20:49:46 -070060 void updateVertices(const float bitmapWidth, const float bitmapHeight,
61 float left, float top, float right, float bottom,
62 const int32_t* xDivs, const int32_t* yDivs,
Romain Guyfb5e23c2010-07-09 13:52:56 -070063 const uint32_t width, const uint32_t height);
Romain Guyf7f93552010-07-08 19:17:03 -070064
65 TextureVertex* vertices;
66 uint32_t verticesCount;
Romain Guyfb5e23c2010-07-09 13:52:56 -070067
68private:
Romain Guy6820ac82010-09-15 18:11:50 -070069 static inline void generateRow(TextureVertex*& vertex, float y1, float y2,
70 float v1, float v2, const int32_t xDivs[], uint32_t xCount,
71 float stretchX, float width, float bitmapWidth);
Romain Guy759ea802010-09-16 20:49:46 -070072 static inline void generateQuad(TextureVertex*& vertex,
73 float x1, float y1, float x2, float y2,
Romain Guy6820ac82010-09-15 18:11:50 -070074 float u1, float v1, float u2, float v2);
Romain Guyf7f93552010-07-08 19:17:03 -070075}; // struct Patch
76
77}; // namespace uirenderer
78}; // namespace android
79
80#endif // ANDROID_UI_PATCH_H