| Index: src/ports/SkImagesSupport_default.cpp
|
| diff --git a/src/ports/SkImagesSupport_default.cpp b/src/ports/SkImagesSupport_default.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..bf752d61703a1094bfcc94bdd3036529743b0a51
|
| --- /dev/null
|
| +++ b/src/ports/SkImagesSupport_default.cpp
|
| @@ -0,0 +1,44 @@
|
| +/*
|
| + * Copyright 2014 Google Inc.
|
| + *
|
| + * Use of this source code is governed by a BSD-style license that can be
|
| + * found in the LICENSE file.
|
| + */
|
| +
|
| +#include "SkImagesSupport.h"
|
| +
|
| +#if SK_SUPPORT_GPU && defined(SK_DEVELOPER)
|
| +#include "GrSurface.h"
|
| +#include "SkBitmap.h"
|
| +#include "SkImageEncoder.h"
|
| +#include <stdio.h>
|
| +#endif
|
| +
|
| +// This file should be compiled to images library when images library is part of the Skia library.
|
| +
|
| +#if SK_SUPPORT_GPU && defined(SK_DEVELOPER)
|
| +bool SkSaveGrSurfacePixelsAsPNG(GrSurface* surface, const char* filename) {
|
| + SkBitmap bm;
|
| + if (!bm.tryAllocPixels(SkImageInfo::MakeN32Premul(surface->width(), surface->height()))) {
|
| + return false;
|
| + }
|
| +
|
| + bool result = surface->readPixels(0, 0, surface->width(), surface->height(), kSkia8888_GrPixelConfig,
|
| + bm.getPixels());
|
| + if (!result) {
|
| + SkDebugf("------ failed to read pixels for %s\n", filename);
|
| + return false;
|
| + }
|
| +
|
| + // remove any previous version of surface file
|
| + remove(filename);
|
| +
|
| + if (!SkImageEncoder::EncodeFile(filename, bm, SkImageEncoder::kPNG_Type, 100)) {
|
| + SkDebugf("------ failed to encode %s\n", filename);
|
| + remove(filename); // remove any partial file
|
| + return false;
|
| + }
|
| +
|
| + return true;
|
| +}
|
| +#endif
|
|
|