rileya@google.com | 9f5898d | 2012-09-11 20:21:44 +0000 | [diff] [blame] | 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" |
rileya@google.com | 9f5898d | 2012-09-11 20:21:44 +0000 | [diff] [blame] | 11 | |
reed@google.com | d86e7ab | 2012-09-27 20:31:31 +0000 | [diff] [blame] | 12 | SkBBoxHierarchyRecord::SkBBoxHierarchyRecord(uint32_t recordFlags, |
| 13 | SkBBoxHierarchy* h, |
robertphillips@google.com | 9b051a3 | 2013-08-20 20:06:40 +0000 | [diff] [blame^] | 14 | SkDevice* device) |
reed@google.com | d86e7ab | 2012-09-27 20:31:31 +0000 | [diff] [blame] | 15 | : INHERITED(recordFlags, device) { |
rileya@google.com | 9f5898d | 2012-09-11 20:21:44 +0000 | [diff] [blame] | 16 | fStateTree = SkNEW(SkPictureStateTree); |
| 17 | fBoundingHierarchy = h; |
| 18 | fBoundingHierarchy->ref(); |
commit-bot@chromium.org | 4b32bd5 | 2013-03-15 15:06:03 +0000 | [diff] [blame] | 19 | fBoundingHierarchy->setClient(this); |
rileya@google.com | 9f5898d | 2012-09-11 20:21:44 +0000 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | void 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 | |
| 29 | int SkBBoxHierarchyRecord::save(SaveFlags flags) { |
| 30 | fStateTree->appendSave(); |
| 31 | return INHERITED::save(flags); |
| 32 | } |
| 33 | |
| 34 | int 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 | |
| 40 | void SkBBoxHierarchyRecord::restore() { |
| 41 | fStateTree->appendRestore(); |
| 42 | INHERITED::restore(); |
| 43 | } |
| 44 | |
| 45 | bool SkBBoxHierarchyRecord::translate(SkScalar dx, SkScalar dy) { |
| 46 | bool result = INHERITED::translate(dx, dy); |
| 47 | fStateTree->appendTransform(getTotalMatrix()); |
| 48 | return result; |
| 49 | } |
| 50 | |
| 51 | bool SkBBoxHierarchyRecord::scale(SkScalar sx, SkScalar sy) { |
| 52 | bool result = INHERITED::scale(sx, sy); |
| 53 | fStateTree->appendTransform(getTotalMatrix()); |
| 54 | return result; |
| 55 | } |
| 56 | |
| 57 | bool SkBBoxHierarchyRecord::rotate(SkScalar degrees) { |
| 58 | bool result = INHERITED::rotate(degrees); |
| 59 | fStateTree->appendTransform(getTotalMatrix()); |
| 60 | return result; |
| 61 | } |
| 62 | |
| 63 | bool SkBBoxHierarchyRecord::skew(SkScalar sx, SkScalar sy) { |
| 64 | bool result = INHERITED::skew(sx, sy); |
| 65 | fStateTree->appendTransform(getTotalMatrix()); |
| 66 | return result; |
| 67 | } |
| 68 | |
| 69 | bool SkBBoxHierarchyRecord::concat(const SkMatrix& matrix) { |
| 70 | bool result = INHERITED::concat(matrix); |
| 71 | fStateTree->appendTransform(getTotalMatrix()); |
| 72 | return result; |
| 73 | } |
| 74 | |
| 75 | void SkBBoxHierarchyRecord::setMatrix(const SkMatrix& matrix) { |
| 76 | INHERITED::setMatrix(matrix); |
| 77 | fStateTree->appendTransform(getTotalMatrix()); |
| 78 | } |
| 79 | |
| 80 | bool 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 | |
| 87 | bool SkBBoxHierarchyRecord::clipRegion(const SkRegion& region, |
| 88 | SkRegion::Op op) { |
| 89 | fStateTree->appendClip(this->writeStream().size()); |
| 90 | return INHERITED::clipRegion(region, op); |
| 91 | } |
| 92 | |
| 93 | bool 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.org | 675de16 | 2012-12-18 19:37:49 +0000 | [diff] [blame] | 100 | bool 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.org | 4b32bd5 | 2013-03-15 15:06:03 +0000 | [diff] [blame] | 106 | |
| 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().size(). |
| 113 | SkPictureStateTree::Draw* draw = static_cast<SkPictureStateTree::Draw*>(data); |
| 114 | return draw->fOffset >= writeStream().size(); |
| 115 | } |