| 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> | 8 #include <cstddef> |
| 9 #include <cstring> | 9 #include <cstring> |
| 10 #include <type_traits> | 10 #include <type_traits> |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 ctSize = SkAlign8(pixmap.ctable()->count() * 4); | 485 ctSize = SkAlign8(pixmap.ctable()->count() * 4); |
| 486 } | 486 } |
| 487 } else { | 487 } else { |
| 488 // Here we're just using presence of data to know whether there is a cod
ec behind the image. | 488 // Here we're just using presence of data to know whether there is a cod
ec behind the image. |
| 489 // In the future we will access the cacherator and get the exact data th
at we want to (e.g. | 489 // In the future we will access the cacherator and get the exact data th
at we want to (e.g. |
| 490 // yuv planes) upload. | 490 // yuv planes) upload. |
| 491 sk_sp<SkData> data(this->refEncoded()); | 491 sk_sp<SkData> data(this->refEncoded()); |
| 492 if (!data && !this->peekPixels(nullptr)) { | 492 if (!data && !this->peekPixels(nullptr)) { |
| 493 return 0; | 493 return 0; |
| 494 } | 494 } |
| 495 info = SkImageInfo::MakeN32(scaledSize.width(), scaledSize.height(), thi
s->alphaType()); | 495 info = as_IB(this)->onImageInfo().makeWH(scaledSize.width(), scaledSize.
height()); |
| 496 pixelSize = SkAlign8(SkAutoPixmapStorage::AllocSize(info, nullptr)); | 496 pixelSize = SkAlign8(SkAutoPixmapStorage::AllocSize(info, nullptr)); |
| 497 if (fillMode) { | 497 if (fillMode) { |
| 498 pixmap.alloc(info); | 498 pixmap.alloc(info); |
| 499 if (isScaled) { | 499 if (isScaled) { |
| 500 if (!this->scalePixels(pixmap, scaleFilterQuality, | 500 if (!this->scalePixels(pixmap, scaleFilterQuality, |
| 501 SkImage::kDisallow_CachingHint)) { | 501 SkImage::kDisallow_CachingHint)) { |
| 502 return 0; | 502 return 0; |
| 503 } | 503 } |
| 504 } else { | 504 } else { |
| 505 if (!this->readPixels(pixmap, 0, 0, SkImage::kDisallow_CachingHi
nt)) { | 505 if (!this->readPixels(pixmap, 0, 0, SkImage::kDisallow_CachingHi
nt)) { |
| 506 return 0; | 506 return 0; |
| 507 } | 507 } |
| 508 } | 508 } |
| 509 SkASSERT(!pixmap.ctable()); | 509 SkASSERT(!pixmap.ctable()); |
| 510 } | 510 } |
| 511 } | 511 } |
| 512 SkAlphaType at = this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaTyp
e; | |
| 513 int mipMapLevelCount = 1; | 512 int mipMapLevelCount = 1; |
| 514 if (useMipMaps) { | 513 if (useMipMaps) { |
| 515 // SkMipMap only deals with the mipmap levels it generates, which does | 514 // SkMipMap only deals with the mipmap levels it generates, which does |
| 516 // not include the base level. | 515 // not include the base level. |
| 517 // That means it generates and holds levels 1-x instead of 0-x. | 516 // That means it generates and holds levels 1-x instead of 0-x. |
| 518 // So the total mipmap level count is 1 more than what | 517 // So the total mipmap level count is 1 more than what |
| 519 // SkMipMap::ComputeLevelCount returns. | 518 // SkMipMap::ComputeLevelCount returns. |
| 520 mipMapLevelCount = SkMipMap::ComputeLevelCount(scaledSize.width(), scale
dSize.height()) + 1; | 519 mipMapLevelCount = SkMipMap::ComputeLevelCount(scaledSize.width(), scale
dSize.height()) + 1; |
| 521 | 520 |
| 522 // We already initialized pixelSize to the size of the base level. | 521 // We already initialized pixelSize to the size of the base level. |
| 523 // SkMipMap will generate the extra mipmap levels. Their sizes need to | 522 // SkMipMap will generate the extra mipmap levels. Their sizes need to |
| 524 // be added to the total. | 523 // be added to the total. |
| 525 // Index 0 here does not refer to the base mipmap level -- it is | 524 // Index 0 here does not refer to the base mipmap level -- it is |
| 526 // SkMipMap's first generated mipmap level (level 1). | 525 // SkMipMap's first generated mipmap level (level 1). |
| 527 for (int currentMipMapLevelIndex = mipMapLevelCount - 2; currentMipMapLe
velIndex >= 0; | 526 for (int currentMipMapLevelIndex = mipMapLevelCount - 2; currentMipMapLe
velIndex >= 0; |
| 528 currentMipMapLevelIndex--) { | 527 currentMipMapLevelIndex--) { |
| 529 SkISize mipSize = SkMipMap::ComputeLevelSize(scaledSize.width(), sca
ledSize.height(), | 528 SkISize mipSize = SkMipMap::ComputeLevelSize(scaledSize.width(), sca
ledSize.height(), |
| 530 currentMipMapLevelIndex
); | 529 currentMipMapLevelIndex
); |
| 531 SkImageInfo mipInfo = SkImageInfo::MakeN32(mipSize.fWidth, mipSize.f
Height, at); | 530 SkImageInfo mipInfo = info.makeWH(mipSize.fWidth, mipSize.fHeight); |
| 532 pixelSize += SkAlign8(SkAutoPixmapStorage::AllocSize(mipInfo, nullpt
r)); | 531 pixelSize += SkAlign8(SkAutoPixmapStorage::AllocSize(mipInfo, nullpt
r)); |
| 533 } | 532 } |
| 534 } | 533 } |
| 535 size_t size = 0; | 534 size_t size = 0; |
| 536 size_t dtiSize = SkAlign8(sizeof(DeferredTextureImage)); | 535 size_t dtiSize = SkAlign8(sizeof(DeferredTextureImage)); |
| 537 size += dtiSize; | 536 size += dtiSize; |
| 538 size += (mipMapLevelCount - 1) * sizeof(MipMapLevelData); | 537 size += (mipMapLevelCount - 1) * sizeof(MipMapLevelData); |
| 539 // We subtract 1 because DeferredTextureImage already includes the base | 538 // We subtract 1 because DeferredTextureImage already includes the base |
| 540 // level in its size | 539 // level in its size |
| 541 size_t pixelOffset = size; | 540 size_t pixelOffset = size; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 static_assert(std::is_standard_layout<MipMapLevelData>::value, | 606 static_assert(std::is_standard_layout<MipMapLevelData>::value, |
| 608 "offsetof, which we use below, requires the type have a st
andard layout"); | 607 "offsetof, which we use below, requires the type have a st
andard layout"); |
| 609 | 608 |
| 610 SkAutoTDelete<SkMipMap> mipmaps(SkMipMap::Build(pixmap, gammaTreatment,
nullptr)); | 609 SkAutoTDelete<SkMipMap> mipmaps(SkMipMap::Build(pixmap, gammaTreatment,
nullptr)); |
| 611 // SkMipMap holds only the mipmap levels it generates. | 610 // SkMipMap holds only the mipmap levels it generates. |
| 612 // A programmer can use the data they provided to SkMipMap::Build as lev
el 0. | 611 // A programmer can use the data they provided to SkMipMap::Build as lev
el 0. |
| 613 // So the SkMipMap provides levels 1-x but it stores them in its own | 612 // So the SkMipMap provides levels 1-x but it stores them in its own |
| 614 // range 0-(x-1). | 613 // range 0-(x-1). |
| 615 for (int generatedMipLevelIndex = 0; generatedMipLevelIndex < mipMapLeve
lCount - 1; | 614 for (int generatedMipLevelIndex = 0; generatedMipLevelIndex < mipMapLeve
lCount - 1; |
| 616 generatedMipLevelIndex++) { | 615 generatedMipLevelIndex++) { |
| 617 SkISize mipSize = SkMipMap::ComputeLevelSize(scaledSize.width(), sca
ledSize.height(), | |
| 618 generatedMipLevelIndex)
; | |
| 619 | |
| 620 SkImageInfo mipInfo = SkImageInfo::MakeN32(mipSize.fWidth, mipSize.f
Height, at); | |
| 621 SkMipMap::Level mipLevel; | 616 SkMipMap::Level mipLevel; |
| 622 mipmaps->getLevel(generatedMipLevelIndex, &mipLevel); | 617 mipmaps->getLevel(generatedMipLevelIndex, &mipLevel); |
| 623 | 618 |
| 624 // Make sure the mipmap data is after the start of the buffer | 619 // Make sure the mipmap data is after the start of the buffer |
| 625 SkASSERT(mipLevelPtr > bufferAsCharPtr); | 620 SkASSERT(mipLevelPtr > bufferAsCharPtr); |
| 626 // Make sure the mipmap data starts before the end of the buffer | 621 // Make sure the mipmap data starts before the end of the buffer |
| 627 SkASSERT(mipLevelPtr < bufferAsCharPtr + pixelOffset + pixelSize); | 622 SkASSERT(mipLevelPtr < bufferAsCharPtr + pixelOffset + pixelSize); |
| 628 // Make sure the mipmap data ends before the end of the buffer | 623 // Make sure the mipmap data ends before the end of the buffer |
| 629 SkASSERT(mipLevelPtr + mipLevel.fPixmap.getSafeSize() <= | 624 SkASSERT(mipLevelPtr + mipLevel.fPixmap.getSafeSize() <= |
| 630 bufferAsCharPtr + pixelOffset + pixelSize); | 625 bufferAsCharPtr + pixelOffset + pixelSize); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 } | 695 } |
| 701 SkAutoTUnref<GrTexture> texture(GrUploadMipMapToTexture(ctx, info, texels, m
ipLevelCount)); | 696 SkAutoTUnref<GrTexture> texture(GrUploadMipMapToTexture(ctx, info, texels, m
ipLevelCount)); |
| 702 if (!texture) { | 697 if (!texture) { |
| 703 return nullptr; | 698 return nullptr; |
| 704 } | 699 } |
| 705 texture->texturePriv().setGammaTreatment(gammaTreatment); | 700 texture->texturePriv().setGammaTreatment(gammaTreatment); |
| 706 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNew
ImageUniqueID, | 701 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNew
ImageUniqueID, |
| 707 info.alphaType(), texture, sk_ref_sp(info.col
orSpace()), | 702 info.alphaType(), texture, sk_ref_sp(info.col
orSpace()), |
| 708 budgeted); | 703 budgeted); |
| 709 } | 704 } |
| OLD | NEW |