blob: 32213a1841fe2cedcfdb66b10ae7160d3393f3e2 [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"
12
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000013SK_DEFINE_INST_COUNT(GrSurface)
commit-bot@chromium.org6c5d9a12013-09-30 18:05:43 +000014
15bool GrSurface::savePixels(const char* filename) {
16 SkBitmap bm;
17 bm.setConfig(SkBitmap::kARGB_8888_Config, this->width(), this->height());
18 bm.allocPixels();
19
skia.committer@gmail.com1d3bfdc2013-10-01 07:01:46 +000020 bool result = readPixels(0, 0, this->width(), this->height(), kSkia8888_GrPixelConfig,
commit-bot@chromium.org6c5d9a12013-09-30 18:05:43 +000021 bm.getPixels());
22 if (!result) {
23 SkDebugf("------ failed to read pixels for %s\n", filename);
24 return false;
25 }
skia.committer@gmail.com1d3bfdc2013-10-01 07:01:46 +000026
commit-bot@chromium.org6c5d9a12013-09-30 18:05:43 +000027 // remove any previous version of this file
28 remove(filename);
29
30 if (!SkImageEncoder::EncodeFile(filename, bm, SkImageEncoder::kPNG_Type, 100)) {
31 SkDebugf("------ failed to encode %s\n", filename);
32 remove(filename); // remove any partial file
33 return false;
34 }
35
36 return true;
37}