Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Side by Side Diff: src/core/SkSpecialImage.cpp

Issue 2246193002: Remove isOpaque from SkSpecialImage, just use alpha type (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Make alphaType pure virtual Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkSpecialImage.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 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 "SkSpecialImage.h" 8 #include "SkSpecialImage.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkImage.h" 10 #include "SkImage.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 } 98 }
99 99
100 sk_sp<GrTexture> resultTex(GrRefCachedBitmapTexture(context, 100 sk_sp<GrTexture> resultTex(GrRefCachedBitmapTexture(context,
101 bmp, 101 bmp,
102 GrTextureParams::ClampNo Filter(), 102 GrTextureParams::ClampNo Filter(),
103 SkSourceGammaTreatment:: kRespect)); 103 SkSourceGammaTreatment:: kRespect));
104 if (!resultTex) { 104 if (!resultTex) {
105 return nullptr; 105 return nullptr;
106 } 106 }
107 107
108 SkAlphaType at = this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaTyp e;
109
110 return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(resultTex->width(), resul tTex->height()), 108 return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(resultTex->width(), resul tTex->height()),
111 this->uniqueID(), 109 this->uniqueID(),
112 resultTex, sk_ref_sp(this->getColorSpace( )), &this->props(), 110 resultTex, sk_ref_sp(this->getColorSpace( )), &this->props(),
113 at); 111 this->alphaType());
114 #else 112 #else
115 return nullptr; 113 return nullptr;
116 #endif 114 #endif
117 } 115 }
118 116
119 void SkSpecialImage::draw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPain t* paint) const { 117 void SkSpecialImage::draw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPain t* paint) const {
120 return as_SIB(this)->onDraw(canvas, x, y, paint); 118 return as_SIB(this)->onDraw(canvas, x, y, paint);
121 } 119 }
122 120
123 bool SkSpecialImage::getROPixels(SkBitmap* bm) const { 121 bool SkSpecialImage::getROPixels(SkBitmap* bm) const {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 { 211 {
214 SkASSERT(bm.pixelRef()); 212 SkASSERT(bm.pixelRef());
215 213
216 // We have to lock now, while bm is still in scope, since it may have co me from our 214 // We have to lock now, while bm is still in scope, since it may have co me from our
217 // cache, which means we need to keep it locked until we (the special) a re done, since 215 // cache, which means we need to keep it locked until we (the special) a re done, since
218 // we cannot re-generate the cache entry (if bm came from a generator). 216 // we cannot re-generate the cache entry (if bm came from a generator).
219 fBitmap.lockPixels(); 217 fBitmap.lockPixels();
220 SkASSERT(fBitmap.getPixels()); 218 SkASSERT(fBitmap.getPixels());
221 } 219 }
222 220
223 bool isOpaque() const override { return fBitmap.isOpaque(); } 221 SkAlphaType alphaType() const override { return fBitmap.alphaType(); }
224 222
225 size_t getSize() const override { return fBitmap.getSize(); } 223 size_t getSize() const override { return fBitmap.getSize(); }
226 224
227 void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) const override { 225 void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) const override {
228 SkRect dst = SkRect::MakeXYWH(x, y, 226 SkRect dst = SkRect::MakeXYWH(x, y,
229 this->subset().width(), this->subset().hei ght()); 227 this->subset().width(), this->subset().hei ght());
230 228
231 canvas->drawBitmapRect(fBitmap, this->subset(), 229 canvas->drawBitmapRect(fBitmap, this->subset(),
232 dst, paint, SkCanvas::kStrict_SrcRectConstraint); 230 dst, paint, SkCanvas::kStrict_SrcRectConstraint);
233 } 231 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 , fColorSpace(std::move(colorSpace)) 325 , fColorSpace(std::move(colorSpace))
328 , fAddedRasterVersionToCache(false) { 326 , fAddedRasterVersionToCache(false) {
329 } 327 }
330 328
331 ~SkSpecialImage_Gpu() override { 329 ~SkSpecialImage_Gpu() override {
332 if (fAddedRasterVersionToCache.load()) { 330 if (fAddedRasterVersionToCache.load()) {
333 SkNotifyBitmapGenIDIsStale(this->uniqueID()); 331 SkNotifyBitmapGenIDIsStale(this->uniqueID());
334 } 332 }
335 } 333 }
336 334
337 bool isOpaque() const override { 335 SkAlphaType alphaType() const override { return fAlphaType; }
338 return GrPixelConfigIsOpaque(fTexture->config()) || fAlphaType == kOpaqu e_SkAlphaType;
339 }
340 336
341 size_t getSize() const override { return fTexture->gpuMemorySize(); } 337 size_t getSize() const override { return fTexture->gpuMemorySize(); }
342 338
343 void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) const override { 339 void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) const override {
344 SkRect dst = SkRect::MakeXYWH(x, y, 340 SkRect dst = SkRect::MakeXYWH(x, y,
345 this->subset().width(), this->subset().hei ght()); 341 this->subset().width(), this->subset().hei ght());
346 342
347 auto img = sk_sp<SkImage>(new SkImage_Gpu(fTexture->width(), fTexture->h eight(), 343 auto img = sk_sp<SkImage>(new SkImage_Gpu(fTexture->width(), fTexture->h eight(),
348 this->uniqueID(), fAlphaType, fTexture.get(), 344 this->uniqueID(), fAlphaType, fTexture.get(),
349 fColorSpace, SkBudgeted::kNo)) ; 345 fColorSpace, SkBudgeted::kNo)) ;
350 346
351 canvas->drawImageRect(img, this->subset(), 347 canvas->drawImageRect(img, this->subset(),
352 dst, paint, SkCanvas::kStrict_SrcRectConstraint); 348 dst, paint, SkCanvas::kStrict_SrcRectConstraint);
353 } 349 }
354 350
355 GrTexture* onPeekTexture() const override { return fTexture.get(); } 351 GrTexture* onPeekTexture() const override { return fTexture.get(); }
356 352
357 sk_sp<GrTexture> onAsTextureRef(GrContext*) const override { return fTexture ; } 353 sk_sp<GrTexture> onAsTextureRef(GrContext*) const override { return fTexture ; }
358 354
359 bool onGetROPixels(SkBitmap* dst) const override { 355 bool onGetROPixels(SkBitmap* dst) const override {
360 if (SkBitmapCache::Find(this->uniqueID(), dst)) { 356 if (SkBitmapCache::Find(this->uniqueID(), dst)) {
361 SkASSERT(dst->getGenerationID() == this->uniqueID()); 357 SkASSERT(dst->getGenerationID() == this->uniqueID());
362 SkASSERT(dst->isImmutable()); 358 SkASSERT(dst->isImmutable());
363 SkASSERT(dst->getPixels()); 359 SkASSERT(dst->getPixels());
364 return true; 360 return true;
365 } 361 }
366 362
367 SkImageInfo info = SkImageInfo::MakeN32(this->width(), this->height(), 363 SkImageInfo info = SkImageInfo::MakeN32(this->width(), this->height(),
368 this->isOpaque() ? kOpaque_SkAlp haType 364 this->alphaType(), fColorSpace);
369 : kPremul_SkAlp haType,
370 fColorSpace);
371 365
372 if (!dst->tryAllocPixels(info)) { 366 if (!dst->tryAllocPixels(info)) {
373 return false; 367 return false;
374 } 368 }
375 369
376 if (!fTexture->readPixels(0, 0, dst->width(), dst->height(), kSkia8888_G rPixelConfig, 370 if (!fTexture->readPixels(0, 0, dst->width(), dst->height(), kSkia8888_G rPixelConfig,
377 dst->getPixels(), dst->rowBytes())) { 371 dst->getPixels(), dst->rowBytes())) {
378 return false; 372 return false;
379 } 373 }
380 374
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 sk_sp<GrTexture> tex, 446 sk_sp<GrTexture> tex,
453 sk_sp<SkColorSpace> colorSpace , 447 sk_sp<SkColorSpace> colorSpace ,
454 const SkSurfaceProps* props, 448 const SkSurfaceProps* props,
455 SkAlphaType at) { 449 SkAlphaType at) {
456 SkASSERT(rect_fits(subset, tex->width(), tex->height())); 450 SkASSERT(rect_fits(subset, tex->width(), tex->height()));
457 return sk_make_sp<SkSpecialImage_Gpu>(subset, uniqueID, std::move(tex), at, 451 return sk_make_sp<SkSpecialImage_Gpu>(subset, uniqueID, std::move(tex), at,
458 std::move(colorSpace), props); 452 std::move(colorSpace), props);
459 } 453 }
460 454
461 #endif 455 #endif
OLDNEW
« no previous file with comments | « src/core/SkSpecialImage.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698