OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2014 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 "SkImagesSupport.h" |
| 9 |
| 10 #if SK_SUPPORT_GPU && defined(SK_DEVELOPER) |
| 11 #include "GrSurface.h" |
| 12 #include "SkBitmap.h" |
| 13 #include "SkImageEncoder.h" |
| 14 #include <stdio.h> |
| 15 #endif |
| 16 |
| 17 // This file should be compiled to images library when images library is part of
the Skia library. |
| 18 |
| 19 #if SK_SUPPORT_GPU && defined(SK_DEVELOPER) |
| 20 bool SkSaveGrSurfacePixelsAsPNG(GrSurface* surface, const char* filename) { |
| 21 SkBitmap bm; |
| 22 if (!bm.tryAllocPixels(SkImageInfo::MakeN32Premul(surface->width(), surface-
>height()))) { |
| 23 return false; |
| 24 } |
| 25 |
| 26 bool result = surface->readPixels(0, 0, surface->width(), surface->height(),
kSkia8888_GrPixelConfig, |
| 27 bm.getPixels()); |
| 28 if (!result) { |
| 29 SkDebugf("------ failed to read pixels for %s\n", filename); |
| 30 return false; |
| 31 } |
| 32 |
| 33 // remove any previous version of surface file |
| 34 remove(filename); |
| 35 |
| 36 if (!SkImageEncoder::EncodeFile(filename, bm, SkImageEncoder::kPNG_Type, 100
)) { |
| 37 SkDebugf("------ failed to encode %s\n", filename); |
| 38 remove(filename); // remove any partial file |
| 39 return false; |
| 40 } |
| 41 |
| 42 return true; |
| 43 } |
| 44 #endif |
OLD | NEW |