GrPath.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright 2012 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #include "src/gpu/GrPath.h"
  8. #include "src/gpu/geometry/GrShape.h"
  9. static inline void write_style_key(uint32_t* key, const GrStyle& style) {
  10. // Pass 1 for the scale since the GPU will apply the style not GrStyle::applyToPath().
  11. GrStyle::WriteKey(key, style, GrStyle::Apply::kPathEffectAndStrokeRec, SK_Scalar1);
  12. }
  13. void GrPath::ComputeKey(const GrShape& shape, GrUniqueKey* key, bool* outIsVolatile) {
  14. int geoCnt = shape.unstyledKeySize();
  15. int styleCnt = GrStyle::KeySize(shape.style(), GrStyle::Apply::kPathEffectAndStrokeRec);
  16. // This should only fail for an arbitrary path effect, and we should not have gotten
  17. // here with anything other than a dash path effect.
  18. SkASSERT(styleCnt >= 0);
  19. if (geoCnt < 0) {
  20. *outIsVolatile = true;
  21. return;
  22. }
  23. static const GrUniqueKey::Domain kGeneralPathDomain = GrUniqueKey::GenerateDomain();
  24. GrUniqueKey::Builder builder(key, kGeneralPathDomain, geoCnt + styleCnt, "Path");
  25. shape.writeUnstyledKey(&builder[0]);
  26. if (styleCnt) {
  27. write_style_key(&builder[geoCnt], shape.style());
  28. }
  29. *outIsVolatile = false;
  30. }
  31. #ifdef SK_DEBUG
  32. bool GrPath::isEqualTo(const SkPath& path, const GrStyle& style) const {
  33. // Since this is only called in debug we don't care about performance.
  34. int cnt0 = GrStyle::KeySize(fStyle, GrStyle::Apply::kPathEffectAndStrokeRec);
  35. int cnt1 = GrStyle::KeySize(style, GrStyle::Apply::kPathEffectAndStrokeRec);
  36. if (cnt0 < 0 || cnt1 < 0 || cnt0 != cnt1) {
  37. return false;
  38. }
  39. if (cnt0) {
  40. SkAutoTArray<uint32_t> key0(cnt0);
  41. SkAutoTArray<uint32_t> key1(cnt0);
  42. write_style_key(key0.get(), fStyle);
  43. write_style_key(key1.get(), style);
  44. if (0 != memcmp(key0.get(), key1.get(), cnt0)) {
  45. return false;
  46. }
  47. }
  48. return fSkPath == path;
  49. }
  50. #endif