gfx/skia/trunk/src/core/SkBBoxHierarchyRecord.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/core/SkBBoxHierarchyRecord.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,111 @@
     1.4 +
     1.5 +/*
     1.6 + * Copyright 2012 Google Inc.
     1.7 + *
     1.8 + * Use of this source code is governed by a BSD-style license that can be
     1.9 + * found in the LICENSE file.
    1.10 + */
    1.11 +
    1.12 +#include "SkBBoxHierarchyRecord.h"
    1.13 +#include "SkPictureStateTree.h"
    1.14 +
    1.15 +SkBBoxHierarchyRecord::SkBBoxHierarchyRecord(const SkISize& size,
    1.16 +                                             uint32_t recordFlags,
    1.17 +                                             SkBBoxHierarchy* h)
    1.18 +    : INHERITED(size, recordFlags) {
    1.19 +    fStateTree = SkNEW(SkPictureStateTree);
    1.20 +    fBoundingHierarchy = h;
    1.21 +    fBoundingHierarchy->ref();
    1.22 +    fBoundingHierarchy->setClient(this);
    1.23 +}
    1.24 +
    1.25 +void SkBBoxHierarchyRecord::handleBBox(const SkRect& bounds) {
    1.26 +    SkIRect r;
    1.27 +    bounds.roundOut(&r);
    1.28 +    SkPictureStateTree::Draw* draw = fStateTree->appendDraw(this->writeStream().bytesWritten());
    1.29 +    fBoundingHierarchy->insert(draw, r, true);
    1.30 +}
    1.31 +
    1.32 +void SkBBoxHierarchyRecord::willSave(SaveFlags flags) {
    1.33 +    fStateTree->appendSave();
    1.34 +    this->INHERITED::willSave(flags);
    1.35 +}
    1.36 +
    1.37 +SkCanvas::SaveLayerStrategy SkBBoxHierarchyRecord::willSaveLayer(const SkRect* bounds,
    1.38 +                                                                 const SkPaint* paint,
    1.39 +                                                                 SaveFlags flags) {
    1.40 +    fStateTree->appendSaveLayer(this->writeStream().bytesWritten());
    1.41 +    return this->INHERITED::willSaveLayer(bounds, paint, flags);
    1.42 +}
    1.43 +
    1.44 +void SkBBoxHierarchyRecord::willRestore() {
    1.45 +    fStateTree->appendRestore();
    1.46 +    this->INHERITED::willRestore();
    1.47 +}
    1.48 +
    1.49 +void SkBBoxHierarchyRecord::didTranslate(SkScalar dx, SkScalar dy) {
    1.50 +    fStateTree->appendTransform(getTotalMatrix());
    1.51 +    INHERITED::didTranslate(dx, dy);
    1.52 +}
    1.53 +
    1.54 +void SkBBoxHierarchyRecord::didScale(SkScalar sx, SkScalar sy) {
    1.55 +    fStateTree->appendTransform(getTotalMatrix());
    1.56 +    INHERITED::didScale(sx, sy);
    1.57 +}
    1.58 +
    1.59 +void SkBBoxHierarchyRecord::didRotate(SkScalar degrees) {
    1.60 +    fStateTree->appendTransform(getTotalMatrix());
    1.61 +    INHERITED::didRotate(degrees);
    1.62 +}
    1.63 +
    1.64 +void SkBBoxHierarchyRecord::didSkew(SkScalar sx, SkScalar sy) {
    1.65 +    fStateTree->appendTransform(getTotalMatrix());
    1.66 +    INHERITED::didSkew(sx, sy);
    1.67 +}
    1.68 +
    1.69 +void SkBBoxHierarchyRecord::didConcat(const SkMatrix& matrix) {
    1.70 +    fStateTree->appendTransform(getTotalMatrix());
    1.71 +    INHERITED::didConcat(matrix);
    1.72 +}
    1.73 +
    1.74 +void SkBBoxHierarchyRecord::didSetMatrix(const SkMatrix& matrix) {
    1.75 +    fStateTree->appendTransform(getTotalMatrix());
    1.76 +    INHERITED::didSetMatrix(matrix);
    1.77 +}
    1.78 +
    1.79 +void SkBBoxHierarchyRecord::onClipRect(const SkRect& rect,
    1.80 +                                       SkRegion::Op op,
    1.81 +                                       ClipEdgeStyle edgeStyle) {
    1.82 +    fStateTree->appendClip(this->writeStream().bytesWritten());
    1.83 +    this->INHERITED::onClipRect(rect, op, edgeStyle);
    1.84 +}
    1.85 +
    1.86 +void SkBBoxHierarchyRecord::onClipRegion(const SkRegion& region,
    1.87 +                                         SkRegion::Op op) {
    1.88 +    fStateTree->appendClip(this->writeStream().bytesWritten());
    1.89 +    this->INHERITED::onClipRegion(region, op);
    1.90 +}
    1.91 +
    1.92 +void SkBBoxHierarchyRecord::onClipPath(const SkPath& path,
    1.93 +                                       SkRegion::Op op,
    1.94 +                                       ClipEdgeStyle edgeStyle) {
    1.95 +    fStateTree->appendClip(this->writeStream().bytesWritten());
    1.96 +    this->INHERITED::onClipPath(path, op, edgeStyle);
    1.97 +}
    1.98 +
    1.99 +void SkBBoxHierarchyRecord::onClipRRect(const SkRRect& rrect,
   1.100 +                                        SkRegion::Op op,
   1.101 +                                        ClipEdgeStyle edgeStyle) {
   1.102 +    fStateTree->appendClip(this->writeStream().bytesWritten());
   1.103 +    this->INHERITED::onClipRRect(rrect, op, edgeStyle);
   1.104 +}
   1.105 +
   1.106 +bool SkBBoxHierarchyRecord::shouldRewind(void* data) {
   1.107 +    // SkBBoxHierarchy::rewindInserts is called by SkPicture after the
   1.108 +    // SkPicture has rewound its command stream.  To match that rewind in the
   1.109 +    // BBH, we rewind all draws that reference commands that were recorded
   1.110 +    // past the point to which the SkPicture has rewound, which is given by
   1.111 +    // writeStream().bytesWritten().
   1.112 +    SkPictureStateTree::Draw* draw = static_cast<SkPictureStateTree::Draw*>(data);
   1.113 +    return draw->fOffset >= writeStream().bytesWritten();
   1.114 +}

mercurial