Move write buffer flags used by SkFlataData::Create into SkFlatController.
Review URL: https://codereview.appspot.com/6446135 git-svn-id: http://skia.googlecode.com/svn/trunk@5091 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
a9d4e84c43
commit
664fab1b34
@ -64,7 +64,8 @@ SkFlatController::SkFlatController()
|
||||
: fBitmapHeap(NULL)
|
||||
, fTypefaceSet(NULL)
|
||||
, fTypefacePlayback(NULL)
|
||||
, fFactorySet(NULL) {}
|
||||
, fFactorySet(NULL)
|
||||
, fWriteBufferFlags(0) {}
|
||||
|
||||
SkFlatController::~SkFlatController() {
|
||||
SkSafeUnref(fBitmapHeap);
|
||||
@ -92,8 +93,7 @@ SkNamedFactorySet* SkFlatController::setNamedFactorySet(SkNamedFactorySet* set)
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
SkFlatData* SkFlatData::Create(SkFlatController* controller, const void* obj,
|
||||
int index, void (*flattenProc)(SkOrderedWriteBuffer&, const void*),
|
||||
uint32_t writeBufferflags) {
|
||||
int index, void (*flattenProc)(SkOrderedWriteBuffer&, const void*)) {
|
||||
// a buffer of 256 bytes should be sufficient for most paints, regions,
|
||||
// and matrices.
|
||||
intptr_t storage[256];
|
||||
@ -102,7 +102,7 @@ SkFlatData* SkFlatData::Create(SkFlatController* controller, const void* obj,
|
||||
buffer.setBitmapHeap(controller->getBitmapHeap());
|
||||
buffer.setTypefaceRecorder(controller->getTypefaceSet());
|
||||
buffer.setNamedFactoryRecorder(controller->getNamedFactorySet());
|
||||
buffer.setFlags(writeBufferflags);
|
||||
buffer.setFlags(controller->getWriteBufferFlags());
|
||||
|
||||
flattenProc(buffer, obj);
|
||||
uint32_t size = buffer.size();
|
||||
|
@ -202,6 +202,11 @@ public:
|
||||
*/
|
||||
SkNamedFactorySet* getNamedFactorySet() { return fFactorySet; }
|
||||
|
||||
/**
|
||||
* Flags to use during creation of SkFlatData objects. Defaults to zero.
|
||||
*/
|
||||
uint32_t getWriteBufferFlags() { return fWriteBufferFlags; }
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Set an SkBitmapHeap to be used to store/read SkBitmaps. Ref counted.
|
||||
@ -228,11 +233,17 @@ protected:
|
||||
*/
|
||||
SkNamedFactorySet* setNamedFactorySet(SkNamedFactorySet*);
|
||||
|
||||
/**
|
||||
* Set the flags to be used during flattening.
|
||||
*/
|
||||
void setWriteBufferFlags(uint32_t flags) { fWriteBufferFlags = flags; }
|
||||
|
||||
private:
|
||||
SkBitmapHeap* fBitmapHeap;
|
||||
SkRefCntSet* fTypefaceSet;
|
||||
SkTypefacePlayback* fTypefacePlayback;
|
||||
SkNamedFactorySet* fFactorySet;
|
||||
uint32_t fWriteBufferFlags;
|
||||
};
|
||||
|
||||
class SkFlatData {
|
||||
@ -295,8 +306,7 @@ public:
|
||||
#endif
|
||||
|
||||
static SkFlatData* Create(SkFlatController* controller, const void* obj, int index,
|
||||
void (*flattenProc)(SkOrderedWriteBuffer&, const void*),
|
||||
uint32_t writeBufferflags);
|
||||
void (*flattenProc)(SkOrderedWriteBuffer&, const void*));
|
||||
|
||||
void unflatten(void* result,
|
||||
void (*unflattenProc)(SkOrderedReadBuffer&, void*),
|
||||
@ -384,13 +394,11 @@ public:
|
||||
* the entry in the dictionary, it returns the actual SkFlatData.
|
||||
*/
|
||||
const SkFlatData* findAndReplace(const T& element,
|
||||
uint32_t writeBufferFlags,
|
||||
const SkFlatData* toReplace, bool* added,
|
||||
bool* replaced) {
|
||||
SkASSERT(added != NULL && replaced != NULL);
|
||||
int oldCount = fData.count();
|
||||
const SkFlatData* flat = this->findAndReturnFlat(element,
|
||||
writeBufferFlags);
|
||||
const SkFlatData* flat = this->findAndReturnFlat(element);
|
||||
*added = fData.count() == oldCount + 1;
|
||||
*replaced = false;
|
||||
if (*added && toReplace != NULL) {
|
||||
@ -429,8 +437,8 @@ public:
|
||||
* This trick allows Compare to always loop until failure. If it fails on
|
||||
* the sentinal value, we know the blocks are equal.
|
||||
*/
|
||||
int find(const T& element, uint32_t writeBufferflags = 0) {
|
||||
return this->findAndReturnFlat(element, writeBufferflags)->index();
|
||||
int find(const T& element) {
|
||||
return this->findAndReturnFlat(element)->index();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -484,10 +492,8 @@ private:
|
||||
int fNextIndex;
|
||||
SkTDArray<const SkFlatData*> fData;
|
||||
|
||||
const SkFlatData* findAndReturnFlat(const T& element,
|
||||
uint32_t writeBufferflags) {
|
||||
SkFlatData* flat = SkFlatData::Create(fController, &element, fNextIndex,
|
||||
fFlattenProc, writeBufferflags);
|
||||
const SkFlatData* findAndReturnFlat(const T& element) {
|
||||
SkFlatData* flat = SkFlatData::Create(fController, &element, fNextIndex, fFlattenProc);
|
||||
|
||||
int hashIndex = ChecksumToHashIndex(flat->checksum());
|
||||
const SkFlatData* candidate = fHash[hashIndex];
|
||||
|
@ -64,9 +64,13 @@ static size_t writeTypeface(SkWriter32* writer, SkTypeface* typeface) {
|
||||
|
||||
class FlattenableHeap : public SkFlatController {
|
||||
public:
|
||||
FlattenableHeap(int numFlatsToKeep, SkNamedFactorySet* fset)
|
||||
FlattenableHeap(int numFlatsToKeep, SkNamedFactorySet* fset, bool isCrossProcess)
|
||||
: fNumFlatsToKeep(numFlatsToKeep) {
|
||||
this->setNamedFactorySet(fset);
|
||||
SkASSERT((isCrossProcess && fset != NULL) || (!isCrossProcess && NULL == fset));
|
||||
if (isCrossProcess) {
|
||||
this->setNamedFactorySet(fset);
|
||||
this->setWriteBufferFlags(SkFlattenableWriteBuffer::kCrossProcess_Flag);
|
||||
}
|
||||
}
|
||||
|
||||
~FlattenableHeap() {
|
||||
@ -348,18 +352,11 @@ int SkGPipeCanvas::flattenToIndex(SkFlattenable* obj, PaintFlats paintflat) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t writeBufferFlags;
|
||||
if (isCrossProcess(fFlags)) {
|
||||
writeBufferFlags = SkFlattenableWriteBuffer::kCrossProcess_Flag;
|
||||
} else {
|
||||
// TODO: See if we can safely move this into the controller
|
||||
writeBufferFlags = 0;
|
||||
}
|
||||
|
||||
fBitmapHeap->deferAddingOwners();
|
||||
bool added, replaced;
|
||||
const SkFlatData* flat = fFlatDictionary.findAndReplace(
|
||||
*obj, writeBufferFlags, fFlattenableHeap.flatToReplace(), &added, &replaced);
|
||||
const SkFlatData* flat = fFlatDictionary.findAndReplace(*obj, fFlattenableHeap.flatToReplace(),
|
||||
&added, &replaced);
|
||||
fBitmapHeap->endAddingOwnersDeferral(added);
|
||||
int index = flat->index();
|
||||
if (added) {
|
||||
@ -407,7 +404,7 @@ SkGPipeCanvas::SkGPipeCanvas(SkGPipeController* controller,
|
||||
: fFactorySet(isCrossProcess(flags) ? SkNEW(SkNamedFactorySet) : NULL)
|
||||
, fWriter(*writer)
|
||||
, fFlags(flags)
|
||||
, fFlattenableHeap(FLATTENABLES_TO_KEEP, fFactorySet)
|
||||
, fFlattenableHeap(FLATTENABLES_TO_KEEP, fFactorySet, isCrossProcess(flags))
|
||||
, fFlatDictionary(&fFlattenableHeap) {
|
||||
fController = controller;
|
||||
fDone = false;
|
||||
|
Loading…
Reference in New Issue
Block a user