skia2/samplecode/SampleCamera.cpp

76 lines
2.3 KiB
C++
Raw Normal View History

Revert "Move SkCamera.h to client_utils/android" This reverts commit 8a54d86c780a22796f8d535f74bf6af33a06c707. Reason for revert: Causing issues with Android CTS Original change's description: > Move SkCamera.h to client_utils/android > > Android still uses this > https://developer.android.com/reference/android/graphics/Camera > but no other client does. > > This adds a little adaption layer until Android is updated > to use the View3D version. > > Move SkCamera.h to View3D.h. Change names to android::skia::CLASS > instead of SkCLASS. (3DView is not a valid class name, so rename it to > View3D.) > > Forward-declare SkMatrix. Do not override SkNoncopyable - just delete > the copy constructor/operator=. Make fU and fV private in Patch3D. > > Make Sk3DView override View3D temporarily until Android can be switched > over to the new class. > > (View3D from http://review.skia.org/291371) > > I made Patch3D and Camera3D be private classes as they are > currently not used by Android and wanted to constrain the > exposed API as much as possible. > > Change-Id: Ibde45478421feeb610e045205c3f20c0e5b1567e > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/532456 > Reviewed-by: Brian Osman <brianosman@google.com> > Reviewed-by: Leon Scroggins <scroggo@google.com> > Commit-Queue: Kevin Lubick <kjlubick@google.com> Change-Id: If6e768524a0e13e14ef886a6f081a09ddc0dc2fd Reviewed-on: https://skia-review.googlesource.com/c/skia/+/533396 Owners-Override: Kevin Lubick <kjlubick@google.com> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Commit-Queue: Kevin Lubick <kjlubick@google.com>
2022-04-25 11:54:10 +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.
*/
#include "include/core/SkCanvas.h"
#include "include/core/SkImage.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"
#include "tools/Resources.h"
#include "tools/timer/TimeUtils.h"
namespace {
class CameraView : public Sample {
SkTArray<sk_sp<SkShader>> fShaders;
int fShaderIndex = 0;
bool fFrontFace = false;
SkScalar fRX = 0;
SkScalar fRY = 0;
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 (GetResourceAsBitmap(resource, &bm)) {
SkRect src = { 0, 0, SkIntToScalar(bm.width()), SkIntToScalar(bm.height()) };
SkRect dst = { -150, -150, 150, 150 };
fShaders.push_back(bm.makeShader(SkSamplingOptions(SkFilterMode::kLinear),
SkMatrix::RectToRect(src, dst)));
}
}
this->setBGColor(0xFFDDDDDD);
}
void onDrawContent(SkCanvas* canvas) override {
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]);
SkRect r = { -150, -150, 150, 150 };
canvas->drawRoundRect(r, 30, 30, paint);
}
}
bool onAnimate(double nanos) override {
fRY = nanos ? TimeUtils::Scaled(1e-9 * nanos, 90, 360) : 0;
return true;
}
};
} // namespace
DEF_SAMPLE( return new CameraView(); )