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

Unified Diff: src/ports/SkImagesSupport_default.cpp

Issue 665913002: Move code to dump GrSurface as a png to helper files (Closed) Base URL: https://skia.googlesource.com/skia.git@separate-image-encoder-01-skimage
Patch Set: address review comments Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/GrTextStrike.cpp ('k') | src/ports/SkImagesSupport_noimages.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « src/gpu/GrTextStrike.cpp ('k') | src/ports/SkImagesSupport_noimages.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698