robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "GrSurface.h" |
| 9 | |
commit-bot@chromium.org | 6c5d9a1 | 2013-09-30 18:05:43 +0000 | [diff] [blame] | 10 | #include "SkBitmap.h" |
| 11 | #include "SkImageEncoder.h" |
bungeman@google.com | fab44db | 2013-10-11 18:50:45 +0000 | [diff] [blame] | 12 | #include <stdio.h> |
commit-bot@chromium.org | 6c5d9a1 | 2013-09-30 18:05:43 +0000 | [diff] [blame] | 13 | |
commit-bot@chromium.org | 6c5d9a1 | 2013-09-30 18:05:43 +0000 | [diff] [blame] | 14 | bool GrSurface::savePixels(const char* filename) { |
| 15 | SkBitmap bm; |
| 16 | bm.setConfig(SkBitmap::kARGB_8888_Config, this->width(), this->height()); |
| 17 | bm.allocPixels(); |
| 18 | |
skia.committer@gmail.com | 1d3bfdc | 2013-10-01 07:01:46 +0000 | [diff] [blame] | 19 | bool result = readPixels(0, 0, this->width(), this->height(), kSkia8888_GrPixelConfig, |
commit-bot@chromium.org | 6c5d9a1 | 2013-09-30 18:05:43 +0000 | [diff] [blame] | 20 | bm.getPixels()); |
| 21 | if (!result) { |
| 22 | SkDebugf("------ failed to read pixels for %s\n", filename); |
| 23 | return false; |
| 24 | } |
skia.committer@gmail.com | 1d3bfdc | 2013-10-01 07:01:46 +0000 | [diff] [blame] | 25 | |
commit-bot@chromium.org | 6c5d9a1 | 2013-09-30 18:05:43 +0000 | [diff] [blame] | 26 | // remove any previous version of this file |
| 27 | remove(filename); |
| 28 | |
| 29 | if (!SkImageEncoder::EncodeFile(filename, bm, SkImageEncoder::kPNG_Type, 100)) { |
| 30 | SkDebugf("------ failed to encode %s\n", filename); |
| 31 | remove(filename); // remove any partial file |
| 32 | return false; |
| 33 | } |
| 34 | |
| 35 | return true; |
| 36 | } |