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

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

Issue 1720933002: Add ContextRec param to SkShader::contextSize() (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: ContextRec plumbing only 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 | « src/core/SkPictureShader.h ('k') | src/core/SkShader.cpp » ('j') | 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"
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 tileShader.reset(tileImage->newShader(fTmx, fTmy, &shaderMatrix)); 230 tileShader.reset(tileImage->newShader(fTmx, fTmy, &shaderMatrix));
231 231
232 const SkImageInfo tileInfo = SkImageInfo::MakeN32Premul(tileSize); 232 const SkImageInfo tileInfo = SkImageInfo::MakeN32Premul(tileSize);
233 SkResourceCache::Add(new BitmapShaderRec(key, tileShader.get(), 233 SkResourceCache::Add(new BitmapShaderRec(key, tileShader.get(),
234 tileInfo.getSafeSize(tileInfo.m inRowBytes()))); 234 tileInfo.getSafeSize(tileInfo.m inRowBytes())));
235 } 235 }
236 236
237 return tileShader.detach(); 237 return tileShader.detach();
238 } 238 }
239 239
240 size_t SkPictureShader::contextSize() const { 240 size_t SkPictureShader::contextSize(const ContextRec&) const {
241 return sizeof(PictureShaderContext); 241 return sizeof(PictureShaderContext);
242 } 242 }
243 243
244 SkShader::Context* SkPictureShader::onCreateContext(const ContextRec& rec, void* storage) const { 244 SkShader::Context* SkPictureShader::onCreateContext(const ContextRec& rec, void* storage) const {
245 SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(*rec.fMatrix, rec. fLocalMatrix)); 245 SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(*rec.fMatrix, rec. fLocalMatrix));
246 if (nullptr == bitmapShader.get()) { 246 if (nullptr == bitmapShader.get()) {
247 return nullptr; 247 return nullptr;
248 } 248 }
249 return PictureShaderContext::Create(storage, *this, rec, bitmapShader); 249 return PictureShaderContext::Create(storage, *this, rec, bitmapShader);
250 } 250 }
251 251
252 //////////////////////////////////////////////////////////////////////////////// ///////// 252 //////////////////////////////////////////////////////////////////////////////// /////////
253 253
254 SkShader::Context* SkPictureShader::PictureShaderContext::Create(void* storage, 254 SkShader::Context* SkPictureShader::PictureShaderContext::Create(void* storage,
255 const SkPictureShader& shader, const ContextRec& rec, SkShade r* bitmapShader) { 255 const SkPictureShader& shader, const ContextRec& rec, SkShade r* bitmapShader) {
256 PictureShaderContext* ctx = new (storage) PictureShaderContext(shader, rec, bitmapShader); 256 PictureShaderContext* ctx = new (storage) PictureShaderContext(shader, rec, bitmapShader);
257 if (nullptr == ctx->fBitmapShaderContext) { 257 if (nullptr == ctx->fBitmapShaderContext) {
258 ctx->~PictureShaderContext(); 258 ctx->~PictureShaderContext();
259 ctx = nullptr; 259 ctx = nullptr;
260 } 260 }
261 return ctx; 261 return ctx;
262 } 262 }
263 263
264 SkPictureShader::PictureShaderContext::PictureShaderContext( 264 SkPictureShader::PictureShaderContext::PictureShaderContext(
265 const SkPictureShader& shader, const ContextRec& rec, SkShader* bitmapSh ader) 265 const SkPictureShader& shader, const ContextRec& rec, SkShader* bitmapSh ader)
266 : INHERITED(shader, rec) 266 : INHERITED(shader, rec)
267 , fBitmapShader(SkRef(bitmapShader)) 267 , fBitmapShader(SkRef(bitmapShader))
268 { 268 {
269 fBitmapShaderContextStorage = sk_malloc_throw(bitmapShader->contextSize()); 269 fBitmapShaderContextStorage = sk_malloc_throw(bitmapShader->contextSize(rec) );
270 fBitmapShaderContext = bitmapShader->createContext(rec, fBitmapShaderContext Storage); 270 fBitmapShaderContext = bitmapShader->createContext(rec, fBitmapShaderContext Storage);
271 //if fBitmapShaderContext is null, we are invalid 271 //if fBitmapShaderContext is null, we are invalid
272 } 272 }
273 273
274 SkPictureShader::PictureShaderContext::~PictureShaderContext() { 274 SkPictureShader::PictureShaderContext::~PictureShaderContext() {
275 if (fBitmapShaderContext) { 275 if (fBitmapShaderContext) {
276 fBitmapShaderContext->~Context(); 276 fBitmapShaderContext->~Context();
277 } 277 }
278 sk_free(fBitmapShaderContextStorage); 278 sk_free(fBitmapShaderContextStorage);
279 } 279 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 if (context) { 321 if (context) {
322 maxTextureSize = context->caps()->maxTextureSize(); 322 maxTextureSize = context->caps()->maxTextureSize();
323 } 323 }
324 SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(viewM, localMatrix , maxTextureSize)); 324 SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(viewM, localMatrix , maxTextureSize));
325 if (!bitmapShader) { 325 if (!bitmapShader) {
326 return nullptr; 326 return nullptr;
327 } 327 }
328 return bitmapShader->asFragmentProcessor(context, viewM, nullptr, fq); 328 return bitmapShader->asFragmentProcessor(context, viewM, nullptr, fq);
329 } 329 }
330 #endif 330 #endif
OLDNEW
« no previous file with comments | « src/core/SkPictureShader.h ('k') | src/core/SkShader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698