aboutsummaryrefslogtreecommitdiffhomepage
path: root/samplecode
diff options
context:
space:
mode:
authorGravatar reed <reed@chromium.org>2015-09-12 09:55:30 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-09-12 09:55:30 -0700
commit94cf37f425adf41815ae60abbff2db50563fd373 (patch)
tree0f86b3efd197aa657b424c17a1aa244fdeb8c696 /samplecode
parent94475cdbfb4bb07b12ef0d5f18db4c4375e357cc (diff)
remove obsolete samples
BUG=skia: TBR= Review URL: https://codereview.chromium.org/1340793002
Diffstat (limited to 'samplecode')
-rw-r--r--samplecode/SampleEncode.cpp233
-rw-r--r--samplecode/SamplePicture.cpp179
2 files changed, 0 insertions, 412 deletions
diff --git a/samplecode/SampleEncode.cpp b/samplecode/SampleEncode.cpp
deleted file mode 100644
index 9ca7d8ae46..0000000000
--- a/samplecode/SampleEncode.cpp
+++ /dev/null
@@ -1,233 +0,0 @@
-
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-#include "SampleCode.h"
-#include "SkView.h"
-#include "SkCanvas.h"
-#include "SkData.h"
-#include "SkImageGenerator.h"
-#include "SkGradientShader.h"
-#include "SkGraphics.h"
-#include "SkImageDecoder.h"
-#include "SkImageEncoder.h"
-#include "SkPath.h"
-#include "SkRegion.h"
-#include "SkShader.h"
-#include "SkUtils.h"
-#include "SkXfermode.h"
-#include "SkColorPriv.h"
-#include "SkColorFilter.h"
-#include "SkTime.h"
-#include "SkTypeface.h"
-
-#include "SkStream.h"
-
-static void make_image(SkBitmap* bm, SkColorType ct, int configIndex) {
- const int width = 98;
- const int height = 100;
- const SkImageInfo info = SkImageInfo::Make(width, height, ct, kPremul_SkAlphaType);
-
- SkBitmap device;
- device.allocN32Pixels(width, height);
- SkCanvas canvas(device);
- SkPaint paint;
-
- paint.setAntiAlias(true);
- canvas.drawColor(SK_ColorRED);
- paint.setColor(SK_ColorBLUE);
- canvas.drawCircle(SkIntToScalar(width)/2, SkIntToScalar(height)/2,
- SkIntToScalar(width)/2, paint);
-
- switch (ct) {
- case kN32_SkColorType:
- bm->swap(device);
- break;
- case kRGB_565_SkColorType: {
- bm->allocPixels(info);
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++) {
- *bm->getAddr16(x, y) = SkPixel32ToPixel16(*device.getAddr32(x, y));
- }
- }
- break;
- }
- case kIndex_8_SkColorType: {
- SkPMColor colors[256];
- for (int i = 0; i < 256; i++) {
- if (configIndex & 1) {
- colors[i] = SkPackARGB32(255-i, 0, 0, 255-i);
- } else {
- colors[i] = SkPackARGB32(0xFF, i, 0, 255-i);
- }
- }
- SkColorTable* ctable = new SkColorTable(colors, 256);
- bm->allocPixels(info, nullptr, ctable);
- ctable->unref();
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++) {
- *bm->getAddr8(x, y) = SkGetPackedR32(*device.getAddr32(x, y));
- }
- }
- break;
- }
- default:
- SkASSERT(0);
- }
-}
-
-// configs to build the original bitmap in. Can be at most these 3
-static const SkColorType gColorTypes[] = {
- kN32_SkColorType,
- kRGB_565_SkColorType,
- kIndex_8_SkColorType, // opaque
- kIndex_8_SkColorType // alpha
-};
-
-static const char* const gConfigLabels[] = {
- "8888", "565", "Index8", "Index8 alpha"
-};
-
-// types to encode into. Can be at most these 3. Must match up with gExt[]
-static const SkImageEncoder::Type gTypes[] = {
- SkImageEncoder::kJPEG_Type,
- SkImageEncoder::kPNG_Type
-};
-
-// must match up with gTypes[]
-static const char* const gExt[] = {
- ".jpg", ".png"
-};
-
-#include <sys/stat.h>
-
-class EncodeView : public SampleView {
-public:
- SkBitmap* fBitmaps;
- SkAutoDataUnref* fEncodedPNGs;
- SkAutoDataUnref* fEncodedJPEGs;
- int fBitmapCount;
-
- EncodeView() {
- fBitmapCount = SK_ARRAY_COUNT(gColorTypes);
- fBitmaps = new SkBitmap[fBitmapCount];
- fEncodedPNGs = new SkAutoDataUnref[fBitmapCount];
- fEncodedJPEGs = new SkAutoDataUnref[fBitmapCount];
- for (int i = 0; i < fBitmapCount; i++) {
- make_image(&fBitmaps[i], gColorTypes[i], i);
-
- for (size_t j = 0; j < SK_ARRAY_COUNT(gTypes); j++) {
- SkAutoTDelete<SkImageEncoder> codec(
- SkImageEncoder::Create(gTypes[j]));
- if (nullptr == 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 (nullptr == 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());
- }
- }
- }
- this->setBGColor(0xFFDDDDDD);
- }
-
- virtual ~EncodeView() {
- delete[] fBitmaps;
- delete[] fEncodedPNGs;
- delete[] fEncodedJPEGs;
- }
-
-protected:
- // overrides from SkEventSink
- virtual bool onQuery(SkEvent* evt) {
- if (SampleCode::TitleQ(*evt)) {
- SampleCode::TitleR(evt, "ImageEncoder");
- return true;
- }
- return this->INHERITED::onQuery(evt);
- }
-
- virtual void onDrawContent(SkCanvas* canvas) {
- if (fBitmapCount == 0) {
- return;
- }
-
- SkPaint paint;
- paint.setAntiAlias(true);
- paint.setTextAlign(SkPaint::kCenter_Align);
-
- canvas->translate(SkIntToScalar(10), SkIntToScalar(20));
-
- SkScalar x = 0, y = 0, maxX = 0;
- const int SPACER = 10;
-
- for (int i = 0; i < fBitmapCount; i++) {
- canvas->drawText(gConfigLabels[i], strlen(gConfigLabels[i]),
- x + SkIntToScalar(fBitmaps[i].width()) / 2, 0,
- paint);
- y = paint.getTextSize();
-
- canvas->drawBitmap(fBitmaps[i], x, y);
-
- SkScalar yy = y;
- for (size_t j = 0; j < SK_ARRAY_COUNT(gTypes); j++) {
- yy += SkIntToScalar(fBitmaps[i].height() + 10);
-
- SkBitmap bm;
- SkData* encoded = nullptr;
- 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(encoded, &bm)) {
- 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);
- if (x > maxX) {
- maxX = x;
- }
- }
-
- y = (paint.getTextSize() + SkIntToScalar(fBitmaps[0].height())) * 3 / 2;
- x = maxX + SkIntToScalar(10);
- paint.setTextAlign(SkPaint::kLeft_Align);
-
- for (size_t j = 0; j < SK_ARRAY_COUNT(gExt); j++) {
- canvas->drawText(gExt[j], strlen(gExt[j]), x, y, paint);
- y += SkIntToScalar(fBitmaps[0].height() + SPACER);
- }
- }
-
- virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y,
- unsigned modi) {
- this->inval(nullptr);
- return this->INHERITED::onFindClickHandler(x, y, modi);
- }
-
-private:
- typedef SampleView INHERITED;
-};
-
-//////////////////////////////////////////////////////////////////////////////
-
-static SkView* MyFactory() { return new EncodeView; }
-static SkViewRegister reg(MyFactory);
diff --git a/samplecode/SamplePicture.cpp b/samplecode/SamplePicture.cpp
deleted file mode 100644
index eb2cd733fe..0000000000
--- a/samplecode/SamplePicture.cpp
+++ /dev/null
@@ -1,179 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "gm.h"
-
-#include "Resources.h"
-#include "SampleCode.h"
-#include "SkCanvas.h"
-#include "SkColorFilter.h"
-#include "SkColorPriv.h"
-#include "SkData.h"
-#include "SkImageGenerator.h"
-#include "SkDumpCanvas.h"
-#include "SkGradientShader.h"
-#include "SkGraphics.h"
-#include "SkImageDecoder.h"
-#include "SkOSFile.h"
-#include "SkPath.h"
-#include "SkPicture.h"
-#include "SkPictureRecorder.h"
-#include "SkRandom.h"
-#include "SkRegion.h"
-#include "SkShader.h"
-#include "SkStream.h"
-#include "SkTime.h"
-#include "SkTypeface.h"
-#include "SkUtils.h"
-#include "SkView.h"
-#include "SkXMLParser.h"
-#include "SkXfermode.h"
-
-///////////////////////////////////////////////////////////////////////////////
-
-static SkBitmap load_bitmap() {
- SkBitmap bm;
- SkString pngFilename = GetResourcePath("mandrill_512.png");
- SkAutoDataUnref data(SkData::NewFromFileName(pngFilename.c_str()));
- if (data.get() != nullptr) {
- SkInstallDiscardablePixelRef(data, &bm);
- }
- return bm;
-}
-
-static void drawCircle(SkCanvas* canvas, int r, SkColor color) {
- SkPaint paint;
- paint.setAntiAlias(true);
- paint.setColor(color);
-
- canvas->drawCircle(SkIntToScalar(r), SkIntToScalar(r), SkIntToScalar(r),
- paint);
-}
-
-class PictureView : public SampleView {
- SkBitmap fBitmap;
-public:
- PictureView() {
-
- fBitmap = load_bitmap();
-
- SkPictureRecorder recorder;
-
- recorder.beginRecording(100, 100, nullptr, 0);
- fSubPicture = recorder.endRecording();
-
- SkCanvas* canvas = recorder.beginRecording(100, 100, nullptr, 0);
- SkPaint paint;
- paint.setAntiAlias(true);
-
- canvas->drawBitmap(fBitmap, 0, 0, nullptr);
-
- drawCircle(canvas, 50, SK_ColorBLACK);
- canvas->drawPicture(fSubPicture);
- canvas->translate(SkIntToScalar(50), 0);
- canvas->drawPicture(fSubPicture);
- canvas->translate(0, SkIntToScalar(50));
- canvas->drawPicture(fSubPicture);
- canvas->translate(SkIntToScalar(-50), 0);
- canvas->drawPicture(fSubPicture);
-
- fPicture = recorder.endRecording();
-
- // fPicture now has (4) references to fSubPicture. We can release our ref,
- // and just unref fPicture in our destructor, and it will in turn take care of
- // the other references to fSubPicture
- fSubPicture->unref();
- }
-
- virtual ~PictureView() {
- fPicture->unref();
- }
-
-protected:
- // overrides from SkEventSink
- bool onQuery(SkEvent* evt) override {
- if (SampleCode::TitleQ(*evt)) {
- SampleCode::TitleR(evt, "Picture");
- return true;
- }
- return this->INHERITED::onQuery(evt);
- }
-
- void drawSomething(SkCanvas* canvas) {
- SkPaint paint;
-
- canvas->save();
- canvas->scale(0.5f, 0.5f);
- canvas->drawBitmap(fBitmap, 0, 0, nullptr);
- canvas->restore();
-
- paint.setAntiAlias(true);
-
- paint.setColor(SK_ColorRED);
- canvas->drawCircle(SkIntToScalar(50), SkIntToScalar(50),
- SkIntToScalar(40), paint);
- paint.setColor(SK_ColorBLACK);
- paint.setTextSize(SkIntToScalar(40));
- canvas->drawText("Picture", 7, SkIntToScalar(50), SkIntToScalar(62),
- paint);
-
- }
-
- void onDrawContent(SkCanvas* canvas) override {
- this->drawSomething(canvas);
-
- SkPictureRecorder recorder;
- this->drawSomething(recorder.beginRecording(100, 100, nullptr, 0));
- SkAutoTUnref<SkPicture> pict(recorder.endRecording());
-
- canvas->save();
- canvas->translate(SkIntToScalar(300), SkIntToScalar(50));
- canvas->scale(-SK_Scalar1, -SK_Scalar1);
- canvas->translate(-SkIntToScalar(100), -SkIntToScalar(50));
- canvas->drawPicture(pict);
- canvas->restore();
-
- canvas->save();
- canvas->translate(SkIntToScalar(200), SkIntToScalar(150));
- canvas->scale(SK_Scalar1, -SK_Scalar1);
- canvas->translate(0, -SkIntToScalar(50));
- canvas->drawPicture(pict);
- canvas->restore();
-
- canvas->save();
- canvas->translate(SkIntToScalar(100), SkIntToScalar(100));
- canvas->scale(-SK_Scalar1, SK_Scalar1);
- canvas->translate(-SkIntToScalar(100), 0);
- canvas->drawPicture(pict);
- canvas->restore();
- }
-
-private:
- #define INVAL_ALL_TYPE "inval-all"
-
- void delayInval(SkMSec delay) {
- (new SkEvent(INVAL_ALL_TYPE, this->getSinkID()))->postDelay(delay);
- }
-
- bool onEvent(const SkEvent& evt) override {
- if (evt.isType(INVAL_ALL_TYPE)) {
- this->inval(nullptr);
- return true;
- }
- return this->INHERITED::onEvent(evt);
- }
-
- SkPicture* fPicture;
- SkPicture* fSubPicture;
-
- typedef SampleView INHERITED;
-};
-
-//////////////////////////////////////////////////////////////////////////////
-
-static SkView* MyFactory() { return new PictureView; }
-static SkViewRegister reg(MyFactory);