2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2014-01-23 02:02:45 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkShader.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/utils/SkCamera.h"
|
|
|
|
#include "samplecode/DecodeFile.h"
|
|
|
|
#include "samplecode/Sample.h"
|
|
|
|
#include "src/effects/SkEmbossMaskFilter.h"
|
2019-07-04 01:01:52 +00:00
|
|
|
#include "tools/Resources.h"
|
2019-07-11 20:32:53 +00:00
|
|
|
#include "tools/timer/TimeUtils.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2019-07-04 01:01:52 +00:00
|
|
|
namespace {
|
2018-08-08 15:36:17 +00:00
|
|
|
class CameraView : public Sample {
|
2016-03-25 16:08:00 +00:00
|
|
|
SkTArray<sk_sp<SkShader>> fShaders;
|
2019-07-04 01:01:52 +00:00
|
|
|
int fShaderIndex = 0;
|
|
|
|
bool fFrontFace = false;
|
|
|
|
SkScalar fRX = 0;
|
|
|
|
SkScalar fRY = 0;
|
2010-12-20 18:26:13 +00:00
|
|
|
|
2019-07-04 01:01:52 +00:00
|
|
|
SkString name() override { return SkString("Camera"); }
|
|
|
|
|
|
|
|
void onOnceBeforeDraw() override {
|
|
|
|
for (const char* resource : {
|
|
|
|
"images/mandrill_512_q075.jpg",
|
|
|
|
"images/dog.jpg",
|
|
|
|
"images/gamut.png",
|
|
|
|
}) {
|
2010-12-20 18:26:13 +00:00
|
|
|
SkBitmap bm;
|
2019-07-04 01:01:52 +00:00
|
|
|
if (GetResourceAsBitmap(resource, &bm)) {
|
2011-04-14 17:53:24 +00:00
|
|
|
SkRect src = { 0, 0, SkIntToScalar(bm.width()), SkIntToScalar(bm.height()) };
|
2010-12-20 18:26:13 +00:00
|
|
|
SkRect dst = { -150, -150, 150, 150 };
|
|
|
|
SkMatrix matrix;
|
|
|
|
matrix.setRectToRect(src, dst, SkMatrix::kFill_ScaleToFit);
|
2019-04-08 17:20:23 +00:00
|
|
|
fShaders.push_back(bm.makeShader(&matrix));
|
2010-12-20 18:26:13 +00:00
|
|
|
}
|
|
|
|
}
|
2011-05-05 01:59:48 +00:00
|
|
|
this->setBGColor(0xFFDDDDDD);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2015-07-13 13:18:39 +00:00
|
|
|
void onDrawContent(SkCanvas* canvas) override {
|
2019-07-04 01:01:52 +00:00
|
|
|
if (fShaders.count() > 0) {
|
|
|
|
canvas->translate(this->width()/2, this->height()/2);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2019-07-04 01:01:52 +00:00
|
|
|
Sk3DView view;
|
|
|
|
view.rotateX(fRX);
|
|
|
|
view.rotateY(fRY);
|
|
|
|
view.applyToCanvas(canvas);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2010-12-20 18:26:13 +00:00
|
|
|
bool frontFace = view.dotWithNormal(0, 0, SK_Scalar1) < 0;
|
|
|
|
if (frontFace != fFrontFace) {
|
|
|
|
fFrontFace = frontFace;
|
|
|
|
fShaderIndex = (fShaderIndex + 1) % fShaders.count();
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2019-07-04 01:01:52 +00:00
|
|
|
SkPaint paint;
|
2010-12-20 18:26:13 +00:00
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setShader(fShaders[fShaderIndex]);
|
2015-03-16 17:08:34 +00:00
|
|
|
paint.setFilterQuality(kLow_SkFilterQuality);
|
2010-12-20 18:26:13 +00:00
|
|
|
SkRect r = { -150, -150, 150, 150 };
|
|
|
|
canvas->drawRoundRect(r, 30, 30, paint);
|
|
|
|
}
|
2015-02-02 03:01:04 +00:00
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2019-07-11 20:32:53 +00:00
|
|
|
bool onAnimate(double nanos) override {
|
|
|
|
fRY = nanos ? TimeUtils::Scaled(1e-9 * nanos, 90, 360) : 0;
|
2015-02-02 03:01:04 +00:00
|
|
|
return true;
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
};
|
2019-07-04 01:01:52 +00:00
|
|
|
} // namespace
|
2018-08-08 15:36:17 +00:00
|
|
|
DEF_SAMPLE( return new CameraView(); )
|