blob: b1d61aebbac513434b8cb4ec4b58433fa0d26118 [file] [log] [blame]
fmalita796e3652016-05-13 11:40:07 -07001/*
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
fmalitab5fc58e2016-05-25 11:31:04 -07008#include "SkPath.h"
fmalita796e3652016-05-13 11:40:07 -07009#include "SkPicture.h"
10#include "SkPictureAnalyzer.h"
fmalitab5fc58e2016-05-25 11:31:04 -070011#include "SkPictureCommon.h"
12#include "SkRecords.h"
fmalita796e3652016-05-13 11:40:07 -070013
14#if SK_SUPPORT_GPU
15
16namespace {
17
18inline bool veto_predicate(uint32_t numSlowPaths) {
19 return numSlowPaths > 5;
20}
21
22} // anonymous namespace
23
24SkPictureGpuAnalyzer::SkPictureGpuAnalyzer(sk_sp<GrContextThreadSafeProxy> /* unused ATM */)
25 : fNumSlowPaths(0) { }
26
27SkPictureGpuAnalyzer::SkPictureGpuAnalyzer(const sk_sp<SkPicture>& picture,
28 sk_sp<GrContextThreadSafeProxy> ctx)
29 : SkPictureGpuAnalyzer(std::move(ctx)) {
fmalita019db3f2016-05-31 06:32:57 -070030 this->analyzePicture(picture.get());
fmalita796e3652016-05-13 11:40:07 -070031}
32
fmalitab5fc58e2016-05-25 11:31:04 -070033void SkPictureGpuAnalyzer::analyzePicture(const SkPicture* picture) {
senorblancoea976732016-06-09 12:43:30 -070034 if (!picture) {
fmalita796e3652016-05-13 11:40:07 -070035 return;
36 }
37
38 fNumSlowPaths += picture->numSlowPaths();
39}
40
fmalitab5fc58e2016-05-25 11:31:04 -070041void SkPictureGpuAnalyzer::analyzeClipPath(const SkPath& path, SkRegion::Op op, bool doAntiAlias) {
fmalitab5fc58e2016-05-25 11:31:04 -070042 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
fmalita796e3652016-05-13 11:40:07 -070053void SkPictureGpuAnalyzer::reset() {
54 fNumSlowPaths = 0;
55}
56
57bool 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