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 12SkBBoxHierarchyRecord::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 22void 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 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().bytesWritten()); 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().bytesWritten()); 84 return INHERITED::clipRect(rect, op, doAntiAlias); 85} 86 87bool SkBBoxHierarchyRecord::clipRegion(const SkRegion& region, 88 SkRegion::Op op) { 89 fStateTree->appendClip(this->writeStream().bytesWritten()); 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().bytesWritten()); 97 return INHERITED::clipPath(path, op, doAntiAlias); 98} 99 100bool 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 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().bytesWritten(). 113 SkPictureStateTree::Draw* draw = static_cast<SkPictureStateTree::Draw*>(data); 114 return draw->fOffset >= writeStream().bytesWritten(); 115} 116