| Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -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 |  | 
| Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 17 | #include "SkiaShader.h" | 
| Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 18 |  | 
| Romain Guy | a1d3c91 | 2011-12-13 14:55:06 -0800 | [diff] [blame] | 19 | #include "Caches.h" | 
| Tom Hudson | 2dc236b | 2014-10-15 15:46:42 -0400 | [diff] [blame] | 20 | #include "Extensions.h" | 
| Leon Scroggins III | d1ad5e6 | 2014-05-05 12:50:38 -0400 | [diff] [blame] | 21 | #include "Matrix.h" | 
| Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 22 | #include "Texture.h" | 
| sergeyv | ec4a4b1 | 2016-10-20 18:39:04 -0700 | [diff] [blame] | 23 | #include "hwui/Bitmap.h" | 
| Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 24 |  | 
| Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 25 | #include <SkMatrix.h> | 
 | 26 | #include <utils/Log.h> | 
 | 27 |  | 
| Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 28 | namespace android { | 
 | 29 | namespace uirenderer { | 
 | 30 |  | 
 | 31 | /////////////////////////////////////////////////////////////////////////////// | 
 | 32 | // Support | 
 | 33 | /////////////////////////////////////////////////////////////////////////////// | 
 | 34 |  | 
| Chris Craik | 216048f | 2015-08-21 15:31:20 -0700 | [diff] [blame] | 35 | static constexpr GLenum gTileModes[] = { | 
| Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 36 |         GL_CLAMP_TO_EDGE,   // == SkShader::kClamp_TileMode | 
 | 37 |         GL_REPEAT,          // == SkShader::kRepeat_Mode | 
 | 38 |         GL_MIRRORED_REPEAT  // == SkShader::kMirror_TileMode | 
 | 39 | }; | 
 | 40 |  | 
| Chris Craik | 216048f | 2015-08-21 15:31:20 -0700 | [diff] [blame] | 41 | static_assert(gTileModes[SkShader::kClamp_TileMode] == GL_CLAMP_TO_EDGE, | 
 | 42 |         "SkShader TileModes have changed"); | 
 | 43 | static_assert(gTileModes[SkShader::kRepeat_TileMode] == GL_REPEAT, | 
 | 44 |         "SkShader TileModes have changed"); | 
 | 45 | static_assert(gTileModes[SkShader::kMirror_TileMode] == GL_MIRRORED_REPEAT, | 
 | 46 |         "SkShader TileModes have changed"); | 
 | 47 |  | 
| Romain Guy | 42e1e0d | 2012-07-30 14:47:51 -0700 | [diff] [blame] | 48 | /** | 
 | 49 |  * This function does not work for n == 0. | 
 | 50 |  */ | 
 | 51 | static inline bool isPowerOfTwo(unsigned int n) { | 
 | 52 |     return !(n & (n - 1)); | 
 | 53 | } | 
 | 54 |  | 
| Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 55 | static inline void bindUniformColor(int slot, FloatColor color) { | 
 | 56 |     glUniform4fv(slot, 1, reinterpret_cast<const float*>(&color)); | 
 | 57 | } | 
 | 58 |  | 
| Leon Scroggins III | d1ad5e6 | 2014-05-05 12:50:38 -0400 | [diff] [blame] | 59 | static inline void bindTexture(Caches* caches, Texture* texture, GLenum wrapS, GLenum wrapT) { | 
| sergeyv | 554ffeb | 2016-11-15 18:01:21 -0800 | [diff] [blame] | 60 |     caches->textureState().bindTexture(texture->target(), texture->id()); | 
| Romain Guy | d21b6e1 | 2011-11-30 20:21:23 -0800 | [diff] [blame] | 61 |     texture->setWrapST(wrapS, wrapT); | 
| Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 62 | } | 
 | 63 |  | 
| Leon Scroggins III | d1ad5e6 | 2014-05-05 12:50:38 -0400 | [diff] [blame] | 64 | /** | 
 | 65 |  * Compute the matrix to transform to screen space. | 
 | 66 |  * @param screenSpace Output param for the computed matrix. | 
 | 67 |  * @param unitMatrix The unit matrix for gradient shaders, as returned by SkShader::asAGradient, | 
 | 68 |  *      or identity. | 
 | 69 |  * @param localMatrix Local matrix, as returned by SkShader::getLocalMatrix(). | 
 | 70 |  * @param modelViewMatrix Model view matrix, as supplied by the OpenGLRenderer. | 
 | 71 |  */ | 
 | 72 | static void computeScreenSpaceMatrix(mat4& screenSpace, const SkMatrix& unitMatrix, | 
 | 73 |         const SkMatrix& localMatrix, const mat4& modelViewMatrix) { | 
 | 74 |     mat4 shaderMatrix; | 
 | 75 |     // uses implicit construction | 
 | 76 |     shaderMatrix.loadInverse(localMatrix); | 
 | 77 |     // again, uses implicit construction | 
 | 78 |     screenSpace.loadMultiply(unitMatrix, shaderMatrix); | 
 | 79 |     screenSpace.multiply(modelViewMatrix); | 
 | 80 | } | 
 | 81 |  | 
| Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 82 | /////////////////////////////////////////////////////////////////////////////// | 
| Romain Guy | a0ed6f0 | 2016-12-12 18:21:32 -0800 | [diff] [blame] | 83 | // Gradient shader matrix helpers | 
| Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 84 | /////////////////////////////////////////////////////////////////////////////// | 
 | 85 |  | 
| Chris Craik | 8284073 | 2015-04-03 09:37:49 -0700 | [diff] [blame] | 86 | static void toLinearUnitMatrix(const SkPoint pts[2], SkMatrix* matrix) { | 
| Romain Guy | e3095e0 | 2010-10-06 16:57:29 -0700 | [diff] [blame] | 87 |     SkVector vec = pts[1] - pts[0]; | 
 | 88 |     const float mag = vec.length(); | 
 | 89 |     const float inv = mag ? 1.0f / mag : 0; | 
 | 90 |  | 
 | 91 |     vec.scale(inv); | 
 | 92 |     matrix->setSinCos(-vec.fY, vec.fX, pts[0].fX, pts[0].fY); | 
 | 93 |     matrix->postTranslate(-pts[0].fX, -pts[0].fY); | 
 | 94 |     matrix->postScale(inv, inv); | 
 | 95 | } | 
 | 96 |  | 
| Romain Guy | 1483094 | 2010-10-07 15:07:45 -0700 | [diff] [blame] | 97 | static void toCircularUnitMatrix(const float x, const float y, const float radius, | 
 | 98 |         SkMatrix* matrix) { | 
 | 99 |     const float inv = 1.0f / radius; | 
 | 100 |     matrix->setTranslate(-x, -y); | 
 | 101 |     matrix->postScale(inv, inv); | 
 | 102 | } | 
 | 103 |  | 
| Romain Guy | 1483094 | 2010-10-07 15:07:45 -0700 | [diff] [blame] | 104 | static void toSweepUnitMatrix(const float x, const float y, SkMatrix* matrix) { | 
 | 105 |     matrix->setTranslate(-x, -y); | 
 | 106 | } | 
 | 107 |  | 
| Leon Scroggins III | d1ad5e6 | 2014-05-05 12:50:38 -0400 | [diff] [blame] | 108 | /////////////////////////////////////////////////////////////////////////////// | 
 | 109 | // Common gradient code | 
 | 110 | /////////////////////////////////////////////////////////////////////////////// | 
| Romain Guy | 1483094 | 2010-10-07 15:07:45 -0700 | [diff] [blame] | 111 |  | 
| Leon Scroggins III | d1ad5e6 | 2014-05-05 12:50:38 -0400 | [diff] [blame] | 112 | static bool isSimpleGradient(const SkShader::GradientInfo& gradInfo) { | 
 | 113 |     return gradInfo.fColorCount == 2 && gradInfo.fTileMode == SkShader::kClamp_TileMode; | 
| Romain Guy | ee916f1 | 2010-09-20 17:53:08 -0700 | [diff] [blame] | 114 | } | 
 | 115 |  | 
| Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 116 | /////////////////////////////////////////////////////////////////////////////// | 
 | 117 | // Store / apply | 
 | 118 | /////////////////////////////////////////////////////////////////////////////// | 
 | 119 |  | 
 | 120 | bool tryStoreGradient(Caches& caches, const SkShader& shader, const Matrix4 modelViewMatrix, | 
 | 121 |         GLuint* textureUnit, ProgramDescription* description, | 
 | 122 |         SkiaShaderData::GradientShaderData* outData) { | 
 | 123 |     SkShader::GradientInfo gradInfo; | 
 | 124 |     gradInfo.fColorCount = 0; | 
 | 125 |     gradInfo.fColors = nullptr; | 
 | 126 |     gradInfo.fColorOffsets = nullptr; | 
 | 127 |  | 
 | 128 |     SkMatrix unitMatrix; | 
 | 129 |     switch (shader.asAGradient(&gradInfo)) { | 
 | 130 |         case SkShader::kLinear_GradientType: | 
 | 131 |             description->gradientType = ProgramDescription::kGradientLinear; | 
 | 132 |  | 
| Chris Craik | 8284073 | 2015-04-03 09:37:49 -0700 | [diff] [blame] | 133 |             toLinearUnitMatrix(gradInfo.fPoint, &unitMatrix); | 
| Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 134 |             break; | 
 | 135 |         case SkShader::kRadial_GradientType: | 
 | 136 |             description->gradientType = ProgramDescription::kGradientCircular; | 
 | 137 |  | 
 | 138 |             toCircularUnitMatrix(gradInfo.fPoint[0].fX, gradInfo.fPoint[0].fY, | 
 | 139 |                     gradInfo.fRadius[0], &unitMatrix); | 
 | 140 |             break; | 
 | 141 |         case SkShader::kSweep_GradientType: | 
 | 142 |             description->gradientType = ProgramDescription::kGradientSweep; | 
 | 143 |  | 
 | 144 |             toSweepUnitMatrix(gradInfo.fPoint[0].fX, gradInfo.fPoint[0].fY, &unitMatrix); | 
 | 145 |             break; | 
 | 146 |         default: | 
 | 147 |             // Do nothing. This shader is unsupported. | 
 | 148 |             return false; | 
 | 149 |     } | 
 | 150 |     description->hasGradient = true; | 
 | 151 |     description->isSimpleGradient = isSimpleGradient(gradInfo); | 
 | 152 |  | 
 | 153 |     computeScreenSpaceMatrix(outData->screenSpace, unitMatrix, | 
 | 154 |             shader.getLocalMatrix(), modelViewMatrix); | 
 | 155 |  | 
 | 156 |     // re-query shader to get full color / offset data | 
 | 157 |     std::unique_ptr<SkColor[]> colorStorage(new SkColor[gradInfo.fColorCount]); | 
 | 158 |     std::unique_ptr<SkScalar[]> colorOffsets(new SkScalar[gradInfo.fColorCount]); | 
 | 159 |     gradInfo.fColors = &colorStorage[0]; | 
 | 160 |     gradInfo.fColorOffsets = &colorOffsets[0]; | 
 | 161 |     shader.asAGradient(&gradInfo); | 
 | 162 |  | 
| Romain Guy | a0ed6f0 | 2016-12-12 18:21:32 -0800 | [diff] [blame] | 163 |     if (CC_UNLIKELY(!description->isSimpleGradient)) { | 
| Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 164 |         outData->gradientSampler = (*textureUnit)++; | 
 | 165 |  | 
 | 166 | #ifndef SK_SCALAR_IS_FLOAT | 
 | 167 |     #error Need to convert gradInfo.fColorOffsets to float! | 
 | 168 | #endif | 
 | 169 |         outData->gradientTexture = caches.gradientCache.get( | 
 | 170 |                 gradInfo.fColors, gradInfo.fColorOffsets, gradInfo.fColorCount); | 
 | 171 |         outData->wrapST = gTileModes[gradInfo.fTileMode]; | 
 | 172 |     } else { | 
 | 173 |         outData->gradientSampler = 0; | 
 | 174 |         outData->gradientTexture = nullptr; | 
 | 175 |  | 
| Romain Guy | a0ed6f0 | 2016-12-12 18:21:32 -0800 | [diff] [blame] | 176 |         outData->startColor.setUnPreMultipliedSRGB(gradInfo.fColors[0]); | 
 | 177 |         outData->endColor.setUnPreMultipliedSRGB(gradInfo.fColors[1]); | 
| Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 178 |     } | 
 | 179 |  | 
| Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 180 |     return true; | 
 | 181 | } | 
 | 182 |  | 
| Romain Guy | 253f2c2 | 2016-09-28 17:34:42 -0700 | [diff] [blame] | 183 | void applyGradient(Caches& caches, const SkiaShaderData::GradientShaderData& data, | 
 | 184 |         const GLsizei width, const GLsizei height) { | 
 | 185 |  | 
| Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 186 |     if (CC_UNLIKELY(data.gradientTexture)) { | 
 | 187 |         caches.textureState().activateTexture(data.gradientSampler); | 
 | 188 |         bindTexture(&caches, data.gradientTexture, data.wrapST, data.wrapST); | 
 | 189 |         glUniform1i(caches.program().getUniform("gradientSampler"), data.gradientSampler); | 
 | 190 |     } else { | 
 | 191 |         bindUniformColor(caches.program().getUniform("startColor"), data.startColor); | 
 | 192 |         bindUniformColor(caches.program().getUniform("endColor"), data.endColor); | 
 | 193 |     } | 
 | 194 |  | 
| Romain Guy | 253f2c2 | 2016-09-28 17:34:42 -0700 | [diff] [blame] | 195 |     glUniform2f(caches.program().getUniform("screenSize"), 1.0f / width, 1.0f / height); | 
| Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 196 |     glUniformMatrix4fv(caches.program().getUniform("screenSpace"), 1, | 
 | 197 |             GL_FALSE, &data.screenSpace.data[0]); | 
 | 198 | } | 
 | 199 |  | 
 | 200 | bool tryStoreBitmap(Caches& caches, const SkShader& shader, const Matrix4& modelViewMatrix, | 
 | 201 |         GLuint* textureUnit, ProgramDescription* description, | 
 | 202 |         SkiaShaderData::BitmapShaderData* outData) { | 
 | 203 |     SkBitmap bitmap; | 
 | 204 |     SkShader::TileMode xy[2]; | 
| Leon Scroggins III | f35b989 | 2015-07-31 10:38:40 -0400 | [diff] [blame] | 205 |     if (!shader.isABitmap(&bitmap, nullptr, xy)) { | 
| Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 206 |         return false; | 
 | 207 |     } | 
 | 208 |  | 
| sergeyv | ec4a4b1 | 2016-10-20 18:39:04 -0700 | [diff] [blame] | 209 |     // TODO: create  hwui-owned BitmapShader. | 
 | 210 |     Bitmap* hwuiBitmap = static_cast<Bitmap*>(bitmap.pixelRef()); | 
 | 211 |     outData->bitmapTexture = caches.textureCache.get(hwuiBitmap); | 
| Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 212 |     if (!outData->bitmapTexture) return false; | 
 | 213 |  | 
 | 214 |     outData->bitmapSampler = (*textureUnit)++; | 
 | 215 |  | 
| John Reck | 38e0c32 | 2015-11-10 12:19:17 -0800 | [diff] [blame] | 216 |     const float width = outData->bitmapTexture->width(); | 
 | 217 |     const float height = outData->bitmapTexture->height(); | 
| Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 218 |  | 
 | 219 |     description->hasBitmap = true; | 
| Romain Guy | dd6f1a7 | 2017-02-17 17:09:21 -0800 | [diff] [blame] | 220 |     description->hasLinearTexture = outData->bitmapTexture->isLinear(); | 
| sergeyv | 9c97e48 | 2016-12-12 16:14:11 -0800 | [diff] [blame] | 221 |     description->isShaderBitmapExternal = hwuiBitmap->isHardware(); | 
| sergeyv | 554ffeb | 2016-11-15 18:01:21 -0800 | [diff] [blame] | 222 |     // gralloc doesn't support non-clamp modes | 
 | 223 |     if (hwuiBitmap->isHardware() || (!caches.extensions().hasNPot() | 
| Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 224 |             && (!isPowerOfTwo(width) || !isPowerOfTwo(height)) | 
| sergeyv | 554ffeb | 2016-11-15 18:01:21 -0800 | [diff] [blame] | 225 |             && (xy[0] != SkShader::kClamp_TileMode || xy[1] != SkShader::kClamp_TileMode))) { | 
 | 226 |         // need non-clamp mode, but it's not supported for this draw, | 
 | 227 |         // so enable custom shader logic to mimic | 
 | 228 |         description->useShaderBasedWrap = true; | 
| Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 229 |         description->bitmapWrapS = gTileModes[xy[0]]; | 
 | 230 |         description->bitmapWrapT = gTileModes[xy[1]]; | 
 | 231 |  | 
 | 232 |         outData->wrapS = GL_CLAMP_TO_EDGE; | 
 | 233 |         outData->wrapT = GL_CLAMP_TO_EDGE; | 
 | 234 |     } else { | 
 | 235 |         outData->wrapS = gTileModes[xy[0]]; | 
 | 236 |         outData->wrapT = gTileModes[xy[1]]; | 
 | 237 |     } | 
 | 238 |  | 
 | 239 |     computeScreenSpaceMatrix(outData->textureTransform, SkMatrix::I(), shader.getLocalMatrix(), | 
 | 240 |             modelViewMatrix); | 
 | 241 |     outData->textureDimension[0] = 1.0f / width; | 
 | 242 |     outData->textureDimension[1] = 1.0f / height; | 
 | 243 |  | 
 | 244 |     return true; | 
 | 245 | } | 
 | 246 |  | 
 | 247 | void applyBitmap(Caches& caches, const SkiaShaderData::BitmapShaderData& data) { | 
 | 248 |     caches.textureState().activateTexture(data.bitmapSampler); | 
 | 249 |     bindTexture(&caches, data.bitmapTexture, data.wrapS, data.wrapT); | 
 | 250 |     data.bitmapTexture->setFilter(GL_LINEAR); | 
 | 251 |  | 
 | 252 |     glUniform1i(caches.program().getUniform("bitmapSampler"), data.bitmapSampler); | 
 | 253 |     glUniformMatrix4fv(caches.program().getUniform("textureTransform"), 1, GL_FALSE, | 
 | 254 |             &data.textureTransform.data[0]); | 
 | 255 |     glUniform2fv(caches.program().getUniform("textureDimension"), 1, &data.textureDimension[0]); | 
 | 256 | } | 
 | 257 |  | 
 | 258 | SkiaShaderType getComposeSubType(const SkShader& shader) { | 
 | 259 |     // First check for a gradient shader. | 
 | 260 |     switch (shader.asAGradient(nullptr)) { | 
 | 261 |         case SkShader::kNone_GradientType: | 
 | 262 |             // Not a gradient shader. Fall through to check for other types. | 
 | 263 |             break; | 
 | 264 |         case SkShader::kLinear_GradientType: | 
 | 265 |         case SkShader::kRadial_GradientType: | 
 | 266 |         case SkShader::kSweep_GradientType: | 
 | 267 |             return kGradient_SkiaShaderType; | 
 | 268 |         default: | 
 | 269 |             // This is a Skia gradient that has no SkiaShader equivalent. Return None to skip. | 
 | 270 |             return kNone_SkiaShaderType; | 
 | 271 |     } | 
 | 272 |  | 
 | 273 |     // The shader is not a gradient. Check for a bitmap shader. | 
| Leon Scroggins III | f35b989 | 2015-07-31 10:38:40 -0400 | [diff] [blame] | 274 |     if (shader.isABitmap()) { | 
| Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 275 |         return kBitmap_SkiaShaderType; | 
 | 276 |     } | 
 | 277 |     return kNone_SkiaShaderType; | 
 | 278 | } | 
 | 279 |  | 
 | 280 | void storeCompose(Caches& caches, const SkShader& bitmapShader, const SkShader& gradientShader, | 
 | 281 |         const Matrix4& modelViewMatrix, GLuint* textureUnit, | 
 | 282 |         ProgramDescription* description, SkiaShaderData* outData) { | 
 | 283 |     LOG_ALWAYS_FATAL_IF(!tryStoreBitmap(caches, bitmapShader, modelViewMatrix, | 
 | 284 |                 textureUnit, description, &outData->bitmapData), | 
 | 285 |             "failed storing bitmap shader data"); | 
 | 286 |     LOG_ALWAYS_FATAL_IF(!tryStoreGradient(caches, gradientShader, modelViewMatrix, | 
 | 287 |                 textureUnit, description, &outData->gradientData), | 
 | 288 |             "failing storing gradient shader data"); | 
 | 289 | } | 
 | 290 |  | 
 | 291 | bool tryStoreCompose(Caches& caches, const SkShader& shader, const Matrix4& modelViewMatrix, | 
 | 292 |         GLuint* textureUnit, ProgramDescription* description, | 
 | 293 |         SkiaShaderData* outData) { | 
 | 294 |  | 
 | 295 |     SkShader::ComposeRec rec; | 
 | 296 |     if (!shader.asACompose(&rec)) return false; | 
 | 297 |  | 
 | 298 |     const SkiaShaderType shaderAType = getComposeSubType(*rec.fShaderA); | 
 | 299 |     const SkiaShaderType shaderBType = getComposeSubType(*rec.fShaderB); | 
 | 300 |  | 
 | 301 |     // check that type enum values are the 2 flags that compose the kCompose value | 
 | 302 |     if ((shaderAType & shaderBType) != 0) return false; | 
 | 303 |     if ((shaderAType | shaderBType) != kCompose_SkiaShaderType) return false; | 
 | 304 |  | 
 | 305 |     mat4 transform; | 
 | 306 |     computeScreenSpaceMatrix(transform, SkMatrix::I(), shader.getLocalMatrix(), modelViewMatrix); | 
 | 307 |     if (shaderAType == kBitmap_SkiaShaderType) { | 
 | 308 |         description->isBitmapFirst = true; | 
 | 309 |         storeCompose(caches, *rec.fShaderA, *rec.fShaderB, | 
 | 310 |                 transform, textureUnit, description, outData); | 
 | 311 |     } else { | 
 | 312 |         description->isBitmapFirst = false; | 
 | 313 |         storeCompose(caches, *rec.fShaderB, *rec.fShaderA, | 
 | 314 |                 transform, textureUnit, description, outData); | 
 | 315 |     } | 
| Mike Reed | c2f31df | 2016-10-28 17:21:45 -0400 | [diff] [blame] | 316 |     description->shadersMode = rec.fBlendMode; | 
| Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 317 |     return true; | 
 | 318 | } | 
 | 319 |  | 
| Chris Craik | 53e51e4 | 2015-06-01 10:35:35 -0700 | [diff] [blame] | 320 | void SkiaShader::store(Caches& caches, const SkShader& shader, const Matrix4& modelViewMatrix, | 
| Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 321 |         GLuint* textureUnit, ProgramDescription* description, | 
 | 322 |         SkiaShaderData* outData) { | 
| Chris Craik | 53e51e4 | 2015-06-01 10:35:35 -0700 | [diff] [blame] | 323 |     if (tryStoreGradient(caches, shader, modelViewMatrix, | 
| Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 324 |             textureUnit, description, &outData->gradientData)) { | 
 | 325 |         outData->skiaShaderType = kGradient_SkiaShaderType; | 
 | 326 |         return; | 
 | 327 |     } | 
 | 328 |  | 
| Chris Craik | 53e51e4 | 2015-06-01 10:35:35 -0700 | [diff] [blame] | 329 |     if (tryStoreBitmap(caches, shader, modelViewMatrix, | 
| Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 330 |             textureUnit, description, &outData->bitmapData)) { | 
 | 331 |         outData->skiaShaderType = kBitmap_SkiaShaderType; | 
 | 332 |         return; | 
 | 333 |     } | 
 | 334 |  | 
| Chris Craik | 53e51e4 | 2015-06-01 10:35:35 -0700 | [diff] [blame] | 335 |     if (tryStoreCompose(caches, shader, modelViewMatrix, | 
| Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 336 |             textureUnit, description, outData)) { | 
 | 337 |         outData->skiaShaderType = kCompose_SkiaShaderType; | 
 | 338 |         return; | 
 | 339 |     } | 
 | 340 |  | 
| Chris Craik | e310f83 | 2015-07-13 13:34:07 -0700 | [diff] [blame] | 341 |     // Unknown/unsupported type, so explicitly ignore shader | 
 | 342 |     outData->skiaShaderType = kNone_SkiaShaderType; | 
| Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 343 | } | 
 | 344 |  | 
| Romain Guy | 253f2c2 | 2016-09-28 17:34:42 -0700 | [diff] [blame] | 345 | void SkiaShader::apply(Caches& caches, const SkiaShaderData& data, | 
 | 346 |         const GLsizei width, const GLsizei height) { | 
| Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 347 |     if (!data.skiaShaderType) return; | 
 | 348 |  | 
 | 349 |     if (data.skiaShaderType & kGradient_SkiaShaderType) { | 
| Romain Guy | 253f2c2 | 2016-09-28 17:34:42 -0700 | [diff] [blame] | 350 |         applyGradient(caches, data.gradientData, width, height); | 
| Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 351 |     } | 
 | 352 |     if (data.skiaShaderType & kBitmap_SkiaShaderType) { | 
 | 353 |         applyBitmap(caches, data.bitmapData); | 
 | 354 |     } | 
| Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 355 | } | 
 | 356 |  | 
| Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 357 | }; // namespace uirenderer | 
 | 358 | }; // namespace android |