| 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" | |
| 11 #include "SkBitmapProcShader.h" | |
| 12 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| 11 #include "SkImageCacherator.h" |
| 13 #include "SkImageGenerator.h" | 12 #include "SkImageGenerator.h" |
| 13 #include "SkImageShader.h" |
| 14 #include "SkMatrixUtils.h" | 14 #include "SkMatrixUtils.h" |
| 15 #include "SkPicture.h" | 15 #include "SkPicture.h" |
| 16 #include "SkReadBuffer.h" | 16 #include "SkReadBuffer.h" |
| 17 #include "SkResourceCache.h" | 17 #include "SkResourceCache.h" |
| 18 | 18 |
| 19 #if SK_SUPPORT_GPU | 19 #if SK_SUPPORT_GPU |
| 20 #include "GrContext.h" | 20 #include "GrContext.h" |
| 21 #include "GrCaps.h" | 21 #include "GrCaps.h" |
| 22 #endif | 22 #endif |
| 23 | 23 |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 | 208 |
| 209 SkAutoTUnref<SkShader> tileShader; | 209 SkAutoTUnref<SkShader> tileShader; |
| 210 BitmapShaderKey key(fPicture->uniqueID(), | 210 BitmapShaderKey key(fPicture->uniqueID(), |
| 211 fTile, | 211 fTile, |
| 212 fTmx, | 212 fTmx, |
| 213 fTmy, | 213 fTmy, |
| 214 tileScale, | 214 tileScale, |
| 215 this->getLocalMatrix()); | 215 this->getLocalMatrix()); |
| 216 | 216 |
| 217 if (!SkResourceCache::Find(key, BitmapShaderRec::Visitor, &tileShader)) { | 217 if (!SkResourceCache::Find(key, BitmapShaderRec::Visitor, &tileShader)) { |
| 218 SkMatrix tileMatrix; | 218 SkMatrix tileMatrix = |
| 219 tileMatrix.setRectToRect(fTile, SkRect::MakeIWH(tileSize.width(), tileSi
ze.height()), | 219 SkMatrix::MakeRectToRect(fTile, SkRect::MakeIWH(tileSize.width(), ti
leSize.height()), |
| 220 SkMatrix::kFill_ScaleToFit); | 220 SkMatrix::kFill_ScaleToFit); |
| 221 SkBitmap bm; | 221 SkAutoTUnref<SkImage> tileImage( |
| 222 if (!SkDEPRECATED_InstallDiscardablePixelRef( | 222 SkImage::NewFromPicture(fPicture, tileSize, &tileMatrix, nullptr)); |
| 223 SkImageGenerator::NewFromPicture(tileSize, fPicture, &tileMatrix, nu
llptr), &bm)) { | 223 if (!tileImage) { |
| 224 return nullptr; | 224 return nullptr; |
| 225 } | 225 } |
| 226 | 226 |
| 227 SkMatrix shaderMatrix = this->getLocalMatrix(); | 227 SkMatrix shaderMatrix = this->getLocalMatrix(); |
| 228 shaderMatrix.preScale(1 / tileScale.width(), 1 / tileScale.height()); | 228 shaderMatrix.preScale(1 / tileScale.width(), 1 / tileScale.height()); |
| 229 tileShader.reset(CreateBitmapShader(bm, fTmx, fTmy, &shaderMatrix)); | 229 tileShader.reset(tileImage->newShader(fTmx, fTmy, &shaderMatrix)); |
| 230 | 230 |
| 231 SkResourceCache::Add(new BitmapShaderRec(key, tileShader.get(), bm.getSi
ze())); | 231 // The actual pixels are accounted for in the SkImage cacherator budget.
Here we |
| 232 // use a rough estimate for the related objects. |
| 233 const size_t bytesUsed = sizeof(SkImageShader) + |
| 234 sizeof(SkImage) + |
| 235 sizeof(SkImageCacherator) + |
| 236 sizeof(SkImageGenerator); |
| 237 SkResourceCache::Add(new BitmapShaderRec(key, tileShader.get(), bytesUse
d)); |
| 232 } | 238 } |
| 233 | 239 |
| 234 return tileShader.detach(); | 240 return tileShader.detach(); |
| 235 } | 241 } |
| 236 | 242 |
| 237 size_t SkPictureShader::contextSize() const { | 243 size_t SkPictureShader::contextSize() const { |
| 238 return sizeof(PictureShaderContext); | 244 return sizeof(PictureShaderContext); |
| 239 } | 245 } |
| 240 | 246 |
| 241 SkShader::Context* SkPictureShader::onCreateContext(const ContextRec& rec, void*
storage) const { | 247 SkShader::Context* SkPictureShader::onCreateContext(const ContextRec& rec, void*
storage) const { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 if (context) { | 330 if (context) { |
| 325 maxTextureSize = context->caps()->maxTextureSize(); | 331 maxTextureSize = context->caps()->maxTextureSize(); |
| 326 } | 332 } |
| 327 SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(viewM, localMatrix
, maxTextureSize)); | 333 SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(viewM, localMatrix
, maxTextureSize)); |
| 328 if (!bitmapShader) { | 334 if (!bitmapShader) { |
| 329 return nullptr; | 335 return nullptr; |
| 330 } | 336 } |
| 331 return bitmapShader->asFragmentProcessor(context, viewM, nullptr, fq, procDa
taManager); | 337 return bitmapShader->asFragmentProcessor(context, viewM, nullptr, fq, procDa
taManager); |
| 332 } | 338 } |
| 333 #endif | 339 #endif |
| OLD | NEW |