michael@0: /* michael@0: * Copyright 2012 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #include "GrSurface.h" michael@0: michael@0: #include "SkBitmap.h" michael@0: #include "SkGr.h" michael@0: #include "SkImageEncoder.h" michael@0: #include michael@0: michael@0: void GrSurface::asImageInfo(SkImageInfo* info) const { michael@0: if (!GrPixelConfig2ColorType(this->config(), &info->fColorType)) { michael@0: sk_throw(); michael@0: } michael@0: info->fWidth = this->width(); michael@0: info->fHeight = this->height(); michael@0: info->fAlphaType = kPremul_SkAlphaType; michael@0: } michael@0: michael@0: bool GrSurface::savePixels(const char* filename) { michael@0: SkBitmap bm; michael@0: if (!bm.allocPixels(SkImageInfo::MakeN32Premul(this->width(), michael@0: this->height()))) { michael@0: return false; michael@0: } michael@0: michael@0: bool result = readPixels(0, 0, this->width(), this->height(), kSkia8888_GrPixelConfig, michael@0: bm.getPixels()); michael@0: if (!result) { michael@0: SkDebugf("------ failed to read pixels for %s\n", filename); michael@0: return false; michael@0: } michael@0: michael@0: // remove any previous version of this file michael@0: remove(filename); michael@0: michael@0: if (!SkImageEncoder::EncodeFile(filename, bm, SkImageEncoder::kPNG_Type, 100)) { michael@0: SkDebugf("------ failed to encode %s\n", filename); michael@0: remove(filename); // remove any partial file michael@0: return false; michael@0: } michael@0: michael@0: return true; michael@0: }