blob: 9c02468ae1c0b97c82ddb87327079ff6f84f416c [file] [log] [blame]
rileya@google.com9f5898d2012-09-11 20:21:44 +00001
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"
rileya@google.com9f5898d2012-09-11 20:21:44 +000011
reed@google.comd86e7ab2012-09-27 20:31:31 +000012SkBBoxHierarchyRecord::SkBBoxHierarchyRecord(uint32_t recordFlags,
13 SkBBoxHierarchy* h,
robertphillips@google.com9b051a32013-08-20 20:06:40 +000014 SkDevice* device)
reed@google.comd86e7ab2012-09-27 20:31:31 +000015 : INHERITED(recordFlags, device) {
rileya@google.com9f5898d2012-09-11 20:21:44 +000016 fStateTree = SkNEW(SkPictureStateTree);
17 fBoundingHierarchy = h;
18 fBoundingHierarchy->ref();
commit-bot@chromium.org4b32bd52013-03-15 15:06:03 +000019 fBoundingHierarchy->setClient(this);
rileya@google.com9f5898d2012-09-11 20:21:44 +000020}
21
22void SkBBoxHierarchyRecord::handleBBox(const SkRect& bounds) {
23 SkIRect r;
24 bounds.roundOut(&r);
25 SkPictureStateTree::Draw* draw = fStateTree->appendDraw(this->writeStream().size());
26 fBoundingHierarchy->insert(draw, r, true);
27}
28
29int SkBBoxHierarchyRecord::save(SaveFlags flags) {
30 fStateTree->appendSave();
31 return INHERITED::save(flags);
32}
33
34int SkBBoxHierarchyRecord::saveLayer(const SkRect* bounds, const SkPaint* paint,
35 SaveFlags flags) {
36 fStateTree->appendSaveLayer(this->writeStream().size());
37 return INHERITED::saveLayer(bounds, paint, flags);
38}
39
40void SkBBoxHierarchyRecord::restore() {
41 fStateTree->appendRestore();
42 INHERITED::restore();
43}
44
45bool SkBBoxHierarchyRecord::translate(SkScalar dx, SkScalar dy) {
46 bool result = INHERITED::translate(dx, dy);
47 fStateTree->appendTransform(getTotalMatrix());
48 return result;
49}
50
51bool SkBBoxHierarchyRecord::scale(SkScalar sx, SkScalar sy) {
52 bool result = INHERITED::scale(sx, sy);
53 fStateTree->appendTransform(getTotalMatrix());
54 return result;
55}
56
57bool SkBBoxHierarchyRecord::rotate(SkScalar degrees) {
58 bool result = INHERITED::rotate(degrees);
59 fStateTree->appendTransform(getTotalMatrix());
60 return result;
61}
62
63bool SkBBoxHierarchyRecord::skew(SkScalar sx, SkScalar sy) {
64 bool result = INHERITED::skew(sx, sy);
65 fStateTree->appendTransform(getTotalMatrix());
66 return result;
67}
68
69bool SkBBoxHierarchyRecord::concat(const SkMatrix& matrix) {
70 bool result = INHERITED::concat(matrix);
71 fStateTree->appendTransform(getTotalMatrix());
72 return result;
73}
74
75void SkBBoxHierarchyRecord::setMatrix(const SkMatrix& matrix) {
76 INHERITED::setMatrix(matrix);
77 fStateTree->appendTransform(getTotalMatrix());
78}
79
80bool SkBBoxHierarchyRecord::clipRect(const SkRect& rect,
81 SkRegion::Op op,
82 bool doAntiAlias) {
83 fStateTree->appendClip(this->writeStream().size());
84 return INHERITED::clipRect(rect, op, doAntiAlias);
85}
86
87bool SkBBoxHierarchyRecord::clipRegion(const SkRegion& region,
88 SkRegion::Op op) {
89 fStateTree->appendClip(this->writeStream().size());
90 return INHERITED::clipRegion(region, op);
91}
92
93bool SkBBoxHierarchyRecord::clipPath(const SkPath& path,
94 SkRegion::Op op,
95 bool doAntiAlias) {
96 fStateTree->appendClip(this->writeStream().size());
97 return INHERITED::clipPath(path, op, doAntiAlias);
98}
99
junov@chromium.org675de162012-12-18 19:37:49 +0000100bool SkBBoxHierarchyRecord::clipRRect(const SkRRect& rrect,
101 SkRegion::Op op,
102 bool doAntiAlias) {
103 fStateTree->appendClip(this->writeStream().size());
104 return INHERITED::clipRRect(rrect, op, doAntiAlias);
105}
commit-bot@chromium.org4b32bd52013-03-15 15:06:03 +0000106
107bool 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().size().
113 SkPictureStateTree::Draw* draw = static_cast<SkPictureStateTree::Draw*>(data);
114 return draw->fOffset >= writeStream().size();
115}