• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <androidfw/ResourceTypes.h>
25 
26 #include "Rect.h"
27 #include "UvMapper.h"
28 
29 #include <vector>
30 
31 namespace android {
32 namespace uirenderer {
33 
34 struct TextureVertex;
35 
36 ///////////////////////////////////////////////////////////////////////////////
37 // 9-patch structures
38 ///////////////////////////////////////////////////////////////////////////////
39 
40 class Patch {
41 public:
42     Patch(const float bitmapWidth, const float bitmapHeight,
43             float width, float height,
44             const UvMapper& mapper, const Res_png_9patch* patch);
45 
46     /**
47      * Returns the size of this patch's mesh in bytes.
48      */
49     uint32_t getSize() const;
50 
51     std::unique_ptr<TextureVertex[]> vertices;
52     uint32_t verticesCount = 0;
53     uint32_t indexCount = 0;
54     bool hasEmptyQuads = false;
55     std::vector<Rect> quads;
56 
57     GLintptr positionOffset = 0;
58     GLintptr textureOffset = 0;
59 
60 private:
61     void generateRow(const int32_t* xDivs, uint32_t xCount, TextureVertex*& vertex,
62             float y1, float y2, float v1, float v2, float stretchX, float rescaleX,
63             float width, float bitmapWidth, uint32_t& quadCount);
64     void generateQuad(TextureVertex*& vertex, float x1, float y1, float x2, float y2,
65             float u1, float v1, float u2, float v2, uint32_t& quadCount);
66 
67     const uint32_t* mColors;
68     UvMapper mUvMapper;
69 }; // struct Patch
70 
71 }; // namespace uirenderer
72 }; // namespace android
73 
74 #endif // ANDROID_HWUI_PATCH_H
75