Add SkBBoxRecord subclass that builds up a BBoxHierarchy and PictureStateTree.
Review URL: https://codereview.appspot.com/6490104 git-svn-id: http://skia.googlecode.com/svn/trunk@5500 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
056f51b431
commit
9f5898d31b
@ -18,6 +18,8 @@
|
||||
'<(skia_src_path)/core/SkBBoxHierarchy.h',
|
||||
'<(skia_src_path)/core/SkBBoxRecord.cpp',
|
||||
'<(skia_src_path)/core/SkBBoxRecord.h',
|
||||
'<(skia_src_path)/core/SkBBoxHierarchyRecord.cpp',
|
||||
'<(skia_src_path)/core/SkBBoxHierarchyRecord.h',
|
||||
'<(skia_src_path)/core/SkBitmap.cpp',
|
||||
'<(skia_src_path)/core/SkBitmapHeap.cpp',
|
||||
'<(skia_src_path)/core/SkBitmapHeap.h',
|
||||
|
97
src/core/SkBBoxHierarchyRecord.cpp
Normal file
97
src/core/SkBBoxHierarchyRecord.cpp
Normal file
@ -0,0 +1,97 @@
|
||||
|
||||
/*
|
||||
* Copyright 2012 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "SkBBoxHierarchyRecord.h"
|
||||
#include "SkPictureStateTree.h"
|
||||
#include "SkBBoxHierarchy.h"
|
||||
|
||||
SkBBoxHierarchyRecord::SkBBoxHierarchyRecord(uint32_t recordFlags, SkBBoxHierarchy* h)
|
||||
: INHERITED(recordFlags) {
|
||||
fStateTree = SkNEW(SkPictureStateTree);
|
||||
fBoundingHierarchy = h;
|
||||
fBoundingHierarchy->ref();
|
||||
}
|
||||
|
||||
void SkBBoxHierarchyRecord::handleBBox(const SkRect& bounds) {
|
||||
SkIRect r;
|
||||
bounds.roundOut(&r);
|
||||
SkPictureStateTree::Draw* draw = fStateTree->appendDraw(this->writeStream().size());
|
||||
fBoundingHierarchy->insert(draw, r, true);
|
||||
}
|
||||
|
||||
int SkBBoxHierarchyRecord::save(SaveFlags flags) {
|
||||
fStateTree->appendSave();
|
||||
return INHERITED::save(flags);
|
||||
}
|
||||
|
||||
int SkBBoxHierarchyRecord::saveLayer(const SkRect* bounds, const SkPaint* paint,
|
||||
SaveFlags flags) {
|
||||
fStateTree->appendSaveLayer(this->writeStream().size());
|
||||
return INHERITED::saveLayer(bounds, paint, flags);
|
||||
}
|
||||
|
||||
void SkBBoxHierarchyRecord::restore() {
|
||||
fStateTree->appendRestore();
|
||||
INHERITED::restore();
|
||||
}
|
||||
|
||||
bool SkBBoxHierarchyRecord::translate(SkScalar dx, SkScalar dy) {
|
||||
bool result = INHERITED::translate(dx, dy);
|
||||
fStateTree->appendTransform(getTotalMatrix());
|
||||
return result;
|
||||
}
|
||||
|
||||
bool SkBBoxHierarchyRecord::scale(SkScalar sx, SkScalar sy) {
|
||||
bool result = INHERITED::scale(sx, sy);
|
||||
fStateTree->appendTransform(getTotalMatrix());
|
||||
return result;
|
||||
}
|
||||
|
||||
bool SkBBoxHierarchyRecord::rotate(SkScalar degrees) {
|
||||
bool result = INHERITED::rotate(degrees);
|
||||
fStateTree->appendTransform(getTotalMatrix());
|
||||
return result;
|
||||
}
|
||||
|
||||
bool SkBBoxHierarchyRecord::skew(SkScalar sx, SkScalar sy) {
|
||||
bool result = INHERITED::skew(sx, sy);
|
||||
fStateTree->appendTransform(getTotalMatrix());
|
||||
return result;
|
||||
}
|
||||
|
||||
bool SkBBoxHierarchyRecord::concat(const SkMatrix& matrix) {
|
||||
bool result = INHERITED::concat(matrix);
|
||||
fStateTree->appendTransform(getTotalMatrix());
|
||||
return result;
|
||||
}
|
||||
|
||||
void SkBBoxHierarchyRecord::setMatrix(const SkMatrix& matrix) {
|
||||
INHERITED::setMatrix(matrix);
|
||||
fStateTree->appendTransform(getTotalMatrix());
|
||||
}
|
||||
|
||||
bool SkBBoxHierarchyRecord::clipRect(const SkRect& rect,
|
||||
SkRegion::Op op,
|
||||
bool doAntiAlias) {
|
||||
fStateTree->appendClip(this->writeStream().size());
|
||||
return INHERITED::clipRect(rect, op, doAntiAlias);
|
||||
}
|
||||
|
||||
bool SkBBoxHierarchyRecord::clipRegion(const SkRegion& region,
|
||||
SkRegion::Op op) {
|
||||
fStateTree->appendClip(this->writeStream().size());
|
||||
return INHERITED::clipRegion(region, op);
|
||||
}
|
||||
|
||||
bool SkBBoxHierarchyRecord::clipPath(const SkPath& path,
|
||||
SkRegion::Op op,
|
||||
bool doAntiAlias) {
|
||||
fStateTree->appendClip(this->writeStream().size());
|
||||
return INHERITED::clipPath(path, op, doAntiAlias);
|
||||
}
|
||||
|
51
src/core/SkBBoxHierarchyRecord.h
Normal file
51
src/core/SkBBoxHierarchyRecord.h
Normal file
@ -0,0 +1,51 @@
|
||||
|
||||
/*
|
||||
* Copyright 2012 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef SkRTreeCanvas_DEFINED
|
||||
#define SkRTreeCanvas_DEFINED
|
||||
|
||||
#include "SkBBoxRecord.h"
|
||||
|
||||
/**
|
||||
* This records bounding box information into an SkBBoxHierarchy, and clip/transform information
|
||||
* into an SkPictureStateTree to allow for efficient culling and correct playback of draws.
|
||||
*/
|
||||
class SkBBoxHierarchyRecord : public SkBBoxRecord {
|
||||
public:
|
||||
/** This will take a ref of h */
|
||||
SkBBoxHierarchyRecord(uint32_t recordFlags, SkBBoxHierarchy* h);
|
||||
|
||||
virtual void handleBBox(const SkRect& bounds) SK_OVERRIDE;
|
||||
|
||||
virtual int save(SaveFlags flags = kMatrixClip_SaveFlag) SK_OVERRIDE;
|
||||
virtual int saveLayer(const SkRect* bounds, const SkPaint* paint,
|
||||
SaveFlags flags = kARGB_ClipLayer_SaveFlag) SK_OVERRIDE;
|
||||
virtual void restore() SK_OVERRIDE;
|
||||
|
||||
virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE;
|
||||
virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE;
|
||||
virtual bool rotate(SkScalar degrees) SK_OVERRIDE;
|
||||
virtual bool skew(SkScalar sx, SkScalar sy) SK_OVERRIDE;
|
||||
virtual bool concat(const SkMatrix& matrix) SK_OVERRIDE;
|
||||
virtual void setMatrix(const SkMatrix& matrix) SK_OVERRIDE;
|
||||
|
||||
virtual bool clipRect(const SkRect& rect,
|
||||
SkRegion::Op op = SkRegion::kIntersect_Op,
|
||||
bool doAntiAlias = false) SK_OVERRIDE;
|
||||
virtual bool clipRegion(const SkRegion& region,
|
||||
SkRegion::Op op = SkRegion::kIntersect_Op) SK_OVERRIDE;
|
||||
virtual bool clipPath(const SkPath& path,
|
||||
SkRegion::Op op = SkRegion::kIntersect_Op,
|
||||
bool doAntiAlias = false) SK_OVERRIDE;
|
||||
|
||||
private:
|
||||
typedef SkBBoxRecord INHERITED;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -8,6 +8,8 @@
|
||||
#include "SkPictureRecord.h"
|
||||
#include "SkTSearch.h"
|
||||
#include "SkPixelRef.h"
|
||||
#include "SkBBoxHierarchy.h"
|
||||
#include "SkPictureStateTree.h"
|
||||
|
||||
#define MIN_WRITER_SIZE 16384
|
||||
#define HEAP_BLOCK_SIZE 4096
|
||||
@ -22,6 +24,8 @@ SkPictureRecord::SkPictureRecord(uint32_t flags) :
|
||||
fPaints(&fFlattenableHeap),
|
||||
fRegions(&fFlattenableHeap),
|
||||
fWriter(MIN_WRITER_SIZE),
|
||||
fBoundingHierarchy(NULL),
|
||||
fStateTree(NULL),
|
||||
fRecordFlags(flags) {
|
||||
#ifdef SK_DEBUG_SIZE
|
||||
fPointBytes = fRectBytes = fTextBytes = 0;
|
||||
@ -40,6 +44,8 @@ SkPictureRecord::SkPictureRecord(uint32_t flags) :
|
||||
SkPictureRecord::~SkPictureRecord() {
|
||||
SkSafeUnref(fBitmapHeap);
|
||||
SkSafeUnref(fPathHeap);
|
||||
SkSafeUnref(fBoundingHierarchy);
|
||||
SkSafeUnref(fStateTree);
|
||||
fFlattenableHeap.setBitmapStorage(NULL);
|
||||
fPictureRefs.unrefAll();
|
||||
}
|
||||
|
@ -16,6 +16,9 @@
|
||||
#include "SkTemplates.h"
|
||||
#include "SkWriter32.h"
|
||||
|
||||
class SkPictureStateTree;
|
||||
class SkBBoxHierarchy;
|
||||
|
||||
class SkPictureRecord : public SkCanvas {
|
||||
public:
|
||||
SkPictureRecord(uint32_t recordFlags);
|
||||
@ -162,6 +165,13 @@ public:
|
||||
void validate() const {}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
|
||||
// These are set to NULL in our constructor, but may be changed by
|
||||
// subclasses, in which case they will be SkSafeUnref'd in our destructor.
|
||||
SkBBoxHierarchy* fBoundingHierarchy;
|
||||
SkPictureStateTree* fStateTree;
|
||||
|
||||
private:
|
||||
SkBitmapHeap* fBitmapHeap;
|
||||
SkChunkFlatController fFlattenableHeap;
|
||||
|
Loading…
Reference in New Issue
Block a user