Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: src/core/SkPictureShader.cpp

Issue 1652943002: SkPictureShader cleanup (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "SkBitmapProcShader.h" 11 #include "SkBitmapProcShader.h"
12 #include "SkCanvas.h" 12 #include "SkCanvas.h"
13 #include "SkImage.h" 13 #include "SkImage.h"
14 #include "SkImageGenerator.h"
15 #include "SkMatrixUtils.h" 14 #include "SkMatrixUtils.h"
16 #include "SkPicture.h" 15 #include "SkPicture.h"
17 #include "SkReadBuffer.h" 16 #include "SkReadBuffer.h"
18 #include "SkResourceCache.h" 17 #include "SkResourceCache.h"
19 18
20 #if SK_SUPPORT_GPU 19 #if SK_SUPPORT_GPU
21 #include "GrContext.h" 20 #include "GrContext.h"
22 #include "GrCaps.h" 21 #include "GrCaps.h"
23 #endif 22 #endif
24 23
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 fTmx, 212 fTmx,
214 fTmy, 213 fTmy,
215 tileScale, 214 tileScale,
216 this->getLocalMatrix()); 215 this->getLocalMatrix());
217 216
218 if (!SkResourceCache::Find(key, BitmapShaderRec::Visitor, &tileShader)) { 217 if (!SkResourceCache::Find(key, BitmapShaderRec::Visitor, &tileShader)) {
219 SkMatrix tileMatrix; 218 SkMatrix tileMatrix;
220 tileMatrix.setRectToRect(fTile, SkRect::MakeIWH(tileSize.width(), tileSi ze.height()), 219 tileMatrix.setRectToRect(fTile, SkRect::MakeIWH(tileSize.width(), tileSi ze.height()),
221 SkMatrix::kFill_ScaleToFit); 220 SkMatrix::kFill_ScaleToFit);
222 221
223 SkAutoTDelete<SkImageGenerator> tileGenerator( 222 SkAutoTUnref<SkImage> tileImage(
224 SkImageGenerator::NewFromPicture(tileSize, fPicture, &tileMatrix, nu llptr)); 223 SkImage::NewFromPicture(fPicture, tileSize, &tileMatrix, nullptr));
225 if (!tileGenerator) {
226 return nullptr;
227 }
228
229 // Grab this before the generator goes poof!
230 const SkImageInfo tileInfo = tileGenerator->getInfo();
231
232 SkAutoTUnref<SkImage> tileImage(SkImage::NewFromGenerator(tileGenerator. detach()));
233 if (!tileImage) { 224 if (!tileImage) {
234 return nullptr; 225 return nullptr;
235 } 226 }
236 227
237 SkMatrix shaderMatrix = this->getLocalMatrix(); 228 SkMatrix shaderMatrix = this->getLocalMatrix();
238 shaderMatrix.preScale(1 / tileScale.width(), 1 / tileScale.height()); 229 shaderMatrix.preScale(1 / tileScale.width(), 1 / tileScale.height());
239 tileShader.reset(tileImage->newShader(fTmx, fTmy, &shaderMatrix)); 230 tileShader.reset(tileImage->newShader(fTmx, fTmy, &shaderMatrix));
240 231
232 const SkImageInfo tileInfo = SkImageInfo::MakeN32Premul(tileSize);
241 SkResourceCache::Add(new BitmapShaderRec(key, tileShader.get(), 233 SkResourceCache::Add(new BitmapShaderRec(key, tileShader.get(),
242 tileInfo.getSafeSize(tileInfo.m inRowBytes()))); 234 tileInfo.getSafeSize(tileInfo.m inRowBytes())));
243 } 235 }
244 236
245 return tileShader.detach(); 237 return tileShader.detach();
246 } 238 }
247 239
248 size_t SkPictureShader::contextSize() const { 240 size_t SkPictureShader::contextSize() const {
249 return sizeof(PictureShaderContext); 241 return sizeof(PictureShaderContext);
250 } 242 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 if (context) { 321 if (context) {
330 maxTextureSize = context->caps()->maxTextureSize(); 322 maxTextureSize = context->caps()->maxTextureSize();
331 } 323 }
332 SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(viewM, localMatrix , maxTextureSize)); 324 SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(viewM, localMatrix , maxTextureSize));
333 if (!bitmapShader) { 325 if (!bitmapShader) {
334 return nullptr; 326 return nullptr;
335 } 327 }
336 return bitmapShader->asFragmentProcessor(context, viewM, nullptr, fq); 328 return bitmapShader->asFragmentProcessor(context, viewM, nullptr, fq);
337 } 329 }
338 #endif 330 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698