|
1 |
|
2 /* |
|
3 * Copyright 2012 Google Inc. |
|
4 * |
|
5 * Use of this source code is governed by a BSD-style license that can be |
|
6 * found in the LICENSE file. |
|
7 */ |
|
8 |
|
9 #include "SkBBoxHierarchyRecord.h" |
|
10 #include "SkPictureStateTree.h" |
|
11 |
|
12 SkBBoxHierarchyRecord::SkBBoxHierarchyRecord(const SkISize& size, |
|
13 uint32_t recordFlags, |
|
14 SkBBoxHierarchy* h) |
|
15 : INHERITED(size, recordFlags) { |
|
16 fStateTree = SkNEW(SkPictureStateTree); |
|
17 fBoundingHierarchy = h; |
|
18 fBoundingHierarchy->ref(); |
|
19 fBoundingHierarchy->setClient(this); |
|
20 } |
|
21 |
|
22 void SkBBoxHierarchyRecord::handleBBox(const SkRect& bounds) { |
|
23 SkIRect r; |
|
24 bounds.roundOut(&r); |
|
25 SkPictureStateTree::Draw* draw = fStateTree->appendDraw(this->writeStream().bytesWritten()); |
|
26 fBoundingHierarchy->insert(draw, r, true); |
|
27 } |
|
28 |
|
29 void SkBBoxHierarchyRecord::willSave(SaveFlags flags) { |
|
30 fStateTree->appendSave(); |
|
31 this->INHERITED::willSave(flags); |
|
32 } |
|
33 |
|
34 SkCanvas::SaveLayerStrategy SkBBoxHierarchyRecord::willSaveLayer(const SkRect* bounds, |
|
35 const SkPaint* paint, |
|
36 SaveFlags flags) { |
|
37 fStateTree->appendSaveLayer(this->writeStream().bytesWritten()); |
|
38 return this->INHERITED::willSaveLayer(bounds, paint, flags); |
|
39 } |
|
40 |
|
41 void SkBBoxHierarchyRecord::willRestore() { |
|
42 fStateTree->appendRestore(); |
|
43 this->INHERITED::willRestore(); |
|
44 } |
|
45 |
|
46 void SkBBoxHierarchyRecord::didTranslate(SkScalar dx, SkScalar dy) { |
|
47 fStateTree->appendTransform(getTotalMatrix()); |
|
48 INHERITED::didTranslate(dx, dy); |
|
49 } |
|
50 |
|
51 void SkBBoxHierarchyRecord::didScale(SkScalar sx, SkScalar sy) { |
|
52 fStateTree->appendTransform(getTotalMatrix()); |
|
53 INHERITED::didScale(sx, sy); |
|
54 } |
|
55 |
|
56 void SkBBoxHierarchyRecord::didRotate(SkScalar degrees) { |
|
57 fStateTree->appendTransform(getTotalMatrix()); |
|
58 INHERITED::didRotate(degrees); |
|
59 } |
|
60 |
|
61 void SkBBoxHierarchyRecord::didSkew(SkScalar sx, SkScalar sy) { |
|
62 fStateTree->appendTransform(getTotalMatrix()); |
|
63 INHERITED::didSkew(sx, sy); |
|
64 } |
|
65 |
|
66 void SkBBoxHierarchyRecord::didConcat(const SkMatrix& matrix) { |
|
67 fStateTree->appendTransform(getTotalMatrix()); |
|
68 INHERITED::didConcat(matrix); |
|
69 } |
|
70 |
|
71 void SkBBoxHierarchyRecord::didSetMatrix(const SkMatrix& matrix) { |
|
72 fStateTree->appendTransform(getTotalMatrix()); |
|
73 INHERITED::didSetMatrix(matrix); |
|
74 } |
|
75 |
|
76 void SkBBoxHierarchyRecord::onClipRect(const SkRect& rect, |
|
77 SkRegion::Op op, |
|
78 ClipEdgeStyle edgeStyle) { |
|
79 fStateTree->appendClip(this->writeStream().bytesWritten()); |
|
80 this->INHERITED::onClipRect(rect, op, edgeStyle); |
|
81 } |
|
82 |
|
83 void SkBBoxHierarchyRecord::onClipRegion(const SkRegion& region, |
|
84 SkRegion::Op op) { |
|
85 fStateTree->appendClip(this->writeStream().bytesWritten()); |
|
86 this->INHERITED::onClipRegion(region, op); |
|
87 } |
|
88 |
|
89 void SkBBoxHierarchyRecord::onClipPath(const SkPath& path, |
|
90 SkRegion::Op op, |
|
91 ClipEdgeStyle edgeStyle) { |
|
92 fStateTree->appendClip(this->writeStream().bytesWritten()); |
|
93 this->INHERITED::onClipPath(path, op, edgeStyle); |
|
94 } |
|
95 |
|
96 void SkBBoxHierarchyRecord::onClipRRect(const SkRRect& rrect, |
|
97 SkRegion::Op op, |
|
98 ClipEdgeStyle edgeStyle) { |
|
99 fStateTree->appendClip(this->writeStream().bytesWritten()); |
|
100 this->INHERITED::onClipRRect(rrect, op, edgeStyle); |
|
101 } |
|
102 |
|
103 bool SkBBoxHierarchyRecord::shouldRewind(void* data) { |
|
104 // SkBBoxHierarchy::rewindInserts is called by SkPicture after the |
|
105 // SkPicture has rewound its command stream. To match that rewind in the |
|
106 // BBH, we rewind all draws that reference commands that were recorded |
|
107 // past the point to which the SkPicture has rewound, which is given by |
|
108 // writeStream().bytesWritten(). |
|
109 SkPictureStateTree::Draw* draw = static_cast<SkPictureStateTree::Draw*>(data); |
|
110 return draw->fOffset >= writeStream().bytesWritten(); |
|
111 } |