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

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

Issue 179343005: Add a class to allocate small objects w/o extra calls to new. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rename the .h file Created 6 years, 9 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
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "SkColorPriv.h" 8 #include "SkColorPriv.h"
9 #include "SkReadBuffer.h" 9 #include "SkReadBuffer.h"
10 #include "SkWriteBuffer.h" 10 #include "SkWriteBuffer.h"
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 return true; 287 return true;
288 case kIndex_8_SkColorType: 288 case kIndex_8_SkColorType:
289 *color = SkUnPreMultiply::PMColorToColor(bm.getIndex8Color(0, 0)); 289 *color = SkUnPreMultiply::PMColorToColor(bm.getIndex8Color(0, 0));
290 return true; 290 return true;
291 default: // just skip the other configs for now 291 default: // just skip the other configs for now
292 break; 292 break;
293 } 293 }
294 return false; 294 return false;
295 } 295 }
296 296
297 #include "SkTemplatesPriv.h"
298
299 static bool bitmapIsTooBig(const SkBitmap& bm) { 297 static bool bitmapIsTooBig(const SkBitmap& bm) {
300 // SkBitmapProcShader stores bitmap coordinates in a 16bit buffer, as it 298 // SkBitmapProcShader stores bitmap coordinates in a 16bit buffer, as it
301 // communicates between its matrix-proc and its sampler-proc. Until we can 299 // communicates between its matrix-proc and its sampler-proc. Until we can
302 // widen that, we have to reject bitmaps that are larger. 300 // widen that, we have to reject bitmaps that are larger.
303 // 301 //
304 const int maxSize = 65535; 302 const int maxSize = 65535;
305 303
306 return bm.width() > maxSize || bm.height() > maxSize; 304 return bm.width() > maxSize || bm.height() > maxSize;
307 } 305 }
308 306
309 SkShader* SkShader::CreateBitmapShader(const SkBitmap& src, 307 SkShader* CreateBitmapShader(const SkBitmap& src, SkShader::TileMode tmx,
310 TileMode tmx, TileMode tmy, 308 SkShader::TileMode tmy, SkTBlitterAllocator* allocator) {
311 void* storage, size_t storageSize) {
312 SkShader* shader; 309 SkShader* shader;
313 SkColor color; 310 SkColor color;
314 if (src.isNull() || bitmapIsTooBig(src)) { 311 if (src.isNull() || bitmapIsTooBig(src)) {
315 SK_PLACEMENT_NEW(shader, SkEmptyShader, storage, storageSize); 312 if (NULL == allocator) {
313 shader = SkNEW(SkEmptyShader);
314 } else {
315 shader = allocator->createT<SkEmptyShader>();
316 }
316 } 317 }
317 else if (canUseColorShader(src, &color)) { 318 else if (canUseColorShader(src, &color)) {
318 SK_PLACEMENT_NEW_ARGS(shader, SkColorShader, storage, storageSize, 319 if (NULL == allocator) {
319 (color)); 320 shader = SkNEW_ARGS(SkColorShader, (color));
321 } else {
322 shader = allocator->createT<SkColorShader>(color);
323 }
320 } else { 324 } else {
321 SK_PLACEMENT_NEW_ARGS(shader, SkBitmapProcShader, storage, 325 if (NULL == allocator) {
322 storageSize, (src, tmx, tmy)); 326 shader = SkNEW_ARGS(SkBitmapProcShader, (src, tmx, tmy));
327 } else {
328 shader = allocator->createT<SkBitmapProcShader>(src, tmx, tmy);
329 }
323 } 330 }
324 return shader; 331 return shader;
325 } 332 }
326 333
327 /////////////////////////////////////////////////////////////////////////////// 334 ///////////////////////////////////////////////////////////////////////////////
328 335
329 #ifdef SK_DEVELOPER 336 #ifdef SK_DEVELOPER
330 void SkBitmapProcShader::toString(SkString* str) const { 337 void SkBitmapProcShader::toString(SkString* str) const {
331 static const char* gTileModeName[SkShader::kTileModeCount] = { 338 static const char* gTileModeName[SkShader::kTileModeCount] = {
332 "clamp", "repeat", "mirror" 339 "clamp", "repeat", "mirror"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 GrEffectRef* effect = NULL; 444 GrEffectRef* effect = NULL;
438 if (paintFilterLevel == SkPaint::kHigh_FilterLevel) { 445 if (paintFilterLevel == SkPaint::kHigh_FilterLevel) {
439 effect = GrBicubicEffect::Create(texture, matrix, tm); 446 effect = GrBicubicEffect::Create(texture, matrix, tm);
440 } else { 447 } else {
441 effect = GrSimpleTextureEffect::Create(texture, matrix, params); 448 effect = GrSimpleTextureEffect::Create(texture, matrix, params);
442 } 449 }
443 GrUnlockAndUnrefCachedBitmapTexture(texture); 450 GrUnlockAndUnrefCachedBitmapTexture(texture);
444 return effect; 451 return effect;
445 } 452 }
446 #endif 453 #endif
OLDNEW
« no previous file with comments | « src/core/SkBitmapProcShader.h ('k') | src/core/SkBlitter.h » ('j') | src/core/SkSmallAllocator.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698