Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 <cstddef> | |
| 9 #include <cstring> | |
| 10 #include <type_traits> | |
| 11 | |
| 8 #include "SkAutoPixmapStorage.h" | 12 #include "SkAutoPixmapStorage.h" |
| 9 #include "GrCaps.h" | 13 #include "GrCaps.h" |
| 10 #include "GrContext.h" | 14 #include "GrContext.h" |
| 11 #include "GrDrawContext.h" | 15 #include "GrDrawContext.h" |
| 12 #include "GrImageIDTextureAdjuster.h" | 16 #include "GrImageIDTextureAdjuster.h" |
| 17 #include "GrTexturePriv.h" | |
| 13 #include "effects/GrYUVEffect.h" | 18 #include "effects/GrYUVEffect.h" |
| 14 #include "SkCanvas.h" | 19 #include "SkCanvas.h" |
| 15 #include "SkBitmapCache.h" | 20 #include "SkBitmapCache.h" |
| 16 #include "SkGrPriv.h" | 21 #include "SkGrPriv.h" |
| 17 #include "SkImage_Gpu.h" | 22 #include "SkImage_Gpu.h" |
| 18 #include "SkMipMap.h" | 23 #include "SkMipMap.h" |
| 19 #include "SkPixelRef.h" | 24 #include "SkPixelRef.h" |
| 20 | 25 |
| 21 SkImage_Gpu::SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType at, GrText ure* tex, | 26 SkImage_Gpu::SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType at, GrText ure* tex, |
| 22 sk_sp<SkColorSpace> colorSpace, SkBudgeted budgeted) | 27 sk_sp<SkColorSpace> colorSpace, SkBudgeted budgeted) |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 351 | 356 |
| 352 //////////////////////////////////////////////////////////////////////////////// /////////////////// | 357 //////////////////////////////////////////////////////////////////////////////// /////////////////// |
| 353 | 358 |
| 354 namespace { | 359 namespace { |
| 355 struct MipMapLevelData { | 360 struct MipMapLevelData { |
| 356 void* fPixelData; | 361 void* fPixelData; |
| 357 size_t fRowBytes; | 362 size_t fRowBytes; |
| 358 }; | 363 }; |
| 359 | 364 |
| 360 struct DeferredTextureImage { | 365 struct DeferredTextureImage { |
| 361 uint32_t fContextUniqueID; | 366 uint32_t fContextUniqueID; |
| 367 // Right now, the gamma treatment is only considered when generating mipmaps | |
| 368 SkSourceGammaTreatment fGammaTreatment; | |
| 362 // We don't store a SkImageInfo because it contains a ref-counted SkColorSpa ce. | 369 // We don't store a SkImageInfo because it contains a ref-counted SkColorSpa ce. |
| 363 int fWidth; | 370 int fWidth; |
| 364 int fHeight; | 371 int fHeight; |
| 365 SkColorType fColorType; | 372 SkColorType fColorType; |
| 366 SkAlphaType fAlphaType; | 373 SkAlphaType fAlphaType; |
| 367 void* fColorSpace; | 374 void* fColorSpace; |
| 368 size_t fColorSpaceSize; | 375 size_t fColorSpaceSize; |
| 369 int fColorTableCnt; | 376 int fColorTableCnt; |
| 370 uint32_t* fColorTableData; | 377 uint32_t* fColorTableData; |
| 371 int fMipMapLevelCount; | 378 int fMipMapLevelCount; |
| 372 // The fMipMapLevelData array may contain more than 1 element. | 379 // The fMipMapLevelData array may contain more than 1 element. |
| 373 // It contains fMipMapLevelCount elements. | 380 // It contains fMipMapLevelCount elements. |
| 374 // That means this struct's size is not known at compile-time. | 381 // That means this struct's size is not known at compile-time. |
| 375 MipMapLevelData fMipMapLevelData[1]; | 382 MipMapLevelData fMipMapLevelData[1]; |
| 376 }; | 383 }; |
| 377 } // anonymous namespace | 384 } // anonymous namespace |
| 378 | 385 |
| 386 static bool should_use_mip_maps(const SkImage::DeferredTextureImageUsageParams & param) { | |
| 387 bool shouldUseMipMaps = false; | |
| 388 | |
| 389 // Use mipmaps if either | |
| 390 // 1.) it is a perspective matrix, or | |
| 391 // 2.) the quality is med/high and the scale is < 1 | |
| 392 if (param.fMatrix.hasPerspective()) { | |
| 393 shouldUseMipMaps = true; | |
| 394 } | |
| 395 if (param.fQuality == kMedium_SkFilterQuality || | |
| 396 param.fQuality == kHigh_SkFilterQuality) { | |
| 397 SkScalar minAxisScale = param.fMatrix.getMinScale(); | |
| 398 if (minAxisScale != -1.f && minAxisScale < 1.f) { | |
| 399 shouldUseMipMaps = true; | |
| 400 } | |
| 401 } | |
| 402 | |
| 403 return shouldUseMipMaps; | |
| 404 } | |
| 405 | |
| 379 size_t SkImage::getDeferredTextureImageData(const GrContextThreadSafeProxy& prox y, | 406 size_t SkImage::getDeferredTextureImageData(const GrContextThreadSafeProxy& prox y, |
| 380 const DeferredTextureImageUsageParam s params[], | 407 const DeferredTextureImageUsageParam s params[], |
| 381 int paramCnt, void* buffer) const { | 408 int paramCnt, void* buffer, |
| 409 SkSourceGammaTreatment gammaTreatmen t) const { | |
| 382 // Extract relevant min/max values from the params array. | 410 // Extract relevant min/max values from the params array. |
| 383 int lowestPreScaleMipLevel = params[0].fPreScaleMipLevel; | 411 int lowestPreScaleMipLevel = params[0].fPreScaleMipLevel; |
| 384 SkFilterQuality highestFilterQuality = params[0].fQuality; | 412 SkFilterQuality highestFilterQuality = params[0].fQuality; |
| 413 bool useMipMaps = should_use_mip_maps(params[0]); | |
| 385 for (int i = 1; i < paramCnt; ++i) { | 414 for (int i = 1; i < paramCnt; ++i) { |
| 386 if (lowestPreScaleMipLevel > params[i].fPreScaleMipLevel) | 415 if (lowestPreScaleMipLevel > params[i].fPreScaleMipLevel) |
| 387 lowestPreScaleMipLevel = params[i].fPreScaleMipLevel; | 416 lowestPreScaleMipLevel = params[i].fPreScaleMipLevel; |
| 388 if (highestFilterQuality < params[i].fQuality) | 417 if (highestFilterQuality < params[i].fQuality) |
| 389 highestFilterQuality = params[i].fQuality; | 418 highestFilterQuality = params[i].fQuality; |
| 419 useMipMaps |= should_use_mip_maps(params[i]); | |
| 390 } | 420 } |
| 391 | 421 |
| 392 const bool fillMode = SkToBool(buffer); | 422 const bool fillMode = SkToBool(buffer); |
| 393 if (fillMode && !SkIsAlign8(reinterpret_cast<intptr_t>(buffer))) { | 423 if (fillMode && !SkIsAlign8(reinterpret_cast<intptr_t>(buffer))) { |
| 394 return 0; | 424 return 0; |
| 395 } | 425 } |
| 396 | 426 |
| 397 // Calculate scaling parameters. | 427 // Calculate scaling parameters. |
| 398 bool isScaled = lowestPreScaleMipLevel != 0; | 428 bool isScaled = lowestPreScaleMipLevel != 0; |
| 399 | 429 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 448 return 0; | 478 return 0; |
| 449 } | 479 } |
| 450 } else { | 480 } else { |
| 451 if (!this->readPixels(pixmap, 0, 0, SkImage::kDisallow_CachingHi nt)) { | 481 if (!this->readPixels(pixmap, 0, 0, SkImage::kDisallow_CachingHi nt)) { |
| 452 return 0; | 482 return 0; |
| 453 } | 483 } |
| 454 } | 484 } |
| 455 SkASSERT(!pixmap.ctable()); | 485 SkASSERT(!pixmap.ctable()); |
| 456 } | 486 } |
| 457 } | 487 } |
| 488 SkAlphaType at = this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaTyp e; | |
| 458 int mipMapLevelCount = 1; | 489 int mipMapLevelCount = 1; |
| 490 if (useMipMaps) { | |
| 491 // SkMipMap only deals with the mipmap levels it generates, which does | |
| 492 // not include the base level. | |
| 493 // That means it generates and holds levels 1-x instead of 0-x. | |
| 494 // So the total mipmap level count is 1 more than what | |
| 495 // SkMipMap::ComputeLevelCount returns. | |
| 496 mipMapLevelCount = SkMipMap::ComputeLevelCount(scaledSize.width(), scale dSize.height()) + 1; | |
| 497 | |
| 498 // We already initialized pixelSize to the size of the base level. | |
| 499 // SkMipMap will generate the extra mipmap levels. Their sizes need to | |
| 500 // be added to the total. | |
| 501 // Index 0 here does not refer to the base mipmap level -- it is | |
| 502 // SkMipMap's first generated mipmap level (level 1). | |
| 503 for (int currentMipMapLevelIndex = mipMapLevelCount - 2; currentMipMapLe velIndex >= 0; | |
| 504 currentMipMapLevelIndex--) { | |
| 505 SkISize mipSize = SkMipMap::ComputeLevelSize(scaledSize.width(), sca ledSize.height(), | |
| 506 currentMipMapLevelIndex ); | |
| 507 SkImageInfo mipInfo = SkImageInfo::MakeN32(mipSize.fWidth, mipSize.f Height, at); | |
| 508 pixelSize += SkAlign8(SkAutoPixmapStorage::AllocSize(mipInfo, nullpt r)); | |
| 509 } | |
| 510 } | |
| 459 size_t size = 0; | 511 size_t size = 0; |
| 460 size_t dtiSize = SkAlign8(sizeof(DeferredTextureImage)); | 512 size_t dtiSize = SkAlign8(sizeof(DeferredTextureImage)); |
| 461 size += dtiSize; | 513 size += dtiSize; |
| 462 size += mipMapLevelCount * sizeof(MipMapLevelData); | 514 size += (mipMapLevelCount - 1) * sizeof(MipMapLevelData); |
| 515 // We subtract 1 because DeferredTextureImage already includes the base | |
| 516 // level in its size | |
| 463 size_t pixelOffset = size; | 517 size_t pixelOffset = size; |
| 464 size += pixelSize; | 518 size += pixelSize; |
| 465 size_t ctOffset = size; | 519 size_t ctOffset = size; |
| 466 size += ctSize; | 520 size += ctSize; |
| 467 size_t colorSpaceOffset = 0; | 521 size_t colorSpaceOffset = 0; |
| 468 size_t colorSpaceSize = 0; | 522 size_t colorSpaceSize = 0; |
| 469 if (info.colorSpace()) { | 523 if (info.colorSpace()) { |
| 470 colorSpaceOffset = size; | 524 colorSpaceOffset = size; |
| 471 colorSpaceSize = info.colorSpace()->writeToMemory(nullptr); | 525 colorSpaceSize = info.colorSpace()->writeToMemory(nullptr); |
| 472 size += colorSpaceSize; | 526 size += colorSpaceSize; |
| 473 } | 527 } |
| 474 if (!fillMode) { | 528 if (!fillMode) { |
| 475 return size; | 529 return size; |
| 476 } | 530 } |
| 477 intptr_t bufferAsInt = reinterpret_cast<intptr_t>(buffer); | 531 intptr_t bufferAsInt = reinterpret_cast<intptr_t>(buffer); |
| 478 void* pixels = reinterpret_cast<void*>(bufferAsInt + pixelOffset); | 532 intptr_t pixelsAsInt = bufferAsInt + pixelOffset; |
| 479 SkPMColor* ct = nullptr; | 533 void* pixels = reinterpret_cast<void*>(pixelsAsInt); |
| 534 void* ct = nullptr; | |
| 480 if (ctSize) { | 535 if (ctSize) { |
| 481 ct = reinterpret_cast<SkPMColor*>(bufferAsInt + ctOffset); | 536 ct = reinterpret_cast<void*>(bufferAsInt + ctOffset); |
| 482 } | 537 } |
| 483 | 538 |
| 484 memcpy(pixels, pixmap.addr(), pixmap.getSafeSize()); | 539 memcpy(reinterpret_cast<void*>(SkAlign8(pixelsAsInt)), pixmap.addr(), pixmap .getSafeSize()); |
| 485 if (ctSize) { | 540 if (ctSize) { |
| 486 memcpy(ct, pixmap.ctable()->readColors(), ctSize); | 541 memcpy(ct, pixmap.ctable()->readColors(), ctSize); |
| 487 } | 542 } |
| 488 | 543 |
| 489 SkASSERT(info == pixmap.info()); | 544 SkASSERT(info == pixmap.info()); |
| 490 size_t rowBytes = pixmap.rowBytes(); | 545 size_t rowBytes = pixmap.rowBytes(); |
| 491 DeferredTextureImage* dti = new (buffer) DeferredTextureImage(); | 546 // offsetof, which we use below, requires the type have standard layout |
| 492 dti->fContextUniqueID = proxy.fContextUniqueID; | 547 SkASSERT(std::is_standard_layout<DeferredTextureImage>::value); |
|
bsalomon
2016/08/29 15:49:31
Can this be a static assert?
cblume
2016/08/29 21:52:58
Done.
| |
| 493 dti->fWidth = info.width(); | 548 memcpy(reinterpret_cast<void*>(bufferAsInt + offsetof(DeferredTextureImage, fGammaTreatment)), |
|
bsalomon
2016/08/29 15:49:31
Is there some way to write this as a template base
cblume
2016/08/29 21:52:58
I simplified it where I could.
To do this, I intr
| |
| 494 dti->fHeight = info.height(); | 549 &gammaTreatment, sizeof(gammaTreatment)); |
| 495 dti->fColorType = info.colorType(); | 550 memcpy(reinterpret_cast<void*>(bufferAsInt + offsetof(DeferredTextureImage, fContextUniqueID)), |
| 496 dti->fAlphaType = info.alphaType(); | 551 &proxy.fContextUniqueID, sizeof(proxy.fContextUniqueID)); |
| 497 dti->fColorTableCnt = ctCount; | 552 int width = info.width(); |
| 498 dti->fColorTableData = ct; | 553 memcpy(reinterpret_cast<void*>(bufferAsInt + offsetof(DeferredTextureImage, fWidth)), |
| 499 dti->fMipMapLevelCount = mipMapLevelCount; | 554 &width, sizeof(width)); |
| 500 dti->fMipMapLevelData[0].fPixelData = pixels; | 555 int height = info.height(); |
| 501 dti->fMipMapLevelData[0].fRowBytes = rowBytes; | 556 memcpy(reinterpret_cast<void*>(bufferAsInt + offsetof(DeferredTextureImage, fHeight)), |
| 557 &height, sizeof(height)); | |
| 558 SkColorType colorType = info.colorType(); | |
| 559 memcpy(reinterpret_cast<void*>(bufferAsInt + offsetof(DeferredTextureImage, fColorType)), | |
| 560 &colorType, sizeof(colorType)); | |
| 561 SkAlphaType alphaType = info.alphaType(); | |
| 562 memcpy(reinterpret_cast<void*>(bufferAsInt + offsetof(DeferredTextureImage, fAlphaType)), | |
| 563 &alphaType, sizeof(alphaType)); | |
| 564 memcpy(reinterpret_cast<void*>(bufferAsInt + offsetof(DeferredTextureImage, fColorTableCnt)), | |
| 565 &ctCount, sizeof(ctCount)); | |
| 566 memcpy(reinterpret_cast<void*>(bufferAsInt + offsetof(DeferredTextureImage, fColorTableData)), | |
| 567 &ct, sizeof(ct)); | |
| 568 memcpy(reinterpret_cast<void*>(bufferAsInt + offsetof(DeferredTextureImage, fMipMapLevelCount)), | |
| 569 &mipMapLevelCount, sizeof(mipMapLevelCount)); | |
| 570 memcpy(reinterpret_cast<void*>(bufferAsInt + | |
| 571 offsetof(DeferredTextureImage, fMipMapLevelDat a[0].fPixelData)), | |
| 572 &pixels, sizeof(pixels)); | |
| 573 memcpy(reinterpret_cast<void*>(bufferAsInt + | |
| 574 offsetof(DeferredTextureImage, fMipMapLevelDat a[0].fRowBytes)), | |
| 575 &rowBytes, sizeof(rowBytes)); | |
| 502 if (colorSpaceSize) { | 576 if (colorSpaceSize) { |
| 503 dti->fColorSpace = reinterpret_cast<void*>(bufferAsInt + colorSpaceOffse t); | 577 void* colorSpace = reinterpret_cast<void*>(bufferAsInt + colorSpaceOffse t); |
| 504 dti->fColorSpaceSize = colorSpaceSize; | 578 memcpy(reinterpret_cast<void*>(bufferAsInt + |
| 505 info.colorSpace()->writeToMemory(dti->fColorSpace); | 579 offsetof(DeferredTextureImage, fColorSpac e)), |
| 580 &colorSpace, sizeof(colorSpace)); | |
| 581 memcpy(reinterpret_cast<void*>(bufferAsInt + | |
| 582 offsetof(DeferredTextureImage, fColorSpac eSize)), | |
| 583 &colorSpaceSize, sizeof(colorSpaceSize)); | |
| 584 info.colorSpace()->writeToMemory(reinterpret_cast<void*>(bufferAsInt + c olorSpaceOffset)); | |
| 506 } else { | 585 } else { |
| 507 dti->fColorSpace = nullptr; | 586 memset(reinterpret_cast<void*>(bufferAsInt + |
| 508 dti->fColorSpaceSize = 0; | 587 offsetof(DeferredTextureImage, fColorSpac e)), |
| 588 0, sizeof(DeferredTextureImage::fColorSpace)); | |
| 589 memset(reinterpret_cast<void*>(bufferAsInt + | |
| 590 offsetof(DeferredTextureImage, fColorSpac eSize)), | |
| 591 0, sizeof(DeferredTextureImage::fColorSpaceSize)); | |
| 592 } | |
| 593 | |
| 594 // Fill in the mipmap levels if they exist | |
| 595 intptr_t mipLevelPtr = bufferAsInt + pixelOffset + SkAlign8(pixmap.getSafeSi ze()); | |
| 596 | |
| 597 if (useMipMaps) { | |
| 598 // offsetof, which we use below, requires the type have standard layout | |
| 599 SkASSERT(std::is_standard_layout<MipMapLevelData>::value); | |
| 600 | |
| 601 SkAutoTDelete<SkMipMap> mipmaps(SkMipMap::Build(pixmap, gammaTreatment, nullptr)); | |
| 602 // SkMipMap holds only the mipmap levels it generates. | |
| 603 // A programmer can use the data they provided to SkMipMap::Build as lev el 0. | |
| 604 // So the SkMipMap provides levels 1-x but it stores them in its own | |
| 605 // range 0-(x-1). | |
| 606 for (int generatedMipLevelIndex = 0; generatedMipLevelIndex < mipMapLeve lCount - 1; | |
| 607 generatedMipLevelIndex++) { | |
| 608 SkISize mipSize = SkMipMap::ComputeLevelSize(scaledSize.width(), sca ledSize.height(), | |
| 609 generatedMipLevelIndex) ; | |
| 610 | |
| 611 SkImageInfo mipInfo = SkImageInfo::MakeN32(mipSize.fWidth, mipSize.f Height, at); | |
| 612 SkMipMap::Level mipLevel; | |
| 613 mipmaps->getLevel(generatedMipLevelIndex, &mipLevel); | |
| 614 | |
| 615 // Make sure the mipmap data is after the start of the buffer | |
| 616 SkASSERT(mipLevelPtr > bufferAsInt); | |
| 617 // Make sure the mipmap data starts before the end of the buffer | |
| 618 SkASSERT(static_cast<size_t>(mipLevelPtr) < bufferAsInt + pixelOffse t + pixelSize); | |
| 619 // Make sure the mipmap data ends before the end of the buffer | |
| 620 SkASSERT(mipLevelPtr + mipLevel.fPixmap.getSafeSize() <= | |
| 621 bufferAsInt + pixelOffset + pixelSize); | |
| 622 | |
| 623 // getSafeSize includes rowbyte padding except for the last row, | |
| 624 // right? | |
| 625 | |
| 626 memcpy(reinterpret_cast<void*>(mipLevelPtr), mipLevel.fPixmap.addr() , | |
| 627 mipLevel.fPixmap.getSafeSize()); | |
| 628 | |
| 629 memcpy(reinterpret_cast<void*>(bufferAsInt + | |
| 630 offsetof(DeferredTextureImage, fMipMapLevelData) + | |
| 631 sizeof(MipMapLevelData) * (generatedMipLevelIndex + 1) + | |
| 632 offsetof(MipMapLevelData, fPixelData)), | |
| 633 &mipLevelPtr, sizeof(void*)); | |
| 634 size_t rowBytes = mipLevel.fPixmap.rowBytes(); | |
| 635 memcpy(reinterpret_cast<void*>(bufferAsInt + | |
| 636 offsetof(DeferredTextureImage, fMipMapLevelData) + | |
| 637 sizeof(MipMapLevelData) * (generatedMipLevelIndex + 1) + | |
| 638 offsetof(MipMapLevelData, fRowBytes)), | |
| 639 &rowBytes, sizeof(rowBytes)); | |
| 640 | |
| 641 mipLevelPtr += SkAlign8(mipLevel.fPixmap.getSafeSize()); | |
| 642 } | |
| 509 } | 643 } |
| 510 return size; | 644 return size; |
| 511 } | 645 } |
| 512 | 646 |
| 513 sk_sp<SkImage> SkImage::MakeFromDeferredTextureImageData(GrContext* context, con st void* data, | 647 sk_sp<SkImage> SkImage::MakeFromDeferredTextureImageData(GrContext* context, con st void* data, |
| 514 SkBudgeted budgeted) { | 648 SkBudgeted budgeted) { |
| 515 if (!data) { | 649 if (!data) { |
| 516 return nullptr; | 650 return nullptr; |
| 517 } | 651 } |
| 518 const DeferredTextureImage* dti = reinterpret_cast<const DeferredTextureImag e*>(data); | 652 const DeferredTextureImage* dti = reinterpret_cast<const DeferredTextureImag e*>(data); |
| 519 | 653 |
| 520 if (!context || context->uniqueID() != dti->fContextUniqueID) { | 654 if (!context || context->uniqueID() != dti->fContextUniqueID) { |
| 521 return nullptr; | 655 return nullptr; |
| 522 } | 656 } |
| 523 SkAutoTUnref<SkColorTable> colorTable; | 657 SkAutoTUnref<SkColorTable> colorTable; |
| 524 if (dti->fColorTableCnt) { | 658 if (dti->fColorTableCnt) { |
| 525 SkASSERT(dti->fColorTableData); | 659 SkASSERT(dti->fColorTableData); |
| 526 colorTable.reset(new SkColorTable(dti->fColorTableData, dti->fColorTable Cnt)); | 660 colorTable.reset(new SkColorTable(dti->fColorTableData, dti->fColorTable Cnt)); |
| 527 } | 661 } |
| 528 SkASSERT(dti->fMipMapLevelCount == 1); | 662 int mipLevelCount = dti->fMipMapLevelCount; |
| 663 SkASSERT(mipLevelCount >= 1); | |
| 529 sk_sp<SkColorSpace> colorSpace; | 664 sk_sp<SkColorSpace> colorSpace; |
| 530 if (dti->fColorSpaceSize) { | 665 if (dti->fColorSpaceSize) { |
| 531 colorSpace = SkColorSpace::Deserialize(dti->fColorSpace, dti->fColorSpac eSize); | 666 colorSpace = SkColorSpace::Deserialize(dti->fColorSpace, dti->fColorSpac eSize); |
| 532 } | 667 } |
| 533 SkImageInfo info = SkImageInfo::Make(dti->fWidth, dti->fHeight, | 668 SkImageInfo info = SkImageInfo::Make(dti->fWidth, dti->fHeight, |
| 534 dti->fColorType, dti->fAlphaType, color Space); | 669 dti->fColorType, dti->fAlphaType, color Space); |
| 535 SkPixmap pixmap; | 670 if (mipLevelCount == 1) { |
| 536 pixmap.reset(info, dti->fMipMapLevelData[0].fPixelData, | 671 SkPixmap pixmap; |
| 537 dti->fMipMapLevelData[0].fRowBytes, colorTable.get()); | 672 pixmap.reset(info, dti->fMipMapLevelData[0].fPixelData, |
| 538 return SkImage::MakeTextureFromPixmap(context, pixmap, budgeted); | 673 dti->fMipMapLevelData[0].fRowBytes, colorTable.get()); |
| 674 return SkImage::MakeTextureFromPixmap(context, pixmap, budgeted); | |
| 675 } else { | |
| 676 SkAutoTDeleteArray<GrMipLevel> texels(new GrMipLevel[mipLevelCount]); | |
| 677 for (int i = 0; i < mipLevelCount; i++) { | |
| 678 texels[i].fPixels = dti->fMipMapLevelData[i].fPixelData; | |
| 679 texels[i].fRowBytes = dti->fMipMapLevelData[i].fRowBytes; | |
| 680 } | |
| 681 | |
| 682 return SkImage::MakeTextureFromMipMap(context, info, texels.get(), | |
| 683 mipLevelCount, SkBudgeted::kYes, | |
| 684 dti->fGammaTreatment); | |
| 685 } | |
| 539 } | 686 } |
| 540 | 687 |
| 541 //////////////////////////////////////////////////////////////////////////////// /////////////////// | 688 //////////////////////////////////////////////////////////////////////////////// /////////////////// |
| 542 | 689 |
| 543 GrTexture* GrDeepCopyTexture(GrTexture* src, SkBudgeted budgeted) { | 690 GrTexture* GrDeepCopyTexture(GrTexture* src, SkBudgeted budgeted) { |
| 544 GrContext* ctx = src->getContext(); | 691 GrContext* ctx = src->getContext(); |
| 545 | 692 |
| 546 GrSurfaceDesc desc = src->desc(); | 693 GrSurfaceDesc desc = src->desc(); |
| 547 GrTexture* dst = ctx->textureProvider()->createTexture(desc, budgeted, nullp tr, 0); | 694 GrTexture* dst = ctx->textureProvider()->createTexture(desc, budgeted, nullp tr, 0); |
| 548 if (!dst) { | 695 if (!dst) { |
| 549 return nullptr; | 696 return nullptr; |
| 550 } | 697 } |
| 551 | 698 |
| 552 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); | 699 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); |
| 553 const SkIPoint dstP = SkIPoint::Make(0, 0); | 700 const SkIPoint dstP = SkIPoint::Make(0, 0); |
| 554 ctx->copySurface(dst, src, srcR, dstP); | 701 ctx->copySurface(dst, src, srcR, dstP); |
| 555 ctx->flushSurfaceWrites(dst); | 702 ctx->flushSurfaceWrites(dst); |
| 556 return dst; | 703 return dst; |
| 557 } | 704 } |
| 558 | 705 |
| 559 sk_sp<SkImage> SkImage::MakeTextureFromMipMap(GrContext* ctx, const SkImageInfo& info, | 706 sk_sp<SkImage> SkImage::MakeTextureFromMipMap(GrContext* ctx, const SkImageInfo& info, |
| 560 const GrMipLevel* texels, int mipL evelCount, | 707 const GrMipLevel* texels, int mipL evelCount, |
| 561 SkBudgeted budgeted) { | 708 SkBudgeted budgeted, |
| 709 SkSourceGammaTreatment gammaTreatm ent) { | |
| 562 if (!ctx) { | 710 if (!ctx) { |
| 563 return nullptr; | 711 return nullptr; |
| 564 } | 712 } |
| 565 SkAutoTUnref<GrTexture> texture(GrUploadMipMapToTexture(ctx, info, texels, m ipLevelCount)); | 713 SkAutoTUnref<GrTexture> texture(GrUploadMipMapToTexture(ctx, info, texels, m ipLevelCount)); |
| 566 if (!texture) { | 714 if (!texture) { |
| 567 return nullptr; | 715 return nullptr; |
| 568 } | 716 } |
| 717 texture->texturePriv().setGammaTreatment(gammaTreatment); | |
| 569 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNew ImageUniqueID, | 718 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNew ImageUniqueID, |
| 570 info.alphaType(), texture, sk_ref_sp(info.col orSpace()), | 719 info.alphaType(), texture, sk_ref_sp(info.col orSpace()), |
| 571 budgeted); | 720 budgeted); |
| 572 } | 721 } |
| OLD | NEW |