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 "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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 // TODO : could consider heurist of sharing pixels, if subset is pretty clos
e to complete | 176 // TODO : could consider heurist of sharing pixels, if subset is pretty clos
e to complete |
177 | 177 |
178 SkImageInfo info = SkImageInfo::MakeN32(subset.width(), subset.height(), fBi
tmap.alphaType()); | 178 SkImageInfo info = SkImageInfo::MakeN32(subset.width(), subset.height(), fBi
tmap.alphaType()); |
179 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); | 179 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); |
180 if (!surface) { | 180 if (!surface) { |
181 return nullptr; | 181 return nullptr; |
182 } | 182 } |
183 surface->getCanvas()->clear(0); | 183 surface->getCanvas()->clear(0); |
184 surface->getCanvas()->drawImage(this, SkIntToScalar(-subset.x()), SkIntToSca
lar(-subset.y()), | 184 surface->getCanvas()->drawImage(this, SkIntToScalar(-subset.x()), SkIntToSca
lar(-subset.y()), |
185 nullptr); | 185 nullptr); |
186 return sk_sp<SkImage>(surface->newImageSnapshot()); | 186 return surface->makeImageSnapshot(); |
187 } | 187 } |
188 | 188 |
189 /////////////////////////////////////////////////////////////////////////////// | 189 /////////////////////////////////////////////////////////////////////////////// |
190 | 190 |
191 sk_sp<SkImage> SkImage::MakeRasterCopy(const SkPixmap& pmap) { | 191 sk_sp<SkImage> SkImage::MakeRasterCopy(const SkPixmap& pmap) { |
192 size_t size; | 192 size_t size; |
193 if (!SkImage_Raster::ValidArgs(pmap.info(), pmap.rowBytes(), | 193 if (!SkImage_Raster::ValidArgs(pmap.info(), pmap.rowBytes(), |
194 pmap.ctable() != nullptr, &size) || !pmap.add
r()) { | 194 pmap.ctable() != nullptr, &size) || !pmap.add
r()) { |
195 return nullptr; | 195 return nullptr; |
196 } | 196 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 // pixelref since the caller might call setImmutable() themselves | 278 // pixelref since the caller might call setImmutable() themselves |
279 // (thus changing our state). | 279 // (thus changing our state). |
280 if (fBitmap.isImmutable()) { | 280 if (fBitmap.isImmutable()) { |
281 bitmap->setInfo(fBitmap.info(), fBitmap.rowBytes()); | 281 bitmap->setInfo(fBitmap.info(), fBitmap.rowBytes()); |
282 bitmap->setPixelRef(fBitmap.pixelRef(), fBitmap.pixelRefOrigin()); | 282 bitmap->setPixelRef(fBitmap.pixelRef(), fBitmap.pixelRefOrigin()); |
283 return true; | 283 return true; |
284 } | 284 } |
285 } | 285 } |
286 return this->INHERITED::onAsLegacyBitmap(bitmap, mode); | 286 return this->INHERITED::onAsLegacyBitmap(bitmap, mode); |
287 } | 287 } |
OLD | NEW |