blob: f712455735a813c95b66816870b035d6ea2870c5 [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);
Romain Guyf7f93552010-07-08 19:17:03 -070065
66 TextureVertex* vertices;
67 uint32_t verticesCount;
Romain Guyfb5e23c2010-07-09 13:52:56 -070068
69private:
Romain Guy6820ac82010-09-15 18:11:50 -070070 static inline void generateRow(TextureVertex*& vertex, float y1, float y2,
71 float v1, float v2, const int32_t xDivs[], uint32_t xCount,
72 float stretchX, float width, float bitmapWidth);
73 static inline void generateQuad(TextureVertex*& vertex, float x1, float y1, float x2, float y2,
74 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