From 4123d0ff867f41c40fd288b31f4c976069753ccc Mon Sep 17 00:00:00 2001 From: Jim Van Verth Date: Mon, 22 May 2017 12:02:21 -0400 Subject: [PATCH] Add serialization support for drawShadowRec Change-Id: Ic7f76681a037d8f53a6fdc25061c39559f5c3e30 Reviewed-on: https://skia-review.googlesource.com/17457 Reviewed-by: Mike Klein Commit-Queue: Jim Van Verth --- include/core/SkWriter32.h | 5 +++++ src/core/SkDrawShadowRec.h | 4 ++-- src/core/SkPictureFlat.h | 2 +- src/core/SkPicturePlayback.cpp | 15 +++++++++++++++ src/core/SkPictureRecord.cpp | 19 +++++++++++++++++++ src/core/SkPictureRecord.h | 1 + src/core/SkReadBuffer.cpp | 6 ++++++ src/core/SkReadBuffer.h | 1 + src/core/SkValidatingReadBuffer.cpp | 6 ++++++ src/core/SkValidatingReadBuffer.h | 1 + 10 files changed, 57 insertions(+), 3 deletions(-) diff --git a/include/core/SkWriter32.h b/include/core/SkWriter32.h index a5ecb3f24a..478d24ba95 100644 --- a/include/core/SkWriter32.h +++ b/include/core/SkWriter32.h @@ -15,6 +15,7 @@ #include "SkMatrix.h" #include "SkPath.h" #include "SkPoint.h" +#include "SkPoint3.h" #include "SkRRect.h" #include "SkRect.h" #include "SkRegion.h" @@ -118,6 +119,10 @@ public: *(SkPoint*)this->reserve(sizeof(pt)) = pt; } + void writePoint3(const SkPoint3& pt) { + *(SkPoint3*)this->reserve(sizeof(pt)) = pt; + } + void writeRect(const SkRect& rect) { *(SkRect*)this->reserve(sizeof(rect)) = rect; } diff --git a/src/core/SkDrawShadowRec.h b/src/core/SkDrawShadowRec.h index 19199c0cad..62f1460407 100644 --- a/src/core/SkDrawShadowRec.h +++ b/src/core/SkDrawShadowRec.h @@ -14,8 +14,8 @@ struct SkDrawShadowRec { SkPoint3 fZPlaneParams; SkPoint3 fLightPos; SkScalar fLightRadius; - float fAmbientAlpha; - float fSpotAlpha; + SkScalar fAmbientAlpha; + SkScalar fSpotAlpha; SkColor fColor; uint32_t fFlags; }; diff --git a/src/core/SkPictureFlat.h b/src/core/SkPictureFlat.h index 5340fcb660..3c257b96ef 100644 --- a/src/core/SkPictureFlat.h +++ b/src/core/SkPictureFlat.h @@ -89,7 +89,7 @@ enum DrawType { TRANSLATE_Z, // deprecated (M60) - DRAW_SHADOWED_PICTURE_LIGHTS, // deprecated (M60) + DRAW_SHADOW_REC, DRAW_IMAGE_LATTICE, DRAW_ARC, DRAW_REGION, diff --git a/src/core/SkPicturePlayback.cpp b/src/core/SkPicturePlayback.cpp index cad665bf21..1e4fe11b8e 100644 --- a/src/core/SkPicturePlayback.cpp +++ b/src/core/SkPicturePlayback.cpp @@ -6,6 +6,7 @@ */ #include "SkCanvas.h" +#include "SkDrawShadowRec.h" #include "SkPatchUtils.h" #include "SkPictureData.h" #include "SkPicturePlayback.h" @@ -570,6 +571,20 @@ void SkPicturePlayback::handleOp(SkReadBuffer* reader, canvas->drawRRect(rrect, *paint); } } break; + case DRAW_SHADOW_REC: { + const auto& path = fPictureData->getPath(reader); + SkDrawShadowRec rec; + reader->readPoint3(&rec.fZPlaneParams); + reader->readPoint3(&rec.fLightPos); + rec.fLightRadius = reader->readScalar(); + rec.fAmbientAlpha = reader->readScalar(); + rec.fSpotAlpha = reader->readScalar(); + rec.fColor = reader->read32(); + rec.fFlags = reader->read32(); + BREAK_ON_READ_ERROR(reader); + + canvas->private_draw_shadow_rec(path, rec); + } break; case DRAW_SPRITE: { /* const SkPaint* paint = */ fPictureData->getPaint(reader); /* const SkImage* image = */ fPictureData->getBitmapAsImage(reader); diff --git a/src/core/SkPictureRecord.cpp b/src/core/SkPictureRecord.cpp index 69a35f59ad..0e1facaa5f 100644 --- a/src/core/SkPictureRecord.cpp +++ b/src/core/SkPictureRecord.cpp @@ -6,6 +6,7 @@ */ #include "SkPictureRecord.h" +#include "SkDrawShadowRec.h" #include "SkImage_Base.h" #include "SkPatchUtils.h" #include "SkPixelRef.h" @@ -786,6 +787,24 @@ void SkPictureRecord::onDrawAtlas(const SkImage* atlas, const SkRSXform xform[], this->validate(initialOffset, size); } +void SkPictureRecord::onDrawShadowRec(const SkPath& path, const SkDrawShadowRec& rec) { + // op + path index + zParams + lightPos + lightRadius + spot/ambient alphas + color + flags + size_t size = 2 * kUInt32Size + 2 * sizeof(SkPoint3) + 3 * sizeof(SkScalar) + 2 * kUInt32Size; + size_t initialOffset = this->addDraw(DRAW_SHADOW_REC, &size); + + this->addPath(path); + + fWriter.writePoint3(rec.fZPlaneParams); + fWriter.writePoint3(rec.fLightPos); + fWriter.writeScalar(rec.fLightRadius); + fWriter.writeScalar(rec.fAmbientAlpha); + fWriter.writeScalar(rec.fSpotAlpha); + fWriter.write32(rec.fColor); + fWriter.write32(rec.fFlags); + + this->validate(initialOffset, size); +} + void SkPictureRecord::onDrawAnnotation(const SkRect& rect, const char key[], SkData* value) { size_t keyLen = fWriter.WriteStringSize(key); size_t valueLen = fWriter.WriteDataSize(value); diff --git a/src/core/SkPictureRecord.h b/src/core/SkPictureRecord.h index 08aa33537f..9a93bf9e1c 100644 --- a/src/core/SkPictureRecord.h +++ b/src/core/SkPictureRecord.h @@ -197,6 +197,7 @@ protected: const SkPaint*) override; void onDrawImageLattice(const SkImage*, const SkCanvas::Lattice& lattice, const SkRect& dst, const SkPaint*) override; + void onDrawShadowRec(const SkPath&, const SkDrawShadowRec&) override; void onDrawVerticesObject(const SkVertices*, SkBlendMode, const SkPaint&) override; void onClipRect(const SkRect&, SkClipOp, ClipEdgeStyle) override; diff --git a/src/core/SkReadBuffer.cpp b/src/core/SkReadBuffer.cpp index 33e1d025dd..2f5b264ae1 100644 --- a/src/core/SkReadBuffer.cpp +++ b/src/core/SkReadBuffer.cpp @@ -151,6 +151,12 @@ void SkReadBuffer::readPoint(SkPoint* point) { point->fY = fReader.readScalar(); } +void SkReadBuffer::readPoint3(SkPoint3* point) { + point->fX = fReader.readScalar(); + point->fY = fReader.readScalar(); + point->fZ = fReader.readScalar(); +} + void SkReadBuffer::readMatrix(SkMatrix* matrix) { fReader.readMatrix(matrix); } diff --git a/src/core/SkReadBuffer.h b/src/core/SkReadBuffer.h index 014e034020..adc529ea77 100644 --- a/src/core/SkReadBuffer.h +++ b/src/core/SkReadBuffer.h @@ -130,6 +130,7 @@ public: virtual void readColor4f(SkColor4f* color); virtual void readPoint(SkPoint* point); SkPoint readPoint() { SkPoint p; this->readPoint(&p); return p; } + virtual void readPoint3(SkPoint3* point); virtual void readMatrix(SkMatrix* matrix); virtual void readIRect(SkIRect* rect); virtual void readRect(SkRect* rect); diff --git a/src/core/SkValidatingReadBuffer.cpp b/src/core/SkValidatingReadBuffer.cpp index 71dbc459ff..01929682d2 100644 --- a/src/core/SkValidatingReadBuffer.cpp +++ b/src/core/SkValidatingReadBuffer.cpp @@ -124,6 +124,12 @@ void SkValidatingReadBuffer::readPoint(SkPoint* point) { point->fY = this->readScalar(); } +void SkValidatingReadBuffer::readPoint3(SkPoint3* point) { + point->fX = this->readScalar(); + point->fY = this->readScalar(); + point->fZ = this->readScalar(); +} + void SkValidatingReadBuffer::readMatrix(SkMatrix* matrix) { size_t size = 0; if (!fError) { diff --git a/src/core/SkValidatingReadBuffer.h b/src/core/SkValidatingReadBuffer.h index 825c4b9af3..fdf7a3f3ff 100644 --- a/src/core/SkValidatingReadBuffer.h +++ b/src/core/SkValidatingReadBuffer.h @@ -46,6 +46,7 @@ public: SkFlattenable* readFlattenable(SkFlattenable::Type type) override; void readColor4f(SkColor4f* color) override; void readPoint(SkPoint* point) override; + void readPoint3(SkPoint3* point) override; void readMatrix(SkMatrix* matrix) override; void readIRect(SkIRect* rect) override; void readRect(SkRect* rect) override;