Add serialization support for drawShadowRec

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>
This commit is contained in:
Jim Van Verth 2017-05-22 12:02:21 -04:00 committed by Skia Commit-Bot
parent ee26363aaa
commit 4123d0ff86
10 changed files with 57 additions and 3 deletions

View 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;
}

View 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;
};

View 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,

View 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);

View 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);

View 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;

View 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);
}

View 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);

View 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) {

View 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;