blob: a659ed227beca243bb4ea1ee6d6e4ee1e4f41400 [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 Guy3b748a42013-04-17 18:54:38 -070024#include <androidfw/ResourceTypes.h>
25
Romain Guy5b3b3522010-10-27 18:57:51 -070026#include "Rect.h"
Romain Guy3b748a42013-04-17 18:54:38 -070027#include "UvMapper.h"
Romain Guyf7f93552010-07-08 19:17:03 -070028
John Reck272a6852015-07-29 16:48:58 -070029#include <vector>
30
Romain Guyf7f93552010-07-08 19:17:03 -070031namespace android {
32namespace uirenderer {
33
Chris Craike84a2082014-12-22 14:28:49 -080034struct TextureVertex;
Tom Hudson2dc236b2014-10-15 15:46:42 -040035
Romain Guy4bb94202010-10-12 15:59:26 -070036///////////////////////////////////////////////////////////////////////////////
37// 9-patch structures
38///////////////////////////////////////////////////////////////////////////////
39
Chris Craik564acf72014-01-02 16:46:18 -080040class Patch {
41public:
John Reck1bcacfd2017-11-03 10:12:19 -070042 Patch(const float bitmapWidth, const float bitmapHeight, float width, float height,
43 const UvMapper& mapper, const Res_png_9patch* patch);
Romain Guyf7f93552010-07-08 19:17:03 -070044
Romain Guy3b748a42013-04-17 18:54:38 -070045 /**
46 * Returns the size of this patch's mesh in bytes.
47 */
48 uint32_t getSize() const;
Romain Guy6f72beb2010-11-30 12:04:14 -080049
Chris Craik51d6a3d2014-12-22 17:16:56 -080050 std::unique_ptr<TextureVertex[]> vertices;
Chris Craike5c65842015-03-02 17:50:26 -080051 uint32_t verticesCount = 0;
52 uint32_t indexCount = 0;
53 bool hasEmptyQuads = false;
John Reck272a6852015-07-29 16:48:58 -070054 std::vector<Rect> quads;
Romain Guyfb5e23c2010-07-09 13:52:56 -070055
Chris Craik8820fd12015-03-03 14:20:47 -080056 GLintptr positionOffset = 0;
Chris Craike5c65842015-03-02 17:50:26 -080057 GLintptr textureOffset = 0;
Romain Guy3b748a42013-04-17 18:54:38 -070058
Romain Guyfb5e23c2010-07-09 13:52:56 -070059private:
John Reck1bcacfd2017-11-03 10:12:19 -070060 void generateRow(const int32_t* xDivs, uint32_t xCount, TextureVertex*& vertex, float y1,
61 float y2, float v1, float v2, float stretchX, float rescaleX, float width,
62 float bitmapWidth, uint32_t& quadCount);
63 void generateQuad(TextureVertex*& vertex, float x1, float y1, float x2, float y2, float u1,
64 float v1, float u2, float v2, uint32_t& quadCount);
Romain Guy3b748a42013-04-17 18:54:38 -070065
Chris Craik8820fd12015-03-03 14:20:47 -080066 const uint32_t* mColors;
Romain Guy3b748a42013-04-17 18:54:38 -070067 UvMapper mUvMapper;
John Reck1bcacfd2017-11-03 10:12:19 -070068}; // struct Patch
Romain Guyf7f93552010-07-08 19:17:03 -070069
John Reck1bcacfd2017-11-03 10:12:19 -070070}; // namespace uirenderer
71}; // namespace android
Romain Guyf7f93552010-07-08 19:17:03 -070072
John Reck1bcacfd2017-11-03 10:12:19 -070073#endif // ANDROID_HWUI_PATCH_H