| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkBitmapProcShader.h" | 8 #include "SkBitmapProcShader.h" |
| 9 #include "SkBitmapProcState.h" | 9 #include "SkBitmapProcState.h" |
| 10 #include "SkBitmapProvider.h" | 10 #include "SkBitmapProvider.h" |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 SkFlattenable* SkBitmapProcShader::CreateProc(SkReadBuffer& buffer) { | 282 SkFlattenable* SkBitmapProcShader::CreateProc(SkReadBuffer& buffer) { |
| 283 SkMatrix lm; | 283 SkMatrix lm; |
| 284 buffer.readMatrix(&lm); | 284 buffer.readMatrix(&lm); |
| 285 SkBitmap bm; | 285 SkBitmap bm; |
| 286 if (!buffer.readBitmap(&bm)) { | 286 if (!buffer.readBitmap(&bm)) { |
| 287 return nullptr; | 287 return nullptr; |
| 288 } | 288 } |
| 289 bm.setImmutable(); | 289 bm.setImmutable(); |
| 290 TileMode mx = (TileMode)buffer.readUInt(); | 290 TileMode mx = (TileMode)buffer.readUInt(); |
| 291 TileMode my = (TileMode)buffer.readUInt(); | 291 TileMode my = (TileMode)buffer.readUInt(); |
| 292 return SkShader::CreateBitmapShader(bm, mx, my, &lm); | 292 return SkShader::MakeBitmapShader(bm, mx, my, &lm).release(); |
| 293 } | 293 } |
| 294 | 294 |
| 295 void SkBitmapProcShader::flatten(SkWriteBuffer& buffer) const { | 295 void SkBitmapProcShader::flatten(SkWriteBuffer& buffer) const { |
| 296 buffer.writeMatrix(this->getLocalMatrix()); | 296 buffer.writeMatrix(this->getLocalMatrix()); |
| 297 buffer.writeBitmap(fRawBitmap); | 297 buffer.writeBitmap(fRawBitmap); |
| 298 buffer.writeUInt(fTileModeX); | 298 buffer.writeUInt(fTileModeX); |
| 299 buffer.writeUInt(fTileModeY); | 299 buffer.writeUInt(fTileModeY); |
| 300 } | 300 } |
| 301 | 301 |
| 302 bool SkBitmapProcShader::isOpaque() const { | 302 bool SkBitmapProcShader::isOpaque() const { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 static bool bitmap_is_too_big(const SkBitmap& bm) { | 345 static bool bitmap_is_too_big(const SkBitmap& bm) { |
| 346 // SkBitmapProcShader stores bitmap coordinates in a 16bit buffer, as it | 346 // SkBitmapProcShader stores bitmap coordinates in a 16bit buffer, as it |
| 347 // communicates between its matrix-proc and its sampler-proc. Until we can | 347 // communicates between its matrix-proc and its sampler-proc. Until we can |
| 348 // widen that, we have to reject bitmaps that are larger. | 348 // widen that, we have to reject bitmaps that are larger. |
| 349 // | 349 // |
| 350 static const int kMaxSize = 65535; | 350 static const int kMaxSize = 65535; |
| 351 | 351 |
| 352 return bm.width() > kMaxSize || bm.height() > kMaxSize; | 352 return bm.width() > kMaxSize || bm.height() > kMaxSize; |
| 353 } | 353 } |
| 354 | 354 |
| 355 SkShader* SkCreateBitmapShader(const SkBitmap& src, SkShader::TileMode tmx, | 355 sk_sp<SkShader> SkMakeBitmapShader(const SkBitmap& src, SkShader::TileMode tmx, |
| 356 SkShader::TileMode tmy, const SkMatrix* localMatr
ix, | 356 SkShader::TileMode tmy, const SkMatrix* local
Matrix, |
| 357 SkTBlitterAllocator* allocator) { | 357 SkTBlitterAllocator* allocator) { |
| 358 SkShader* shader; | 358 SkShader* shader; |
| 359 SkColor color; | 359 SkColor color; |
| 360 if (src.isNull() || bitmap_is_too_big(src)) { | 360 if (src.isNull() || bitmap_is_too_big(src)) { |
| 361 if (nullptr == allocator) { | 361 if (nullptr == allocator) { |
| 362 shader = new SkEmptyShader; | 362 shader = new SkEmptyShader; |
| 363 } else { | 363 } else { |
| 364 shader = allocator->createT<SkEmptyShader>(); | 364 shader = allocator->createT<SkEmptyShader>(); |
| 365 } | 365 } |
| 366 } else if (can_use_color_shader(src, &color)) { | 366 } else if (can_use_color_shader(src, &color)) { |
| 367 if (nullptr == allocator) { | 367 if (nullptr == allocator) { |
| 368 shader = new SkColorShader(color); | 368 shader = new SkColorShader(color); |
| 369 } else { | 369 } else { |
| 370 shader = allocator->createT<SkColorShader>(color); | 370 shader = allocator->createT<SkColorShader>(color); |
| 371 } | 371 } |
| 372 } else { | 372 } else { |
| 373 if (nullptr == allocator) { | 373 if (nullptr == allocator) { |
| 374 shader = new SkBitmapProcShader(src, tmx, tmy, localMatrix); | 374 shader = new SkBitmapProcShader(src, tmx, tmy, localMatrix); |
| 375 } else { | 375 } else { |
| 376 shader = allocator->createT<SkBitmapProcShader>(src, tmx, tmy, local
Matrix); | 376 shader = allocator->createT<SkBitmapProcShader>(src, tmx, tmy, local
Matrix); |
| 377 } | 377 } |
| 378 } | 378 } |
| 379 return shader; | 379 return sk_sp<SkShader>(shader); |
| 380 } | 380 } |
| 381 | 381 |
| 382 /////////////////////////////////////////////////////////////////////////////// | 382 /////////////////////////////////////////////////////////////////////////////// |
| 383 | 383 |
| 384 #ifndef SK_IGNORE_TO_STRING | 384 #ifndef SK_IGNORE_TO_STRING |
| 385 void SkBitmapProcShader::toString(SkString* str) const { | 385 void SkBitmapProcShader::toString(SkString* str) const { |
| 386 static const char* gTileModeName[SkShader::kTileModeCount] = { | 386 static const char* gTileModeName[SkShader::kTileModeCount] = { |
| 387 "clamp", "repeat", "mirror" | 387 "clamp", "repeat", "mirror" |
| 388 }; | 388 }; |
| 389 | 389 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 inner.reset(GrSimpleTextureEffect::Create(texture, matrix, params)); | 458 inner.reset(GrSimpleTextureEffect::Create(texture, matrix, params)); |
| 459 } | 459 } |
| 460 | 460 |
| 461 if (kAlpha_8_SkColorType == fRawBitmap.colorType()) { | 461 if (kAlpha_8_SkColorType == fRawBitmap.colorType()) { |
| 462 return GrFragmentProcessor::MulOutputByInputUnpremulColor(inner); | 462 return GrFragmentProcessor::MulOutputByInputUnpremulColor(inner); |
| 463 } | 463 } |
| 464 return GrFragmentProcessor::MulOutputByInputAlpha(inner); | 464 return GrFragmentProcessor::MulOutputByInputAlpha(inner); |
| 465 } | 465 } |
| 466 | 466 |
| 467 #endif | 467 #endif |
| OLD | NEW |