OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 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 "SkGr.h" | 8 #include "SkGr.h" |
9 | 9 |
10 #include "GrCaps.h" | 10 #include "GrCaps.h" |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 | 273 |
274 // If the config isn't renderable try converting to either A8 or an 32 bit c
onfig. Otherwise, | 274 // If the config isn't renderable try converting to either A8 or an 32 bit c
onfig. Otherwise, |
275 // fail. | 275 // fail. |
276 if (!caps->isConfigRenderable(rtDesc.fConfig, false)) { | 276 if (!caps->isConfigRenderable(rtDesc.fConfig, false)) { |
277 if (GrPixelConfigIsAlphaOnly(rtDesc.fConfig)) { | 277 if (GrPixelConfigIsAlphaOnly(rtDesc.fConfig)) { |
278 if (caps->isConfigRenderable(kAlpha_8_GrPixelConfig, false)) { | 278 if (caps->isConfigRenderable(kAlpha_8_GrPixelConfig, false)) { |
279 rtDesc.fConfig = kAlpha_8_GrPixelConfig; | 279 rtDesc.fConfig = kAlpha_8_GrPixelConfig; |
280 } else if (caps->isConfigRenderable(kSkia8888_GrPixelConfig, false))
{ | 280 } else if (caps->isConfigRenderable(kSkia8888_GrPixelConfig, false))
{ |
281 rtDesc.fConfig = kSkia8888_GrPixelConfig; | 281 rtDesc.fConfig = kSkia8888_GrPixelConfig; |
282 } else { | 282 } else { |
283 return NULL; | 283 return nullptr; |
284 } | 284 } |
285 } else if (kRGB_GrColorComponentFlags == | 285 } else if (kRGB_GrColorComponentFlags == |
286 (kRGB_GrColorComponentFlags & GrPixelConfigComponentMask(rtDe
sc.fConfig))) { | 286 (kRGB_GrColorComponentFlags & GrPixelConfigComponentMask(rtDe
sc.fConfig))) { |
287 if (caps->isConfigRenderable(kSkia8888_GrPixelConfig, false)) { | 287 if (caps->isConfigRenderable(kSkia8888_GrPixelConfig, false)) { |
288 rtDesc.fConfig = kSkia8888_GrPixelConfig; | 288 rtDesc.fConfig = kSkia8888_GrPixelConfig; |
289 } else { | 289 } else { |
290 return NULL; | 290 return nullptr; |
291 } | 291 } |
292 } else { | 292 } else { |
293 return NULL; | 293 return nullptr; |
294 } | 294 } |
295 } | 295 } |
296 | 296 |
297 GrTexture* stretched = create_texture_for_bmp(context, optionalKey, rtDesc,
pixelRef, NULL, 0); | 297 GrTexture* stretched = create_texture_for_bmp(context, optionalKey, rtDesc,
pixelRef, nullptr, 0); |
298 | 298 |
299 if (!stretched) { | 299 if (!stretched) { |
300 return NULL; | 300 return nullptr; |
301 } | 301 } |
302 GrPaint paint; | 302 GrPaint paint; |
303 | 303 |
304 // If filtering is not desired then we want to ensure all texels in the resa
mpled image are | 304 // If filtering is not desired then we want to ensure all texels in the resa
mpled image are |
305 // copies of texels from the original. | 305 // copies of texels from the original. |
306 GrTextureParams params(SkShader::kClamp_TileMode, | 306 GrTextureParams params(SkShader::kClamp_TileMode, |
307 Stretch::kBilerp_Type == stretch.fType ? | 307 Stretch::kBilerp_Type == stretch.fType ? |
308 GrTextureParams::kBilerp_FilterMode : | 308 GrTextureParams::kBilerp_FilterMode : |
309 GrTextureParams::kNone_FilterMode); | 309 GrTextureParams::kNone_FilterMode); |
310 paint.addColorTextureProcessor(inputTexture, SkMatrix::I(), params); | 310 paint.addColorTextureProcessor(inputTexture, SkMatrix::I(), params); |
311 | 311 |
312 SkRect rect = SkRect::MakeWH(SkIntToScalar(rtDesc.fWidth), SkIntToScalar(rtD
esc.fHeight)); | 312 SkRect rect = SkRect::MakeWH(SkIntToScalar(rtDesc.fWidth), SkIntToScalar(rtD
esc.fHeight)); |
313 SkRect localRect = SkRect::MakeWH(1.f, 1.f); | 313 SkRect localRect = SkRect::MakeWH(1.f, 1.f); |
314 | 314 |
315 GrDrawContext* drawContext = context->drawContext(); | 315 GrDrawContext* drawContext = context->drawContext(); |
316 if (!drawContext) { | 316 if (!drawContext) { |
317 return NULL; | 317 return nullptr; |
318 } | 318 } |
319 | 319 |
320 drawContext->drawNonAARectToRect(stretched->asRenderTarget(), GrClip::WideOp
en(), paint, | 320 drawContext->drawNonAARectToRect(stretched->asRenderTarget(), GrClip::WideOp
en(), paint, |
321 SkMatrix::I(), rect, localRect); | 321 SkMatrix::I(), rect, localRect); |
322 | 322 |
323 return stretched; | 323 return stretched; |
324 } | 324 } |
325 | 325 |
326 #ifndef SK_IGNORE_ETC1_SUPPORT | 326 #ifndef SK_IGNORE_ETC1_SUPPORT |
327 static GrTexture *load_etc1_texture(GrContext* ctx, const GrUniqueKey& optionalK
ey, | 327 static GrTexture *load_etc1_texture(GrContext* ctx, const GrUniqueKey& optionalK
ey, |
328 const SkBitmap &bm, GrSurfaceDesc desc) { | 328 const SkBitmap &bm, GrSurfaceDesc desc) { |
329 SkAutoTUnref<SkData> data(bm.pixelRef()->refEncodedData()); | 329 SkAutoTUnref<SkData> data(bm.pixelRef()->refEncodedData()); |
330 | 330 |
331 // Is this even encoded data? | 331 // Is this even encoded data? |
332 if (NULL == data) { | 332 if (nullptr == data) { |
333 return NULL; | 333 return nullptr; |
334 } | 334 } |
335 | 335 |
336 // Is this a valid PKM encoded data? | 336 // Is this a valid PKM encoded data? |
337 const uint8_t *bytes = data->bytes(); | 337 const uint8_t *bytes = data->bytes(); |
338 if (etc1_pkm_is_valid(bytes)) { | 338 if (etc1_pkm_is_valid(bytes)) { |
339 uint32_t encodedWidth = etc1_pkm_get_width(bytes); | 339 uint32_t encodedWidth = etc1_pkm_get_width(bytes); |
340 uint32_t encodedHeight = etc1_pkm_get_height(bytes); | 340 uint32_t encodedHeight = etc1_pkm_get_height(bytes); |
341 | 341 |
342 // Does the data match the dimensions of the bitmap? If not, | 342 // Does the data match the dimensions of the bitmap? If not, |
343 // then we don't know how to scale the image to match it... | 343 // then we don't know how to scale the image to match it... |
344 if (encodedWidth != static_cast<uint32_t>(bm.width()) || | 344 if (encodedWidth != static_cast<uint32_t>(bm.width()) || |
345 encodedHeight != static_cast<uint32_t>(bm.height())) { | 345 encodedHeight != static_cast<uint32_t>(bm.height())) { |
346 return NULL; | 346 return nullptr; |
347 } | 347 } |
348 | 348 |
349 // Everything seems good... skip ahead to the data. | 349 // Everything seems good... skip ahead to the data. |
350 bytes += ETC_PKM_HEADER_SIZE; | 350 bytes += ETC_PKM_HEADER_SIZE; |
351 desc.fConfig = kETC1_GrPixelConfig; | 351 desc.fConfig = kETC1_GrPixelConfig; |
352 } else if (SkKTXFile::is_ktx(bytes)) { | 352 } else if (SkKTXFile::is_ktx(bytes)) { |
353 SkKTXFile ktx(data); | 353 SkKTXFile ktx(data); |
354 | 354 |
355 // Is it actually an ETC1 texture? | 355 // Is it actually an ETC1 texture? |
356 if (!ktx.isCompressedFormat(SkTextureCompressor::kETC1_Format)) { | 356 if (!ktx.isCompressedFormat(SkTextureCompressor::kETC1_Format)) { |
357 return NULL; | 357 return nullptr; |
358 } | 358 } |
359 | 359 |
360 // Does the data match the dimensions of the bitmap? If not, | 360 // Does the data match the dimensions of the bitmap? If not, |
361 // then we don't know how to scale the image to match it... | 361 // then we don't know how to scale the image to match it... |
362 if (ktx.width() != bm.width() || ktx.height() != bm.height()) { | 362 if (ktx.width() != bm.width() || ktx.height() != bm.height()) { |
363 return NULL; | 363 return nullptr; |
364 } | 364 } |
365 | 365 |
366 bytes = ktx.pixelData(); | 366 bytes = ktx.pixelData(); |
367 desc.fConfig = kETC1_GrPixelConfig; | 367 desc.fConfig = kETC1_GrPixelConfig; |
368 } else { | 368 } else { |
369 return NULL; | 369 return nullptr; |
370 } | 370 } |
371 | 371 |
372 return create_texture_for_bmp(ctx, optionalKey, desc, bm.pixelRef(), bytes,
0); | 372 return create_texture_for_bmp(ctx, optionalKey, desc, bm.pixelRef(), bytes,
0); |
373 } | 373 } |
374 #endif // SK_IGNORE_ETC1_SUPPORT | 374 #endif // SK_IGNORE_ETC1_SUPPORT |
375 | 375 |
376 static GrTexture* load_yuv_texture(GrContext* ctx, const GrUniqueKey& optionalKe
y, | 376 static GrTexture* load_yuv_texture(GrContext* ctx, const GrUniqueKey& optionalKe
y, |
377 const SkBitmap& bm, const GrSurfaceDesc& desc
) { | 377 const SkBitmap& bm, const GrSurfaceDesc& desc
) { |
378 // Subsets are not supported, the whole pixelRef is loaded when using YUV de
coding | 378 // Subsets are not supported, the whole pixelRef is loaded when using YUV de
coding |
379 SkPixelRef* pixelRef = bm.pixelRef(); | 379 SkPixelRef* pixelRef = bm.pixelRef(); |
380 if ((NULL == pixelRef) || | 380 if ((nullptr == pixelRef) || |
381 (pixelRef->info().width() != bm.info().width()) || | 381 (pixelRef->info().width() != bm.info().width()) || |
382 (pixelRef->info().height() != bm.info().height())) { | 382 (pixelRef->info().height() != bm.info().height())) { |
383 return NULL; | 383 return nullptr; |
384 } | 384 } |
385 | 385 |
386 const bool useCache = optionalKey.isValid(); | 386 const bool useCache = optionalKey.isValid(); |
387 SkYUVPlanesCache::Info yuvInfo; | 387 SkYUVPlanesCache::Info yuvInfo; |
388 SkAutoTUnref<SkCachedData> cachedData; | 388 SkAutoTUnref<SkCachedData> cachedData; |
389 SkAutoMalloc storage; | 389 SkAutoMalloc storage; |
390 if (useCache) { | 390 if (useCache) { |
391 cachedData.reset(SkYUVPlanesCache::FindAndRef(pixelRef->getGenerationID(
), &yuvInfo)); | 391 cachedData.reset(SkYUVPlanesCache::FindAndRef(pixelRef->getGenerationID(
), &yuvInfo)); |
392 } | 392 } |
393 | 393 |
394 void* planes[3]; | 394 void* planes[3]; |
395 if (cachedData.get()) { | 395 if (cachedData.get()) { |
396 planes[0] = (void*)cachedData->data(); | 396 planes[0] = (void*)cachedData->data(); |
397 planes[1] = (uint8_t*)planes[0] + yuvInfo.fSizeInMemory[0]; | 397 planes[1] = (uint8_t*)planes[0] + yuvInfo.fSizeInMemory[0]; |
398 planes[2] = (uint8_t*)planes[1] + yuvInfo.fSizeInMemory[1]; | 398 planes[2] = (uint8_t*)planes[1] + yuvInfo.fSizeInMemory[1]; |
399 } else { | 399 } else { |
400 // Fetch yuv plane sizes for memory allocation. Here, width and height c
an be | 400 // Fetch yuv plane sizes for memory allocation. Here, width and height c
an be |
401 // rounded up to JPEG block size and be larger than the image's width an
d height. | 401 // rounded up to JPEG block size and be larger than the image's width an
d height. |
402 if (!pixelRef->getYUV8Planes(yuvInfo.fSize, NULL, NULL, NULL)) { | 402 if (!pixelRef->getYUV8Planes(yuvInfo.fSize, nullptr, nullptr, nullptr))
{ |
403 return NULL; | 403 return nullptr; |
404 } | 404 } |
405 | 405 |
406 // Allocate the memory for YUV | 406 // Allocate the memory for YUV |
407 size_t totalSize(0); | 407 size_t totalSize(0); |
408 for (int i = 0; i < 3; ++i) { | 408 for (int i = 0; i < 3; ++i) { |
409 yuvInfo.fRowBytes[i] = yuvInfo.fSize[i].fWidth; | 409 yuvInfo.fRowBytes[i] = yuvInfo.fSize[i].fWidth; |
410 yuvInfo.fSizeInMemory[i] = yuvInfo.fRowBytes[i] * yuvInfo.fSize[i].f
Height; | 410 yuvInfo.fSizeInMemory[i] = yuvInfo.fRowBytes[i] * yuvInfo.fSize[i].f
Height; |
411 totalSize += yuvInfo.fSizeInMemory[i]; | 411 totalSize += yuvInfo.fSizeInMemory[i]; |
412 } | 412 } |
413 if (useCache) { | 413 if (useCache) { |
414 cachedData.reset(SkResourceCache::NewCachedData(totalSize)); | 414 cachedData.reset(SkResourceCache::NewCachedData(totalSize)); |
415 planes[0] = cachedData->writable_data(); | 415 planes[0] = cachedData->writable_data(); |
416 } else { | 416 } else { |
417 storage.reset(totalSize); | 417 storage.reset(totalSize); |
418 planes[0] = storage.get(); | 418 planes[0] = storage.get(); |
419 } | 419 } |
420 planes[1] = (uint8_t*)planes[0] + yuvInfo.fSizeInMemory[0]; | 420 planes[1] = (uint8_t*)planes[0] + yuvInfo.fSizeInMemory[0]; |
421 planes[2] = (uint8_t*)planes[1] + yuvInfo.fSizeInMemory[1]; | 421 planes[2] = (uint8_t*)planes[1] + yuvInfo.fSizeInMemory[1]; |
422 | 422 |
423 // Get the YUV planes and update plane sizes to actual image size | 423 // Get the YUV planes and update plane sizes to actual image size |
424 if (!pixelRef->getYUV8Planes(yuvInfo.fSize, planes, yuvInfo.fRowBytes, | 424 if (!pixelRef->getYUV8Planes(yuvInfo.fSize, planes, yuvInfo.fRowBytes, |
425 &yuvInfo.fColorSpace)) { | 425 &yuvInfo.fColorSpace)) { |
426 return NULL; | 426 return nullptr; |
427 } | 427 } |
428 | 428 |
429 if (useCache) { | 429 if (useCache) { |
430 // Decoding is done, cache the resulting YUV planes | 430 // Decoding is done, cache the resulting YUV planes |
431 SkYUVPlanesCache::Add(pixelRef->getGenerationID(), cachedData, &yuvI
nfo); | 431 SkYUVPlanesCache::Add(pixelRef->getGenerationID(), cachedData, &yuvI
nfo); |
432 } | 432 } |
433 } | 433 } |
434 | 434 |
435 GrSurfaceDesc yuvDesc; | 435 GrSurfaceDesc yuvDesc; |
436 yuvDesc.fConfig = kAlpha_8_GrPixelConfig; | 436 yuvDesc.fConfig = kAlpha_8_GrPixelConfig; |
437 SkAutoTUnref<GrTexture> yuvTextures[3]; | 437 SkAutoTUnref<GrTexture> yuvTextures[3]; |
438 for (int i = 0; i < 3; ++i) { | 438 for (int i = 0; i < 3; ++i) { |
439 yuvDesc.fWidth = yuvInfo.fSize[i].fWidth; | 439 yuvDesc.fWidth = yuvInfo.fSize[i].fWidth; |
440 yuvDesc.fHeight = yuvInfo.fSize[i].fHeight; | 440 yuvDesc.fHeight = yuvInfo.fSize[i].fHeight; |
441 bool needsExactTexture = | 441 bool needsExactTexture = |
442 (yuvDesc.fWidth != yuvInfo.fSize[0].fWidth) || | 442 (yuvDesc.fWidth != yuvInfo.fSize[0].fWidth) || |
443 (yuvDesc.fHeight != yuvInfo.fSize[0].fHeight); | 443 (yuvDesc.fHeight != yuvInfo.fSize[0].fHeight); |
444 if (needsExactTexture) { | 444 if (needsExactTexture) { |
445 yuvTextures[i].reset(ctx->textureProvider()->createTexture(yuvDesc,
true)); | 445 yuvTextures[i].reset(ctx->textureProvider()->createTexture(yuvDesc,
true)); |
446 } else { | 446 } else { |
447 yuvTextures[i].reset(ctx->textureProvider()->createApproxTexture(yuv
Desc)); | 447 yuvTextures[i].reset(ctx->textureProvider()->createApproxTexture(yuv
Desc)); |
448 } | 448 } |
449 if (!yuvTextures[i] || | 449 if (!yuvTextures[i] || |
450 !yuvTextures[i]->writePixels(0, 0, yuvDesc.fWidth, yuvDesc.fHeight, | 450 !yuvTextures[i]->writePixels(0, 0, yuvDesc.fWidth, yuvDesc.fHeight, |
451 yuvDesc.fConfig, planes[i], yuvInfo.fRo
wBytes[i])) { | 451 yuvDesc.fConfig, planes[i], yuvInfo.fRo
wBytes[i])) { |
452 return NULL; | 452 return nullptr; |
453 } | 453 } |
454 } | 454 } |
455 | 455 |
456 GrSurfaceDesc rtDesc = desc; | 456 GrSurfaceDesc rtDesc = desc; |
457 rtDesc.fFlags = rtDesc.fFlags | kRenderTarget_GrSurfaceFlag; | 457 rtDesc.fFlags = rtDesc.fFlags | kRenderTarget_GrSurfaceFlag; |
458 | 458 |
459 GrTexture* result = create_texture_for_bmp(ctx, optionalKey, rtDesc, pixelRe
f, NULL, 0); | 459 GrTexture* result = create_texture_for_bmp(ctx, optionalKey, rtDesc, pixelRe
f, nullptr, 0); |
460 if (!result) { | 460 if (!result) { |
461 return NULL; | 461 return nullptr; |
462 } | 462 } |
463 | 463 |
464 GrRenderTarget* renderTarget = result->asRenderTarget(); | 464 GrRenderTarget* renderTarget = result->asRenderTarget(); |
465 SkASSERT(renderTarget); | 465 SkASSERT(renderTarget); |
466 | 466 |
467 GrPaint paint; | 467 GrPaint paint; |
468 SkAutoTUnref<GrFragmentProcessor> | 468 SkAutoTUnref<GrFragmentProcessor> |
469 yuvToRgbProcessor(GrYUVtoRGBEffect::Create(paint.getProcessorDataManager
(), yuvTextures[0], | 469 yuvToRgbProcessor(GrYUVtoRGBEffect::Create(paint.getProcessorDataManager
(), yuvTextures[0], |
470 yuvTextures[1], yuvTextures[2
], | 470 yuvTextures[1], yuvTextures[2
], |
471 yuvInfo.fSize, yuvInfo.fColor
Space)); | 471 yuvInfo.fSize, yuvInfo.fColor
Space)); |
472 paint.addColorFragmentProcessor(yuvToRgbProcessor); | 472 paint.addColorFragmentProcessor(yuvToRgbProcessor); |
473 SkRect r = SkRect::MakeWH(SkIntToScalar(yuvInfo.fSize[0].fWidth), | 473 SkRect r = SkRect::MakeWH(SkIntToScalar(yuvInfo.fSize[0].fWidth), |
474 SkIntToScalar(yuvInfo.fSize[0].fHeight)); | 474 SkIntToScalar(yuvInfo.fSize[0].fHeight)); |
475 | 475 |
476 GrDrawContext* drawContext = ctx->drawContext(); | 476 GrDrawContext* drawContext = ctx->drawContext(); |
477 if (!drawContext) { | 477 if (!drawContext) { |
478 return NULL; | 478 return nullptr; |
479 } | 479 } |
480 | 480 |
481 drawContext->drawRect(renderTarget, GrClip::WideOpen(), paint, SkMatrix::I()
, r); | 481 drawContext->drawRect(renderTarget, GrClip::WideOpen(), paint, SkMatrix::I()
, r); |
482 | 482 |
483 return result; | 483 return result; |
484 } | 484 } |
485 | 485 |
486 static GrTexture* create_unstretched_bitmap_texture(GrContext* ctx, | 486 static GrTexture* create_unstretched_bitmap_texture(GrContext* ctx, |
487 const SkBitmap& origBitmap, | 487 const SkBitmap& origBitmap, |
488 const GrUniqueKey& optionalK
ey) { | 488 const GrUniqueKey& optionalK
ey) { |
489 if (origBitmap.width() < ctx->caps()->minTextureSize() || | 489 if (origBitmap.width() < ctx->caps()->minTextureSize() || |
490 origBitmap.height() < ctx->caps()->minTextureSize()) { | 490 origBitmap.height() < ctx->caps()->minTextureSize()) { |
491 return NULL; | 491 return nullptr; |
492 } | 492 } |
493 SkBitmap tmpBitmap; | 493 SkBitmap tmpBitmap; |
494 | 494 |
495 const SkBitmap* bitmap = &origBitmap; | 495 const SkBitmap* bitmap = &origBitmap; |
496 | 496 |
497 GrSurfaceDesc desc; | 497 GrSurfaceDesc desc; |
498 generate_bitmap_texture_desc(*bitmap, &desc); | 498 generate_bitmap_texture_desc(*bitmap, &desc); |
499 const GrCaps* caps = ctx->caps(); | 499 const GrCaps* caps = ctx->caps(); |
500 | 500 |
501 if (kIndex_8_SkColorType == bitmap->colorType()) { | 501 if (kIndex_8_SkColorType == bitmap->colorType()) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 } | 534 } |
535 #endif // SK_IGNORE_ETC1_SUPPORT | 535 #endif // SK_IGNORE_ETC1_SUPPORT |
536 | 536 |
537 GrTexture *texture = load_yuv_texture(ctx, optionalKey, *bitmap, desc); | 537 GrTexture *texture = load_yuv_texture(ctx, optionalKey, *bitmap, desc); |
538 if (texture) { | 538 if (texture) { |
539 return texture; | 539 return texture; |
540 } | 540 } |
541 | 541 |
542 SkAutoLockPixels alp(*bitmap); | 542 SkAutoLockPixels alp(*bitmap); |
543 if (!bitmap->readyToDraw()) { | 543 if (!bitmap->readyToDraw()) { |
544 return NULL; | 544 return nullptr; |
545 } | 545 } |
546 | 546 |
547 return create_texture_for_bmp(ctx, optionalKey, desc, origBitmap.pixelRef(), | 547 return create_texture_for_bmp(ctx, optionalKey, desc, origBitmap.pixelRef(), |
548 bitmap->getPixels(), bitmap->rowBytes()); | 548 bitmap->getPixels(), bitmap->rowBytes()); |
549 } | 549 } |
550 | 550 |
551 static SkBitmap stretch_on_cpu(const SkBitmap& bmp, const Stretch& stretch) { | 551 static SkBitmap stretch_on_cpu(const SkBitmap& bmp, const Stretch& stretch) { |
552 SkBitmap stretched; | 552 SkBitmap stretched; |
553 stretched.allocN32Pixels(stretch.fWidth, stretch.fHeight); | 553 stretched.allocN32Pixels(stretch.fWidth, stretch.fHeight); |
554 SkCanvas canvas(stretched); | 554 SkCanvas canvas(stretched); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 | 673 |
674 result = create_bitmap_texture(ctx, bitmap, stretch, key, resizedKey); | 674 result = create_bitmap_texture(ctx, bitmap, stretch, key, resizedKey); |
675 if (result) { | 675 if (result) { |
676 return result; | 676 return result; |
677 } | 677 } |
678 | 678 |
679 SkErrorInternals::SetError( kInternalError_SkError, | 679 SkErrorInternals::SetError( kInternalError_SkError, |
680 "---- failed to create texture for cache [%d %d]
\n", | 680 "---- failed to create texture for cache [%d %d]
\n", |
681 bitmap.width(), bitmap.height()); | 681 bitmap.width(), bitmap.height()); |
682 | 682 |
683 return NULL; | 683 return nullptr; |
684 } | 684 } |
685 | 685 |
686 // TODO: make this be the canonical signature, and turn the version that takes G
rTextureParams* | 686 // TODO: make this be the canonical signature, and turn the version that takes G
rTextureParams* |
687 // into a wrapper that contains the inverse of these tables. | 687 // into a wrapper that contains the inverse of these tables. |
688 GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, | 688 GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, |
689 const SkBitmap& bitmap, | 689 const SkBitmap& bitmap, |
690 SkImageUsageType usage) { | 690 SkImageUsageType usage) { |
691 // Just need a params that will trigger the correct cache key / etc, since t
he usage doesn't | 691 // Just need a params that will trigger the correct cache key / etc, since t
he usage doesn't |
692 // tell us the specifics about filter level or specific tiling. | 692 // tell us the specifics about filter level or specific tiling. |
693 | 693 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
778 | 778 |
779 /////////////////////////////////////////////////////////////////////////////// | 779 /////////////////////////////////////////////////////////////////////////////// |
780 | 780 |
781 bool SkPaint2GrPaintNoShader(GrContext* context, GrRenderTarget* rt, const SkPai
nt& skPaint, | 781 bool SkPaint2GrPaintNoShader(GrContext* context, GrRenderTarget* rt, const SkPai
nt& skPaint, |
782 GrColor paintColor, bool constantColor, GrPaint* gr
Paint) { | 782 GrColor paintColor, bool constantColor, GrPaint* gr
Paint) { |
783 | 783 |
784 grPaint->setDither(skPaint.isDither()); | 784 grPaint->setDither(skPaint.isDither()); |
785 grPaint->setAntiAlias(skPaint.isAntiAlias()); | 785 grPaint->setAntiAlias(skPaint.isAntiAlias()); |
786 | 786 |
787 SkXfermode* mode = skPaint.getXfermode(); | 787 SkXfermode* mode = skPaint.getXfermode(); |
788 GrXPFactory* xpFactory = NULL; | 788 GrXPFactory* xpFactory = nullptr; |
789 if (!SkXfermode::AsXPFactory(mode, &xpFactory)) { | 789 if (!SkXfermode::AsXPFactory(mode, &xpFactory)) { |
790 // Fall back to src-over | 790 // Fall back to src-over |
791 // return false here? | 791 // return false here? |
792 xpFactory = GrPorterDuffXPFactory::Create(SkXfermode::kSrcOver_Mode); | 792 xpFactory = GrPorterDuffXPFactory::Create(SkXfermode::kSrcOver_Mode); |
793 } | 793 } |
794 SkASSERT(xpFactory); | 794 SkASSERT(xpFactory); |
795 grPaint->setXPFactory(xpFactory)->unref(); | 795 grPaint->setXPFactory(xpFactory)->unref(); |
796 | 796 |
797 //set the color of the paint to the one of the parameter | 797 //set the color of the paint to the one of the parameter |
798 grPaint->setColor(paintColor); | 798 grPaint->setColor(paintColor); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
837 } | 837 } |
838 } | 838 } |
839 } | 839 } |
840 #endif | 840 #endif |
841 return true; | 841 return true; |
842 } | 842 } |
843 | 843 |
844 bool SkPaint2GrPaint(GrContext* context, GrRenderTarget* rt, const SkPaint& skPa
int, | 844 bool SkPaint2GrPaint(GrContext* context, GrRenderTarget* rt, const SkPaint& skPa
int, |
845 const SkMatrix& viewM, bool constantColor, GrPaint* grPaint
) { | 845 const SkMatrix& viewM, bool constantColor, GrPaint* grPaint
) { |
846 SkShader* shader = skPaint.getShader(); | 846 SkShader* shader = skPaint.getShader(); |
847 if (NULL == shader) { | 847 if (nullptr == shader) { |
848 return SkPaint2GrPaintNoShader(context, rt, skPaint, SkColor2GrColor(skP
aint.getColor()), | 848 return SkPaint2GrPaintNoShader(context, rt, skPaint, SkColor2GrColor(skP
aint.getColor()), |
849 constantColor, grPaint); | 849 constantColor, grPaint); |
850 } | 850 } |
851 | 851 |
852 GrColor paintColor = SkColor2GrColor(skPaint.getColor()); | 852 GrColor paintColor = SkColor2GrColor(skPaint.getColor()); |
853 | 853 |
854 // Start a new block here in order to preserve our context state after calli
ng | 854 // Start a new block here in order to preserve our context state after calli
ng |
855 // asFragmentProcessor(). Since these calls get passed back to the client, w
e don't really | 855 // asFragmentProcessor(). Since these calls get passed back to the client, w
e don't really |
856 // want them messing around with the context. | 856 // want them messing around with the context. |
857 { | 857 { |
858 // Allow the shader to modify paintColor and also create an effect to be
installed as | 858 // Allow the shader to modify paintColor and also create an effect to be
installed as |
859 // the first color effect on the GrPaint. | 859 // the first color effect on the GrPaint. |
860 GrFragmentProcessor* fp = NULL; | 860 GrFragmentProcessor* fp = nullptr; |
861 if (!shader->asFragmentProcessor(context, skPaint, viewM, NULL, &paintCo
lor, | 861 if (!shader->asFragmentProcessor(context, skPaint, viewM, nullptr, &pain
tColor, |
862 grPaint->getProcessorDataManager(), &fp
)) { | 862 grPaint->getProcessorDataManager(), &fp
)) { |
863 return false; | 863 return false; |
864 } | 864 } |
865 if (fp) { | 865 if (fp) { |
866 grPaint->addColorFragmentProcessor(fp)->unref(); | 866 grPaint->addColorFragmentProcessor(fp)->unref(); |
867 constantColor = false; | 867 constantColor = false; |
868 } | 868 } |
869 } | 869 } |
870 | 870 |
871 // The grcolor is automatically set when calling asFragmentProcessor. | 871 // The grcolor is automatically set when calling asFragmentProcessor. |
872 // If the shader can be seen as an effect it returns true and adds its effec
t to the grpaint. | 872 // If the shader can be seen as an effect it returns true and adds its effec
t to the grpaint. |
873 return SkPaint2GrPaintNoShader(context, rt, skPaint, paintColor, constantCol
or, grPaint); | 873 return SkPaint2GrPaintNoShader(context, rt, skPaint, paintColor, constantCol
or, grPaint); |
874 } | 874 } |
875 | 875 |
876 SkImageInfo GrMakeInfoFromTexture(GrTexture* tex, int w, int h, bool isOpaque) { | 876 SkImageInfo GrMakeInfoFromTexture(GrTexture* tex, int w, int h, bool isOpaque) { |
877 #ifdef SK_DEBUG | 877 #ifdef SK_DEBUG |
878 const GrSurfaceDesc& desc = tex->desc(); | 878 const GrSurfaceDesc& desc = tex->desc(); |
879 SkASSERT(w <= desc.fWidth); | 879 SkASSERT(w <= desc.fWidth); |
880 SkASSERT(h <= desc.fHeight); | 880 SkASSERT(h <= desc.fHeight); |
881 #endif | 881 #endif |
882 const GrPixelConfig config = tex->config(); | 882 const GrPixelConfig config = tex->config(); |
883 SkColorType ct; | 883 SkColorType ct; |
884 SkAlphaType at = isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType; | 884 SkAlphaType at = isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType; |
885 if (!GrPixelConfig2ColorAndProfileType(config, &ct, NULL)) { | 885 if (!GrPixelConfig2ColorAndProfileType(config, &ct, nullptr)) { |
886 ct = kUnknown_SkColorType; | 886 ct = kUnknown_SkColorType; |
887 } | 887 } |
888 return SkImageInfo::Make(w, h, ct, at); | 888 return SkImageInfo::Make(w, h, ct, at); |
889 } | 889 } |
890 | 890 |
891 | 891 |
892 void GrWrapTextureInBitmap(GrTexture* src, int w, int h, bool isOpaque, SkBitmap
* dst) { | 892 void GrWrapTextureInBitmap(GrTexture* src, int w, int h, bool isOpaque, SkBitmap
* dst) { |
893 const SkImageInfo info = GrMakeInfoFromTexture(src, w, h, isOpaque); | 893 const SkImageInfo info = GrMakeInfoFromTexture(src, w, h, isOpaque); |
894 dst->setInfo(info); | 894 dst->setInfo(info); |
895 dst->setPixelRef(new SkGrPixelRef(info, src))->unref(); | 895 dst->setPixelRef(new SkGrPixelRef(info, src))->unref(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 SkErrorInternals::SetError( kInvalidPaint_SkError, | 929 SkErrorInternals::SetError( kInvalidPaint_SkError, |
930 "Sorry, I don't understand the filtering
" | 930 "Sorry, I don't understand the filtering
" |
931 "mode you asked for. Falling back to " | 931 "mode you asked for. Falling back to " |
932 "MIPMaps."); | 932 "MIPMaps."); |
933 textureFilterMode = GrTextureParams::kMipMap_FilterMode; | 933 textureFilterMode = GrTextureParams::kMipMap_FilterMode; |
934 break; | 934 break; |
935 | 935 |
936 } | 936 } |
937 return textureFilterMode; | 937 return textureFilterMode; |
938 } | 938 } |
OLD | NEW |