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

Side by Side Diff: src/image/SkImage.cpp

Issue 2250663002: Add alphaType() to SkImage (Closed) Base URL: https://skia.googlesource.com/skia.git@special-image-alpha-type
Patch Set: Remove virtuals from SkImage, slight cleanup 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 | « include/core/SkImage.h ('k') | src/image/SkImage_Base.h » ('j') | 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 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 "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkBitmapCache.h" 9 #include "SkBitmapCache.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 // 99 //
100 SkBitmap bm; 100 SkBitmap bm;
101 if (as_IB(this)->getROPixels(&bm)) { 101 if (as_IB(this)->getROPixels(&bm)) {
102 bm.lockPixels(); 102 bm.lockPixels();
103 bm.unlockPixels(); 103 bm.unlockPixels();
104 } 104 }
105 } 105 }
106 106
107 //////////////////////////////////////////////////////////////////////////////// /////////////////// 107 //////////////////////////////////////////////////////////////////////////////// ///////////////////
108 108
109 SkAlphaType SkImage::alphaType() const {
110 return as_IB(this)->onAlphaType();
111 }
112
109 sk_sp<SkShader> SkImage::makeShader(SkShader::TileMode tileX, SkShader::TileMode tileY, 113 sk_sp<SkShader> SkImage::makeShader(SkShader::TileMode tileX, SkShader::TileMode tileY,
110 const SkMatrix* localMatrix) const { 114 const SkMatrix* localMatrix) const {
111 return SkImageShader::Make(sk_ref_sp(const_cast<SkImage*>(this)), tileX, til eY, localMatrix); 115 return SkImageShader::Make(sk_ref_sp(const_cast<SkImage*>(this)), tileX, til eY, localMatrix);
112 } 116 }
113 117
114 #ifdef SK_SUPPORT_LEGACY_CREATESHADER_PTR 118 #ifdef SK_SUPPORT_LEGACY_CREATESHADER_PTR
115 SkShader* SkImage::newShader(SkShader::TileMode tileX, SkShader::TileMode tileY, 119 SkShader* SkImage::newShader(SkShader::TileMode tileX, SkShader::TileMode tileY,
116 const SkMatrix* localMatrix) const { 120 const SkMatrix* localMatrix) const {
117 return this->makeShader(tileX, tileY, localMatrix).release(); 121 return this->makeShader(tileX, tileY, localMatrix).release();
118 } 122 }
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 } 317 }
314 318
315 bool SkImage::asLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) const { 319 bool SkImage::asLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) const {
316 return as_IB(this)->onAsLegacyBitmap(bitmap, mode); 320 return as_IB(this)->onAsLegacyBitmap(bitmap, mode);
317 } 321 }
318 322
319 bool SkImage_Base::onAsLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) con st { 323 bool SkImage_Base::onAsLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) con st {
320 // As the base-class, all we can do is make a copy (regardless of mode). 324 // As the base-class, all we can do is make a copy (regardless of mode).
321 // Subclasses that want to be more optimal should override. 325 // Subclasses that want to be more optimal should override.
322 SkImageInfo info = this->onImageInfo().makeColorType(kN32_SkColorType) 326 SkImageInfo info = this->onImageInfo().makeColorType(kN32_SkColorType)
323 .makeAlphaType(this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAl phaType); 327 .makeAlphaType(this->alphaType());
324 if (!bitmap->tryAllocPixels(info)) { 328 if (!bitmap->tryAllocPixels(info)) {
325 return false; 329 return false;
326 } 330 }
327 if (!this->readPixels(bitmap->info(), bitmap->getPixels(), bitmap->rowBytes( ), 0, 0)) { 331 if (!this->readPixels(bitmap->info(), bitmap->getPixels(), bitmap->rowBytes( ), 0, 0)) {
328 bitmap->reset(); 332 bitmap->reset();
329 return false; 333 return false;
330 } 334 }
331 335
332 if (kRO_LegacyBitmapMode == mode) { 336 if (kRO_LegacyBitmapMode == mode) {
333 bitmap->setImmutable(); 337 bitmap->setImmutable();
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 SkASSERT(image); 522 SkASSERT(image);
519 SkASSERT(ctx); 523 SkASSERT(ctx);
520 as_IB(image)->onPinAsTexture(ctx); 524 as_IB(image)->onPinAsTexture(ctx);
521 } 525 }
522 526
523 void SkImage_unpinAsTexture(const SkImage* image, GrContext* ctx) { 527 void SkImage_unpinAsTexture(const SkImage* image, GrContext* ctx) {
524 SkASSERT(image); 528 SkASSERT(image);
525 SkASSERT(ctx); 529 SkASSERT(ctx);
526 as_IB(image)->onUnpinAsTexture(ctx); 530 as_IB(image)->onUnpinAsTexture(ctx);
527 } 531 }
OLDNEW
« no previous file with comments | « include/core/SkImage.h ('k') | src/image/SkImage_Base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698