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>
227 lines
5.6 KiB
C++
227 lines
5.6 KiB
C++
/*
|
|
* 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/SkColorFilter.h"
|
|
#include "include/core/SkColorPriv.h"
|
|
#include "include/core/SkImage.h"
|
|
#include "include/core/SkMaskFilter.h"
|
|
#include "include/core/SkPath.h"
|
|
#include "include/core/SkRegion.h"
|
|
#include "include/core/SkShader.h"
|
|
#include "include/core/SkTime.h"
|
|
#include "include/core/SkTypeface.h"
|
|
#include "include/effects/SkGradientShader.h"
|
|
#include "include/utils/SkCamera.h"
|
|
#include "samplecode/Sample.h"
|
|
#include "src/utils/SkUTF.h"
|
|
|
|
static void make_paint(SkPaint* paint, const SkMatrix& localMatrix) {
|
|
SkColor colors[] = { 0, SK_ColorWHITE };
|
|
SkPoint pts[] = { { 0, 0 }, { 0, SK_Scalar1*20 } };
|
|
paint->setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, 2,
|
|
SkTileMode::kClamp, 0, &localMatrix));
|
|
paint->setBlendMode(SkBlendMode::kDstIn);
|
|
}
|
|
|
|
// test drawing with strips of fading gradient above and below
|
|
static void test_fade(SkCanvas* canvas) {
|
|
SkAutoCanvasRestore ar(canvas, true);
|
|
|
|
SkRect r;
|
|
|
|
SkAutoCanvasRestore ar2(canvas, false);
|
|
|
|
// create the layers
|
|
|
|
r.setWH(100, 100);
|
|
canvas->clipRect(r);
|
|
|
|
r.fBottom = SkIntToScalar(20);
|
|
canvas->saveLayer(&r, nullptr);
|
|
|
|
r.fTop = SkIntToScalar(80);
|
|
r.fBottom = SkIntToScalar(100);
|
|
canvas->saveLayer(&r, nullptr);
|
|
|
|
// now draw the "content"
|
|
|
|
if ((true)) {
|
|
r.setWH(100, 100);
|
|
|
|
canvas->saveLayerAlpha(&r, 0x80);
|
|
|
|
SkPaint p;
|
|
p.setColor(SK_ColorRED);
|
|
p.setAntiAlias(true);
|
|
canvas->drawOval(r, p);
|
|
|
|
canvas->restore();
|
|
} else {
|
|
r.setWH(100, 100);
|
|
|
|
SkPaint p;
|
|
p.setColor(SK_ColorRED);
|
|
p.setAntiAlias(true);
|
|
canvas->drawOval(r, p);
|
|
}
|
|
|
|
// return;
|
|
|
|
// now apply an effect
|
|
SkMatrix m;
|
|
m.setScale(SK_Scalar1, -SK_Scalar1);
|
|
m.postTranslate(0, SkIntToScalar(100));
|
|
|
|
SkPaint paint;
|
|
make_paint(&paint, m);
|
|
r.setWH(100, 20);
|
|
// SkDebugf("--------- draw top grad\n");
|
|
canvas->drawRect(r, paint);
|
|
|
|
r.fTop = SkIntToScalar(80);
|
|
r.fBottom = SkIntToScalar(100);
|
|
// SkDebugf("--------- draw bot grad\n");
|
|
canvas->drawRect(r, paint);
|
|
}
|
|
|
|
class LayersView : public Sample {
|
|
public:
|
|
LayersView() {}
|
|
|
|
protected:
|
|
SkString name() override { return SkString("Layers"); }
|
|
|
|
void drawBG(SkCanvas* canvas) {
|
|
canvas->drawColor(SK_ColorGRAY);
|
|
}
|
|
|
|
void onDrawContent(SkCanvas* canvas) override {
|
|
this->drawBG(canvas);
|
|
|
|
if ((true)) {
|
|
SkRect r;
|
|
r.setWH(220, 120);
|
|
SkPaint p;
|
|
canvas->saveLayer(&r, &p);
|
|
canvas->drawColor(0xFFFF0000);
|
|
p.setAlpha(0); // or 0
|
|
p.setBlendMode(SkBlendMode::kSrc);
|
|
canvas->drawOval(r, p);
|
|
canvas->restore();
|
|
return;
|
|
}
|
|
|
|
if ((false)) {
|
|
SkRect r;
|
|
r.setWH(220, 120);
|
|
SkPaint p;
|
|
p.setAlpha(0x88);
|
|
p.setAntiAlias(true);
|
|
|
|
if (true) {
|
|
canvas->saveLayer(&r, &p);
|
|
p.setColor(0xFFFF0000);
|
|
canvas->drawOval(r, p);
|
|
canvas->restore();
|
|
}
|
|
|
|
p.setColor(0xFF0000FF);
|
|
r.offset(SkIntToScalar(20), SkIntToScalar(50));
|
|
canvas->drawOval(r, p);
|
|
}
|
|
|
|
if ((false)) {
|
|
SkPaint p;
|
|
p.setAlpha(0x88);
|
|
p.setAntiAlias(true);
|
|
|
|
canvas->translate(SkIntToScalar(300), 0);
|
|
|
|
SkRect r;
|
|
r.setWH(220, 60);
|
|
|
|
canvas->saveLayer(&r, &p);
|
|
|
|
r.setWH(220, 120);
|
|
p.setColor(SK_ColorBLUE);
|
|
canvas->drawOval(r, p);
|
|
canvas->restore();
|
|
return;
|
|
}
|
|
|
|
test_fade(canvas);
|
|
}
|
|
|
|
private:
|
|
using INHERITED = Sample;
|
|
};
|
|
DEF_SAMPLE( return new LayersView; )
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "include/effects/SkImageFilters.h"
|
|
|
|
#include "tools/Resources.h"
|
|
|
|
class BackdropView : public Sample {
|
|
SkPoint fCenter;
|
|
SkScalar fAngle;
|
|
sk_sp<SkImage> fImage;
|
|
sk_sp<SkImageFilter> fFilter;
|
|
public:
|
|
BackdropView() {
|
|
fCenter.set(200, 150);
|
|
fAngle = 0;
|
|
fImage = GetResourceAsImage("images/mandrill_512.png");
|
|
fFilter = SkImageFilters::Dilate(8, 8, nullptr);
|
|
}
|
|
|
|
protected:
|
|
SkString name() override { return SkString("Backdrop"); }
|
|
|
|
void onDrawContent(SkCanvas* canvas) override {
|
|
canvas->drawImage(fImage.get(), 0, 0);
|
|
|
|
const SkScalar w = 250;
|
|
const SkScalar h = 150;
|
|
SkPath path;
|
|
path.addOval(SkRect::MakeXYWH(-w/2, -h/2, w, h));
|
|
SkMatrix m;
|
|
m.setRotate(fAngle);
|
|
m.postTranslate(fCenter.x(), fCenter.y());
|
|
path.transform(m);
|
|
|
|
canvas->clipPath(path, SkClipOp::kIntersect, true);
|
|
const SkRect bounds = path.getBounds();
|
|
|
|
SkPaint paint;
|
|
paint.setAlpha(0xCC);
|
|
canvas->saveLayer(SkCanvas::SaveLayerRec(&bounds, &paint, fFilter.get(), 0));
|
|
|
|
canvas->restore();
|
|
}
|
|
|
|
bool onAnimate(double nanos) override {
|
|
fAngle = SkDoubleToScalar(fmod(1e-9 * nanos * 360 / 5, 360));
|
|
return true;
|
|
}
|
|
|
|
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey modi) override {
|
|
return new Click();
|
|
}
|
|
|
|
bool onClick(Click* click) override {
|
|
fCenter = click->fCurr;
|
|
return true;
|
|
}
|
|
|
|
private:
|
|
using INHERITED = Sample;
|
|
};
|
|
DEF_SAMPLE( return new BackdropView; )
|