Romain Guy | fb5e23c | 2010-07-09 13:52:56 -0700 | [diff] [blame] | 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 | #define LOG_TAG "OpenGLRenderer" |
| 18 | |
Romain Guy | 6820ac8 | 2010-09-15 18:11:50 -0700 | [diff] [blame] | 19 | #include <cmath> |
Romain Guy | fb5e23c | 2010-07-09 13:52:56 -0700 | [diff] [blame] | 20 | |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 21 | #include <utils/Log.h> |
| 22 | |
Romain Guy | fb5e23c | 2010-07-09 13:52:56 -0700 | [diff] [blame] | 23 | #include "Patch.h" |
Romain Guy | 03750a0 | 2010-10-18 14:06:08 -0700 | [diff] [blame] | 24 | #include "Caches.h" |
Romain Guy | a5ef39a | 2010-12-03 16:48:20 -0800 | [diff] [blame] | 25 | #include "Properties.h" |
Romain Guy | fb5e23c | 2010-07-09 13:52:56 -0700 | [diff] [blame] | 26 | |
| 27 | namespace android { |
| 28 | namespace uirenderer { |
| 29 | |
| 30 | /////////////////////////////////////////////////////////////////////////////// |
| 31 | // Constructors/destructor |
| 32 | /////////////////////////////////////////////////////////////////////////////// |
| 33 | |
Romain Guy | 6f72beb | 2010-11-30 12:04:14 -0800 | [diff] [blame] | 34 | Patch::Patch(const uint32_t xCount, const uint32_t yCount, const int8_t emptyQuads): |
Romain Guy | a5ef39a | 2010-12-03 16:48:20 -0800 | [diff] [blame] | 35 | mXCount(xCount), mYCount(yCount), mEmptyQuads(emptyQuads) { |
| 36 | // Initialized with the maximum number of vertices we will need |
Romain Guy | fb5e23c | 2010-07-09 13:52:56 -0700 | [diff] [blame] | 37 | // 2 triangles per patch, 3 vertices per triangle |
Romain Guy | 8ab4079 | 2010-12-07 13:30:10 -0800 | [diff] [blame] | 38 | uint32_t maxVertices = ((xCount + 1) * (yCount + 1) - emptyQuads) * 2 * 3; |
Romain Guy | a5ef39a | 2010-12-03 16:48:20 -0800 | [diff] [blame] | 39 | mVertices = new TextureVertex[maxVertices]; |
Romain Guy | 6f72beb | 2010-11-30 12:04:14 -0800 | [diff] [blame] | 40 | mUploaded = false; |
| 41 | |
Romain Guy | a5ef39a | 2010-12-03 16:48:20 -0800 | [diff] [blame] | 42 | verticesCount = 0; |
| 43 | hasEmptyQuads = emptyQuads > 0; |
| 44 | |
Romain Guy | 6f72beb | 2010-11-30 12:04:14 -0800 | [diff] [blame] | 45 | mColorKey = 0; |
| 46 | mXDivs = new int32_t[mXCount]; |
| 47 | mYDivs = new int32_t[mYCount]; |
Romain Guy | 03750a0 | 2010-10-18 14:06:08 -0700 | [diff] [blame] | 48 | |
Romain Guy | a5ef39a | 2010-12-03 16:48:20 -0800 | [diff] [blame] | 49 | PATCH_LOGD(" patch: xCount = %d, yCount = %d, emptyQuads = %d, max vertices = %d", |
| 50 | xCount, yCount, emptyQuads, maxVertices); |
Romain Guy | bd41a11 | 2010-12-02 17:16:26 -0800 | [diff] [blame] | 51 | |
Romain Guy | 03750a0 | 2010-10-18 14:06:08 -0700 | [diff] [blame] | 52 | glGenBuffers(1, &meshBuffer); |
Romain Guy | fb5e23c | 2010-07-09 13:52:56 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | Patch::~Patch() { |
Romain Guy | 03750a0 | 2010-10-18 14:06:08 -0700 | [diff] [blame] | 56 | delete[] mVertices; |
Romain Guy | 6f72beb | 2010-11-30 12:04:14 -0800 | [diff] [blame] | 57 | delete[] mXDivs; |
| 58 | delete[] mYDivs; |
Romain Guy | 03750a0 | 2010-10-18 14:06:08 -0700 | [diff] [blame] | 59 | glDeleteBuffers(1, &meshBuffer); |
Romain Guy | fb5e23c | 2010-07-09 13:52:56 -0700 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | 6f72beb | 2010-11-30 12:04:14 -0800 | [diff] [blame] | 63 | // Patch management |
| 64 | /////////////////////////////////////////////////////////////////////////////// |
| 65 | |
| 66 | void Patch::copy(const int32_t* xDivs, const int32_t* yDivs) { |
| 67 | memcpy(mXDivs, xDivs, mXCount * sizeof(int32_t)); |
| 68 | memcpy(mYDivs, yDivs, mYCount * sizeof(int32_t)); |
| 69 | } |
| 70 | |
| 71 | void Patch::copy(const int32_t* yDivs) { |
| 72 | memcpy(mYDivs, yDivs, mYCount * sizeof(int32_t)); |
| 73 | } |
| 74 | |
| 75 | void Patch::updateColorKey(const uint32_t colorKey) { |
| 76 | mColorKey = colorKey; |
| 77 | } |
| 78 | |
| 79 | bool Patch::matches(const int32_t* xDivs, const int32_t* yDivs, const uint32_t colorKey) { |
| 80 | if (mColorKey != colorKey) { |
| 81 | updateColorKey(colorKey); |
| 82 | copy(xDivs, yDivs); |
| 83 | return false; |
| 84 | } |
| 85 | |
| 86 | for (uint32_t i = 0; i < mXCount; i++) { |
| 87 | if (mXDivs[i] != xDivs[i]) { |
| 88 | // The Y divs may or may not match, copy everything |
| 89 | copy(xDivs, yDivs); |
| 90 | return false; |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | for (uint32_t i = 0; i < mYCount; i++) { |
| 95 | if (mYDivs[i] != yDivs[i]) { |
| 96 | // We know all the X divs match, copy only Y divs |
| 97 | copy(yDivs); |
| 98 | return false; |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | return true; |
| 103 | } |
| 104 | |
| 105 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | fb5e23c | 2010-07-09 13:52:56 -0700 | [diff] [blame] | 106 | // Vertices management |
| 107 | /////////////////////////////////////////////////////////////////////////////// |
| 108 | |
Romain Guy | 759ea80 | 2010-09-16 20:49:46 -0700 | [diff] [blame] | 109 | void Patch::updateVertices(const float bitmapWidth, const float bitmapHeight, |
Romain Guy | 6f72beb | 2010-11-30 12:04:14 -0800 | [diff] [blame] | 110 | float left, float top, float right, float bottom) { |
Romain Guy | a5ef39a | 2010-12-03 16:48:20 -0800 | [diff] [blame] | 111 | #if RENDER_LAYERS_AS_REGIONS |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 112 | if (hasEmptyQuads) quads.clear(); |
Romain Guy | a5ef39a | 2010-12-03 16:48:20 -0800 | [diff] [blame] | 113 | #endif |
| 114 | |
| 115 | // Reset the vertices count here, we will count exactly how many |
| 116 | // vertices we actually need when generating the quads |
| 117 | verticesCount = 0; |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 118 | |
Romain Guy | 6f72beb | 2010-11-30 12:04:14 -0800 | [diff] [blame] | 119 | const uint32_t xStretchCount = (mXCount + 1) >> 1; |
| 120 | const uint32_t yStretchCount = (mYCount + 1) >> 1; |
Romain Guy | fb5e23c | 2010-07-09 13:52:56 -0700 | [diff] [blame] | 121 | |
Romain Guy | 6820ac8 | 2010-09-15 18:11:50 -0700 | [diff] [blame] | 122 | float stretchX = 0.0f; |
| 123 | float stretchY = 0.0; |
Romain Guy | fb5e23c | 2010-07-09 13:52:56 -0700 | [diff] [blame] | 124 | |
| 125 | const float meshWidth = right - left; |
| 126 | |
Romain Guy | fb5e23c | 2010-07-09 13:52:56 -0700 | [diff] [blame] | 127 | if (xStretchCount > 0) { |
| 128 | uint32_t stretchSize = 0; |
Romain Guy | 6f72beb | 2010-11-30 12:04:14 -0800 | [diff] [blame] | 129 | for (uint32_t i = 1; i < mXCount; i += 2) { |
| 130 | stretchSize += mXDivs[i] - mXDivs[i - 1]; |
Romain Guy | fb5e23c | 2010-07-09 13:52:56 -0700 | [diff] [blame] | 131 | } |
Romain Guy | 6820ac8 | 2010-09-15 18:11:50 -0700 | [diff] [blame] | 132 | const float xStretchTex = stretchSize; |
Romain Guy | fb5e23c | 2010-07-09 13:52:56 -0700 | [diff] [blame] | 133 | const float fixed = bitmapWidth - stretchSize; |
Romain Guy | 6820ac8 | 2010-09-15 18:11:50 -0700 | [diff] [blame] | 134 | const float xStretch = right - left - fixed; |
| 135 | stretchX = xStretch / xStretchTex; |
Romain Guy | fb5e23c | 2010-07-09 13:52:56 -0700 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | if (yStretchCount > 0) { |
| 139 | uint32_t stretchSize = 0; |
Romain Guy | 6f72beb | 2010-11-30 12:04:14 -0800 | [diff] [blame] | 140 | for (uint32_t i = 1; i < mYCount; i += 2) { |
| 141 | stretchSize += mYDivs[i] - mYDivs[i - 1]; |
Romain Guy | fb5e23c | 2010-07-09 13:52:56 -0700 | [diff] [blame] | 142 | } |
Romain Guy | 6820ac8 | 2010-09-15 18:11:50 -0700 | [diff] [blame] | 143 | const float yStretchTex = stretchSize; |
Romain Guy | fb5e23c | 2010-07-09 13:52:56 -0700 | [diff] [blame] | 144 | const float fixed = bitmapHeight - stretchSize; |
Romain Guy | 6820ac8 | 2010-09-15 18:11:50 -0700 | [diff] [blame] | 145 | const float yStretch = bottom - top - fixed; |
| 146 | stretchY = yStretch / yStretchTex; |
Romain Guy | fb5e23c | 2010-07-09 13:52:56 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Romain Guy | 03750a0 | 2010-10-18 14:06:08 -0700 | [diff] [blame] | 149 | TextureVertex* vertex = mVertices; |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 150 | uint32_t quadCount = 0; |
Romain Guy | fb5e23c | 2010-07-09 13:52:56 -0700 | [diff] [blame] | 151 | |
Romain Guy | 6820ac8 | 2010-09-15 18:11:50 -0700 | [diff] [blame] | 152 | float previousStepY = 0.0f; |
Romain Guy | fb5e23c | 2010-07-09 13:52:56 -0700 | [diff] [blame] | 153 | |
Romain Guy | 6820ac8 | 2010-09-15 18:11:50 -0700 | [diff] [blame] | 154 | float y1 = 0.0f; |
Romain Guy | f504a2f | 2011-05-26 16:40:55 -0700 | [diff] [blame] | 155 | float y2 = 0.0f; |
Romain Guy | 6820ac8 | 2010-09-15 18:11:50 -0700 | [diff] [blame] | 156 | float v1 = 0.0f; |
| 157 | |
Romain Guy | eb6a4a1 | 2011-01-18 14:02:16 -0800 | [diff] [blame] | 158 | for (uint32_t i = 0; i < mYCount; i++) { |
Romain Guy | 6f72beb | 2010-11-30 12:04:14 -0800 | [diff] [blame] | 159 | float stepY = mYDivs[i]; |
Romain Guy | 5e7c469 | 2011-10-20 20:31:50 -0700 | [diff] [blame] | 160 | const float segment = stepY - previousStepY; |
Romain Guy | 6820ac8 | 2010-09-15 18:11:50 -0700 | [diff] [blame] | 161 | |
Romain Guy | 6820ac8 | 2010-09-15 18:11:50 -0700 | [diff] [blame] | 162 | if (i & 1) { |
Romain Guy | 8ab4079 | 2010-12-07 13:30:10 -0800 | [diff] [blame] | 163 | y2 = y1 + floorf(segment * stretchY + 0.5f); |
Romain Guy | fb5e23c | 2010-07-09 13:52:56 -0700 | [diff] [blame] | 164 | } else { |
Romain Guy | 5e7c469 | 2011-10-20 20:31:50 -0700 | [diff] [blame] | 165 | y2 = y1 + segment; |
Romain Guy | fb5e23c | 2010-07-09 13:52:56 -0700 | [diff] [blame] | 166 | } |
Romain Guy | 5e7c469 | 2011-10-20 20:31:50 -0700 | [diff] [blame] | 167 | |
| 168 | float vOffset = y1 == y2 ? 0.0f : 0.5 - (0.5 * segment / (y2 - y1)); |
| 169 | float v2 = fmax(0.0f, stepY - vOffset) / bitmapHeight; |
| 170 | v1 += vOffset / bitmapHeight; |
Romain Guy | 6820ac8 | 2010-09-15 18:11:50 -0700 | [diff] [blame] | 171 | |
Romain Guy | eb6a4a1 | 2011-01-18 14:02:16 -0800 | [diff] [blame] | 172 | if (stepY > 0.0f) { |
Romain Guy | f504a2f | 2011-05-26 16:40:55 -0700 | [diff] [blame] | 173 | #if DEBUG_EXPLODE_PATCHES |
| 174 | y1 += i * EXPLODE_GAP; |
| 175 | y2 += i * EXPLODE_GAP; |
| 176 | #endif |
Romain Guy | eb6a4a1 | 2011-01-18 14:02:16 -0800 | [diff] [blame] | 177 | generateRow(vertex, y1, y2, v1, v2, stretchX, right - left, |
| 178 | bitmapWidth, quadCount); |
Romain Guy | f504a2f | 2011-05-26 16:40:55 -0700 | [diff] [blame] | 179 | #if DEBUG_EXPLODE_PATCHES |
| 180 | y2 -= i * EXPLODE_GAP; |
| 181 | #endif |
Romain Guy | eb6a4a1 | 2011-01-18 14:02:16 -0800 | [diff] [blame] | 182 | } |
Romain Guy | 6820ac8 | 2010-09-15 18:11:50 -0700 | [diff] [blame] | 183 | |
| 184 | y1 = y2; |
Romain Guy | 5e7c469 | 2011-10-20 20:31:50 -0700 | [diff] [blame] | 185 | v1 = stepY / bitmapHeight; |
Romain Guy | 6820ac8 | 2010-09-15 18:11:50 -0700 | [diff] [blame] | 186 | |
| 187 | previousStepY = stepY; |
Romain Guy | fb5e23c | 2010-07-09 13:52:56 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Romain Guy | fdbec3e | 2011-01-19 10:37:35 -0800 | [diff] [blame] | 190 | if (previousStepY != bitmapHeight) { |
Romain Guy | f504a2f | 2011-05-26 16:40:55 -0700 | [diff] [blame] | 191 | y2 = bottom - top; |
| 192 | #if DEBUG_EXPLODE_PATCHES |
| 193 | y1 += mYCount * EXPLODE_GAP; |
| 194 | y2 += mYCount * EXPLODE_GAP; |
| 195 | #endif |
Romain Guy | 5e7c469 | 2011-10-20 20:31:50 -0700 | [diff] [blame] | 196 | generateRow(vertex, y1, y2, v1, 1.0f, stretchX, right - left, bitmapWidth, quadCount); |
Romain Guy | fdbec3e | 2011-01-19 10:37:35 -0800 | [diff] [blame] | 197 | } |
Romain Guy | 03750a0 | 2010-10-18 14:06:08 -0700 | [diff] [blame] | 198 | |
Romain Guy | a5ef39a | 2010-12-03 16:48:20 -0800 | [diff] [blame] | 199 | if (verticesCount > 0) { |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame^] | 200 | Caches& caches = Caches::getInstance(); |
| 201 | caches.bindMeshBuffer(meshBuffer); |
Romain Guy | a5ef39a | 2010-12-03 16:48:20 -0800 | [diff] [blame] | 202 | if (!mUploaded) { |
| 203 | glBufferData(GL_ARRAY_BUFFER, sizeof(TextureVertex) * verticesCount, |
| 204 | mVertices, GL_DYNAMIC_DRAW); |
| 205 | mUploaded = true; |
| 206 | } else { |
| 207 | glBufferSubData(GL_ARRAY_BUFFER, 0, |
| 208 | sizeof(TextureVertex) * verticesCount, mVertices); |
| 209 | } |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame^] | 210 | caches.resetVertexPointers(); |
Romain Guy | 6f72beb | 2010-11-30 12:04:14 -0800 | [diff] [blame] | 211 | } |
Romain Guy | a5ef39a | 2010-12-03 16:48:20 -0800 | [diff] [blame] | 212 | |
| 213 | PATCH_LOGD(" patch: new vertices count = %d", verticesCount); |
Romain Guy | fb5e23c | 2010-07-09 13:52:56 -0700 | [diff] [blame] | 214 | } |
| 215 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 216 | void Patch::generateRow(TextureVertex*& vertex, float y1, float y2, float v1, float v2, |
Romain Guy | eb6a4a1 | 2011-01-18 14:02:16 -0800 | [diff] [blame] | 217 | float stretchX, float width, float bitmapWidth, uint32_t& quadCount) { |
Romain Guy | 6820ac8 | 2010-09-15 18:11:50 -0700 | [diff] [blame] | 218 | float previousStepX = 0.0f; |
Romain Guy | fb5e23c | 2010-07-09 13:52:56 -0700 | [diff] [blame] | 219 | |
Romain Guy | 6820ac8 | 2010-09-15 18:11:50 -0700 | [diff] [blame] | 220 | float x1 = 0.0f; |
Romain Guy | f504a2f | 2011-05-26 16:40:55 -0700 | [diff] [blame] | 221 | float x2 = 0.0f; |
Romain Guy | 6820ac8 | 2010-09-15 18:11:50 -0700 | [diff] [blame] | 222 | float u1 = 0.0f; |
Romain Guy | fb5e23c | 2010-07-09 13:52:56 -0700 | [diff] [blame] | 223 | |
Romain Guy | 6820ac8 | 2010-09-15 18:11:50 -0700 | [diff] [blame] | 224 | // Generate the row quad by quad |
Romain Guy | eb6a4a1 | 2011-01-18 14:02:16 -0800 | [diff] [blame] | 225 | for (uint32_t i = 0; i < mXCount; i++) { |
Romain Guy | 6f72beb | 2010-11-30 12:04:14 -0800 | [diff] [blame] | 226 | float stepX = mXDivs[i]; |
Romain Guy | 5e7c469 | 2011-10-20 20:31:50 -0700 | [diff] [blame] | 227 | const float segment = stepX - previousStepX; |
Romain Guy | 6820ac8 | 2010-09-15 18:11:50 -0700 | [diff] [blame] | 228 | |
Romain Guy | 6820ac8 | 2010-09-15 18:11:50 -0700 | [diff] [blame] | 229 | if (i & 1) { |
Romain Guy | 8ab4079 | 2010-12-07 13:30:10 -0800 | [diff] [blame] | 230 | x2 = x1 + floorf(segment * stretchX + 0.5f); |
Romain Guy | fb5e23c | 2010-07-09 13:52:56 -0700 | [diff] [blame] | 231 | } else { |
Romain Guy | 5e7c469 | 2011-10-20 20:31:50 -0700 | [diff] [blame] | 232 | x2 = x1 + segment; |
Romain Guy | fb5e23c | 2010-07-09 13:52:56 -0700 | [diff] [blame] | 233 | } |
Romain Guy | 5e7c469 | 2011-10-20 20:31:50 -0700 | [diff] [blame] | 234 | |
| 235 | float uOffset = x1 == x2 ? 0.0f : 0.5 - (0.5 * segment / (x2 - x1)); |
| 236 | float u2 = fmax(0.0f, stepX - uOffset) / bitmapWidth; |
| 237 | u1 += uOffset / bitmapWidth; |
Romain Guy | fb5e23c | 2010-07-09 13:52:56 -0700 | [diff] [blame] | 238 | |
Romain Guy | eb6a4a1 | 2011-01-18 14:02:16 -0800 | [diff] [blame] | 239 | if (stepX > 0.0f) { |
Romain Guy | f504a2f | 2011-05-26 16:40:55 -0700 | [diff] [blame] | 240 | #if DEBUG_EXPLODE_PATCHES |
| 241 | x1 += i * EXPLODE_GAP; |
| 242 | x2 += i * EXPLODE_GAP; |
| 243 | #endif |
Romain Guy | eb6a4a1 | 2011-01-18 14:02:16 -0800 | [diff] [blame] | 244 | generateQuad(vertex, x1, y1, x2, y2, u1, v1, u2, v2, quadCount); |
Romain Guy | f504a2f | 2011-05-26 16:40:55 -0700 | [diff] [blame] | 245 | #if DEBUG_EXPLODE_PATCHES |
| 246 | x2 -= i * EXPLODE_GAP; |
| 247 | #endif |
Romain Guy | eb6a4a1 | 2011-01-18 14:02:16 -0800 | [diff] [blame] | 248 | } |
Romain Guy | 6820ac8 | 2010-09-15 18:11:50 -0700 | [diff] [blame] | 249 | |
| 250 | x1 = x2; |
Romain Guy | 5e7c469 | 2011-10-20 20:31:50 -0700 | [diff] [blame] | 251 | u1 = stepX / bitmapWidth; |
Romain Guy | 6820ac8 | 2010-09-15 18:11:50 -0700 | [diff] [blame] | 252 | |
| 253 | previousStepX = stepX; |
Romain Guy | fb5e23c | 2010-07-09 13:52:56 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Romain Guy | fdbec3e | 2011-01-19 10:37:35 -0800 | [diff] [blame] | 256 | if (previousStepX != bitmapWidth) { |
Romain Guy | f504a2f | 2011-05-26 16:40:55 -0700 | [diff] [blame] | 257 | x2 = width; |
| 258 | #if DEBUG_EXPLODE_PATCHES |
| 259 | x1 += mXCount * EXPLODE_GAP; |
| 260 | x2 += mXCount * EXPLODE_GAP; |
| 261 | #endif |
| 262 | generateQuad(vertex, x1, y1, x2, y2, u1, v1, 1.0f, v2, quadCount); |
Romain Guy | fdbec3e | 2011-01-19 10:37:35 -0800 | [diff] [blame] | 263 | } |
Romain Guy | fb5e23c | 2010-07-09 13:52:56 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Romain Guy | 7444da5 | 2011-01-17 10:53:31 -0800 | [diff] [blame] | 266 | void Patch::generateQuad(TextureVertex*& vertex, float x1, float y1, float x2, float y2, |
Romain Guy | eb6a4a1 | 2011-01-18 14:02:16 -0800 | [diff] [blame] | 267 | float u1, float v1, float u2, float v2, uint32_t& quadCount) { |
Romain Guy | a5ef39a | 2010-12-03 16:48:20 -0800 | [diff] [blame] | 268 | const uint32_t oldQuadCount = quadCount; |
Romain Guy | eb6a4a1 | 2011-01-18 14:02:16 -0800 | [diff] [blame] | 269 | quadCount++; |
Romain Guy | bd41a11 | 2010-12-02 17:16:26 -0800 | [diff] [blame] | 270 | |
Romain Guy | a5ef39a | 2010-12-03 16:48:20 -0800 | [diff] [blame] | 271 | // Skip degenerate and transparent (empty) quads |
Romain Guy | eb6a4a1 | 2011-01-18 14:02:16 -0800 | [diff] [blame] | 272 | if ((mColorKey >> oldQuadCount) & 0x1) { |
Romain Guy | fb13abd | 2011-01-16 15:16:38 -0800 | [diff] [blame] | 273 | #if DEBUG_PATCHES_EMPTY_VERTICES |
| 274 | PATCH_LOGD(" quad %d (empty)", oldQuadCount); |
Romain Guy | 5e7c469 | 2011-10-20 20:31:50 -0700 | [diff] [blame] | 275 | PATCH_LOGD(" left, top = %.2f, %.2f\t\tu1, v1 = %.4f, %.4f", x1, y1, u1, v1); |
| 276 | PATCH_LOGD(" right, bottom = %.2f, %.2f\t\tu2, v2 = %.4f, %.4f", x2, y2, u2, v2); |
Romain Guy | fb13abd | 2011-01-16 15:16:38 -0800 | [diff] [blame] | 277 | #endif |
Romain Guy | 7444da5 | 2011-01-17 10:53:31 -0800 | [diff] [blame] | 278 | return; |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 279 | } |
| 280 | |
Romain Guy | a5ef39a | 2010-12-03 16:48:20 -0800 | [diff] [blame] | 281 | #if RENDER_LAYERS_AS_REGIONS |
| 282 | // Record all non empty quads |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 283 | if (hasEmptyQuads) { |
| 284 | Rect bounds(x1, y1, x2, y2); |
| 285 | quads.add(bounds); |
| 286 | } |
Romain Guy | a5ef39a | 2010-12-03 16:48:20 -0800 | [diff] [blame] | 287 | #endif |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 288 | |
Romain Guy | 6820ac8 | 2010-09-15 18:11:50 -0700 | [diff] [blame] | 289 | // Left triangle |
| 290 | TextureVertex::set(vertex++, x1, y1, u1, v1); |
| 291 | TextureVertex::set(vertex++, x2, y1, u2, v1); |
| 292 | TextureVertex::set(vertex++, x1, y2, u1, v2); |
Romain Guy | fb5e23c | 2010-07-09 13:52:56 -0700 | [diff] [blame] | 293 | |
Romain Guy | 6820ac8 | 2010-09-15 18:11:50 -0700 | [diff] [blame] | 294 | // Right triangle |
| 295 | TextureVertex::set(vertex++, x1, y2, u1, v2); |
| 296 | TextureVertex::set(vertex++, x2, y1, u2, v1); |
| 297 | TextureVertex::set(vertex++, x2, y2, u2, v2); |
Romain Guy | a5ef39a | 2010-12-03 16:48:20 -0800 | [diff] [blame] | 298 | |
| 299 | // A quad is made of 2 triangles, 6 vertices |
| 300 | verticesCount += 6; |
| 301 | |
| 302 | #if DEBUG_PATCHES_VERTICES |
| 303 | PATCH_LOGD(" quad %d", oldQuadCount); |
Romain Guy | 5e7c469 | 2011-10-20 20:31:50 -0700 | [diff] [blame] | 304 | PATCH_LOGD(" left, top = %.2f, %.2f\t\tu1, v1 = %.4f, %.4f", x1, y1, u1, v1); |
| 305 | PATCH_LOGD(" right, bottom = %.2f, %.2f\t\tu2, v2 = %.4f, %.4f", x2, y2, u2, v2); |
Romain Guy | a5ef39a | 2010-12-03 16:48:20 -0800 | [diff] [blame] | 306 | #endif |
Romain Guy | fb5e23c | 2010-07-09 13:52:56 -0700 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | }; // namespace uirenderer |
| 310 | }; // namespace android |