Roll WebRTC 9846:9854, Libjingle 9845:9853
[chromium-blink-merge.git] / skia / ext / analysis_canvas.h
blob4c53e3d89256ee878625bd8b7cbec189efa4783f
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef SKIA_EXT_ANALYSIS_CANVAS_H_
6 #define SKIA_EXT_ANALYSIS_CANVAS_H_
8 #include "base/compiler_specific.h"
9 #include "third_party/skia/include/core/SkCanvas.h"
10 #include "third_party/skia/include/core/SkPicture.h"
12 namespace skia {
14 // Does not render anything, but gathers statistics about a region
15 // (specified as a clip rectangle) of an SkPicture as the picture is
16 // played back through it.
17 // To use: play a picture into the canvas, and then check result.
18 class SK_API AnalysisCanvas : public SkCanvas, public SkPicture::AbortCallback {
19 public:
20 AnalysisCanvas(int width, int height);
21 ~AnalysisCanvas() override;
23 // Returns true when a SkColor can be used to represent result.
24 bool GetColorIfSolid(SkColor* color) const;
26 void SetForceNotSolid(bool flag);
27 void SetForceNotTransparent(bool flag);
29 // SkPicture::AbortCallback override.
30 bool abort() override;
32 // SkCanvas overrides.
33 void onDrawPaint(const SkPaint& paint) override;
34 void onDrawPoints(PointMode,
35 size_t count,
36 const SkPoint pts[],
37 const SkPaint&) override;
38 void onDrawOval(const SkRect&, const SkPaint&) override;
39 void onDrawRect(const SkRect&, const SkPaint&) override;
40 void onDrawRRect(const SkRRect&, const SkPaint&) override;
41 void onDrawPath(const SkPath& path, const SkPaint&) override;
42 void onDrawBitmap(const SkBitmap&,
43 SkScalar left,
44 SkScalar top,
45 const SkPaint* paint = NULL) override;
46 void onDrawBitmapRect(const SkBitmap&,
47 const SkRect* src,
48 const SkRect& dst,
49 const SkPaint* paint,
50 SrcRectConstraint) override;
51 void onDrawBitmapNine(const SkBitmap& bitmap,
52 const SkIRect& center,
53 const SkRect& dst,
54 const SkPaint* paint = NULL) override;
55 void onDrawImage(const SkImage*,
56 SkScalar left,
57 SkScalar top,
58 const SkPaint* paint = NULL) override;
59 void onDrawImageRect(const SkImage*,
60 const SkRect* src,
61 const SkRect& dst,
62 const SkPaint* paint,
63 SrcRectConstraint) override;
64 void onDrawSprite(const SkBitmap&,
65 int left,
66 int top,
67 const SkPaint* paint = NULL) override;
68 void onDrawVertices(VertexMode,
69 int vertexCount,
70 const SkPoint vertices[],
71 const SkPoint texs[],
72 const SkColor colors[],
73 SkXfermode*,
74 const uint16_t indices[],
75 int indexCount,
76 const SkPaint&) override;
78 protected:
79 void willSave() override;
80 SaveLayerStrategy willSaveLayer(const SkRect*,
81 const SkPaint*,
82 SaveFlags) override;
83 void willRestore() override;
85 void onClipRect(const SkRect& rect,
86 SkRegion::Op op,
87 ClipEdgeStyle edge_style) override;
88 void onClipRRect(const SkRRect& rrect,
89 SkRegion::Op op,
90 ClipEdgeStyle edge_style) override;
91 void onClipPath(const SkPath& path,
92 SkRegion::Op op,
93 ClipEdgeStyle edge_style) override;
94 void onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) override;
96 void onDrawText(const void* text,
97 size_t byteLength,
98 SkScalar x,
99 SkScalar y,
100 const SkPaint&) override;
101 void onDrawPosText(const void* text,
102 size_t byteLength,
103 const SkPoint pos[],
104 const SkPaint&) override;
105 void onDrawPosTextH(const void* text,
106 size_t byteLength,
107 const SkScalar xpos[],
108 SkScalar constY,
109 const SkPaint&) override;
110 void onDrawTextOnPath(const void* text,
111 size_t byteLength,
112 const SkPath& path,
113 const SkMatrix* matrix,
114 const SkPaint&) override;
115 void onDrawTextBlob(const SkTextBlob* blob,
116 SkScalar x,
117 SkScalar y,
118 const SkPaint& paint) override;
119 void onDrawDRRect(const SkRRect& outer,
120 const SkRRect& inner,
121 const SkPaint&) override;
123 void OnComplexClip();
125 private:
126 typedef SkCanvas INHERITED;
128 int saved_stack_size_;
129 int force_not_solid_stack_level_;
130 int force_not_transparent_stack_level_;
132 bool is_forced_not_solid_;
133 bool is_forced_not_transparent_;
134 bool is_solid_color_;
135 SkColor color_;
136 bool is_transparent_;
137 int draw_op_count_;
140 } // namespace skia
142 #endif // SKIA_EXT_ANALYSIS_CANVAS_H_