fmalita | 796e365 | 2016-05-13 11:40:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 | |
fmalita | b5fc58e | 2016-05-25 11:31:04 -0700 | [diff] [blame] | 8 | #include "SkPath.h" |
fmalita | 796e365 | 2016-05-13 11:40:07 -0700 | [diff] [blame] | 9 | #include "SkPicture.h" |
| 10 | #include "SkPictureAnalyzer.h" |
fmalita | b5fc58e | 2016-05-25 11:31:04 -0700 | [diff] [blame] | 11 | #include "SkPictureCommon.h" |
| 12 | #include "SkRecords.h" |
fmalita | 796e365 | 2016-05-13 11:40:07 -0700 | [diff] [blame] | 13 | |
| 14 | #if SK_SUPPORT_GPU |
| 15 | |
| 16 | namespace { |
| 17 | |
| 18 | inline bool veto_predicate(uint32_t numSlowPaths) { |
| 19 | return numSlowPaths > 5; |
| 20 | } |
| 21 | |
| 22 | } // anonymous namespace |
| 23 | |
| 24 | SkPictureGpuAnalyzer::SkPictureGpuAnalyzer(sk_sp<GrContextThreadSafeProxy> /* unused ATM */) |
| 25 | : fNumSlowPaths(0) { } |
| 26 | |
| 27 | SkPictureGpuAnalyzer::SkPictureGpuAnalyzer(const sk_sp<SkPicture>& picture, |
| 28 | sk_sp<GrContextThreadSafeProxy> ctx) |
| 29 | : SkPictureGpuAnalyzer(std::move(ctx)) { |
fmalita | 019db3f | 2016-05-31 06:32:57 -0700 | [diff] [blame] | 30 | this->analyzePicture(picture.get()); |
fmalita | 796e365 | 2016-05-13 11:40:07 -0700 | [diff] [blame] | 31 | } |
| 32 | |
fmalita | b5fc58e | 2016-05-25 11:31:04 -0700 | [diff] [blame] | 33 | void SkPictureGpuAnalyzer::analyzePicture(const SkPicture* picture) { |
senorblanco | ea97673 | 2016-06-09 12:43:30 -0700 | [diff] [blame] | 34 | if (!picture) { |
fmalita | 796e365 | 2016-05-13 11:40:07 -0700 | [diff] [blame] | 35 | return; |
| 36 | } |
| 37 | |
| 38 | fNumSlowPaths += picture->numSlowPaths(); |
| 39 | } |
| 40 | |
fmalita | b5fc58e | 2016-05-25 11:31:04 -0700 | [diff] [blame] | 41 | void SkPictureGpuAnalyzer::analyzeClipPath(const SkPath& path, SkRegion::Op op, bool doAntiAlias) { |
fmalita | b5fc58e | 2016-05-25 11:31:04 -0700 | [diff] [blame] | 42 | const SkRecords::ClipPath clipOp = { |
| 43 | SkIRect::MakeEmpty(), // Willie don't care. |
| 44 | path, |
| 45 | SkRecords::RegionOpAndAA(op, doAntiAlias) |
| 46 | }; |
| 47 | |
| 48 | SkPathCounter counter; |
| 49 | counter(clipOp); |
| 50 | fNumSlowPaths += counter.fNumSlowPathsAndDashEffects; |
| 51 | } |
| 52 | |
fmalita | 796e365 | 2016-05-13 11:40:07 -0700 | [diff] [blame] | 53 | void SkPictureGpuAnalyzer::reset() { |
| 54 | fNumSlowPaths = 0; |
| 55 | } |
| 56 | |
| 57 | bool SkPictureGpuAnalyzer::suitableForGpuRasterization(const char** whyNot) const { |
| 58 | if(veto_predicate(fNumSlowPaths)) { |
| 59 | if (whyNot) { *whyNot = "Too many slow paths (either concave or dashed)."; } |
| 60 | return false; |
| 61 | } |
| 62 | return true; |
| 63 | } |
| 64 | |
| 65 | #endif // SK_SUPPORT_GPU |