blob: 5d3ad034f4759e96765398d27d7ab637426f1881 [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 Guyfb5e23c2010-07-09 13:52:56 -070022#include <SkBitmap.h>
Romain Guyf7f93552010-07-08 19:17:03 -070023
24#include "Vertex.h"
25
26namespace android {
27namespace uirenderer {
28
29/**
30 * Description of a patch.
31 */
32struct PatchDescription {
33 PatchDescription(): xCount(0), yCount(0) { }
34 PatchDescription(const uint32_t xCount, const uint32_t yCount):
35 xCount(xCount), yCount(yCount) { }
36 PatchDescription(const PatchDescription& description):
37 xCount(description.xCount), yCount(description.yCount) { }
38
39 uint32_t xCount;
40 uint32_t yCount;
41
42 bool operator<(const PatchDescription& rhs) const {
43 if (xCount == rhs.xCount) {
44 return yCount < rhs.yCount;
45 }
46 return xCount < rhs.xCount;
47 }
48
49 bool operator==(const PatchDescription& rhs) const {
50 return xCount == rhs.xCount && yCount == rhs.yCount;
51 }
52}; // struct PatchDescription
53
54/**
55 * An OpenGL patch. This contains an array of vertices and an array of
56 * indices to render the vertices.
57 */
58struct Patch {
Romain Guyfb5e23c2010-07-09 13:52:56 -070059 Patch(const uint32_t xCount, const uint32_t yCount);
60 ~Patch();
Romain Guyf7f93552010-07-08 19:17:03 -070061
Romain Guyfb5e23c2010-07-09 13:52:56 -070062 void updateVertices(const SkBitmap* bitmap, float left, float top, float right, float bottom,
63 const int32_t* xDivs, const int32_t* yDivs,
64 const uint32_t width, const uint32_t height);
65 void dump();
Romain Guyf7f93552010-07-08 19:17:03 -070066
67 uint32_t xCount;
68 uint32_t yCount;
69
70 uint16_t* indices;
71 uint32_t indicesCount;
72
73 TextureVertex* vertices;
74 uint32_t verticesCount;
Romain Guyfb5e23c2010-07-09 13:52:56 -070075
76private:
77 static inline void generateVertices(TextureVertex* vertex, float y, float v,
78 const int32_t xDivs[], uint32_t xCount, float xStretch, float xStretchTex,
79 float width, float widthTex);
Romain Guyf7f93552010-07-08 19:17:03 -070080}; // struct Patch
81
82}; // namespace uirenderer
83}; // namespace android
84
85#endif // ANDROID_UI_PATCH_H