6c78b8d3ae
This reverts commit 8a54d86c78
.
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>
148 lines
5.3 KiB
C++
148 lines
5.3 KiB
C++
|
|
/*
|
|
* Copyright 2020 Google LLC
|
|
*
|
|
* 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/SkColorFilter.h"
|
|
#include "include/core/SkPath.h"
|
|
#include "include/core/SkPoint3.h"
|
|
#include "include/pathops/SkPathOps.h"
|
|
#include "include/utils/SkCamera.h"
|
|
#include "include/utils/SkShadowUtils.h"
|
|
#include "samplecode/Sample.h"
|
|
#include "src/core/SkBlurMask.h"
|
|
#include "src/utils/SkUTF.h"
|
|
#include "tools/ToolUtils.h"
|
|
#include "tools/timer/TimeUtils.h"
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
class MaterialShadowsView : public Sample {
|
|
SkPath fCirclePath;
|
|
SkPath fCapsulePath;
|
|
SkPath fLargeRRPath;
|
|
SkPath fSmallRRPath;
|
|
|
|
SkPoint3 fLightPos;
|
|
|
|
void onOnceBeforeDraw() override {
|
|
fCirclePath.addCircle(0, 0, 56/2);
|
|
fCapsulePath.addRRect(SkRRect::MakeRectXY(SkRect::MakeXYWH(-64, -24, 128, 48), 24, 24));
|
|
fLargeRRPath.addRRect(SkRRect::MakeRectXY(SkRect::MakeXYWH(-64, -64, 128, 128), 4, 4));
|
|
fSmallRRPath.addRRect(SkRRect::MakeRectXY(SkRect::MakeXYWH(-40, -40, 80, 80), 4, 4));
|
|
|
|
fLightPos = SkPoint3::Make(0, -700, 700);
|
|
}
|
|
|
|
SkString name() override { return SkString("MaterialShadows"); }
|
|
|
|
void drawShadowedPath(SkCanvas* canvas, const SkPath& path,
|
|
const SkPoint3& zPlaneParams,
|
|
const SkPaint& paint, SkScalar ambientAlpha,
|
|
const SkPoint3& lightPos, SkScalar lightRadius, SkScalar spotAlpha) {
|
|
uint32_t flags = 0;
|
|
flags |= SkShadowFlags::kDirectionalLight_ShadowFlag;
|
|
|
|
SkColor ambientColor = SkColorSetARGB(ambientAlpha * 255, 0, 0, 0);
|
|
SkColor spotColor = SkColorSetARGB(spotAlpha * 255, 0, 0, 0);
|
|
SkShadowUtils::DrawShadow(canvas, path, zPlaneParams, lightPos, lightRadius,
|
|
ambientColor, spotColor, flags);
|
|
|
|
canvas->drawPath(path, paint);
|
|
}
|
|
|
|
void onDrawContent(SkCanvas* canvas) override {
|
|
canvas->drawColor(0xFFFFFFFF);
|
|
|
|
const SkScalar kLightRadius = 1.1f;
|
|
const SkScalar kAmbientAlpha = 0.05f;
|
|
const SkScalar kSpotAlpha = 0.35f;
|
|
|
|
const SkScalar elevations[] = { 1, 3, 6, 8, 12, 24 };
|
|
|
|
SkPaint paint;
|
|
paint.setAntiAlias(true);
|
|
|
|
SkPoint3 lightPos = fLightPos;
|
|
SkPoint3 zPlaneParams = SkPoint3::Make(0, 0, 0);
|
|
|
|
paint.setColor(SK_ColorWHITE);
|
|
canvas->save();
|
|
canvas->translate(80, 80);
|
|
for (unsigned int i = 0; i < SK_ARRAY_COUNT(elevations); ++i) {
|
|
zPlaneParams.fZ = elevations[i];
|
|
this->drawShadowedPath(canvas, fCirclePath, zPlaneParams, paint, kAmbientAlpha,
|
|
lightPos, kLightRadius, kSpotAlpha);
|
|
canvas->translate(80, 0);
|
|
}
|
|
canvas->restore();
|
|
|
|
canvas->save();
|
|
canvas->translate(120, 175);
|
|
for (unsigned int i = 0; i < SK_ARRAY_COUNT(elevations); ++i) {
|
|
zPlaneParams.fZ = elevations[i];
|
|
this->drawShadowedPath(canvas, fCapsulePath, zPlaneParams, paint, kAmbientAlpha,
|
|
lightPos, kLightRadius, kSpotAlpha);
|
|
canvas->translate(160, 0);
|
|
}
|
|
canvas->restore();
|
|
|
|
canvas->save();
|
|
canvas->translate(120, 320);
|
|
for (unsigned int i = 0; i < SK_ARRAY_COUNT(elevations); ++i) {
|
|
zPlaneParams.fZ = elevations[i];
|
|
this->drawShadowedPath(canvas, fLargeRRPath, zPlaneParams, paint, kAmbientAlpha,
|
|
lightPos, kLightRadius, kSpotAlpha);
|
|
canvas->translate(160, 0);
|
|
}
|
|
canvas->restore();
|
|
|
|
canvas->save();
|
|
canvas->translate(100, 475);
|
|
for (unsigned int i = 0; i < SK_ARRAY_COUNT(elevations); ++i) {
|
|
zPlaneParams.fZ = elevations[i];
|
|
this->drawShadowedPath(canvas, fSmallRRPath, zPlaneParams, paint, kAmbientAlpha,
|
|
lightPos, kLightRadius, kSpotAlpha);
|
|
canvas->translate(160, 0);
|
|
}
|
|
canvas->restore();
|
|
|
|
canvas->save();
|
|
canvas->translate(100, 600);
|
|
for (unsigned int i = 0; i < SK_ARRAY_COUNT(elevations); ++i) {
|
|
canvas->save();
|
|
zPlaneParams.fZ = elevations[i];
|
|
canvas->rotate(10);
|
|
this->drawShadowedPath(canvas, fSmallRRPath, zPlaneParams, paint, kAmbientAlpha,
|
|
lightPos, kLightRadius, kSpotAlpha);
|
|
canvas->restore();
|
|
canvas->translate(160, 0);
|
|
}
|
|
canvas->restore();
|
|
|
|
canvas->save();
|
|
canvas->translate(100, 725);
|
|
for (unsigned int i = 0; i < SK_ARRAY_COUNT(elevations); ++i) {
|
|
canvas->save();
|
|
zPlaneParams.fZ = elevations[i];
|
|
canvas->rotate(45);
|
|
this->drawShadowedPath(canvas, fSmallRRPath, zPlaneParams, paint, kAmbientAlpha,
|
|
lightPos, kLightRadius, kSpotAlpha);
|
|
canvas->restore();
|
|
canvas->translate(160, 0);
|
|
}
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
private:
|
|
using INHERITED = Sample;
|
|
};
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
DEF_SAMPLE( return new MaterialShadowsView(); )
|