| 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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
| 9 #include "SkBitmapCache.h" | 9 #include "SkBitmapCache.h" |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 } | 289 } |
| 290 | 290 |
| 291 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 291 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 292 | 292 |
| 293 sk_sp<SkImage> SkImage::MakeFromBitmap(const SkBitmap& bm) { | 293 sk_sp<SkImage> SkImage::MakeFromBitmap(const SkBitmap& bm) { |
| 294 SkPixelRef* pr = bm.pixelRef(); | 294 SkPixelRef* pr = bm.pixelRef(); |
| 295 if (nullptr == pr) { | 295 if (nullptr == pr) { |
| 296 return nullptr; | 296 return nullptr; |
| 297 } | 297 } |
| 298 | 298 |
| 299 #if SK_SUPPORT_GPU | |
| 300 if (GrTexture* tex = pr->getTexture()) { | |
| 301 SkAutoTUnref<GrTexture> unrefCopy; | |
| 302 if (!bm.isImmutable()) { | |
| 303 tex = GrDeepCopyTexture(tex, SkBudgeted::kNo); | |
| 304 if (nullptr == tex) { | |
| 305 return nullptr; | |
| 306 } | |
| 307 unrefCopy.reset(tex); | |
| 308 } | |
| 309 const SkImageInfo info = bm.info(); | |
| 310 return sk_make_sp<SkImage_Gpu>(info.width(), info.height(), bm.getGenera
tionID(), | |
| 311 info.alphaType(), tex, sk_ref_sp(info.col
orSpace()), | |
| 312 SkBudgeted::kNo); | |
| 313 } | |
| 314 #endif | |
| 315 | |
| 316 return SkMakeImageFromRasterBitmap(bm, kIfMutable_SkCopyPixelsMode); | 299 return SkMakeImageFromRasterBitmap(bm, kIfMutable_SkCopyPixelsMode); |
| 317 } | 300 } |
| 318 | 301 |
| 319 bool SkImage::asLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) const { | 302 bool SkImage::asLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) const { |
| 320 return as_IB(this)->onAsLegacyBitmap(bitmap, mode); | 303 return as_IB(this)->onAsLegacyBitmap(bitmap, mode); |
| 321 } | 304 } |
| 322 | 305 |
| 323 bool SkImage_Base::onAsLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) con
st { | 306 bool SkImage_Base::onAsLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) con
st { |
| 324 // As the base-class, all we can do is make a copy (regardless of mode). | 307 // As the base-class, all we can do is make a copy (regardless of mode). |
| 325 // Subclasses that want to be more optimal should override. | 308 // Subclasses that want to be more optimal should override. |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 SkASSERT(image); | 505 SkASSERT(image); |
| 523 SkASSERT(ctx); | 506 SkASSERT(ctx); |
| 524 as_IB(image)->onPinAsTexture(ctx); | 507 as_IB(image)->onPinAsTexture(ctx); |
| 525 } | 508 } |
| 526 | 509 |
| 527 void SkImage_unpinAsTexture(const SkImage* image, GrContext* ctx) { | 510 void SkImage_unpinAsTexture(const SkImage* image, GrContext* ctx) { |
| 528 SkASSERT(image); | 511 SkASSERT(image); |
| 529 SkASSERT(ctx); | 512 SkASSERT(ctx); |
| 530 as_IB(image)->onUnpinAsTexture(ctx); | 513 as_IB(image)->onUnpinAsTexture(ctx); |
| 531 } | 514 } |
| OLD | NEW |