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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 /////////////////////////////////////////////////////////////////////////////// | 207 /////////////////////////////////////////////////////////////////////////////// |
208 | 208 |
209 sk_sp<SkImage> SkImage::MakeRasterCopy(const SkPixmap& pmap) { | 209 sk_sp<SkImage> SkImage::MakeRasterCopy(const SkPixmap& pmap) { |
210 size_t size; | 210 size_t size; |
211 if (!SkImage_Raster::ValidArgs(pmap.info(), pmap.rowBytes(), | 211 if (!SkImage_Raster::ValidArgs(pmap.info(), pmap.rowBytes(), |
212 pmap.ctable() != nullptr, &size) || !pmap.add
r()) { | 212 pmap.ctable() != nullptr, &size) || !pmap.add
r()) { |
213 return nullptr; | 213 return nullptr; |
214 } | 214 } |
215 | 215 |
216 // Here we actually make a copy of the caller's pixel data | 216 // Here we actually make a copy of the caller's pixel data |
217 sk_sp<SkData> data(SkData::NewWithCopy(pmap.addr(), size)); | 217 sk_sp<SkData> data(SkData::MakeWithCopy(pmap.addr(), size)); |
218 return sk_make_sp<SkImage_Raster>(pmap.info(), std::move(data), pmap.rowByte
s(), pmap.ctable()); | 218 return sk_make_sp<SkImage_Raster>(pmap.info(), std::move(data), pmap.rowByte
s(), pmap.ctable()); |
219 } | 219 } |
220 | 220 |
221 | 221 |
222 sk_sp<SkImage> SkImage::MakeRasterData(const SkImageInfo& info, sk_sp<SkData> da
ta, | 222 sk_sp<SkImage> SkImage::MakeRasterData(const SkImageInfo& info, sk_sp<SkData> da
ta, |
223 size_t rowBytes) { | 223 size_t rowBytes) { |
224 size_t size; | 224 size_t size; |
225 if (!SkImage_Raster::ValidArgs(info, rowBytes, false, &size) || !data) { | 225 if (!SkImage_Raster::ValidArgs(info, rowBytes, false, &size) || !data) { |
226 return nullptr; | 226 return nullptr; |
227 } | 227 } |
228 | 228 |
229 // did they give us enough data? | 229 // did they give us enough data? |
230 if (data->size() < size) { | 230 if (data->size() < size) { |
231 return nullptr; | 231 return nullptr; |
232 } | 232 } |
233 | 233 |
234 SkColorTable* ctable = nullptr; | 234 SkColorTable* ctable = nullptr; |
235 return sk_make_sp<SkImage_Raster>(info, std::move(data), rowBytes, ctable); | 235 return sk_make_sp<SkImage_Raster>(info, std::move(data), rowBytes, ctable); |
236 } | 236 } |
237 | 237 |
238 sk_sp<SkImage> SkImage::MakeFromRaster(const SkPixmap& pmap, RasterReleaseProc p
roc, | 238 sk_sp<SkImage> SkImage::MakeFromRaster(const SkPixmap& pmap, RasterReleaseProc p
roc, |
239 ReleaseContext ctx) { | 239 ReleaseContext ctx) { |
240 size_t size; | 240 size_t size; |
241 if (!SkImage_Raster::ValidArgs(pmap.info(), pmap.rowBytes(), false, &size) |
| !pmap.addr()) { | 241 if (!SkImage_Raster::ValidArgs(pmap.info(), pmap.rowBytes(), false, &size) |
| !pmap.addr()) { |
242 return nullptr; | 242 return nullptr; |
243 } | 243 } |
244 | 244 |
245 sk_sp<SkData> data(SkData::NewWithProc(pmap.addr(), size, proc, ctx)); | 245 sk_sp<SkData> data(SkData::MakeWithProc(pmap.addr(), size, proc, ctx)); |
246 return sk_make_sp<SkImage_Raster>(pmap.info(), std::move(data), pmap.rowByte
s(), pmap.ctable()); | 246 return sk_make_sp<SkImage_Raster>(pmap.info(), std::move(data), pmap.rowByte
s(), pmap.ctable()); |
247 } | 247 } |
248 | 248 |
249 sk_sp<SkImage> SkMakeImageFromPixelRef(const SkImageInfo& info, SkPixelRef* pr, | 249 sk_sp<SkImage> SkMakeImageFromPixelRef(const SkImageInfo& info, SkPixelRef* pr, |
250 const SkIPoint& pixelRefOrigin, size_t ro
wBytes) { | 250 const SkIPoint& pixelRefOrigin, size_t ro
wBytes) { |
251 if (!SkImage_Raster::ValidArgs(info, rowBytes, false, nullptr)) { | 251 if (!SkImage_Raster::ValidArgs(info, rowBytes, false, nullptr)) { |
252 return nullptr; | 252 return nullptr; |
253 } | 253 } |
254 return sk_make_sp<SkImage_Raster>(info, pr, pixelRefOrigin, rowBytes); | 254 return sk_make_sp<SkImage_Raster>(info, pr, pixelRefOrigin, rowBytes); |
255 } | 255 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 // pixelref since the caller might call setImmutable() themselves | 296 // pixelref since the caller might call setImmutable() themselves |
297 // (thus changing our state). | 297 // (thus changing our state). |
298 if (fBitmap.isImmutable()) { | 298 if (fBitmap.isImmutable()) { |
299 bitmap->setInfo(fBitmap.info(), fBitmap.rowBytes()); | 299 bitmap->setInfo(fBitmap.info(), fBitmap.rowBytes()); |
300 bitmap->setPixelRef(fBitmap.pixelRef(), fBitmap.pixelRefOrigin()); | 300 bitmap->setPixelRef(fBitmap.pixelRef(), fBitmap.pixelRefOrigin()); |
301 return true; | 301 return true; |
302 } | 302 } |
303 } | 303 } |
304 return this->INHERITED::onAsLegacyBitmap(bitmap, mode); | 304 return this->INHERITED::onAsLegacyBitmap(bitmap, mode); |
305 } | 305 } |
OLD | NEW |