blob: a9109cd77f5efb3bbef587785d439034bebd504b [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>
Romain Guy2728f962010-10-08 18:36:15 -070021#include <cstring>
Romain Guyf7f93552010-07-08 19:17:03 -070022
Romain Guyf7f93552010-07-08 19:17:03 -070023#include "Vertex.h"
24
25namespace android {
26namespace uirenderer {
27
28/**
29 * Description of a patch.
30 */
31struct PatchDescription {
Romain Guy2728f962010-10-08 18:36:15 -070032 PatchDescription(): bitmapWidth(0), bitmapHeight(0),
33 pixelWidth(0), pixelHeight(0), xCount(0), yCount(0) { }
34 PatchDescription(const float bitmapWidth, const float bitmapHeight,
35 const float pixelWidth, const float pixelHeight,
36 const uint32_t xCount, const uint32_t yCount):
37 bitmapWidth(bitmapWidth), bitmapHeight(bitmapHeight),
38 pixelWidth(pixelWidth), pixelHeight(pixelHeight),
Romain Guyf7f93552010-07-08 19:17:03 -070039 xCount(xCount), yCount(yCount) { }
40 PatchDescription(const PatchDescription& description):
Romain Guy2728f962010-10-08 18:36:15 -070041 bitmapWidth(description.bitmapWidth), bitmapHeight(description.bitmapHeight),
42 pixelWidth(description.pixelWidth), pixelHeight(description.pixelHeight),
Romain Guyf7f93552010-07-08 19:17:03 -070043 xCount(description.xCount), yCount(description.yCount) { }
44
Romain Guy2728f962010-10-08 18:36:15 -070045 float bitmapWidth;
46 float bitmapHeight;
47 float pixelWidth;
48 float pixelHeight;
Romain Guyf7f93552010-07-08 19:17:03 -070049 uint32_t xCount;
50 uint32_t yCount;
51
52 bool operator<(const PatchDescription& rhs) const {
Romain Guy2728f962010-10-08 18:36:15 -070053 return memcmp(this, &rhs, sizeof(PatchDescription)) < 0;
Romain Guyf7f93552010-07-08 19:17:03 -070054 }
55}; // struct PatchDescription
56
57/**
58 * An OpenGL patch. This contains an array of vertices and an array of
59 * indices to render the vertices.
60 */
61struct Patch {
Romain Guyfb5e23c2010-07-09 13:52:56 -070062 Patch(const uint32_t xCount, const uint32_t yCount);
63 ~Patch();
Romain Guyf7f93552010-07-08 19:17:03 -070064
Romain Guy759ea802010-09-16 20:49:46 -070065 void updateVertices(const float bitmapWidth, const float bitmapHeight,
66 float left, float top, float right, float bottom,
67 const int32_t* xDivs, const int32_t* yDivs,
Romain Guyfb5e23c2010-07-09 13:52:56 -070068 const uint32_t width, const uint32_t height);
Romain Guyf7f93552010-07-08 19:17:03 -070069
70 TextureVertex* vertices;
71 uint32_t verticesCount;
Romain Guyfb5e23c2010-07-09 13:52:56 -070072
73private:
Romain Guy6820ac82010-09-15 18:11:50 -070074 static inline void generateRow(TextureVertex*& vertex, float y1, float y2,
75 float v1, float v2, const int32_t xDivs[], uint32_t xCount,
76 float stretchX, float width, float bitmapWidth);
Romain Guy759ea802010-09-16 20:49:46 -070077 static inline void generateQuad(TextureVertex*& vertex,
78 float x1, float y1, float x2, float y2,
Romain Guy6820ac82010-09-15 18:11:50 -070079 float u1, float v1, float u2, float v2);
Romain Guyf7f93552010-07-08 19:17:03 -070080}; // struct Patch
81
82}; // namespace uirenderer
83}; // namespace android
84
85#endif // ANDROID_UI_PATCH_H