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 | |
| 8 | #ifndef SkPictureAnalyzer_DEFINED |
| 9 | #define SkPictureAnalyzer_DEFINED |
| 10 | |
| 11 | #include "SkRefCnt.h" |
fmalita | b5fc58e | 2016-05-25 11:31:04 -0700 | [diff] [blame] | 12 | #include "SkRegion.h" |
fmalita | 796e365 | 2016-05-13 11:40:07 -0700 | [diff] [blame] | 13 | #include "SkTypes.h" |
| 14 | |
| 15 | #if SK_SUPPORT_GPU |
| 16 | #include "GrContext.h" |
| 17 | |
fmalita | b5fc58e | 2016-05-25 11:31:04 -0700 | [diff] [blame] | 18 | class SkPath; |
fmalita | 796e365 | 2016-05-13 11:40:07 -0700 | [diff] [blame] | 19 | class SkPicture; |
| 20 | |
| 21 | /** \class SkPictureGpuAnalyzer |
| 22 | |
| 23 | Gathers GPU-related statistics for one or more SkPictures. |
| 24 | */ |
| 25 | class SK_API SkPictureGpuAnalyzer final : public SkNoncopyable { |
| 26 | public: |
| 27 | explicit SkPictureGpuAnalyzer(sk_sp<GrContextThreadSafeProxy> = nullptr); |
| 28 | explicit SkPictureGpuAnalyzer(const sk_sp<SkPicture>& picture, |
| 29 | sk_sp<GrContextThreadSafeProxy> = nullptr); |
| 30 | |
| 31 | /** |
| 32 | * Process the given picture and accumulate its stats. |
| 33 | */ |
fmalita | b5fc58e | 2016-05-25 11:31:04 -0700 | [diff] [blame] | 34 | void analyzePicture(const SkPicture*); |
| 35 | |
fmalita | b5fc58e | 2016-05-25 11:31:04 -0700 | [diff] [blame] | 36 | /** |
| 37 | * Process an explicit clipPath op. |
| 38 | */ |
| 39 | void analyzeClipPath(const SkPath&, SkRegion::Op, bool doAntiAlias); |
fmalita | 796e365 | 2016-05-13 11:40:07 -0700 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * Reset all accumulated stats. |
| 43 | */ |
| 44 | void reset(); |
| 45 | |
| 46 | /** |
| 47 | * Returns true if the analyzed pictures are suitable for rendering on the GPU. |
| 48 | */ |
| 49 | bool suitableForGpuRasterization(const char** whyNot = nullptr) const; |
| 50 | |
senorblanco | ea97673 | 2016-06-09 12:43:30 -0700 | [diff] [blame] | 51 | /** |
| 52 | * Returns the number of commands which are slow to draw on the GPU, capped at the predicate |
| 53 | * max. |
| 54 | */ |
| 55 | uint32_t numSlowGpuCommands() { return fNumSlowPaths; } |
| 56 | |
fmalita | 796e365 | 2016-05-13 11:40:07 -0700 | [diff] [blame] | 57 | private: |
| 58 | uint32_t fNumSlowPaths; |
| 59 | |
| 60 | typedef SkNoncopyable INHERITED; |
| 61 | }; |
| 62 | |
| 63 | #endif // SK_SUPPORT_GPU |
| 64 | |
| 65 | #endif // SkPictureAnalyzer_DEFINED |