| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  * Copyright 2014 Google Inc. | 2  * Copyright 2014 Google Inc. | 
| 3  * | 3  * | 
| 4  * Use of this source code is governed by a BSD-style license that can be | 4  * Use of this source code is governed by a BSD-style license that can be | 
| 5  * found in the LICENSE file. | 5  * found in the LICENSE file. | 
| 6  */ | 6  */ | 
| 7 | 7 | 
| 8 #include "SkPictureShader.h" | 8 #include "SkPictureShader.h" | 
| 9 | 9 | 
| 10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" | 
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 134 } | 134 } | 
| 135 | 135 | 
| 136 void SkPictureShader::flatten(SkWriteBuffer& buffer) const { | 136 void SkPictureShader::flatten(SkWriteBuffer& buffer) const { | 
| 137     buffer.writeMatrix(this->getLocalMatrix()); | 137     buffer.writeMatrix(this->getLocalMatrix()); | 
| 138     buffer.write32(fTmx); | 138     buffer.write32(fTmx); | 
| 139     buffer.write32(fTmy); | 139     buffer.write32(fTmy); | 
| 140     buffer.writeRect(fTile); | 140     buffer.writeRect(fTile); | 
| 141     fPicture->flatten(buffer); | 141     fPicture->flatten(buffer); | 
| 142 } | 142 } | 
| 143 | 143 | 
| 144 SkShader* SkPictureShader::refBitmapShader(const SkMatrix& matrix, const SkMatri
     x* localM) const { | 144 SkShader* SkPictureShader::refBitmapShader(const SkMatrix& matrix, const SkMatri
     x* localM, | 
|  | 145                                             const int maxTextureSize) const { | 
| 145     SkASSERT(fPicture && !fPicture->cullRect().isEmpty()); | 146     SkASSERT(fPicture && !fPicture->cullRect().isEmpty()); | 
| 146 | 147 | 
| 147     SkMatrix m; | 148     SkMatrix m; | 
| 148     m.setConcat(matrix, this->getLocalMatrix()); | 149     m.setConcat(matrix, this->getLocalMatrix()); | 
| 149     if (localM) { | 150     if (localM) { | 
| 150         m.preConcat(*localM); | 151         m.preConcat(*localM); | 
| 151     } | 152     } | 
| 152 | 153 | 
| 153     // Use a rotation-invariant scale | 154     // Use a rotation-invariant scale | 
| 154     SkPoint scale; | 155     SkPoint scale; | 
| 155     // | 156     // | 
| 156     // TODO: replace this with decomposeScale() -- but beware LayoutTest rebasel
     ines! | 157     // TODO: replace this with decomposeScale() -- but beware LayoutTest rebasel
     ines! | 
| 157     // | 158     // | 
| 158     if (!SkDecomposeUpper2x2(m, NULL, &scale, NULL)) { | 159     if (!SkDecomposeUpper2x2(m, NULL, &scale, NULL)) { | 
| 159         // Decomposition failed, use an approximation. | 160         // Decomposition failed, use an approximation. | 
| 160         scale.set(SkScalarSqrt(m.getScaleX() * m.getScaleX() + m.getSkewX() * m.
     getSkewX()), | 161         scale.set(SkScalarSqrt(m.getScaleX() * m.getScaleX() + m.getSkewX() * m.
     getSkewX()), | 
| 161                   SkScalarSqrt(m.getScaleY() * m.getScaleY() + m.getSkewY() * m.
     getSkewY())); | 162                   SkScalarSqrt(m.getScaleY() * m.getScaleY() + m.getSkewY() * m.
     getSkewY())); | 
| 162     } | 163     } | 
| 163     SkSize scaledSize = SkSize::Make(SkScalarAbs(scale.x() * fTile.width()), | 164     SkSize scaledSize = SkSize::Make(SkScalarAbs(scale.x() * fTile.width()), | 
| 164                                      SkScalarAbs(scale.y() * fTile.height())); | 165                                      SkScalarAbs(scale.y() * fTile.height())); | 
| 165 | 166 | 
| 166     // Clamp the tile size to about 4M pixels | 167     // Clamp the tile size to about 4M pixels | 
| 167     static const SkScalar kMaxTileArea = 2048 * 2048; | 168     static const SkScalar kMaxTileArea = 2048 * 2048; | 
| 168     SkScalar tileArea = SkScalarMul(scaledSize.width(), scaledSize.height()); | 169     SkScalar tileArea = SkScalarMul(scaledSize.width(), scaledSize.height()); | 
| 169     if (tileArea > kMaxTileArea) { | 170     if (tileArea > kMaxTileArea) { | 
| 170         SkScalar clampScale = SkScalarSqrt(SkScalarDiv(kMaxTileArea, tileArea)); | 171         SkScalar clampScale = SkScalarSqrt(SkScalarDiv(kMaxTileArea, tileArea)); | 
| 171         scaledSize.set(SkScalarMul(scaledSize.width(), clampScale), | 172         scaledSize.set(SkScalarMul(scaledSize.width(), clampScale), | 
| 172                        SkScalarMul(scaledSize.height(), clampScale)); | 173                        SkScalarMul(scaledSize.height(), clampScale)); | 
| 173     } | 174     } | 
|  | 175 #if SK_SUPPORT_GPU | 
|  | 176     // Scale down the tile size if larger than maxTextureSize for GPU Path or it
      should fail on create texture | 
|  | 177     if (maxTextureSize) { | 
|  | 178         if (scaledSize.width() > maxTextureSize || scaledSize.height() > maxText
     ureSize) { | 
|  | 179             SkScalar downScale = SkScalarDiv(maxTextureSize, | 
|  | 180                                             SkMax32(scaledSize.width(), scaledSi
     ze.height())); | 
|  | 181             scaledSize.set(SkScalarMul(scaledSize.width(), downScale), | 
|  | 182                            SkScalarMul(scaledSize.height(), downScale)); | 
|  | 183         } | 
|  | 184     } | 
|  | 185 #endif | 
| 174 | 186 | 
| 175     SkISize tileSize = scaledSize.toRound(); | 187     SkISize tileSize = scaledSize.toRound(); | 
| 176     if (tileSize.isEmpty()) { | 188     if (tileSize.isEmpty()) { | 
| 177         return NULL; | 189         return NULL; | 
| 178     } | 190     } | 
| 179 | 191 | 
| 180     // The actual scale, compensating for rounding & clamping. | 192     // The actual scale, compensating for rounding & clamping. | 
| 181     SkSize tileScale = SkSize::Make(SkIntToScalar(tileSize.width()) / fTile.widt
     h(), | 193     SkSize tileScale = SkSize::Make(SkIntToScalar(tileSize.width()) / fTile.widt
     h(), | 
| 182                                     SkIntToScalar(tileSize.height()) / fTile.hei
     ght()); | 194                                     SkIntToScalar(tileSize.height()) / fTile.hei
     ght()); | 
| 183 | 195 | 
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 292 | 304 | 
| 293     this->INHERITED::toString(str); | 305     this->INHERITED::toString(str); | 
| 294 } | 306 } | 
| 295 #endif | 307 #endif | 
| 296 | 308 | 
| 297 #if SK_SUPPORT_GPU | 309 #if SK_SUPPORT_GPU | 
| 298 bool SkPictureShader::asFragmentProcessor(GrContext* context, const SkPaint& pai
     nt, | 310 bool SkPictureShader::asFragmentProcessor(GrContext* context, const SkPaint& pai
     nt, | 
| 299                                           const SkMatrix& viewM, const SkMatrix*
      localMatrix, | 311                                           const SkMatrix& viewM, const SkMatrix*
      localMatrix, | 
| 300                                           GrColor* paintColor, | 312                                           GrColor* paintColor, | 
| 301                                           GrFragmentProcessor** fp) const { | 313                                           GrFragmentProcessor** fp) const { | 
| 302     SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(viewM, localMatrix
     )); | 314     int maxTextureSize = 0; | 
|  | 315     if (context) { | 
|  | 316         maxTextureSize = context->getMaxTextureSize(); | 
|  | 317     } | 
|  | 318     SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(viewM, localMatrix
     , maxTextureSize)); | 
| 303     if (!bitmapShader) { | 319     if (!bitmapShader) { | 
| 304         return false; | 320         return false; | 
| 305     } | 321     } | 
| 306     return bitmapShader->asFragmentProcessor(context, paint, viewM, NULL, paintC
     olor, fp); | 322     return bitmapShader->asFragmentProcessor(context, paint, viewM, NULL, paintC
     olor, fp); | 
| 307 } | 323 } | 
| 308 #else | 324 #else | 
| 309 bool SkPictureShader::asFragmentProcessor(GrContext*, const SkPaint&, const SkMa
     trix&, | 325 bool SkPictureShader::asFragmentProcessor(GrContext*, const SkPaint&, const SkMa
     trix&, | 
| 310                                           const SkMatrix*, GrColor*, | 326                                           const SkMatrix*, GrColor*, | 
| 311                                           GrFragmentProcessor**) const { | 327                                           GrFragmentProcessor**) const { | 
| 312     SkDEBUGFAIL("Should not call in GPU-less build"); | 328     SkDEBUGFAIL("Should not call in GPU-less build"); | 
| 313     return false; | 329     return false; | 
| 314 } | 330 } | 
| 315 #endif | 331 #endif | 
| OLD | NEW | 
|---|