blob: 1ba045d04528b40b354af8770f1755d5ac473799 [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
Romain Guy5b3b3522010-10-27 18:57:51 -070017#ifndef ANDROID_HWUI_PATCH_H
18#define ANDROID_HWUI_PATCH_H
Romain Guyf7f93552010-07-08 19:17:03 -070019
20#include <sys/types.h>
21
Romain Guy03750a02010-10-18 14:06:08 -070022#include <GLES2/gl2.h>
23
Romain Guy5b3b3522010-10-27 18:57:51 -070024#include <utils/Vector.h>
25
Romain Guy3b748a42013-04-17 18:54:38 -070026#include <androidfw/ResourceTypes.h>
27
Romain Guy5b3b3522010-10-27 18:57:51 -070028#include "Rect.h"
Romain Guy3b748a42013-04-17 18:54:38 -070029#include "UvMapper.h"
Romain Guyf7f93552010-07-08 19:17:03 -070030#include "Vertex.h"
31
32namespace android {
33namespace uirenderer {
34
Romain Guy4bb94202010-10-12 15:59:26 -070035///////////////////////////////////////////////////////////////////////////////
36// 9-patch structures
37///////////////////////////////////////////////////////////////////////////////
38
Chris Craik564acf72014-01-02 16:46:18 -080039class Patch {
40public:
Romain Guy3b748a42013-04-17 18:54:38 -070041 Patch();
Romain Guyfb5e23c2010-07-09 13:52:56 -070042 ~Patch();
Romain Guyf7f93552010-07-08 19:17:03 -070043
Romain Guy3b748a42013-04-17 18:54:38 -070044 /**
45 * Returns the size of this patch's mesh in bytes.
46 */
47 uint32_t getSize() const;
Romain Guy6f72beb2010-11-30 12:04:14 -080048
Romain Guy03c00b52013-06-20 18:30:28 -070049 TextureVertex* vertices;
Romain Guyf7f93552010-07-08 19:17:03 -070050 uint32_t verticesCount;
Romain Guy3b748a42013-04-17 18:54:38 -070051 uint32_t indexCount;
Romain Guy5b3b3522010-10-27 18:57:51 -070052 bool hasEmptyQuads;
Romain Guya5ef39a2010-12-03 16:48:20 -080053 Vector<Rect> quads;
Romain Guyfb5e23c2010-07-09 13:52:56 -070054
Romain Guy3b748a42013-04-17 18:54:38 -070055 GLintptr offset;
56 GLintptr textureOffset;
57
58 TextureVertex* createMesh(const float bitmapWidth, const float bitmapHeight,
Romain Guy03c00b52013-06-20 18:30:28 -070059 float width, float height, const Res_png_9patch* patch);
Romain Guy3b748a42013-04-17 18:54:38 -070060 TextureVertex* createMesh(const float bitmapWidth, const float bitmapHeight,
Romain Guy03c00b52013-06-20 18:30:28 -070061 float width, float height, const UvMapper& mapper, const Res_png_9patch* patch);
Romain Guy3b748a42013-04-17 18:54:38 -070062
Romain Guyfb5e23c2010-07-09 13:52:56 -070063private:
Romain Guy3b748a42013-04-17 18:54:38 -070064 void generateRow(const int32_t* xDivs, uint32_t xCount, TextureVertex*& vertex,
65 float y1, float y2, float v1, float v2, float stretchX, float rescaleX,
Romain Guy41d35ae2012-10-10 16:06:04 -070066 float width, float bitmapWidth, uint32_t& quadCount);
Romain Guy3b748a42013-04-17 18:54:38 -070067 void generateQuad(TextureVertex*& vertex, float x1, float y1, float x2, float y2,
68 float u1, float v1, float u2, float v2, uint32_t& quadCount);
69
Narayan Kamath6381dd42014-03-03 17:12:03 +000070 const uint32_t* mColors;
Romain Guy3b748a42013-04-17 18:54:38 -070071 UvMapper mUvMapper;
Romain Guyf7f93552010-07-08 19:17:03 -070072}; // struct Patch
73
74}; // namespace uirenderer
75}; // namespace android
76
Romain Guy5b3b3522010-10-27 18:57:51 -070077#endif // ANDROID_HWUI_PATCH_H