• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
8 #include "SkPath.h"
9 #include "SkPicture.h"
10 #include "SkPictureAnalyzer.h"
11 #include "SkPictureCommon.h"
12 #include "SkRecords.h"
13 
14 #if SK_SUPPORT_GPU
15 
16 namespace {
17 
veto_predicate(uint32_t numSlowPaths)18 inline bool veto_predicate(uint32_t numSlowPaths) {
19     return numSlowPaths > 5;
20 }
21 
22 } // anonymous namespace
23 
SkPictureGpuAnalyzer(sk_sp<GrContextThreadSafeProxy>)24 SkPictureGpuAnalyzer::SkPictureGpuAnalyzer(sk_sp<GrContextThreadSafeProxy> /* unused ATM */)
25     : fNumSlowPaths(0) { }
26 
SkPictureGpuAnalyzer(const sk_sp<SkPicture> & picture,sk_sp<GrContextThreadSafeProxy> ctx)27 SkPictureGpuAnalyzer::SkPictureGpuAnalyzer(const sk_sp<SkPicture>& picture,
28                                            sk_sp<GrContextThreadSafeProxy> ctx)
29     : SkPictureGpuAnalyzer(std::move(ctx)) {
30     this->analyzePicture(picture.get());
31 }
32 
analyzePicture(const SkPicture * picture)33 void SkPictureGpuAnalyzer::analyzePicture(const SkPicture* picture) {
34     if (!picture) {
35         return;
36     }
37 
38     fNumSlowPaths += picture->numSlowPaths();
39 }
40 
analyzeClipPath(const SkPath & path,SkClipOp op,bool doAntiAlias)41 void SkPictureGpuAnalyzer::analyzeClipPath(const SkPath& path, SkClipOp op, bool doAntiAlias) {
42     const SkRecords::ClipPath clipOp = {
43         SkIRect::MakeEmpty(), // Willie don't care.
44         path,
45         SkRecords::ClipOpAndAA(op, doAntiAlias)
46     };
47 
48     SkPathCounter counter;
49     counter(clipOp);
50     fNumSlowPaths += counter.fNumSlowPathsAndDashEffects;
51 }
52 
reset()53 void SkPictureGpuAnalyzer::reset() {
54     fNumSlowPaths = 0;
55 }
56 
suitableForGpuRasterization(const char ** whyNot) const57 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
66