blob: 3ac8bc2280ce7255aef93d979c6503abd7159b80 [file] [log] [blame]
robertphillips@google.com7d501ab2012-06-21 21:09:06 +00001/*
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.org6c5d9a12013-09-30 18:05:43 +000010#include "SkBitmap.h"
11#include "SkImageEncoder.h"
bungeman@google.comfab44db2013-10-11 18:50:45 +000012#include <stdio.h>
commit-bot@chromium.org6c5d9a12013-09-30 18:05:43 +000013
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000014SK_DEFINE_INST_COUNT(GrSurface)
commit-bot@chromium.org6c5d9a12013-09-30 18:05:43 +000015
16bool GrSurface::savePixels(const char* filename) {
17 SkBitmap bm;
18 bm.setConfig(SkBitmap::kARGB_8888_Config, this->width(), this->height());
19 bm.allocPixels();
20
skia.committer@gmail.com1d3bfdc2013-10-01 07:01:46 +000021 bool result = readPixels(0, 0, this->width(), this->height(), kSkia8888_GrPixelConfig,
commit-bot@chromium.org6c5d9a12013-09-30 18:05:43 +000022 bm.getPixels());
23 if (!result) {
24 SkDebugf("------ failed to read pixels for %s\n", filename);
25 return false;
26 }
skia.committer@gmail.com1d3bfdc2013-10-01 07:01:46 +000027
commit-bot@chromium.org6c5d9a12013-09-30 18:05:43 +000028 // remove any previous version of this file
29 remove(filename);
30
31 if (!SkImageEncoder::EncodeFile(filename, bm, SkImageEncoder::kPNG_Type, 100)) {
32 SkDebugf("------ failed to encode %s\n", filename);
33 remove(filename); // remove any partial file
34 return false;
35 }
36
37 return true;
38}