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 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 FILL_MEMBER(dtiBufferFiller, fWidth, &width); | 576 FILL_MEMBER(dtiBufferFiller, fWidth, &width); |
577 int height = info.height(); | 577 int height = info.height(); |
578 FILL_MEMBER(dtiBufferFiller, fHeight, &height); | 578 FILL_MEMBER(dtiBufferFiller, fHeight, &height); |
579 SkColorType colorType = info.colorType(); | 579 SkColorType colorType = info.colorType(); |
580 FILL_MEMBER(dtiBufferFiller, fColorType, &colorType); | 580 FILL_MEMBER(dtiBufferFiller, fColorType, &colorType); |
581 SkAlphaType alphaType = info.alphaType(); | 581 SkAlphaType alphaType = info.alphaType(); |
582 FILL_MEMBER(dtiBufferFiller, fAlphaType, &alphaType); | 582 FILL_MEMBER(dtiBufferFiller, fAlphaType, &alphaType); |
583 FILL_MEMBER(dtiBufferFiller, fColorTableCnt, &ctCount); | 583 FILL_MEMBER(dtiBufferFiller, fColorTableCnt, &ctCount); |
584 FILL_MEMBER(dtiBufferFiller, fColorTableData, &ct); | 584 FILL_MEMBER(dtiBufferFiller, fColorTableData, &ct); |
585 FILL_MEMBER(dtiBufferFiller, fMipMapLevelCount, &mipMapLevelCount); | 585 FILL_MEMBER(dtiBufferFiller, fMipMapLevelCount, &mipMapLevelCount); |
586 // FILL_MEMBER(dtiBufferFiller, fMipMapLevelCount[0].fPixelData, &pixels); | |
587 memcpy(reinterpret_cast<void*>(bufferAsInt + | 586 memcpy(reinterpret_cast<void*>(bufferAsInt + |
588 offsetof(DeferredTextureImage, fMipMapLevelDat
a[0].fPixelData)), | 587 offsetof(DeferredTextureImage, fMipMapLevelDat
a[0].fPixelData)), |
589 &pixels, sizeof(pixels)); | 588 &pixels, sizeof(pixels)); |
590 memcpy(reinterpret_cast<void*>(bufferAsInt + | 589 memcpy(reinterpret_cast<void*>(bufferAsInt + |
591 offsetof(DeferredTextureImage, fMipMapLevelDat
a[0].fRowBytes)), | 590 offsetof(DeferredTextureImage, fMipMapLevelDat
a[0].fRowBytes)), |
592 &rowBytes, sizeof(rowBytes)); | 591 &rowBytes, sizeof(rowBytes)); |
593 if (colorSpaceSize) { | 592 if (colorSpaceSize) { |
594 void* colorSpace = reinterpret_cast<void*>(bufferAsInt + colorSpaceOffse
t); | 593 void* colorSpace = reinterpret_cast<void*>(bufferAsInt + colorSpaceOffse
t); |
595 FILL_MEMBER(dtiBufferFiller, fColorSpace, &colorSpace); | 594 FILL_MEMBER(dtiBufferFiller, fColorSpace, &colorSpace); |
596 FILL_MEMBER(dtiBufferFiller, fColorSpaceSize, &colorSpaceSize); | 595 FILL_MEMBER(dtiBufferFiller, fColorSpaceSize, &colorSpaceSize); |
597 info.colorSpace()->writeToMemory(reinterpret_cast<void*>(bufferAsInt + c
olorSpaceOffset)); | 596 info.colorSpace()->writeToMemory(reinterpret_cast<void*>(bufferAsInt + c
olorSpaceOffset)); |
598 } else { | 597 } else { |
599 memset(reinterpret_cast<void*>(bufferAsInt + | 598 memset(reinterpret_cast<void*>(bufferAsInt + |
600 offsetof(DeferredTextureImage, fColorSpac
e)), | 599 offsetof(DeferredTextureImage, fColorSpac
e)), |
601 0, sizeof(DeferredTextureImage::fColorSpace)); | 600 0, sizeof(DeferredTextureImage::fColorSpace)); |
602 memset(reinterpret_cast<void*>(bufferAsInt + | 601 memset(reinterpret_cast<void*>(bufferAsInt + |
603 offsetof(DeferredTextureImage, fColorSpac
eSize)), | 602 offsetof(DeferredTextureImage, fColorSpac
eSize)), |
604 0, sizeof(DeferredTextureImage::fColorSpaceSize)); | 603 0, sizeof(DeferredTextureImage::fColorSpaceSize)); |
605 } | 604 } |
606 | 605 |
607 // Fill in the mipmap levels if they exist | 606 // Fill in the mipmap levels if they exist |
608 intptr_t mipLevelPtr = bufferAsInt + pixelOffset + SkAlign8(pixmap.getSafeSi
ze()); | 607 intptr_t mipLevelPtr = pixelsAsInt + SkAlign8(pixmap.getSafeSize()); |
609 | 608 |
610 if (useMipMaps) { | 609 if (useMipMaps) { |
611 // offsetof, which we use below, requires the type have standard layout | 610 static_assert(std::is_standard_layout<MipMapLevelData>::value, |
612 SkASSERT(std::is_standard_layout<MipMapLevelData>::value); | 611 "offsetof, which we use below, requires the type have a st
andard layout"); |
613 | 612 |
614 SkAutoTDelete<SkMipMap> mipmaps(SkMipMap::Build(pixmap, gammaTreatment,
nullptr)); | 613 SkAutoTDelete<SkMipMap> mipmaps(SkMipMap::Build(pixmap, gammaTreatment,
nullptr)); |
615 // SkMipMap holds only the mipmap levels it generates. | 614 // SkMipMap holds only the mipmap levels it generates. |
616 // A programmer can use the data they provided to SkMipMap::Build as lev
el 0. | 615 // A programmer can use the data they provided to SkMipMap::Build as lev
el 0. |
617 // So the SkMipMap provides levels 1-x but it stores them in its own | 616 // So the SkMipMap provides levels 1-x but it stores them in its own |
618 // range 0-(x-1). | 617 // range 0-(x-1). |
619 for (int generatedMipLevelIndex = 0; generatedMipLevelIndex < mipMapLeve
lCount - 1; | 618 for (int generatedMipLevelIndex = 0; generatedMipLevelIndex < mipMapLeve
lCount - 1; |
620 generatedMipLevelIndex++) { | 619 generatedMipLevelIndex++) { |
621 SkISize mipSize = SkMipMap::ComputeLevelSize(scaledSize.width(), sca
ledSize.height(), | 620 SkISize mipSize = SkMipMap::ComputeLevelSize(scaledSize.width(), sca
ledSize.height(), |
622 generatedMipLevelIndex)
; | 621 generatedMipLevelIndex)
; |
623 | 622 |
624 SkImageInfo mipInfo = SkImageInfo::MakeN32(mipSize.fWidth, mipSize.f
Height, at); | 623 SkImageInfo mipInfo = SkImageInfo::MakeN32(mipSize.fWidth, mipSize.f
Height, at); |
625 SkMipMap::Level mipLevel; | 624 SkMipMap::Level mipLevel; |
626 mipmaps->getLevel(generatedMipLevelIndex, &mipLevel); | 625 mipmaps->getLevel(generatedMipLevelIndex, &mipLevel); |
627 | 626 |
628 // Make sure the mipmap data is after the start of the buffer | 627 // Make sure the mipmap data is after the start of the buffer |
629 SkASSERT(mipLevelPtr > bufferAsInt); | 628 SkASSERT_RELEASE(mipLevelPtr > bufferAsInt); |
630 // Make sure the mipmap data starts before the end of the buffer | 629 // Make sure the mipmap data starts before the end of the buffer |
631 SkASSERT(static_cast<size_t>(mipLevelPtr) < bufferAsInt + pixelOffse
t + pixelSize); | 630 SkASSERT_RELEASE(static_cast<size_t>(mipLevelPtr) < bufferAsInt + pi
xelOffset + pixelSize); |
632 // Make sure the mipmap data ends before the end of the buffer | 631 // Make sure the mipmap data ends before the end of the buffer |
633 SkASSERT(mipLevelPtr + mipLevel.fPixmap.getSafeSize() <= | 632 SkASSERT_RELEASE(mipLevelPtr + mipLevel.fPixmap.getSafeSize() <= |
634 bufferAsInt + pixelOffset + pixelSize); | 633 bufferAsInt + pixelOffset + pixelSize); |
635 | 634 |
636 // getSafeSize includes rowbyte padding except for the last row, | 635 // getSafeSize includes rowbyte padding except for the last row, |
637 // right? | 636 // right? |
638 | 637 |
639 memcpy(reinterpret_cast<void*>(mipLevelPtr), mipLevel.fPixmap.addr()
, | 638 memcpy(reinterpret_cast<void*>(mipLevelPtr), mipLevel.fPixmap.addr()
, |
640 mipLevel.fPixmap.getSafeSize()); | 639 mipLevel.fPixmap.getSafeSize()); |
641 | 640 |
642 memcpy(reinterpret_cast<void*>(bufferAsInt + | 641 memcpy(reinterpret_cast<void*>(bufferAsInt + |
643 offsetof(DeferredTextureImage, fMipMapLevelData) + | 642 offsetof(DeferredTextureImage, fMipMapLevelData) + |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 } | 708 } |
710 SkAutoTUnref<GrTexture> texture(GrUploadMipMapToTexture(ctx, info, texels, m
ipLevelCount)); | 709 SkAutoTUnref<GrTexture> texture(GrUploadMipMapToTexture(ctx, info, texels, m
ipLevelCount)); |
711 if (!texture) { | 710 if (!texture) { |
712 return nullptr; | 711 return nullptr; |
713 } | 712 } |
714 texture->texturePriv().setGammaTreatment(gammaTreatment); | 713 texture->texturePriv().setGammaTreatment(gammaTreatment); |
715 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNew
ImageUniqueID, | 714 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNew
ImageUniqueID, |
716 info.alphaType(), texture, sk_ref_sp(info.col
orSpace()), | 715 info.alphaType(), texture, sk_ref_sp(info.col
orSpace()), |
717 budgeted); | 716 budgeted); |
718 } | 717 } |
OLD | NEW |