Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Unified Diff: src/utils/SkShadowPaintFilterCanvas.cpp

Issue 2294323003: made point light shadows (Closed)
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/utils/SkShadowPaintFilterCanvas.cpp
diff --git a/src/utils/SkShadowPaintFilterCanvas.cpp b/src/utils/SkShadowPaintFilterCanvas.cpp
index ef29c3709d95ba7a45c413aa922544ed2d5ff971..8d7585913bec2393f084697cb10e27519a47e58b 100644
--- a/src/utils/SkShadowPaintFilterCanvas.cpp
+++ b/src/utils/SkShadowPaintFilterCanvas.cpp
@@ -51,7 +51,7 @@ bool SkShadowPaintFilterCanvas::onFilter(SkTCopyOnFirstWrite<SkPaint>* paint, Ty
SkISize SkShadowPaintFilterCanvas::ComputeDepthMapSize(const SkLights::Light& light, int maxDepth,
int width, int height) {
if (light.type() != SkLights::Light::kDirectional_LightType) {
- return SkISize::Make(width *2 , height * 2);
+ return SkISize::Make(width * 2, height * 2);
}
int dMapWidth = SkMin32(maxDepth * fabs(light.dir().fX) + width,
@@ -73,7 +73,7 @@ void SkShadowPaintFilterCanvas::onDrawPicture(const SkPicture *picture, const Sk
}
}
robertphillips 2016/08/31 22:18:19 const SkRect&
vjiaoblack 2016/09/01 19:22:47 Done.
-void SkShadowPaintFilterCanvas::updateMatrix() {
+void SkShadowPaintFilterCanvas::updateMatrix(const SkRect boundRect) {
this->save();
// It is up to the user to set the 0th light in fLights to
@@ -84,43 +84,59 @@ void SkShadowPaintFilterCanvas::updateMatrix() {
SkScalar y = lightDir.fY * this->getZ();
this->translate(x, y);
+ } else if (this->fLights->light(0).type() == SkLights::Light::kPoint_LightType) {
robertphillips 2016/08/31 22:18:19 How does all this interact with the CTM and saveLa
vjiaoblack 2016/09/01 19:22:47 I'll test it.
+ const SkPoint3& lightPos = this->fLights->light(0).pos();
+
+ SkScalar scale = (lightPos.fZ) / (lightPos.fZ - this->getZ());
+
+ this->translate(-boundRect.centerX() * scale, -boundRect.centerY() * scale);
+ this->scale(scale, scale);
+ this->translate(boundRect.centerX() / scale, boundRect.centerY() / scale);
+
robertphillips 2016/08/31 22:18:19 Why 400?
vjiaoblack 2016/09/01 19:22:48 because it's the current height of the diffuse map
+ // pass in 400 as height
+ this->translate((boundRect.centerX() - lightPos.fX) *
+ (this->getZ() / (lightPos.fZ - this->getZ())) / scale,
+ - ((400 - boundRect.centerY()) - lightPos.fY) *
+ (this->getZ() / (lightPos.fZ - this->getZ())) / scale);
}
}
void SkShadowPaintFilterCanvas::onDrawPaint(const SkPaint &paint) {
- this->updateMatrix();
+ SkISize size = this->getBaseLayerSize();
+ this->updateMatrix(SkRect::MakeIWH(size.fWidth, size.fHeight));
this->INHERITED::onDrawPaint(paint);
this->restore();
}
void SkShadowPaintFilterCanvas::onDrawPoints(PointMode mode, size_t count, const SkPoint pts[],
const SkPaint &paint) {
- this->updateMatrix();
+ SkISize size = this->getBaseLayerSize();
+ this->updateMatrix(SkRect::MakeIWH(size.fWidth, size.fHeight));
this->INHERITED::onDrawPoints(mode, count, pts, paint);
this->restore();
}
void SkShadowPaintFilterCanvas::onDrawRect(const SkRect &rect, const SkPaint &paint) {
- this->updateMatrix();
+ this->updateMatrix(rect);
this->INHERITED::onDrawRect(rect, paint);
this->restore();
}
void SkShadowPaintFilterCanvas::onDrawRRect(const SkRRect &rrect, const SkPaint &paint) {
- this->updateMatrix();
+ this->updateMatrix(rrect.getBounds());
this->INHERITED::onDrawRRect(rrect, paint);
this->restore();
}
void SkShadowPaintFilterCanvas::onDrawDRRect(const SkRRect &outer, const SkRRect &inner,
const SkPaint &paint) {
- this->updateMatrix();
+ this->updateMatrix(outer.getBounds());
this->INHERITED::onDrawDRRect(outer, inner, paint);
this->restore();
}
void SkShadowPaintFilterCanvas::onDrawOval(const SkRect &rect, const SkPaint &paint) {
- this->updateMatrix();
+ this->updateMatrix(rect);
this->INHERITED::onDrawOval(rect, paint);
this->restore();
}
@@ -128,20 +144,20 @@ void SkShadowPaintFilterCanvas::onDrawOval(const SkRect &rect, const SkPaint &pa
void SkShadowPaintFilterCanvas::onDrawArc(const SkRect &rect, SkScalar startAngle,
SkScalar sweepAngle, bool useCenter,
const SkPaint &paint) {
- this->updateMatrix();
+ this->updateMatrix(rect);
this->INHERITED::onDrawArc(rect, startAngle, sweepAngle, useCenter, paint);
this->restore();
}
void SkShadowPaintFilterCanvas::onDrawPath(const SkPath &path, const SkPaint &paint) {
- this->updateMatrix();
+ this->updateMatrix(path.getBounds());
this->INHERITED::onDrawPath(path, paint);
this->restore();
}
void SkShadowPaintFilterCanvas::onDrawBitmap(const SkBitmap &bm, SkScalar left, SkScalar top,
const SkPaint *paint) {
- this->updateMatrix();
+ this->updateMatrix(SkRect::MakeXYWH(left, top, bm.width(), bm.height()));
this->INHERITED::onDrawBitmap(bm, left, top, paint);
this->restore();
}
@@ -149,21 +165,21 @@ void SkShadowPaintFilterCanvas::onDrawBitmap(const SkBitmap &bm, SkScalar left,
void SkShadowPaintFilterCanvas::onDrawBitmapRect(const SkBitmap &bm, const SkRect *src,
const SkRect &dst, const SkPaint *paint,
SrcRectConstraint constraint) {
- this->updateMatrix();
+ this->updateMatrix(dst);
this->INHERITED::onDrawBitmapRect(bm, src, dst, paint, constraint);
this->restore();
}
void SkShadowPaintFilterCanvas::onDrawBitmapNine(const SkBitmap &bm, const SkIRect &center,
const SkRect &dst, const SkPaint *paint) {
- this->updateMatrix();
+ this->updateMatrix(dst);
this->INHERITED::onDrawBitmapNine(bm, center, dst, paint);
this->restore();
}
void SkShadowPaintFilterCanvas::onDrawImage(const SkImage *image, SkScalar left,
SkScalar top, const SkPaint *paint) {
- this->updateMatrix();
+ this->updateMatrix(SkRect::MakeXYWH(left, top, image->width(), image->height()));
this->INHERITED::onDrawImage(image, left, top, paint);
this->restore();
}
@@ -171,14 +187,14 @@ void SkShadowPaintFilterCanvas::onDrawImage(const SkImage *image, SkScalar left,
void SkShadowPaintFilterCanvas::onDrawImageRect(const SkImage *image, const SkRect *src,
const SkRect &dst, const SkPaint *paint,
SrcRectConstraint constraint) {
- this->updateMatrix();
+ this->updateMatrix(dst);
this->INHERITED::onDrawImageRect(image, src, dst, paint, constraint);
this->restore();
}
void SkShadowPaintFilterCanvas::onDrawImageNine(const SkImage *image, const SkIRect &center,
const SkRect &dst, const SkPaint *paint) {
- this->updateMatrix();
+ this->updateMatrix(dst);
this->INHERITED::onDrawImageNine(image, center, dst, paint);
this->restore();
}
@@ -189,7 +205,8 @@ void SkShadowPaintFilterCanvas::onDrawVertices(VertexMode vmode, int vertexCount
const SkColor colors[], SkXfermode *xmode,
const uint16_t indices[], int indexCount,
const SkPaint &paint) {
- this->updateMatrix();
+ SkISize size = this->getBaseLayerSize();
+ this->updateMatrix(SkRect::MakeIWH(size.fWidth, size.fHeight));
this->INHERITED::onDrawVertices(vmode, vertexCount, vertices, texs, colors,
xmode, indices, indexCount, paint);
this->restore();
@@ -198,21 +215,23 @@ void SkShadowPaintFilterCanvas::onDrawVertices(VertexMode vmode, int vertexCount
void SkShadowPaintFilterCanvas::onDrawPatch(const SkPoint cubics[], const SkColor colors[],
const SkPoint texCoords[], SkXfermode *xmode,
const SkPaint &paint) {
- this->updateMatrix();
+ SkISize size = this->getBaseLayerSize();
+ this->updateMatrix(SkRect::MakeIWH(size.fWidth, size.fHeight));
this->INHERITED::onDrawPatch(cubics, colors, texCoords, xmode, paint);
this->restore();
}
void SkShadowPaintFilterCanvas::onDrawText(const void *text, size_t byteLength, SkScalar x,
SkScalar y, const SkPaint &paint) {
- this->updateMatrix();
+ this->updateMatrix(paint.getFontBounds().makeOffset(x, y));
this->INHERITED::onDrawText(text, byteLength, x, y, paint);
this->restore();
}
void SkShadowPaintFilterCanvas::onDrawPosText(const void *text, size_t byteLength,
const SkPoint pos[], const SkPaint &paint) {
- this->updateMatrix();
+ SkISize size = this->getBaseLayerSize();
+ this->updateMatrix(SkRect::MakeIWH(size.fWidth, size.fHeight));
this->INHERITED::onDrawPosText(text, byteLength, pos, paint);
this->restore();
}
@@ -220,7 +239,8 @@ void SkShadowPaintFilterCanvas::onDrawPosText(const void *text, size_t byteLengt
void SkShadowPaintFilterCanvas::onDrawPosTextH(const void *text, size_t byteLength,
const SkScalar xpos[],
SkScalar constY, const SkPaint &paint) {
- this->updateMatrix();
+ SkISize size = this->getBaseLayerSize();
+ this->updateMatrix(SkRect::MakeIWH(size.fWidth, size.fHeight));
this->INHERITED::onDrawPosTextH(text, byteLength, xpos, constY, paint);
this->restore();
}
@@ -228,7 +248,7 @@ void SkShadowPaintFilterCanvas::onDrawPosTextH(const void *text, size_t byteLeng
void SkShadowPaintFilterCanvas::onDrawTextOnPath(const void *text, size_t byteLength,
const SkPath &path, const SkMatrix *matrix,
const SkPaint &paint) {
- this->updateMatrix();
+ this->updateMatrix(path.getBounds());
this->INHERITED::onDrawTextOnPath(text, byteLength, path, matrix, paint);
this->restore();
}
@@ -236,14 +256,15 @@ void SkShadowPaintFilterCanvas::onDrawTextOnPath(const void *text, size_t byteLe
void SkShadowPaintFilterCanvas::onDrawTextRSXform(const void *text, size_t byteLength,
const SkRSXform xform[], const SkRect *cull,
const SkPaint &paint) {
robertphillips 2016/08/31 22:18:19 Isn't the cull parameter optional?
vjiaoblack 2016/09/01 19:22:47 Done.
- this->updateMatrix();
+ this->updateMatrix(*cull);
this->INHERITED::onDrawTextRSXform(text, byteLength, xform, cull, paint);
this->restore();
}
void SkShadowPaintFilterCanvas::onDrawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y,
const SkPaint &paint) {
- this->updateMatrix();
+ SkISize size = this->getBaseLayerSize();
+ this->updateMatrix(SkRect::MakeIWH(size.fWidth, size.fHeight));
this->INHERITED::onDrawTextBlob(blob, x, y, paint);
this->restore();
}
« src/utils/SkShadowPaintFilterCanvas.h ('K') | « src/utils/SkShadowPaintFilterCanvas.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698