aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2014-11-12 09:19:02 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2014-11-12 09:19:02 -0800
commita74ce853c824c5ae30e219ddf46a61d91cc0ab2a (patch)
tree430aa1ed91ad860f1a32175bd36d446d3498ed05
parentd41e5bb1cc527f04e28c811ca3809fc65a74149a (diff)
Start stripping out complicated parts of SkPicture{Record,Data}.
First step: no more paint flattening or deduplication. BUG=skia: Review URL: https://codereview.chromium.org/723593002
-rw-r--r--gyp/tests.gypi1
-rw-r--r--src/core/SkPictureData.cpp5
-rw-r--r--src/core/SkPictureFlat.h43
-rw-r--r--src/core/SkPictureRecord.cpp9
-rw-r--r--src/core/SkPictureRecord.h5
-rw-r--r--tests/BitmapHeapTest.cpp10
-rw-r--r--tests/FlatDataTest.cpp70
7 files changed, 12 insertions, 131 deletions
diff --git a/gyp/tests.gypi b/gyp/tests.gypi
index b21d61ec55..b6a8faafc6 100644
--- a/gyp/tests.gypi
+++ b/gyp/tests.gypi
@@ -90,7 +90,6 @@
'../tests/ErrorTest.cpp',
'../tests/FillPathTest.cpp',
'../tests/FitsInTest.cpp',
- '../tests/FlatDataTest.cpp',
'../tests/FlateTest.cpp',
'../tests/FloatingPointTextureTest.cpp',
'../tests/FontHostStreamTest.cpp',
diff --git a/src/core/SkPictureData.cpp b/src/core/SkPictureData.cpp
index 896c2e6bf3..0ccb7764c4 100644
--- a/src/core/SkPictureData.cpp
+++ b/src/core/SkPictureData.cpp
@@ -48,11 +48,8 @@ SkPictureData::SkPictureData(const SkPictureRecord& record,
fContentInfo.set(record.fContentInfo);
- // copy over the refcnt dictionary to our reader
- record.fFlattenableHeap.setupPlaybacks();
-
fBitmaps = record.fBitmapHeap->extractBitmaps();
- fPaints = record.fPaints.unflattenToArray();
+ fPaints = SkTRefArray<SkPaint>::Create(record.fPaints.begin(), record.fPaints.count());
fBitmapHeap.reset(SkSafeRef(record.fBitmapHeap));
fPathHeap.reset(SkSafeRef(record.pathHeap()));
diff --git a/src/core/SkPictureFlat.h b/src/core/SkPictureFlat.h
index bd2ad2927a..40f6a0a803 100644
--- a/src/core/SkPictureFlat.h
+++ b/src/core/SkPictureFlat.h
@@ -570,47 +570,4 @@ private:
SkTDynamicHash<SkFlatData, SkFlatData, SkFlatData::HashTraits> fHash;
};
-struct SkPaintFlatteningTraits {
- static void Flatten(SkWriteBuffer& buffer, const SkPaint& paint) { paint.flatten(buffer); }
- static void Unflatten(SkReadBuffer& buffer, SkPaint* paint) { paint->unflatten(buffer); }
-};
-
-typedef SkFlatDictionary<SkPaint, SkPaintFlatteningTraits> SkPaintDictionary;
-
-class SkChunkFlatController : public SkFlatController {
-public:
- SkChunkFlatController(size_t minSize)
- : fHeap(minSize)
- , fTypefaceSet(SkNEW(SkRefCntSet))
- , fLastAllocated(NULL) {
- this->setTypefaceSet(fTypefaceSet);
- this->setTypefacePlayback(&fTypefacePlayback);
- }
-
- virtual void* allocThrow(size_t bytes) SK_OVERRIDE {
- fLastAllocated = fHeap.allocThrow(bytes);
- return fLastAllocated;
- }
-
- virtual void unalloc(void* ptr) SK_OVERRIDE {
- // fHeap can only free a pointer if it was the last one allocated. Otherwise, we'll just
- // have to wait until fHeap is destroyed.
- if (ptr == fLastAllocated) (void)fHeap.unalloc(ptr);
- }
-
- void setupPlaybacks() const {
- fTypefacePlayback.reset(fTypefaceSet.get());
- }
-
- void setBitmapStorage(SkBitmapHeap* heap) {
- this->setBitmapHeap(heap);
- }
-
-private:
- SkChunkAlloc fHeap;
- SkAutoTUnref<SkRefCntSet> fTypefaceSet;
- void* fLastAllocated;
- mutable SkTypefacePlayback fTypefacePlayback;
-};
-
#endif
diff --git a/src/core/SkPictureRecord.cpp b/src/core/SkPictureRecord.cpp
index 40ecc6a51f..00c51ac305 100644
--- a/src/core/SkPictureRecord.cpp
+++ b/src/core/SkPictureRecord.cpp
@@ -31,12 +31,9 @@ static const uint32_t kSaveLayerWithBoundsSize = 4 * kUInt32Size + sizeof(SkRect
SkPictureRecord::SkPictureRecord(const SkISize& dimensions, uint32_t flags)
: INHERITED(dimensions.width(), dimensions.height())
- , fFlattenableHeap(HEAP_BLOCK_SIZE)
- , fPaints(&fFlattenableHeap)
, fRecordFlags(flags) {
fBitmapHeap = SkNEW(SkBitmapHeap);
- fFlattenableHeap.setBitmapStorage(fBitmapHeap);
fFirstSavedLayerIndex = kNoSavedLayerIndex;
fInitialSaveCount = kNoInitialSave;
@@ -44,7 +41,6 @@ SkPictureRecord::SkPictureRecord(const SkISize& dimensions, uint32_t flags)
SkPictureRecord::~SkPictureRecord() {
SkSafeUnref(fBitmapHeap);
- fFlattenableHeap.setBitmapStorage(NULL);
fPictureRefs.unrefAll();
fTextBlobRefs.unrefAll();
}
@@ -926,9 +922,8 @@ void SkPictureRecord::addPaintPtr(const SkPaint* paint) {
fContentInfo.onAddPaintPtr(paint);
if (paint) {
- const SkFlatData* flat = fPaints.findAndReturnFlat(*paint);
- SkASSERT(flat && flat->index() != 0);
- this->addInt(flat->index());
+ fPaints.push_back(*paint);
+ this->addInt(fPaints.count());
} else {
this->addInt(0);
}
diff --git a/src/core/SkPictureRecord.h b/src/core/SkPictureRecord.h
index 032c5f6033..bac5586eca 100644
--- a/src/core/SkPictureRecord.h
+++ b/src/core/SkPictureRecord.h
@@ -13,7 +13,6 @@
#include "SkPathHeap.h"
#include "SkPicture.h"
#include "SkPictureData.h"
-#include "SkPictureFlat.h"
#include "SkTemplates.h"
#include "SkWriter32.h"
@@ -244,9 +243,7 @@ private:
SkPictureContentInfo fContentInfo;
SkAutoTUnref<SkPathHeap> fPathHeap;
- SkChunkFlatController fFlattenableHeap;
-
- SkPaintDictionary fPaints;
+ SkTArray<SkPaint> fPaints;
SkWriter32 fWriter;
diff --git a/tests/BitmapHeapTest.cpp b/tests/BitmapHeapTest.cpp
index dc9905e9f3..d65ebb67ca 100644
--- a/tests/BitmapHeapTest.cpp
+++ b/tests/BitmapHeapTest.cpp
@@ -15,6 +15,13 @@
#include "SkShader.h"
#include "Test.h"
+struct SimpleFlatController : public SkFlatController {
+ SimpleFlatController() : SkFlatController() {}
+ virtual void* allocThrow(size_t bytes) { return sk_malloc_throw(bytes); }
+ virtual void unalloc(void* ptr) { sk_free(ptr); }
+ void setBitmapStorage(SkBitmapHeap* h) { this->setBitmapHeap(h); }
+};
+
struct SkShaderTraits {
static void Flatten(SkWriteBuffer& buffer, const SkShader& shader) {
buffer.writeFlattenable(&shader);
@@ -23,7 +30,6 @@ struct SkShaderTraits {
typedef SkFlatDictionary<SkShader, SkShaderTraits> FlatDictionary;
class SkBitmapHeapTester {
-
public:
static int32_t GetRefCount(const SkBitmapHeapEntry* entry) {
return entry->fRefCount;
@@ -44,7 +50,7 @@ DEF_TEST(BitmapHeap, reporter) {
// Flatten, storing it in the bitmap heap.
SkBitmapHeap heap(1, 1);
- SkChunkFlatController controller(1024);
+ SimpleFlatController controller;
controller.setBitmapStorage(&heap);
FlatDictionary dictionary(&controller);
diff --git a/tests/FlatDataTest.cpp b/tests/FlatDataTest.cpp
deleted file mode 100644
index 2be92b6f41..0000000000
--- a/tests/FlatDataTest.cpp
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * 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 "SkBitmap.h"
-#include "SkCanvas.h"
-#include "SkColor.h"
-#include "SkColorFilter.h"
-#include "SkGradientShader.h"
-#include "SkPaint.h"
-#include "SkPictureFlat.h"
-#include "SkShader.h"
-#include "SkXfermode.h"
-#include "Test.h"
-
-struct SkFlattenableTraits {
- static void Flatten(SkWriteBuffer& buffer, const SkFlattenable& flattenable) {
- buffer.writeFlattenable(&flattenable);
- }
-};
-
-class Controller : public SkChunkFlatController {
-public:
- Controller() : INHERITED(1024) {
- this->INHERITED::setNamedFactorySet(SkNEW(SkNamedFactorySet))->unref();
- }
-private:
- typedef SkChunkFlatController INHERITED;
-};
-
-/**
- * Verify that two SkFlatData objects that created from the same object are
- * identical when using an SkNamedFactorySet.
- * @param reporter Object to report failures.
- * @param obj Flattenable object to be flattened.
- * @param flattenProc Function that flattens objects with the same type as obj.
- */
-template <typename Traits, typename T>
-static void testCreate(skiatest::Reporter* reporter, const T& obj) {
- Controller controller;
- // No need to delete data because that will be taken care of by the controller.
- SkFlatData* data1 = SkFlatData::Create<Traits>(&controller, obj, 0);
- SkFlatData* data2 = SkFlatData::Create<Traits>(&controller, obj, 1);
- REPORTER_ASSERT(reporter, *data1 == *data2);
-}
-
-DEF_TEST(FlatData, reporter) {
- // Test flattening SkShader
- SkPoint points[2];
- points[0].set(0, 0);
- points[1].set(SkIntToScalar(20), SkIntToScalar(20));
- SkColor colors[2];
- colors[0] = SK_ColorRED;
- colors[1] = SK_ColorBLUE;
-
- SkAutoTUnref<SkShader> shader(SkGradientShader::CreateLinear(points, colors, NULL, 2,
- SkShader::kRepeat_TileMode));
- testCreate<SkFlattenableTraits>(reporter, *shader);
-
- // Test SkColorFilter
- SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateLightingFilter(SK_ColorBLUE, SK_ColorRED));
- testCreate<SkFlattenableTraits>(reporter, *cf);
-
- // Test SkXfermode
- SkAutoTUnref<SkXfermode> xfer(SkXfermode::Create(SkXfermode::kDstOver_Mode));
- testCreate<SkFlattenableTraits>(reporter, *xfer);
-}