Chromium Code Reviews| Index: src/gpu/GrPath.cpp |
| diff --git a/src/gpu/GrPath.cpp b/src/gpu/GrPath.cpp |
| index 91a245d854383579168af01eeb764769ec76e913..1252d235cb594533693ca2847ab729a87fecbec3 100644 |
| --- a/src/gpu/GrPath.cpp |
| +++ b/src/gpu/GrPath.cpp |
| @@ -6,9 +6,8 @@ |
| */ |
| #include "GrPath.h" |
| -#include "GrStyle.h" |
| +#include "GrShape.h" |
| -namespace { |
| // Verb count limit for generating path key from content of a volatile path. |
| // The value should accomodate at least simple rects and rrects. |
| static const int kSimpleVolatilePathVerbLimit = 10; |
| @@ -26,58 +25,12 @@ static inline void write_style_key(uint32_t* dst, const GrStyle& style) { |
| GrStyle::WriteKey(dst, style, GrStyle::Apply::kPathEffectAndStrokeRec, SK_Scalar1); |
| } |
| - |
| -inline static bool compute_key_for_line_path(const SkPath& path, const GrStyle& style, |
|
bsalomon
2016/09/15 14:53:50
GrShape already computes geometric keys for simple
|
| - GrUniqueKey* key) { |
| - SkPoint pts[2]; |
| - if (!path.isLine(pts)) { |
| - return false; |
| - } |
| - static_assert((sizeof(pts) % sizeof(uint32_t)) == 0 && sizeof(pts) > sizeof(uint32_t), |
| - "pts_needs_padding"); |
| - int styleDataCnt = style_data_cnt(style); |
| - |
| - const int kBaseData32Cnt = 1 + sizeof(pts) / sizeof(uint32_t); |
| - static const GrUniqueKey::Domain kOvalPathDomain = GrUniqueKey::GenerateDomain(); |
| - GrUniqueKey::Builder builder(key, kOvalPathDomain, kBaseData32Cnt + styleDataCnt); |
| - builder[0] = path.getFillType(); |
| - memcpy(&builder[1], &pts, sizeof(pts)); |
| - if (styleDataCnt > 0) { |
| - write_style_key(&builder[kBaseData32Cnt], style); |
| - } |
| - return true; |
| -} |
| - |
| -inline static bool compute_key_for_oval_path(const SkPath& path, const GrStyle& style, |
| - GrUniqueKey* key) { |
| - SkRect rect; |
| - // Point order is significant when dashing, so we cannot devolve to a rect key. |
| - if (style.pathEffect() || !path.isOval(&rect)) { |
| - return false; |
| - } |
| - static_assert((sizeof(rect) % sizeof(uint32_t)) == 0 && sizeof(rect) > sizeof(uint32_t), |
| - "rect_needs_padding"); |
| - |
| - const int kBaseData32Cnt = 1 + sizeof(rect) / sizeof(uint32_t); |
| - int styleDataCnt = style_data_cnt(style); |
| - static const GrUniqueKey::Domain kOvalPathDomain = GrUniqueKey::GenerateDomain(); |
| - GrUniqueKey::Builder builder(key, kOvalPathDomain, kBaseData32Cnt + styleDataCnt); |
| - builder[0] = path.getFillType(); |
| - memcpy(&builder[1], &rect, sizeof(rect)); |
| - if (styleDataCnt > 0) { |
| - write_style_key(&builder[kBaseData32Cnt], style); |
| - } |
| - return true; |
| -} |
| - |
| // Encodes the full path data to the unique key for very small, volatile paths. This is typically |
| // hit when clipping stencils the clip stack. Intention is that this handles rects too, since |
| // SkPath::isRect seems to do non-trivial amount of work. |
| -inline static bool compute_key_for_simple_path(const SkPath& path, const GrStyle& style, |
| - GrUniqueKey* key) { |
| - if (!path.isVolatile()) { |
| - return false; |
| - } |
| +inline static bool compute_key_for_simple_path(const GrShape& shape, GrUniqueKey* key) { |
| + SkPath path; |
| + shape.asPath(&path); |
| // The check below should take care of negative values casted positive. |
| const int verbCnt = path.countVerbs(); |
| if (verbCnt > kSimpleVolatilePathVerbLimit) { |
| @@ -124,7 +77,7 @@ inline static bool compute_key_for_simple_path(const SkPath& path, const GrStyle |
| // 2) stroke data (varying size) |
| const int baseData32Cnt = 2 + verbData32Cnt + pointData32Cnt + conicWeightData32Cnt; |
| - const int styleDataCnt = style_data_cnt(style); |
| + const int styleDataCnt = style_data_cnt(shape.style()); |
| static const GrUniqueKey::Domain kSimpleVolatilePathDomain = GrUniqueKey::GenerateDomain(); |
| GrUniqueKey::Builder builder(key, kSimpleVolatilePathDomain, baseData32Cnt + styleDataCnt); |
| int i = 0; |
| @@ -169,45 +122,32 @@ inline static bool compute_key_for_simple_path(const SkPath& path, const GrStyle |
| } |
| SkASSERT(i == baseData32Cnt); |
| if (styleDataCnt > 0) { |
| - write_style_key(&builder[baseData32Cnt], style); |
| + write_style_key(&builder[baseData32Cnt], shape.style()); |
| } |
| return true; |
| } |
| -inline static void compute_key_for_general_path(const SkPath& path, const GrStyle& style, |
| - GrUniqueKey* key) { |
| - const int kBaseData32Cnt = 2; |
| - int styleDataCnt = style_data_cnt(style); |
| - static const GrUniqueKey::Domain kGeneralPathDomain = GrUniqueKey::GenerateDomain(); |
| - GrUniqueKey::Builder builder(key, kGeneralPathDomain, kBaseData32Cnt + styleDataCnt); |
| - builder[0] = path.getGenerationID(); |
| - builder[1] = path.getFillType(); |
| - if (styleDataCnt > 0) { |
| - write_style_key(&builder[kBaseData32Cnt], style); |
| +inline static bool compute_key_for_general_shape(const GrShape& shape, GrUniqueKey* key) { |
| + if (!shape.hasUnstyledKey()) { |
| + return false; |
| } |
| + int cnt = shape.unstyledKeySize(); |
| + static const GrUniqueKey::Domain kGeneralPathDomain = GrUniqueKey::GenerateDomain(); |
| + GrUniqueKey::Builder builder(key, kGeneralPathDomain, cnt); |
| + shape.writeUnstyledKey(&builder[0]); |
| + return true; |
| } |
| -} |
| - |
| -void GrPath::ComputeKey(const SkPath& path, const GrStyle& style, GrUniqueKey* key, |
| - bool* outIsVolatile) { |
| - if (compute_key_for_line_path(path, style, key)) { |
| - *outIsVolatile = false; |
| - return; |
| - } |
| +void GrPath::ComputeKey(const GrShape& shape, GrUniqueKey* key, bool* outIsVolatile) { |
| - if (compute_key_for_oval_path(path, style, key)) { |
| + if (compute_key_for_simple_path(shape, key)) { |
| *outIsVolatile = false; |
| return; |
| } |
| - if (compute_key_for_simple_path(path, style, key)) { |
| - *outIsVolatile = false; |
| - return; |
| + if (!compute_key_for_general_shape(shape, key)) { |
| + *outIsVolatile = true; |
| } |
| - |
| - compute_key_for_general_path(path, style, key); |
| - *outIsVolatile = path.isVolatile(); |
| } |
| #ifdef SK_DEBUG |