| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "SkImage_Base.h" | 8 #include "SkImage_Base.h" |
| 9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 GrTexture* SkImage_Generator::asTextureRef(GrContext* ctx, const GrTextureParams
& params) const { | 72 GrTexture* SkImage_Generator::asTextureRef(GrContext* ctx, const GrTextureParams
& params) const { |
| 73 return fCache->lockAsTexture(ctx, params, this); | 73 return fCache->lockAsTexture(ctx, params, this); |
| 74 } | 74 } |
| 75 | 75 |
| 76 sk_sp<SkImage> SkImage_Generator::onMakeSubset(const SkIRect& subset) const { | 76 sk_sp<SkImage> SkImage_Generator::onMakeSubset(const SkIRect& subset) const { |
| 77 // TODO: make this lazy, by wrapping the subset inside a new generator or so
mething | 77 // TODO: make this lazy, by wrapping the subset inside a new generator or so
mething |
| 78 // For now, we do effectively what we did before, make it a raster | 78 // For now, we do effectively what we did before, make it a raster |
| 79 | 79 |
| 80 const SkImageInfo info = SkImageInfo::MakeN32(subset.width(), subset.height(
), | 80 const SkImageInfo info = SkImageInfo::MakeN32(subset.width(), subset.height(
), |
| 81 this->isOpaque() ? kOpaque_SkAlphaType : k
Premul_SkAlphaType); | 81 this->isOpaque() ? kOpaque_SkAlphaType : k
Premul_SkAlphaType); |
| 82 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); | 82 auto surface(SkSurface::MakeRaster(info)); |
| 83 if (!surface) { | 83 if (!surface) { |
| 84 return nullptr; | 84 return nullptr; |
| 85 } | 85 } |
| 86 surface->getCanvas()->clear(0); | 86 surface->getCanvas()->clear(0); |
| 87 surface->getCanvas()->drawImage(this, SkIntToScalar(-subset.x()), SkIntToSca
lar(-subset.y()), | 87 surface->getCanvas()->drawImage(this, SkIntToScalar(-subset.x()), SkIntToSca
lar(-subset.y()), |
| 88 nullptr); | 88 nullptr); |
| 89 return surface->makeImageSnapshot(); | 89 return surface->makeImageSnapshot(); |
| 90 } | 90 } |
| 91 | 91 |
| 92 sk_sp<SkImage> SkImage::MakeFromGenerator(SkImageGenerator* generator, const SkI
Rect* subset) { | 92 sk_sp<SkImage> SkImage::MakeFromGenerator(SkImageGenerator* generator, const SkI
Rect* subset) { |
| 93 if (!generator) { | 93 if (!generator) { |
| 94 return nullptr; | 94 return nullptr; |
| 95 } | 95 } |
| 96 SkImageCacherator* cache = SkImageCacherator::NewFromGenerator(generator, su
bset); | 96 SkImageCacherator* cache = SkImageCacherator::NewFromGenerator(generator, su
bset); |
| 97 if (!cache) { | 97 if (!cache) { |
| 98 return nullptr; | 98 return nullptr; |
| 99 } | 99 } |
| 100 return sk_make_sp<SkImage_Generator>(cache); | 100 return sk_make_sp<SkImage_Generator>(cache); |
| 101 } | 101 } |
| OLD | NEW |