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 "GrSurface.h" | 8 #include "GrSurface.h" |
9 | 9 |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
11 #include "SkImageEncoder.h" | 11 #include "SkImageEncoder.h" |
12 #include <stdio.h> | 12 #include <stdio.h> |
13 | 13 |
14 SK_DEFINE_INST_COUNT(GrSurface) | |
15 | |
16 bool GrSurface::savePixels(const char* filename) { | 14 bool GrSurface::savePixels(const char* filename) { |
17 SkBitmap bm; | 15 SkBitmap bm; |
18 bm.setConfig(SkBitmap::kARGB_8888_Config, this->width(), this->height()); | 16 bm.setConfig(SkBitmap::kARGB_8888_Config, this->width(), this->height()); |
19 bm.allocPixels(); | 17 bm.allocPixels(); |
20 | 18 |
21 bool result = readPixels(0, 0, this->width(), this->height(), kSkia8888_GrPi
xelConfig, | 19 bool result = readPixels(0, 0, this->width(), this->height(), kSkia8888_GrPi
xelConfig, |
22 bm.getPixels()); | 20 bm.getPixels()); |
23 if (!result) { | 21 if (!result) { |
24 SkDebugf("------ failed to read pixels for %s\n", filename); | 22 SkDebugf("------ failed to read pixels for %s\n", filename); |
25 return false; | 23 return false; |
26 } | 24 } |
27 | 25 |
28 // remove any previous version of this file | 26 // remove any previous version of this file |
29 remove(filename); | 27 remove(filename); |
30 | 28 |
31 if (!SkImageEncoder::EncodeFile(filename, bm, SkImageEncoder::kPNG_Type, 100
)) { | 29 if (!SkImageEncoder::EncodeFile(filename, bm, SkImageEncoder::kPNG_Type, 100
)) { |
32 SkDebugf("------ failed to encode %s\n", filename); | 30 SkDebugf("------ failed to encode %s\n", filename); |
33 remove(filename); // remove any partial file | 31 remove(filename); // remove any partial file |
34 return false; | 32 return false; |
35 } | 33 } |
36 | 34 |
37 return true; | 35 return true; |
38 } | 36 } |
OLD | NEW |