| OLD | NEW | 
|   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 SkImageInfo GrSurface::info() const { | 
|  16     if (!GrPixelConfig2ColorType(this->config(), &info->fColorType)) { |  16     SkImageInfo info; | 
 |  17     if (!GrPixelConfig2ColorType(this->config(), &info.fColorType)) { | 
|  17         sk_throw(); |  18         sk_throw(); | 
|  18     } |  19     } | 
|  19     info->fWidth = this->width(); |  20     info.fWidth = this->width(); | 
|  20     info->fHeight = this->height(); |  21     info.fHeight = this->height(); | 
|  21     info->fAlphaType = kPremul_SkAlphaType; |  22     info.fAlphaType = kPremul_SkAlphaType; | 
 |  23     return info; | 
|  22 } |  24 } | 
|  23  |  25  | 
|  24 bool GrSurface::savePixels(const char* filename) { |  26 bool GrSurface::savePixels(const char* filename) { | 
|  25     SkBitmap bm; |  27     SkBitmap bm; | 
|  26     if (!bm.allocPixels(SkImageInfo::MakeN32Premul(this->width(), |  28     if (!bm.allocPixels(SkImageInfo::MakeN32Premul(this->width(), | 
|  27                                                    this->height()))) { |  29                                                    this->height()))) { | 
|  28         return false; |  30         return false; | 
|  29     } |  31     } | 
|  30  |  32  | 
|  31     bool result = readPixels(0, 0, this->width(), this->height(), kSkia8888_GrPi
    xelConfig, |  33     bool result = readPixels(0, 0, this->width(), this->height(), kSkia8888_GrPi
    xelConfig, | 
|  32                              bm.getPixels()); |  34                              bm.getPixels()); | 
|  33     if (!result) { |  35     if (!result) { | 
|  34         SkDebugf("------ failed to read pixels for %s\n", filename); |  36         SkDebugf("------ failed to read pixels for %s\n", filename); | 
|  35         return false; |  37         return false; | 
|  36     } |  38     } | 
|  37  |  39  | 
|  38     // remove any previous version of this file |  40     // remove any previous version of this file | 
|  39     remove(filename); |  41     remove(filename); | 
|  40  |  42  | 
|  41     if (!SkImageEncoder::EncodeFile(filename, bm, SkImageEncoder::kPNG_Type, 100
    )) { |  43     if (!SkImageEncoder::EncodeFile(filename, bm, SkImageEncoder::kPNG_Type, 100
    )) { | 
|  42         SkDebugf("------ failed to encode %s\n", filename); |  44         SkDebugf("------ failed to encode %s\n", filename); | 
|  43         remove(filename);   // remove any partial file |  45         remove(filename);   // remove any partial file | 
|  44         return false; |  46         return false; | 
|  45     } |  47     } | 
|  46  |  48  | 
|  47     return true; |  49     return true; | 
|  48 } |  50 } | 
| OLD | NEW |