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

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

Issue 143073008: add installPixels (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase Created 6 years, 11 months 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
« no previous file with comments | « src/gpu/GrSWMaskHelper.cpp ('k') | src/gpu/SkGrPixelRef.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "SkGr.h"
12 #include "SkImageEncoder.h" 12 #include "SkImageEncoder.h"
13 #include <stdio.h> 13 #include <stdio.h>
14 14
15 void GrSurface::asImageInfo(SkImageInfo* info) const { 15 void GrSurface::asImageInfo(SkImageInfo* info) const {
16 if (!GrPixelConfig2ColorType(this->config(), &info->fColorType)) { 16 if (!GrPixelConfig2ColorType(this->config(), &info->fColorType)) {
17 sk_throw(); 17 sk_throw();
18 } 18 }
19 info->fWidth = this->width(); 19 info->fWidth = this->width();
20 info->fHeight = this->height(); 20 info->fHeight = this->height();
21 info->fAlphaType = kPremul_SkAlphaType; 21 info->fAlphaType = kPremul_SkAlphaType;
22 } 22 }
23 23
24 bool GrSurface::savePixels(const char* filename) { 24 bool GrSurface::savePixels(const char* filename) {
25 SkBitmap bm; 25 SkBitmap bm;
26 bm.setConfig(SkBitmap::kARGB_8888_Config, this->width(), this->height()); 26 if (!bm.allocPixels(SkImageInfo::MakeN32Premul(this->width(),
27 bm.allocPixels(); 27 this->height()))) {
28 return false;
29 }
28 30
29 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,
30 bm.getPixels()); 32 bm.getPixels());
31 if (!result) { 33 if (!result) {
32 SkDebugf("------ failed to read pixels for %s\n", filename); 34 SkDebugf("------ failed to read pixels for %s\n", filename);
33 return false; 35 return false;
34 } 36 }
35 37
36 // remove any previous version of this file 38 // remove any previous version of this file
37 remove(filename); 39 remove(filename);
38 40
39 if (!SkImageEncoder::EncodeFile(filename, bm, SkImageEncoder::kPNG_Type, 100 )) { 41 if (!SkImageEncoder::EncodeFile(filename, bm, SkImageEncoder::kPNG_Type, 100 )) {
40 SkDebugf("------ failed to encode %s\n", filename); 42 SkDebugf("------ failed to encode %s\n", filename);
41 remove(filename); // remove any partial file 43 remove(filename); // remove any partial file
42 return false; 44 return false;
43 } 45 }
44 46
45 return true; 47 return true;
46 } 48 }
OLDNEW
« no previous file with comments | « src/gpu/GrSWMaskHelper.cpp ('k') | src/gpu/SkGrPixelRef.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698