experimental: saveCamera()

bug: skia:9768
Change-Id: I84b8f32933023d3376b51c2b93cc843863008828
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/264476
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2020-01-14 16:44:47 -05:00 committed by Skia Commit-Bot
parent 8800042f69
commit ee0a03a3f3
3 changed files with 17 additions and 3 deletions

View File

@ -754,6 +754,8 @@ public:
*/
int saveLayer(const SaveLayerRec& layerRec);
int saveCamera(const SkMatrix44& projection, const SkMatrix44& camera);
/** Removes changes to SkMatrix and clip since SkCanvas state was
last saved. The state is removed from the stack.

View File

@ -47,7 +47,7 @@ protected:
}
public:
void setupCamera(SkCanvas* canvas, const SkRect& area, SkScalar zscale) {
void saveCamera(SkCanvas* canvas, const SkRect& area, SkScalar zscale) {
SkMatrix44 camera,
perspective,
viewport;
@ -57,7 +57,7 @@ public:
viewport.setScale(area.width()*0.5f, area.height()*0.5f, zscale)
.postTranslate(area.centerX(), area.centerY(), 0);
canvas->concat(viewport * perspective * camera * inv(viewport));
canvas->saveCamera(viewport * perspective, camera * inv(viewport));
}
bool onChar(SkUnichar uni) override {
@ -201,12 +201,14 @@ class SampleRR3D : public Sample3DView {
void onDrawContent(SkCanvas* canvas) override {
canvas->translate(400, 300);
this->setupCamera(canvas, {0, 0, 400, 400}, 200);
this->saveCamera(canvas, {0, 0, 400, 400}, 200);
for (auto f : faces) {
SkAutoCanvasRestore acr(canvas, true);
this->drawContent(canvas, f.asM44(200));
}
canvas->restore();
}
};
DEF_SAMPLE( return new SampleRR3D(); )

View File

@ -733,6 +733,16 @@ void SkCanvas::doSave() {
this->internalSave();
}
int SkCanvas::saveCamera(const SkMatrix44& projection, const SkMatrix44& camera) {
// TODO: add a virtual for this, and update clients (e.g. chrome)
int n = this->save();
this->concat(projection);
// TODO: remember this point in the matrix stack, so we can communicate it to shaders
// that want to perform lighting.
this->concat(camera);
return n;
}
void SkCanvas::restore() {
if (fMCRec->fDeferredSaveCount > 0) {
SkASSERT(fSaveCount > 1);