Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: src/core/SkAutoPixmapStorage.cpp

Issue 1787883002: Add SkSpecialImage::extractSubset & NewFromPixmap (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Update to ToT Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkAutoPixmapStorage.h ('k') | src/core/SkPixmap.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1
2 /*
3 * Copyright 2016 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9 #include "SkAutoPixmapStorage.h"
10 #include "SkData.h"
11
12 SkAutoPixmapStorage::SkAutoPixmapStorage() : fStorage(nullptr) {}
13
14 SkAutoPixmapStorage::~SkAutoPixmapStorage() {
15 this->freeStorage();
16 }
17
18 size_t SkAutoPixmapStorage::AllocSize(const SkImageInfo& info, size_t* rowBytes) {
19 size_t rb = info.minRowBytes();
20 if (rowBytes) {
21 *rowBytes = rb;
22 }
23 return info.getSafeSize(rb);
24 }
25
26 bool SkAutoPixmapStorage::tryAlloc(const SkImageInfo& info) {
27 this->freeStorage();
28
29 size_t rb;
30 size_t size = AllocSize(info, &rb);
31 if (0 == size) {
32 return false;
33 }
34 void* pixels = sk_malloc_flags(size, 0);
35 if (nullptr == pixels) {
36 return false;
37 }
38 this->reset(info, pixels, rb);
39 fStorage = pixels;
40 return true;
41 }
42
43 void SkAutoPixmapStorage::alloc(const SkImageInfo& info) {
44 if (!this->tryAlloc(info)) {
45 sk_throw();
46 }
47 }
48
49 const SkData* SkAutoPixmapStorage::detachPixelsAsData() {
50 if (!fStorage) {
51 return nullptr;
52 }
53
54 auto data = SkData::MakeFromMalloc(fStorage, this->getSafeSize());
55 fStorage = nullptr;
56 this->INHERITED::reset();
57
58 return data.release();
59 }
60
61 void SkAutoPixmapStorage::release() {
62 fStorage = nullptr;
63 this->INHERITED::reset();
64 }
OLDNEW
« no previous file with comments | « src/core/SkAutoPixmapStorage.h ('k') | src/core/SkPixmap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698