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

Side by Side Diff: src/gpu/GrSurface.cpp

Issue 510423005: make allocPixels throw on failure (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 6 years, 3 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/gpu/GrSWMaskHelper.cpp ('k') | src/gpu/SkGrPixelRef.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "GrSurface.h" 8 #include "GrSurface.h"
9 9
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
11 #include "SkGr.h" 11 #include "SkGr.h"
12 #include "SkImageEncoder.h" 12 #include "SkImageEncoder.h"
13 #include <stdio.h> 13 #include <stdio.h>
14 14
15 SkImageInfo GrSurface::info() const { 15 SkImageInfo GrSurface::info() const {
16 SkImageInfo info; 16 SkImageInfo info;
17 if (!GrPixelConfig2ColorType(this->config(), &info.fColorType)) { 17 if (!GrPixelConfig2ColorType(this->config(), &info.fColorType)) {
18 sk_throw(); 18 sk_throw();
19 } 19 }
20 info.fWidth = this->width(); 20 info.fWidth = this->width();
21 info.fHeight = this->height(); 21 info.fHeight = this->height();
22 info.fAlphaType = kPremul_SkAlphaType; 22 info.fAlphaType = kPremul_SkAlphaType;
23 return info; 23 return info;
24 } 24 }
25 25
26 bool GrSurface::savePixels(const char* filename) { 26 bool GrSurface::savePixels(const char* filename) {
27 SkBitmap bm; 27 SkBitmap bm;
28 if (!bm.allocPixels(SkImageInfo::MakeN32Premul(this->width(), 28 if (!bm.tryAllocPixels(SkImageInfo::MakeN32Premul(this->width(), this->heigh t()))) {
29 this->height()))) {
30 return false; 29 return false;
31 } 30 }
32 31
33 bool result = readPixels(0, 0, this->width(), this->height(), kSkia8888_GrPi xelConfig, 32 bool result = readPixels(0, 0, this->width(), this->height(), kSkia8888_GrPi xelConfig,
34 bm.getPixels()); 33 bm.getPixels());
35 if (!result) { 34 if (!result) {
36 SkDebugf("------ failed to read pixels for %s\n", filename); 35 SkDebugf("------ failed to read pixels for %s\n", filename);
37 return false; 36 return false;
38 } 37 }
39 38
40 // remove any previous version of this file 39 // remove any previous version of this file
41 remove(filename); 40 remove(filename);
42 41
43 if (!SkImageEncoder::EncodeFile(filename, bm, SkImageEncoder::kPNG_Type, 100 )) { 42 if (!SkImageEncoder::EncodeFile(filename, bm, SkImageEncoder::kPNG_Type, 100 )) {
44 SkDebugf("------ failed to encode %s\n", filename); 43 SkDebugf("------ failed to encode %s\n", filename);
45 remove(filename); // remove any partial file 44 remove(filename); // remove any partial file
46 return false; 45 return false;
47 } 46 }
48 47
49 return true; 48 return true;
50 } 49 }
OLDNEW
« no previous file with comments | « src/gpu/GrSWMaskHelper.cpp ('k') | src/gpu/SkGrPixelRef.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698