Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(278)

Side by Side Diff: src/gpu/GrSurface.cpp

Issue 68973005: Expand pixelref to return SkImageInfo and rowbytes (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: new convention: require SkImageInfo in constructor Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "SkGr.h"
11 #include "SkImageEncoder.h" 12 #include "SkImageEncoder.h"
12 #include <stdio.h> 13 #include <stdio.h>
13 14
14 SK_DEFINE_INST_COUNT(GrSurface) 15 SK_DEFINE_INST_COUNT(GrSurface)
15 16
17 void GrSurface::asImageInfo(SkImageInfo* info) const {
18 if (!GrPixelConfig2ColorType(this->config(), &info->fColorType)) {
19 sk_throw();
20 }
21 info->fWidth = this->width();
22 info->fHeight = this->height();
23 info->fAlphaType = kPremul_SkAlphaType;
24 }
25
16 bool GrSurface::savePixels(const char* filename) { 26 bool GrSurface::savePixels(const char* filename) {
17 SkBitmap bm; 27 SkBitmap bm;
18 bm.setConfig(SkBitmap::kARGB_8888_Config, this->width(), this->height()); 28 bm.setConfig(SkBitmap::kARGB_8888_Config, this->width(), this->height());
19 bm.allocPixels(); 29 bm.allocPixels();
20 30
21 bool result = readPixels(0, 0, this->width(), this->height(), kSkia8888_GrPi xelConfig, 31 bool result = readPixels(0, 0, this->width(), this->height(), kSkia8888_GrPi xelConfig,
22 bm.getPixels()); 32 bm.getPixels());
23 if (!result) { 33 if (!result) {
24 SkDebugf("------ failed to read pixels for %s\n", filename); 34 SkDebugf("------ failed to read pixels for %s\n", filename);
25 return false; 35 return false;
26 } 36 }
27 37
28 // remove any previous version of this file 38 // remove any previous version of this file
29 remove(filename); 39 remove(filename);
30 40
31 if (!SkImageEncoder::EncodeFile(filename, bm, SkImageEncoder::kPNG_Type, 100 )) { 41 if (!SkImageEncoder::EncodeFile(filename, bm, SkImageEncoder::kPNG_Type, 100 )) {
32 SkDebugf("------ failed to encode %s\n", filename); 42 SkDebugf("------ failed to encode %s\n", filename);
33 remove(filename); // remove any partial file 43 remove(filename); // remove any partial file
34 return false; 44 return false;
35 } 45 }
36 46
37 return true; 47 return true;
38 } 48 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698