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 "SkAutoPixmapStorage.h" | 8 #include "SkAutoPixmapStorage.h" |
9 #include "GrCaps.h" | 9 #include "GrCaps.h" |
10 #include "GrContext.h" | 10 #include "GrContext.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 } | 44 } |
45 | 45 |
46 SkImageInfo SkImage_Gpu::onImageInfo() const { | 46 SkImageInfo SkImage_Gpu::onImageInfo() const { |
47 SkColorType ct; | 47 SkColorType ct; |
48 if (!GrPixelConfigToColorType(fTexture->config(), &ct)) { | 48 if (!GrPixelConfigToColorType(fTexture->config(), &ct)) { |
49 ct = kUnknown_SkColorType; | 49 ct = kUnknown_SkColorType; |
50 } | 50 } |
51 return SkImageInfo::Make(fTexture->width(), fTexture->height(), ct, fAlphaTy
pe, fColorSpace); | 51 return SkImageInfo::Make(fTexture->width(), fTexture->height(), ct, fAlphaTy
pe, fColorSpace); |
52 } | 52 } |
53 | 53 |
54 static SkImageInfo make_info(int w, int h, bool isOpaque, sk_sp<SkColorSpace> co
lorSpace) { | 54 static SkImageInfo make_info(int w, int h, SkAlphaType at, sk_sp<SkColorSpace> c
olorSpace) { |
55 return SkImageInfo::MakeN32(w, h, isOpaque ? kOpaque_SkAlphaType : kPremul_S
kAlphaType, | 55 return SkImageInfo::MakeN32(w, h, at, std::move(colorSpace)); |
56 std::move(colorSpace)); | |
57 } | 56 } |
58 | 57 |
59 bool SkImage_Gpu::getROPixels(SkBitmap* dst, CachingHint chint) const { | 58 bool SkImage_Gpu::getROPixels(SkBitmap* dst, CachingHint chint) const { |
60 if (SkBitmapCache::Find(this->uniqueID(), dst)) { | 59 if (SkBitmapCache::Find(this->uniqueID(), dst)) { |
61 SkASSERT(dst->getGenerationID() == this->uniqueID()); | 60 SkASSERT(dst->getGenerationID() == this->uniqueID()); |
62 SkASSERT(dst->isImmutable()); | 61 SkASSERT(dst->isImmutable()); |
63 SkASSERT(dst->getPixels()); | 62 SkASSERT(dst->getPixels()); |
64 return true; | 63 return true; |
65 } | 64 } |
66 | 65 |
67 if (!dst->tryAllocPixels(make_info(this->width(), this->height(), this->isOp
aque(), | 66 if (!dst->tryAllocPixels(make_info(this->width(), this->height(), this->alph
aType(), |
68 this->fColorSpace))) { | 67 this->fColorSpace))) { |
69 return false; | 68 return false; |
70 } | 69 } |
71 if (!fTexture->readPixels(0, 0, dst->width(), dst->height(), kSkia8888_GrPix
elConfig, | 70 if (!fTexture->readPixels(0, 0, dst->width(), dst->height(), kSkia8888_GrPix
elConfig, |
72 dst->getPixels(), dst->rowBytes())) { | 71 dst->getPixels(), dst->rowBytes())) { |
73 return false; | 72 return false; |
74 } | 73 } |
75 | 74 |
76 dst->pixelRef()->setImmutableWithID(this->uniqueID()); | 75 dst->pixelRef()->setImmutableWithID(this->uniqueID()); |
77 if (kAllow_CachingHint == chint) { | 76 if (kAllow_CachingHint == chint) { |
78 SkBitmapCache::Add(this->uniqueID(), *dst); | 77 SkBitmapCache::Add(this->uniqueID(), *dst); |
79 fAddedRasterVersionToCache.store(true); | 78 fAddedRasterVersionToCache.store(true); |
80 } | 79 } |
81 return true; | 80 return true; |
82 } | 81 } |
83 | 82 |
84 GrTexture* SkImage_Gpu::asTextureRef(GrContext* ctx, const GrTextureParams& para
ms, | 83 GrTexture* SkImage_Gpu::asTextureRef(GrContext* ctx, const GrTextureParams& para
ms, |
85 SkSourceGammaTreatment gammaTreatment) cons
t { | 84 SkSourceGammaTreatment gammaTreatment) cons
t { |
86 GrTextureAdjuster adjuster(this->peekTexture(), this->bounds(), this->unique
ID(), | 85 GrTextureAdjuster adjuster(this->peekTexture(), this->bounds(), this->unique
ID(), |
87 this->onImageInfo().colorSpace()); | 86 this->onImageInfo().colorSpace()); |
88 return adjuster.refTextureSafeForParams(params, gammaTreatment, nullptr); | 87 return adjuster.refTextureSafeForParams(params, gammaTreatment, nullptr); |
89 } | 88 } |
90 | 89 |
91 bool SkImage_Gpu::isOpaque() const { | |
92 return GrPixelConfigIsOpaque(fTexture->config()) || fAlphaType == kOpaque_Sk
AlphaType; | |
93 } | |
94 | |
95 static void apply_premul(const SkImageInfo& info, void* pixels, size_t rowBytes)
{ | 90 static void apply_premul(const SkImageInfo& info, void* pixels, size_t rowBytes)
{ |
96 switch (info.colorType()) { | 91 switch (info.colorType()) { |
97 case kRGBA_8888_SkColorType: | 92 case kRGBA_8888_SkColorType: |
98 case kBGRA_8888_SkColorType: | 93 case kBGRA_8888_SkColorType: |
99 break; | 94 break; |
100 default: | 95 default: |
101 return; // nothing to do | 96 return; // nothing to do |
102 } | 97 } |
103 | 98 |
104 // SkColor is not necesarily RGBA or BGRA, but it is one of them on little-e
ndian, | 99 // SkColor is not necesarily RGBA or BGRA, but it is one of them on little-e
ndian, |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 sk_ref_sp(maker->getColorSpace()), SkBudgeted
::kNo); | 297 sk_ref_sp(maker->getColorSpace()), SkBudgeted
::kNo); |
303 } | 298 } |
304 | 299 |
305 sk_sp<SkImage> SkImage::makeTextureImage(GrContext *context) const { | 300 sk_sp<SkImage> SkImage::makeTextureImage(GrContext *context) const { |
306 if (!context) { | 301 if (!context) { |
307 return nullptr; | 302 return nullptr; |
308 } | 303 } |
309 if (GrTexture* peek = as_IB(this)->peekTexture()) { | 304 if (GrTexture* peek = as_IB(this)->peekTexture()) { |
310 return peek->getContext() == context ? sk_ref_sp(const_cast<SkImage*>(th
is)) : nullptr; | 305 return peek->getContext() == context ? sk_ref_sp(const_cast<SkImage*>(th
is)) : nullptr; |
311 } | 306 } |
312 // No way to check whether a image is premul or not? | |
313 SkAlphaType at = this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaTyp
e; | |
314 | 307 |
315 if (SkImageCacherator* cacher = as_IB(this)->peekCacherator()) { | 308 if (SkImageCacherator* cacher = as_IB(this)->peekCacherator()) { |
316 GrImageTextureMaker maker(context, cacher, this, kDisallow_CachingHint); | 309 GrImageTextureMaker maker(context, cacher, this, kDisallow_CachingHint); |
317 return create_image_from_maker(&maker, at, this->uniqueID()); | 310 return create_image_from_maker(&maker, this->alphaType(), this->uniqueID
()); |
318 } | 311 } |
319 | 312 |
320 if (const SkBitmap* bmp = as_IB(this)->onPeekBitmap()) { | 313 if (const SkBitmap* bmp = as_IB(this)->onPeekBitmap()) { |
321 GrBitmapTextureMaker maker(context, *bmp); | 314 GrBitmapTextureMaker maker(context, *bmp); |
322 return create_image_from_maker(&maker, at, this->uniqueID()); | 315 return create_image_from_maker(&maker, this->alphaType(), this->uniqueID
()); |
323 } | 316 } |
324 return nullptr; | 317 return nullptr; |
325 } | 318 } |
326 | 319 |
327 sk_sp<SkImage> SkImage::makeNonTextureImage() const { | 320 sk_sp<SkImage> SkImage::makeNonTextureImage() const { |
328 if (!this->isTextureBacked()) { | 321 if (!this->isTextureBacked()) { |
329 return sk_ref_sp(const_cast<SkImage*>(this)); | 322 return sk_ref_sp(const_cast<SkImage*>(this)); |
330 } | 323 } |
331 SkImageInfo info = as_IB(this)->onImageInfo(); | 324 SkImageInfo info = as_IB(this)->onImageInfo(); |
332 size_t rowBytes = info.minRowBytes(); | 325 size_t rowBytes = info.minRowBytes(); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 ctSize = SkAlign8(pixmap.ctable()->count() * 4); | 431 ctSize = SkAlign8(pixmap.ctable()->count() * 4); |
439 } | 432 } |
440 } else { | 433 } else { |
441 // Here we're just using presence of data to know whether there is a cod
ec behind the image. | 434 // Here we're just using presence of data to know whether there is a cod
ec behind the image. |
442 // In the future we will access the cacherator and get the exact data th
at we want to (e.g. | 435 // In the future we will access the cacherator and get the exact data th
at we want to (e.g. |
443 // yuv planes) upload. | 436 // yuv planes) upload. |
444 sk_sp<SkData> data(this->refEncoded()); | 437 sk_sp<SkData> data(this->refEncoded()); |
445 if (!data && !this->peekPixels(nullptr)) { | 438 if (!data && !this->peekPixels(nullptr)) { |
446 return 0; | 439 return 0; |
447 } | 440 } |
448 SkAlphaType at = this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlph
aType; | 441 info = SkImageInfo::MakeN32(scaledSize.width(), scaledSize.height(), thi
s->alphaType()); |
449 info = SkImageInfo::MakeN32(scaledSize.width(), scaledSize.height(), at)
; | |
450 pixelSize = SkAlign8(SkAutoPixmapStorage::AllocSize(info, nullptr)); | 442 pixelSize = SkAlign8(SkAutoPixmapStorage::AllocSize(info, nullptr)); |
451 if (fillMode) { | 443 if (fillMode) { |
452 pixmap.alloc(info); | 444 pixmap.alloc(info); |
453 if (isScaled) { | 445 if (isScaled) { |
454 if (!this->scalePixels(pixmap, scaleFilterQuality, | 446 if (!this->scalePixels(pixmap, scaleFilterQuality, |
455 SkImage::kDisallow_CachingHint)) { | 447 SkImage::kDisallow_CachingHint)) { |
456 return 0; | 448 return 0; |
457 } | 449 } |
458 } else { | 450 } else { |
459 if (!this->readPixels(pixmap, 0, 0, SkImage::kDisallow_CachingHi
nt)) { | 451 if (!this->readPixels(pixmap, 0, 0, SkImage::kDisallow_CachingHi
nt)) { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 return nullptr; | 563 return nullptr; |
572 } | 564 } |
573 SkAutoTUnref<GrTexture> texture(GrUploadMipMapToTexture(ctx, info, texels, m
ipLevelCount)); | 565 SkAutoTUnref<GrTexture> texture(GrUploadMipMapToTexture(ctx, info, texels, m
ipLevelCount)); |
574 if (!texture) { | 566 if (!texture) { |
575 return nullptr; | 567 return nullptr; |
576 } | 568 } |
577 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNew
ImageUniqueID, | 569 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNew
ImageUniqueID, |
578 info.alphaType(), texture, sk_ref_sp(info.col
orSpace()), | 570 info.alphaType(), texture, sk_ref_sp(info.col
orSpace()), |
579 budgeted); | 571 budgeted); |
580 } | 572 } |
OLD | NEW |