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 | |
robertphillips | 0bdbea7 | 2014-06-11 11:37:55 -0700 | [diff] [blame] | 12 | SkBBoxHierarchyRecord::SkBBoxHierarchyRecord(const SkISize& size, |
commit-bot@chromium.org | 19fafef | 2014-02-17 15:28:00 +0000 | [diff] [blame] | 13 | uint32_t recordFlags, |
| 14 | SkBBoxHierarchy* h) |
robertphillips | 0bdbea7 | 2014-06-11 11:37:55 -0700 | [diff] [blame] | 15 | : INHERITED(size, recordFlags) { |
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); |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 25 | SkPictureStateTree::Draw* draw = fStateTree->appendDraw(this->writeStream().bytesWritten()); |
rileya@google.com | 9f5898d | 2012-09-11 20:21:44 +0000 | [diff] [blame] | 26 | fBoundingHierarchy->insert(draw, r, true); |
| 27 | } |
| 28 | |
Florin Malita | 5f6102d | 2014-06-30 10:13:28 -0400 | [diff] [blame] | 29 | void SkBBoxHierarchyRecord::willSave() { |
rileya@google.com | 9f5898d | 2012-09-11 20:21:44 +0000 | [diff] [blame] | 30 | fStateTree->appendSave(); |
Florin Malita | 5f6102d | 2014-06-30 10:13:28 -0400 | [diff] [blame] | 31 | this->INHERITED::willSave(); |
rileya@google.com | 9f5898d | 2012-09-11 20:21:44 +0000 | [diff] [blame] | 32 | } |
| 33 | |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 34 | SkCanvas::SaveLayerStrategy SkBBoxHierarchyRecord::willSaveLayer(const SkRect* bounds, |
| 35 | const SkPaint* paint, |
| 36 | SaveFlags flags) { |
senorblanco@chromium.org | 68250c8 | 2014-05-06 22:52:55 +0000 | [diff] [blame] | 37 | // For now, assume all filters affect transparent black. |
| 38 | // FIXME: This could be made less conservative as an optimization. |
| 39 | bool paintAffectsTransparentBlack = NULL != paint && |
| 40 | ((NULL != paint->getImageFilter()) || |
| 41 | (NULL != paint->getColorFilter())); |
| 42 | SkRect drawBounds; |
| 43 | if (paintAffectsTransparentBlack) { |
mtklein | d910f54 | 2014-08-22 09:06:34 -0700 | [diff] [blame^] | 44 | SkIRect deviceBounds; |
| 45 | this->getClipDeviceBounds(&deviceBounds); |
| 46 | drawBounds.set(deviceBounds); |
senorblanco@chromium.org | 68250c8 | 2014-05-06 22:52:55 +0000 | [diff] [blame] | 47 | } |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 48 | fStateTree->appendSaveLayer(this->writeStream().bytesWritten()); |
senorblanco@chromium.org | 68250c8 | 2014-05-06 22:52:55 +0000 | [diff] [blame] | 49 | SkCanvas::SaveLayerStrategy strategy = this->INHERITED::willSaveLayer(bounds, paint, flags); |
| 50 | if (paintAffectsTransparentBlack) { |
| 51 | this->handleBBox(drawBounds); |
| 52 | this->addNoOp(); |
| 53 | } |
| 54 | return strategy; |
rileya@google.com | 9f5898d | 2012-09-11 20:21:44 +0000 | [diff] [blame] | 55 | } |
| 56 | |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 57 | void SkBBoxHierarchyRecord::willRestore() { |
rileya@google.com | 9f5898d | 2012-09-11 20:21:44 +0000 | [diff] [blame] | 58 | fStateTree->appendRestore(); |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 59 | this->INHERITED::willRestore(); |
rileya@google.com | 9f5898d | 2012-09-11 20:21:44 +0000 | [diff] [blame] | 60 | } |
| 61 | |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 62 | void SkBBoxHierarchyRecord::didConcat(const SkMatrix& matrix) { |
rileya@google.com | 9f5898d | 2012-09-11 20:21:44 +0000 | [diff] [blame] | 63 | fStateTree->appendTransform(getTotalMatrix()); |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 64 | INHERITED::didConcat(matrix); |
rileya@google.com | 9f5898d | 2012-09-11 20:21:44 +0000 | [diff] [blame] | 65 | } |
| 66 | |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 67 | void SkBBoxHierarchyRecord::didSetMatrix(const SkMatrix& matrix) { |
rileya@google.com | 9f5898d | 2012-09-11 20:21:44 +0000 | [diff] [blame] | 68 | fStateTree->appendTransform(getTotalMatrix()); |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 69 | INHERITED::didSetMatrix(matrix); |
rileya@google.com | 9f5898d | 2012-09-11 20:21:44 +0000 | [diff] [blame] | 70 | } |
| 71 | |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 72 | void SkBBoxHierarchyRecord::onClipRect(const SkRect& rect, |
| 73 | SkRegion::Op op, |
| 74 | ClipEdgeStyle edgeStyle) { |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 75 | fStateTree->appendClip(this->writeStream().bytesWritten()); |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 76 | this->INHERITED::onClipRect(rect, op, edgeStyle); |
rileya@google.com | 9f5898d | 2012-09-11 20:21:44 +0000 | [diff] [blame] | 77 | } |
| 78 | |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 79 | void SkBBoxHierarchyRecord::onClipRegion(const SkRegion& region, |
| 80 | SkRegion::Op op) { |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 81 | fStateTree->appendClip(this->writeStream().bytesWritten()); |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 82 | this->INHERITED::onClipRegion(region, op); |
rileya@google.com | 9f5898d | 2012-09-11 20:21:44 +0000 | [diff] [blame] | 83 | } |
| 84 | |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 85 | void SkBBoxHierarchyRecord::onClipPath(const SkPath& path, |
| 86 | SkRegion::Op op, |
| 87 | ClipEdgeStyle edgeStyle) { |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 88 | fStateTree->appendClip(this->writeStream().bytesWritten()); |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 89 | this->INHERITED::onClipPath(path, op, edgeStyle); |
rileya@google.com | 9f5898d | 2012-09-11 20:21:44 +0000 | [diff] [blame] | 90 | } |
| 91 | |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 92 | void SkBBoxHierarchyRecord::onClipRRect(const SkRRect& rrect, |
| 93 | SkRegion::Op op, |
| 94 | ClipEdgeStyle edgeStyle) { |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 95 | fStateTree->appendClip(this->writeStream().bytesWritten()); |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 96 | this->INHERITED::onClipRRect(rrect, op, edgeStyle); |
junov@chromium.org | 675de16 | 2012-12-18 19:37:49 +0000 | [diff] [blame] | 97 | } |
commit-bot@chromium.org | 4b32bd5 | 2013-03-15 15:06:03 +0000 | [diff] [blame] | 98 | |
| 99 | bool SkBBoxHierarchyRecord::shouldRewind(void* data) { |
| 100 | // SkBBoxHierarchy::rewindInserts is called by SkPicture after the |
| 101 | // SkPicture has rewound its command stream. To match that rewind in the |
| 102 | // BBH, we rewind all draws that reference commands that were recorded |
| 103 | // past the point to which the SkPicture has rewound, which is given by |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 104 | // writeStream().bytesWritten(). |
commit-bot@chromium.org | 4b32bd5 | 2013-03-15 15:06:03 +0000 | [diff] [blame] | 105 | SkPictureStateTree::Draw* draw = static_cast<SkPictureStateTree::Draw*>(data); |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 106 | return draw->fOffset >= writeStream().bytesWritten(); |
commit-bot@chromium.org | 4b32bd5 | 2013-03-15 15:06:03 +0000 | [diff] [blame] | 107 | } |