• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
SkBBoxHierarchyRecord(uint32_t recordFlags,SkBBoxHierarchy * h,SkBaseDevice * device)12 SkBBoxHierarchyRecord::SkBBoxHierarchyRecord(uint32_t recordFlags,
13                                              SkBBoxHierarchy* h,
14                                              SkBaseDevice* device)
15     : INHERITED(recordFlags, device) {
16     fStateTree = SkNEW(SkPictureStateTree);
17     fBoundingHierarchy = h;
18     fBoundingHierarchy->ref();
19     fBoundingHierarchy->setClient(this);
20 }
21 
handleBBox(const SkRect & bounds)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 
save(SaveFlags flags)29 int SkBBoxHierarchyRecord::save(SaveFlags flags) {
30     fStateTree->appendSave();
31     return INHERITED::save(flags);
32 }
33 
saveLayer(const SkRect * bounds,const SkPaint * paint,SaveFlags flags)34 int SkBBoxHierarchyRecord::saveLayer(const SkRect* bounds, const SkPaint* paint,
35                                      SaveFlags flags) {
36     fStateTree->appendSaveLayer(this->writeStream().bytesWritten());
37     return INHERITED::saveLayer(bounds, paint, flags);
38 }
39 
restore()40 void SkBBoxHierarchyRecord::restore() {
41     fStateTree->appendRestore();
42     INHERITED::restore();
43 }
44 
translate(SkScalar dx,SkScalar dy)45 bool SkBBoxHierarchyRecord::translate(SkScalar dx, SkScalar dy) {
46     bool result = INHERITED::translate(dx, dy);
47     fStateTree->appendTransform(getTotalMatrix());
48     return result;
49 }
50 
scale(SkScalar sx,SkScalar sy)51 bool SkBBoxHierarchyRecord::scale(SkScalar sx, SkScalar sy) {
52     bool result = INHERITED::scale(sx, sy);
53     fStateTree->appendTransform(getTotalMatrix());
54     return result;
55 }
56 
rotate(SkScalar degrees)57 bool SkBBoxHierarchyRecord::rotate(SkScalar degrees) {
58     bool result = INHERITED::rotate(degrees);
59     fStateTree->appendTransform(getTotalMatrix());
60     return result;
61 }
62 
skew(SkScalar sx,SkScalar sy)63 bool SkBBoxHierarchyRecord::skew(SkScalar sx, SkScalar sy) {
64     bool result = INHERITED::skew(sx, sy);
65     fStateTree->appendTransform(getTotalMatrix());
66     return result;
67 }
68 
concat(const SkMatrix & matrix)69 bool SkBBoxHierarchyRecord::concat(const SkMatrix& matrix) {
70     bool result = INHERITED::concat(matrix);
71     fStateTree->appendTransform(getTotalMatrix());
72     return result;
73 }
74 
setMatrix(const SkMatrix & matrix)75 void SkBBoxHierarchyRecord::setMatrix(const SkMatrix& matrix) {
76     INHERITED::setMatrix(matrix);
77     fStateTree->appendTransform(getTotalMatrix());
78 }
79 
clipRect(const SkRect & rect,SkRegion::Op op,bool doAntiAlias)80 bool SkBBoxHierarchyRecord::clipRect(const SkRect& rect,
81                                      SkRegion::Op op,
82                                      bool doAntiAlias) {
83     fStateTree->appendClip(this->writeStream().bytesWritten());
84     return INHERITED::clipRect(rect, op, doAntiAlias);
85 }
86 
clipRegion(const SkRegion & region,SkRegion::Op op)87 bool SkBBoxHierarchyRecord::clipRegion(const SkRegion& region,
88                                        SkRegion::Op op) {
89     fStateTree->appendClip(this->writeStream().bytesWritten());
90     return INHERITED::clipRegion(region, op);
91 }
92 
clipPath(const SkPath & path,SkRegion::Op op,bool doAntiAlias)93 bool SkBBoxHierarchyRecord::clipPath(const SkPath& path,
94                                      SkRegion::Op op,
95                                      bool doAntiAlias) {
96     fStateTree->appendClip(this->writeStream().bytesWritten());
97     return INHERITED::clipPath(path, op, doAntiAlias);
98 }
99 
clipRRect(const SkRRect & rrect,SkRegion::Op op,bool doAntiAlias)100 bool SkBBoxHierarchyRecord::clipRRect(const SkRRect& rrect,
101                                       SkRegion::Op op,
102                                       bool doAntiAlias) {
103     fStateTree->appendClip(this->writeStream().bytesWritten());
104     return INHERITED::clipRRect(rrect, op, doAntiAlias);
105 }
106 
shouldRewind(void * data)107 bool SkBBoxHierarchyRecord::shouldRewind(void* data) {
108     // SkBBoxHierarchy::rewindInserts is called by SkPicture after the
109     // SkPicture has rewound its command stream.  To match that rewind in the
110     // BBH, we rewind all draws that reference commands that were recorded
111     // past the point to which the SkPicture has rewound, which is given by
112     // writeStream().bytesWritten().
113     SkPictureStateTree::Draw* draw = static_cast<SkPictureStateTree::Draw*>(data);
114     return draw->fOffset >= writeStream().bytesWritten();
115 }
116