aboutsummaryrefslogtreecommitdiffhomepage
path: root/samplecode
diff options
context:
space:
mode:
authorGravatar halcanary@google.com <halcanary@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-01-10 14:53:49 +0000
committerGravatar halcanary@google.com <halcanary@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-01-10 14:53:49 +0000
commit9acb8cdf20423e80d5687ba3c8e11545e3bc8020 (patch)
tree4f40494195f6c4d41ab3925c6e4f0ff376eeaec4 /samplecode
parent6791138dc0a2dc4bb77eebfd56da408104c18eab (diff)
SampleApp Cleanup:
- Set resoursePath to sensible default. - Remove verbosity of DitherBitmap. - SampleEncode no longer tries to mkdir('/encoded'), now stores encoded data in memory and uses the SkDecodingImageGenerator to decode. BUG= R=reed@google.com Review URL: https://codereview.chromium.org/132513003 git-svn-id: http://skia.googlecode.com/svn/trunk@13015 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'samplecode')
-rw-r--r--samplecode/SampleApp.cpp2
-rw-r--r--samplecode/SampleDitherBitmap.cpp16
-rw-r--r--samplecode/SampleEncode.cpp77
3 files changed, 58 insertions, 37 deletions
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp
index 010fc2553c..d5fe18217f 100644
--- a/samplecode/SampleApp.cpp
+++ b/samplecode/SampleApp.cpp
@@ -815,7 +815,7 @@ SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev
SkTQSort(fSamples.begin(), fSamples.end() ? fSamples.end() - 1 : NULL, compareSampleTitle);
}
- const char* resourcePath = NULL;
+ const char* resourcePath = "resources"; // same default as tests
fMSAASampleCount = 0;
const char* const commandName = argv[0];
diff --git a/samplecode/SampleDitherBitmap.cpp b/samplecode/SampleDitherBitmap.cpp
index 9132ceb195..dc439002d0 100644
--- a/samplecode/SampleDitherBitmap.cpp
+++ b/samplecode/SampleDitherBitmap.cpp
@@ -37,7 +37,7 @@ static void draw_gradient(SkCanvas* canvas) {
draw_rect(canvas, r, p);
}
-static void test_pathregion() {
+static bool test_pathregion() {
SkPath path;
SkRegion region;
path.moveTo(25071800.f, -141823808.f);
@@ -49,8 +49,7 @@ static void test_pathregion() {
SkIRect bounds;
path.getBounds().round(&bounds);
SkRegion clip(bounds);
- bool result = region.setPath(path, clip); // <-- !! DOWN !!
- SkDebugf("----- result %d\n", result);
+ return region.setPath(path, clip); // <-- !! DOWN !!
}
static SkBitmap make_bitmap() {
@@ -79,9 +78,10 @@ static SkBitmap make_bitmap() {
class DitherBitmapView : public SampleView {
SkBitmap fBM8;
SkBitmap fBM32;
+ bool fResult;
public:
DitherBitmapView() {
- test_pathregion();
+ fResult = test_pathregion();
fBM8 = make_bitmap();
fBM8.copyTo(&fBM32, SkBitmap::kARGB_8888_Config);
@@ -138,6 +138,14 @@ protected:
canvas->translate(0, SkIntToScalar(fBM8.height() *3));
draw_gradient(canvas);
+
+ char resultTrue[] = "SkRegion::setPath returned true";
+ char resultFalse[] = "SkRegion::setPath returned false";
+ SkPaint p;
+ if (fResult)
+ canvas->drawText(resultTrue, sizeof(resultTrue) - 1, 0, 50, p);
+ else
+ canvas->drawText(resultFalse, sizeof(resultFalse) - 1, 0, 50, p);
}
private:
diff --git a/samplecode/SampleEncode.cpp b/samplecode/SampleEncode.cpp
index 594c2a1644..45666a3b06 100644
--- a/samplecode/SampleEncode.cpp
+++ b/samplecode/SampleEncode.cpp
@@ -8,6 +8,8 @@
#include "SampleCode.h"
#include "SkView.h"
#include "SkCanvas.h"
+#include "SkData.h"
+#include "SkDecodingImageGenerator.h"
#include "SkGradientShader.h"
#include "SkGraphics.h"
#include "SkImageDecoder.h"
@@ -103,44 +105,43 @@ static const char* const gExt[] = {
".jpg", ".png"
};
-static const char* gPath = "/encoded/";
-
-static void make_name(SkString* name, int config, int ext) {
- name->set(gPath);
- name->append(gConfigLabels[config]);
- name->append(gExt[ext]);
-}
-
#include <sys/stat.h>
class EncodeView : public SampleView {
public:
- SkBitmap* fBitmaps;
- size_t fBitmapCount;
+ SkBitmap* fBitmaps;
+ SkAutoDataUnref* fEncodedPNGs;
+ SkAutoDataUnref* fEncodedJPEGs;
+ size_t fBitmapCount;
EncodeView() {
#if 1
- (void)mkdir(gPath, S_IRWXU | S_IRWXG | S_IRWXO);
-
fBitmapCount = SK_ARRAY_COUNT(gConfigs);
fBitmaps = new SkBitmap[fBitmapCount];
+ fEncodedPNGs = new SkAutoDataUnref[fBitmapCount];
+ fEncodedJPEGs = new SkAutoDataUnref[fBitmapCount];
for (size_t i = 0; i < fBitmapCount; i++) {
make_image(&fBitmaps[i], gConfigs[i], i);
- for (size_t j = 0; j < SK_ARRAY_COUNT(gExt); j++) {
- SkString path;
- make_name(&path, i, j);
-
- // remove any previous run of this file
- remove(path.c_str());
-
- SkImageEncoder* codec = SkImageEncoder::Create(gTypes[j]);
- if (NULL == codec ||
- !codec->encodeFile(path.c_str(), fBitmaps[i], 100)) {
- SkDebugf("------ failed to encode %s\n", path.c_str());
- remove(path.c_str()); // remove any partial file
+ for (size_t j = 0; j < SK_ARRAY_COUNT(gTypes); j++) {
+ SkAutoTDelete<SkImageEncoder> codec(
+ SkImageEncoder::Create(gTypes[j]));
+ if (NULL == codec.get()) {
+ SkDebugf("[%s:%d] failed to encode %s%s\n",
+ __FILE__, __LINE__,gConfigLabels[i], gExt[j]);
+ continue;
+ }
+ SkAutoDataUnref data(codec->encodeData(fBitmaps[i], 100));
+ if (NULL == data.get()) {
+ SkDebugf("[%s:%d] failed to encode %s%s\n",
+ __FILE__, __LINE__,gConfigLabels[i], gExt[j]);
+ continue;
+ }
+ if (SkImageEncoder::kJPEG_Type == gTypes[j]) {
+ fEncodedJPEGs[i].reset(data.detach());
+ } else if (SkImageEncoder::kPNG_Type == gTypes[j]) {
+ fEncodedPNGs[i].reset(data.detach());
}
- delete codec;
}
}
#else
@@ -152,6 +153,8 @@ public:
virtual ~EncodeView() {
delete[] fBitmaps;
+ delete[] fEncodedPNGs;
+ delete[] fEncodedJPEGs;
}
protected:
@@ -187,16 +190,26 @@ protected:
canvas->drawBitmap(fBitmaps[i], x, y);
SkScalar yy = y;
- for (size_t j = 0; j < SK_ARRAY_COUNT(gExt); j++) {
+ for (size_t j = 0; j < SK_ARRAY_COUNT(gTypes); j++) {
yy += SkIntToScalar(fBitmaps[i].height() + 10);
SkBitmap bm;
- SkString name;
-
- make_name(&name, i, j);
-
- SkImageDecoder::DecodeFile(name.c_str(), &bm);
- canvas->drawBitmap(bm, x, yy);
+ SkData* encoded = NULL;
+ if (SkImageEncoder::kJPEG_Type == gTypes[j]) {
+ encoded = fEncodedJPEGs[i].get();
+ } else if (SkImageEncoder::kPNG_Type == gTypes[j]) {
+ encoded = fEncodedPNGs[i].get();
+ }
+ if (encoded) {
+ if (!SkInstallDiscardablePixelRef(
+ SkDecodingImageGenerator::Create(encoded,
+ SkDecodingImageGenerator::Options()),
+ &bm, NULL)) {
+ SkDebugf("[%s:%d] failed to decode %s%s\n",
+ __FILE__, __LINE__,gConfigLabels[i], gExt[j]);
+ }
+ canvas->drawBitmap(bm, x, yy);
+ }
}
x += SkIntToScalar(fBitmaps[i].width() + SPACER);