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 "SkColorPriv.h" | 8 #include "SkColorPriv.h" |
9 #include "SkConfig8888.h" | 9 #include "SkConfig8888.h" |
10 #include "SkData.h" | 10 #include "SkData.h" |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 SkPaint paint; | 274 SkPaint paint; |
275 paint.setFilterQuality(quality); | 275 paint.setFilterQuality(quality); |
276 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 276 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
277 surface->getCanvas()->drawBitmapRect(bitmap, SkRect::MakeIWH(dst.width(), ds
t.height()), | 277 surface->getCanvas()->drawBitmapRect(bitmap, SkRect::MakeIWH(dst.width(), ds
t.height()), |
278 &paint); | 278 &paint); |
279 return true; | 279 return true; |
280 } | 280 } |
281 | 281 |
282 ////////////////////////////////////////////////////////////////////////////////
////////////////// | 282 ////////////////////////////////////////////////////////////////////////////////
////////////////// |
283 | 283 |
| 284 SkAutoPixmapStorage::SkAutoPixmapStorage() : fStorage(nullptr) {} |
| 285 |
| 286 SkAutoPixmapStorage::~SkAutoPixmapStorage() { |
| 287 this->freeStorage(); |
| 288 } |
| 289 |
| 290 size_t SkAutoPixmapStorage::AllocSize(const SkImageInfo& info, size_t* rowBytes)
{ |
| 291 size_t rb = info.minRowBytes(); |
| 292 if (rowBytes) { |
| 293 *rowBytes = rb; |
| 294 } |
| 295 return info.getSafeSize(rb); |
| 296 } |
| 297 |
| 298 bool SkAutoPixmapStorage::tryAlloc(const SkImageInfo& info) { |
| 299 this->freeStorage(); |
| 300 |
| 301 size_t rb; |
| 302 size_t size = AllocSize(info, &rb); |
| 303 if (0 == size) { |
| 304 return false; |
| 305 } |
| 306 void* pixels = sk_malloc_flags(size, 0); |
| 307 if (nullptr == pixels) { |
| 308 return false; |
| 309 } |
| 310 this->reset(info, pixels, rb); |
| 311 fStorage = pixels; |
| 312 return true; |
| 313 } |
| 314 |
| 315 void SkAutoPixmapStorage::alloc(const SkImageInfo& info) { |
| 316 if (!this->tryAlloc(info)) { |
| 317 sk_throw(); |
| 318 } |
| 319 } |
| 320 |
| 321 const SkData* SkAutoPixmapStorage::detachPixelsAsData() { |
| 322 if (!fStorage) { |
| 323 return nullptr; |
| 324 } |
| 325 |
| 326 auto data = SkData::MakeFromMalloc(fStorage, this->getSafeSize()); |
| 327 fStorage = nullptr; |
| 328 this->INHERITED::reset(); |
| 329 |
| 330 return data.release(); |
| 331 } |
OLD | NEW |