Add serialization support for drawShadowRec
authorJim Van Verth <jvanverth@google.com>
Mon, 22 May 2017 16:02:21 +0000 (12:02 -0400)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Mon, 22 May 2017 18:02:53 +0000 (18:02 +0000)
Change-Id: Ic7f76681a037d8f53a6fdc25061c39559f5c3e30
Reviewed-on: https://skia-review.googlesource.com/17457
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Jim Van Verth <jvanverth@google.com>

include/core/SkWriter32.h
src/core/SkDrawShadowRec.h
src/core/SkPictureFlat.h
src/core/SkPicturePlayback.cpp
src/core/SkPictureRecord.cpp
src/core/SkPictureRecord.h
src/core/SkReadBuffer.cpp
src/core/SkReadBuffer.h
src/core/SkValidatingReadBuffer.cpp
src/core/SkValidatingReadBuffer.h

index a5ecb3f..478d24b 100644 (file)
@@ -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;
     }
index 19199c0..62f1460 100644 (file)
@@ -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;
 };
index 5340fcb..3c257b9 100644 (file)
@@ -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,
index cad665b..1e4fe11 100644 (file)
@@ -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);
index 69a35f5..0e1faca 100644 (file)
@@ -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);
index 08aa335..9a93bf9 100644 (file)
@@ -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;
index 33e1d02..2f5b264 100644 (file)
@@ -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);
 }
index 014e034..adc529e 100644 (file)
@@ -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);
index 71dbc45..0192968 100644 (file)
@@ -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) {
index 825c4b9..fdf7a3f 100644 (file)
@@ -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;