From 455c41a014c7762761c5e286c63662565a3093be Mon Sep 17 00:00:00 2001 From: Hal Canary Date: Wed, 3 Jul 2019 21:01:52 -0400 Subject: [PATCH] Sample/Camera: make it work without /skimages Change-Id: I7e876ffb7e59ccedb3da80ef3cd5ca385ab89873 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/225547 Reviewed-by: Ben Wagner Commit-Queue: Hal Canary --- samplecode/SampleCamera.cpp | 61 +++++++++++++++---------------------- 1 file changed, 24 insertions(+), 37 deletions(-) diff --git a/samplecode/SampleCamera.cpp b/samplecode/SampleCamera.cpp index 3e47070b61..3ad74550aa 100644 --- a/samplecode/SampleCamera.cpp +++ b/samplecode/SampleCamera.cpp @@ -6,66 +6,59 @@ */ #include "include/core/SkCanvas.h" -#include "include/core/SkPath.h" -#include "include/core/SkRegion.h" #include "include/core/SkShader.h" #include "include/core/SkString.h" -#include "include/effects/SkGradientShader.h" #include "include/utils/SkCamera.h" -#include "include/utils/SkRandom.h" #include "samplecode/DecodeFile.h" #include "samplecode/Sample.h" #include "src/effects/SkEmbossMaskFilter.h" -#include "src/utils/SkUTF.h" +#include "tools/Resources.h" #include "tools/timer/AnimTimer.h" +namespace { class CameraView : public Sample { SkTArray> fShaders; - int fShaderIndex; - bool fFrontFace; -public: - CameraView() { - fRX = fRY = fRZ = 0; - fShaderIndex = 0; - fFrontFace = false; + int fShaderIndex = 0; + bool fFrontFace = false; + SkScalar fRX = 0; + SkScalar fRY = 0; - for (int i = 0;; i++) { - SkString str; - str.printf("/skimages/elephant%d.jpeg", i); + SkString name() override { return SkString("Camera"); } + + void onOnceBeforeDraw() override { + for (const char* resource : { + "images/mandrill_512_q075.jpg", + "images/dog.jpg", + "images/gamut.png", + }) { SkBitmap bm; - if (decode_file(str.c_str(), &bm)) { + if (GetResourceAsBitmap(resource, &bm)) { SkRect src = { 0, 0, SkIntToScalar(bm.width()), SkIntToScalar(bm.height()) }; SkRect dst = { -150, -150, 150, 150 }; SkMatrix matrix; matrix.setRectToRect(src, dst, SkMatrix::kFill_ScaleToFit); - fShaders.push_back(bm.makeShader(&matrix)); - } else { - break; } } this->setBGColor(0xFFDDDDDD); } -protected: - SkString name() override { return SkString("Camera"); } - void onDrawContent(SkCanvas* canvas) override { - canvas->translate(this->width()/2, this->height()/2); - - Sk3DView view; - view.rotateX(fRX); - view.rotateY(fRY); - view.applyToCanvas(canvas); - - SkPaint paint; if (fShaders.count() > 0) { + canvas->translate(this->width()/2, this->height()/2); + + Sk3DView view; + view.rotateX(fRX); + view.rotateY(fRY); + view.applyToCanvas(canvas); + bool frontFace = view.dotWithNormal(0, 0, SK_Scalar1) < 0; if (frontFace != fFrontFace) { fFrontFace = frontFace; fShaderIndex = (fShaderIndex + 1) % fShaders.count(); } + SkPaint paint; paint.setAntiAlias(true); paint.setShader(fShaders[fShaderIndex]); paint.setFilterQuality(kLow_SkFilterQuality); @@ -82,12 +75,6 @@ protected: } return true; } - -private: - SkScalar fRX, fRY, fRZ; - typedef Sample INHERITED; }; - -////////////////////////////////////////////////////////////////////////////// - +} // namespace DEF_SAMPLE( return new CameraView(); )