Patch.h revision 13ba0054846ce630ca31e8f26169fd9388faee02
1/*
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_HWUI_PATCH_H
18#define ANDROID_HWUI_PATCH_H
19
20#include <sys/types.h>
21
22#include <GLES2/gl2.h>
23
24#include <utils/Vector.h>
25
26#include "Rect.h"
27#include "Vertex.h"
28
29namespace android {
30namespace uirenderer {
31
32///////////////////////////////////////////////////////////////////////////////
33// Defines
34///////////////////////////////////////////////////////////////////////////////
35
36#define EXPLODE_GAP 4
37
38///////////////////////////////////////////////////////////////////////////////
39// 9-patch structures
40///////////////////////////////////////////////////////////////////////////////
41
42/**
43 * An OpenGL patch. This contains an array of vertices and an array of
44 * indices to render the vertices.
45 */
46struct Patch {
47    Patch(const uint32_t xCount, const uint32_t yCount, const int8_t emptyQuads);
48    ~Patch();
49
50    void updateVertices(const float bitmapWidth, const float bitmapHeight,
51            float left, float top, float right, float bottom);
52
53    void updateColorKey(const uint32_t colorKey);
54    void copy(const int32_t* xDivs, const int32_t* yDivs);
55    bool matches(const int32_t* xDivs, const int32_t* yDivs,
56            const uint32_t colorKey, const int8_t emptyQuads);
57
58    GLuint meshBuffer;
59    uint32_t verticesCount;
60    bool hasEmptyQuads;
61    Vector<Rect> quads;
62
63private:
64    TextureVertex* mVertices;
65    uint32_t mAllocatedVerticesCount;
66
67    int32_t* mXDivs;
68    int32_t* mYDivs;
69    uint32_t mColorKey;
70
71    uint32_t mXCount;
72    uint32_t mYCount;
73    int8_t mEmptyQuads;
74
75    void generateRow(TextureVertex*& vertex, float y1, float y2,
76            float v1, float v2, float stretchX, float rescaleX,
77            float width, float bitmapWidth, uint32_t& quadCount);
78    void generateQuad(TextureVertex*& vertex,
79            float x1, float y1, float x2, float y2,
80            float u1, float v1, float u2, float v2,
81            uint32_t& quadCount);
82}; // struct Patch
83
84}; // namespace uirenderer
85}; // namespace android
86
87#endif // ANDROID_HWUI_PATCH_H
88