From 82365915476caedc130d0e36012a1ce0c007c4ae Mon Sep 17 00:00:00 2001 From: robertphillips Date: Wed, 12 Nov 2014 09:32:34 -0800 Subject: Rename GrAccelData to SkLayerInfo and move it to src/core Review URL: https://codereview.chromium.org/719133002 --- src/core/SkLayerInfo.cpp | 15 ++++++++ src/core/SkLayerInfo.h | 77 ++++++++++++++++++++++++++++++++++++++++ src/core/SkPictureRecorder.cpp | 21 +++-------- src/core/SkRecordDraw.cpp | 47 +++++++++++-------------- src/core/SkRecordDraw.h | 8 ++--- src/gpu/GrLayerCache.h | 4 +-- src/gpu/GrLayerHoister.cpp | 25 ++++++------- src/gpu/GrLayerHoister.h | 1 - src/gpu/GrPictureUtils.cpp | 21 ----------- src/gpu/GrPictureUtils.h | 79 ------------------------------------------ src/gpu/SkGpuDevice.cpp | 5 ++- 11 files changed, 135 insertions(+), 168 deletions(-) create mode 100644 src/core/SkLayerInfo.cpp create mode 100644 src/core/SkLayerInfo.h delete mode 100644 src/gpu/GrPictureUtils.cpp delete mode 100644 src/gpu/GrPictureUtils.h (limited to 'src') diff --git a/src/core/SkLayerInfo.cpp b/src/core/SkLayerInfo.cpp new file mode 100644 index 0000000000..d427fa7c21 --- /dev/null +++ b/src/core/SkLayerInfo.cpp @@ -0,0 +1,15 @@ +/* + * Copyright 2014 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkLayerInfo.h" + +SkPicture::AccelData::Key SkLayerInfo::ComputeKey() { + static const SkPicture::AccelData::Key gGPUID = SkPicture::AccelData::GenerateDomain(); + + return gGPUID; +} + diff --git a/src/core/SkLayerInfo.h b/src/core/SkLayerInfo.h new file mode 100644 index 0000000000..dd0eaf032a --- /dev/null +++ b/src/core/SkLayerInfo.h @@ -0,0 +1,77 @@ +/* + * Copyright 2014 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkLayerInfo_DEFINED +#define SkLayerInfo_DEFINED + +#include "SkPicture.h" +#include "SkTArray.h" + +// This class stores information about the saveLayer/restore pairs found +// within an SkPicture. It is used by Ganesh to perform layer hoisting. +class SkLayerInfo : public SkPicture::AccelData { +public: + // Information about a given saveLayer/restore block in an SkPicture + class BlockInfo { + public: + BlockInfo() : fPicture(NULL), fPaint(NULL) {} + ~BlockInfo() { SkSafeUnref(fPicture); SkDELETE(fPaint); } + + // The picture owning the layer. If the owning picture is the top-most + // one (i.e., the picture for which this SkLayerInfo was created) then + // this pointer is NULL. If it is a nested picture then the pointer + // is non-NULL and owns a ref on the picture. + const SkPicture* fPicture; + // The device space bounds of this layer. + SkRect fBounds; + // The pre-matrix begins as the identity and accumulates the transforms + // of the containing SkPictures (if any). This matrix state has to be + // part of the initial matrix during replay so that it will be + // preserved across setMatrix calls. + SkMatrix fPreMat; + // The matrix state (in the leaf picture) in which this layer's draws + // must occur. It will/can be overridden by setMatrix calls in the + // layer itself. It does not include the translation needed to map the + // layer's top-left point to the origin (which must be part of the + // initial matrix). + SkMatrix fLocalMat; + // The paint to use on restore. Can be NULL since it is optional. + const SkPaint* fPaint; + // The index of this saveLayer in the picture. + size_t fSaveLayerOpID; + // The index of the matching restore in the picture. + size_t fRestoreOpID; + // True if this saveLayer has at least one other saveLayer nested within it. + // False otherwise. + bool fHasNestedLayers; + // True if this saveLayer is nested within another. False otherwise. + bool fIsNested; + }; + + SkLayerInfo(Key key) : INHERITED(key) { } + + BlockInfo& addBlock() { return fBlocks.push_back(); } + + int numBlocks() const { return fBlocks.count(); } + + const BlockInfo& block(int index) const { + SkASSERT(index < fBlocks.count()); + + return fBlocks[index]; + } + + // We may, in the future, need to pass in the GPUDevice in order to + // incorporate the clip and matrix state into the key + static SkPicture::AccelData::Key ComputeKey(); + +private: + SkTArray fBlocks; + + typedef SkPicture::AccelData INHERITED; +}; + +#endif // SkLayerInfo_DEFINED diff --git a/src/core/SkPictureRecorder.cpp b/src/core/SkPictureRecorder.cpp index 160446797d..3441a0dfeb 100644 --- a/src/core/SkPictureRecorder.cpp +++ b/src/core/SkPictureRecorder.cpp @@ -5,6 +5,7 @@ * found in the LICENSE file. */ +#include "SkLayerInfo.h" #include "SkPictureRecorder.h" #include "SkRecord.h" #include "SkRecordDraw.h" @@ -12,12 +13,6 @@ #include "SkRecordOpts.h" #include "SkTypes.h" -// Must place SK_SUPPORT_GPU after other includes so it is defined in the -// Android framework build. -#if SK_SUPPORT_GPU -#include "GrPictureUtils.h" -#endif - SkPictureRecorder::SkPictureRecorder() {} SkPictureRecorder::~SkPictureRecorder() {} @@ -47,37 +42,29 @@ SkPicture* SkPictureRecorder::endRecording() { // TODO: delay as much of this work until just before first playback? SkRecordOptimize(fRecord); -#if SK_SUPPORT_GPU - SkAutoTUnref saveLayerData; + SkAutoTUnref saveLayerData; if (fBBH && (fFlags & kComputeSaveLayerInfo_RecordFlag)) { - SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey(); + SkPicture::AccelData::Key key = SkLayerInfo::ComputeKey(); - saveLayerData.reset(SkNEW_ARGS(GrAccelData, (key))); + saveLayerData.reset(SkNEW_ARGS(SkLayerInfo, (key))); } -#endif if (fBBH.get()) { SkRect cullRect = SkRect::MakeWH(fCullWidth, fCullHeight); -#if SK_SUPPORT_GPU if (saveLayerData) { SkRecordComputeLayers(cullRect, *fRecord, fBBH.get(), saveLayerData); } else { -#endif SkRecordFillBounds(cullRect, *fRecord, fBBH.get()); -#if SK_SUPPORT_GPU } -#endif } SkPicture* pict = SkNEW_ARGS(SkPicture, (fCullWidth, fCullHeight, fRecord.detach(), fBBH.get())); -#if SK_SUPPORT_GPU if (saveLayerData) { pict->EXPERIMENTAL_addAccelData(saveLayerData); } -#endif return pict; } diff --git a/src/core/SkRecordDraw.cpp b/src/core/SkRecordDraw.cpp index 9075e508f7..e35e5a0a9d 100644 --- a/src/core/SkRecordDraw.cpp +++ b/src/core/SkRecordDraw.cpp @@ -5,13 +5,10 @@ * found in the LICENSE file. */ +#include "SkLayerInfo.h" #include "SkRecordDraw.h" #include "SkPatchUtils.h" -#if SK_SUPPORT_GPU -#include "GrPictureUtils.h" -#endif - void SkRecordDraw(const SkRecord& record, SkCanvas* canvas, const SkBBoxHierarchy* bbh, @@ -570,11 +567,10 @@ private: SkTDArray fControlIndices; }; -#if SK_SUPPORT_GPU // SkRecord visitor to gather saveLayer/restore information. class CollectLayers : SkNoncopyable { public: - CollectLayers(const SkRect& cullRect, const SkRecord& record, GrAccelData* accelData) + CollectLayers(const SkRect& cullRect, const SkRecord& record, SkLayerInfo* accelData) : fSaveLayersInStack(0) , fAccelData(accelData) , fFillBounds(cullRect, record) { @@ -624,10 +620,10 @@ private: void trackSaveLayers(const DrawPicture& dp) { // For sub-pictures, we wrap their layer information within the parent // picture's rendering hierarchy - SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey(); + SkPicture::AccelData::Key key = SkLayerInfo::ComputeKey(); - const GrAccelData* childData = - static_cast(dp.picture->EXPERIMENTAL_getAccelData(key)); + const SkLayerInfo* childData = + static_cast(dp.picture->EXPERIMENTAL_getAccelData(key)); if (!childData) { // If the child layer hasn't been generated with saveLayer data we // assume the worst (i.e., that it does contain layers which nest @@ -638,8 +634,8 @@ private: return; } - for (int i = 0; i < childData->numSaveLayers(); ++i) { - const GrAccelData::SaveLayerInfo& src = childData->saveLayerInfo(i); + for (int i = 0; i < childData->numBlocks(); ++i) { + const SkLayerInfo::BlockInfo& src = childData->block(i); FillBounds::Bounds newBound = fFillBounds.adjustAndMap(src.fBounds, dp.paint); if (newBound.isEmpty()) { @@ -648,7 +644,7 @@ private: this->updateStackForSaveLayer(); - GrAccelData::SaveLayerInfo& dst = fAccelData->addSaveLayerInfo(); + SkLayerInfo::BlockInfo& dst = fAccelData->addBlock(); // If src.fPicture is NULL the layer is in dp.picture; otherwise // it belongs to a sub-picture. @@ -706,30 +702,29 @@ private: --fSaveLayersInStack; - GrAccelData::SaveLayerInfo& slInfo = fAccelData->addSaveLayerInfo(); + SkLayerInfo::BlockInfo& block = fAccelData->addBlock(); - SkASSERT(NULL == slInfo.fPicture); // This layer is in the top-most picture + SkASSERT(NULL == block.fPicture); // This layer is in the top-most picture - slInfo.fBounds = fFillBounds.getBounds(sli.fStartIndex); - slInfo.fLocalMat = fFillBounds.ctm(); - slInfo.fPreMat = SkMatrix::I(); + block.fBounds = fFillBounds.getBounds(sli.fStartIndex); + block.fLocalMat = fFillBounds.ctm(); + block.fPreMat = SkMatrix::I(); if (sli.fPaint) { - slInfo.fPaint = SkNEW_ARGS(SkPaint, (*sli.fPaint)); + block.fPaint = SkNEW_ARGS(SkPaint, (*sli.fPaint)); } - slInfo.fSaveLayerOpID = sli.fStartIndex; - slInfo.fRestoreOpID = fFillBounds.currentOp(); - slInfo.fHasNestedLayers = sli.fHasNestedSaveLayer; - slInfo.fIsNested = fSaveLayersInStack > 0; + block.fSaveLayerOpID = sli.fStartIndex; + block.fRestoreOpID = fFillBounds.currentOp(); + block.fHasNestedLayers = sli.fHasNestedSaveLayer; + block.fIsNested = fSaveLayersInStack > 0; } // Used to collect saveLayer information for layer hoisting int fSaveLayersInStack; SkTDArray fSaveLayerStack; - GrAccelData* fAccelData; + SkLayerInfo* fAccelData; SkRecords::FillBounds fFillBounds; }; -#endif } // namespace SkRecords @@ -744,9 +739,8 @@ void SkRecordFillBounds(const SkRect& cullRect, const SkRecord& record, SkBBoxHi visitor.cleanUp(bbh); } -#if SK_SUPPORT_GPU void SkRecordComputeLayers(const SkRect& cullRect, const SkRecord& record, - SkBBoxHierarchy* bbh, GrAccelData* data) { + SkBBoxHierarchy* bbh, SkLayerInfo* data) { SkRecords::CollectLayers visitor(cullRect, record, data); for (unsigned curOp = 0; curOp < record.count(); curOp++) { @@ -756,5 +750,4 @@ void SkRecordComputeLayers(const SkRect& cullRect, const SkRecord& record, visitor.cleanUp(bbh); } -#endif diff --git a/src/core/SkRecordDraw.h b/src/core/SkRecordDraw.h index 8df64cbecd..9b39dd6adb 100644 --- a/src/core/SkRecordDraw.h +++ b/src/core/SkRecordDraw.h @@ -14,15 +14,13 @@ #include "SkMatrix.h" #include "SkRecord.h" +class SkLayerInfo; + // Fill a BBH to be used by SkRecordDraw to accelerate playback. void SkRecordFillBounds(const SkRect& cullRect, const SkRecord&, SkBBoxHierarchy*); -#if SK_SUPPORT_GPU -class GrAccelData; - void SkRecordComputeLayers(const SkRect& cullRect, const SkRecord& record, - SkBBoxHierarchy* bbh, GrAccelData* data); -#endif + SkBBoxHierarchy* bbh, SkLayerInfo* data); // Draw an SkRecord into an SkCanvas. A convenience wrapper around SkRecords::Draw. void SkRecordDraw(const SkRecord&, SkCanvas*, const SkBBoxHierarchy*, SkDrawPictureCallback*); diff --git a/src/gpu/GrLayerCache.h b/src/gpu/GrLayerCache.h index 69b59cf747..8dec8e594d 100644 --- a/src/gpu/GrLayerCache.h +++ b/src/gpu/GrLayerCache.h @@ -9,15 +9,13 @@ #define GrLayerCache_DEFINED #include "GrAtlas.h" -#include "GrPictureUtils.h" #include "GrRect.h" #include "SkChecksum.h" #include "SkMessageBus.h" +#include "SkPicture.h" #include "SkTDynamicHash.h" -class SkPicture; - // Set to 0 to disable caching of hoisted layers #define GR_CACHE_HOISTED_LAYERS 0 diff --git a/src/gpu/GrLayerHoister.cpp b/src/gpu/GrLayerHoister.cpp index c74913d757..bc635aea07 100644 --- a/src/gpu/GrLayerHoister.cpp +++ b/src/gpu/GrLayerHoister.cpp @@ -11,6 +11,7 @@ #include "SkCanvas.h" #include "SkGrPixelRef.h" +#include "SkLayerInfo.h" #include "SkRecordDraw.h" #include "SkSurface.h" @@ -18,7 +19,7 @@ // required texture/render target resources. static void prepare_for_hoisting(GrLayerCache* layerCache, const SkPicture* topLevelPicture, - const GrAccelData::SaveLayerInfo& info, + const SkLayerInfo::BlockInfo& info, const SkIRect& layerRect, SkTDArray* needRendering, SkTDArray* recycled, @@ -93,22 +94,22 @@ void GrLayerHoister::FindLayersToAtlas(GrContext* context, layerCache->processDeletedPictures(); - SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey(); + SkPicture::AccelData::Key key = SkLayerInfo::ComputeKey(); const SkPicture::AccelData* topLevelData = topLevelPicture->EXPERIMENTAL_getAccelData(key); if (!topLevelData) { return; } - const GrAccelData *topLevelGPUData = static_cast(topLevelData); - if (0 == topLevelGPUData->numSaveLayers()) { + const SkLayerInfo *topLevelGPUData = static_cast(topLevelData); + if (0 == topLevelGPUData->numBlocks()) { return; } - atlased->setReserve(atlased->count() + topLevelGPUData->numSaveLayers()); + atlased->setReserve(atlased->count() + topLevelGPUData->numBlocks()); - for (int i = 0; i < topLevelGPUData->numSaveLayers(); ++i) { - const GrAccelData::SaveLayerInfo& info = topLevelGPUData->saveLayerInfo(i); + for (int i = 0; i < topLevelGPUData->numBlocks(); ++i) { + const SkLayerInfo::BlockInfo& info = topLevelGPUData->block(i); // TODO: ignore perspective projected layers here? bool disallowAtlasing = info.fHasNestedLayers || info.fIsNested || @@ -145,21 +146,21 @@ void GrLayerHoister::FindLayersToHoist(GrContext* context, layerCache->processDeletedPictures(); - SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey(); + SkPicture::AccelData::Key key = SkLayerInfo::ComputeKey(); const SkPicture::AccelData* topLevelData = topLevelPicture->EXPERIMENTAL_getAccelData(key); if (!topLevelData) { return; } - const GrAccelData *topLevelGPUData = static_cast(topLevelData); - if (0 == topLevelGPUData->numSaveLayers()) { + const SkLayerInfo *topLevelGPUData = static_cast(topLevelData); + if (0 == topLevelGPUData->numBlocks()) { return; } // Find and prepare for hoisting all the layers that intersect the query rect - for (int i = 0; i < topLevelGPUData->numSaveLayers(); ++i) { - const GrAccelData::SaveLayerInfo& info = topLevelGPUData->saveLayerInfo(i); + for (int i = 0; i < topLevelGPUData->numBlocks(); ++i) { + const SkLayerInfo::BlockInfo& info = topLevelGPUData->block(i); if (info.fIsNested) { // Parent layers are currently hoisted while nested layers are not. continue; diff --git a/src/gpu/GrLayerHoister.h b/src/gpu/GrLayerHoister.h index 0780c1e801..12d8a842a0 100644 --- a/src/gpu/GrLayerHoister.h +++ b/src/gpu/GrLayerHoister.h @@ -11,7 +11,6 @@ #include "SkPicture.h" #include "SkTDArray.h" -class GrAccelData; struct GrCachedLayer; class GrReplacements; struct SkRect; diff --git a/src/gpu/GrPictureUtils.cpp b/src/gpu/GrPictureUtils.cpp deleted file mode 100644 index e8e965bb57..0000000000 --- a/src/gpu/GrPictureUtils.cpp +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2014 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "GrPictureUtils.h" - -#include "SkBBoxHierarchy.h" -#include "SkPaintPriv.h" -#include "SkPatchUtils.h" -#include "SkRecord.h" -#include "SkRecords.h" - -SkPicture::AccelData::Key GrAccelData::ComputeAccelDataKey() { - static const SkPicture::AccelData::Key gGPUID = SkPicture::AccelData::GenerateDomain(); - - return gGPUID; -} - diff --git a/src/gpu/GrPictureUtils.h b/src/gpu/GrPictureUtils.h deleted file mode 100644 index f24910507d..0000000000 --- a/src/gpu/GrPictureUtils.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2014 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef GrPictureUtils_DEFINED -#define GrPictureUtils_DEFINED - -#include "SkPicture.h" -#include "SkTArray.h" - -// This class encapsulates the GPU-backend-specific acceleration data -// for a single SkPicture -class GrAccelData : public SkPicture::AccelData { -public: - // Information about a given saveLayer in an SkPicture - class SaveLayerInfo { - public: - SaveLayerInfo() : fPicture(NULL), fPaint(NULL) {} - ~SaveLayerInfo() { SkSafeUnref(fPicture); SkDELETE(fPaint); } - - // The picture owning the layer. If the owning picture is the top-most - // one (i.e., the picture for which this GrAccelData was created) then - // this pointer is NULL. If it is a nested picture then the pointer - // is non-NULL and owns a ref on the picture. - const SkPicture* fPicture; - // The device space bounds of this layer. - SkRect fBounds; - // The pre-matrix begins as the identity and accumulates the transforms - // of the containing SkPictures (if any). This matrix state has to be - // part of the initial matrix during replay so that it will be - // preserved across setMatrix calls. - SkMatrix fPreMat; - // The matrix state (in the leaf picture) in which this layer's draws - // must occur. It will/can be overridden by setMatrix calls in the - // layer itself. It does not include the translation needed to map the - // layer's top-left point to the origin (which must be part of the - // initial matrix). - SkMatrix fLocalMat; - // The paint to use on restore. Can be NULL since it is optional. - const SkPaint* fPaint; - // The ID of this saveLayer in the picture. 0 is an invalid ID. - size_t fSaveLayerOpID; - // The ID of the matching restore in the picture. 0 is an invalid ID. - size_t fRestoreOpID; - // True if this saveLayer has at least one other saveLayer nested within it. - // False otherwise. - bool fHasNestedLayers; - // True if this saveLayer is nested within another. False otherwise. - bool fIsNested; - }; - - GrAccelData(Key key) : INHERITED(key) { } - - virtual ~GrAccelData() { } - - SaveLayerInfo& addSaveLayerInfo() { return fSaveLayerInfo.push_back(); } - - int numSaveLayers() const { return fSaveLayerInfo.count(); } - - const SaveLayerInfo& saveLayerInfo(int index) const { - SkASSERT(index < fSaveLayerInfo.count()); - - return fSaveLayerInfo[index]; - } - - // We may, in the future, need to pass in the GPUDevice in order to - // incorporate the clip and matrix state into the key - static SkPicture::AccelData::Key ComputeAccelDataKey(); - -private: - SkTArray fSaveLayerInfo; - - typedef SkPicture::AccelData INHERITED; -}; - -#endif // GrPictureUtils_DEFINED diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index 06f6eb7778..124f994612 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -15,9 +15,7 @@ #include "GrContext.h" #include "GrBitmapTextContext.h" #include "GrDistanceFieldTextContext.h" -#include "GrLayerCache.h" #include "GrLayerHoister.h" -#include "GrPictureUtils.h" #include "GrRecordReplaceDraw.h" #include "GrStrokeInfo.h" #include "GrTracing.h" @@ -29,6 +27,7 @@ #include "SkDrawProcs.h" #include "SkGlyphCache.h" #include "SkImageFilter.h" +#include "SkLayerInfo.h" #include "SkMaskFilter.h" #include "SkPathEffect.h" #include "SkPicture.h" @@ -1796,7 +1795,7 @@ bool SkGpuDevice::EXPERIMENTAL_drawPicture(SkCanvas* mainCanvas, const SkPicture return false; } - SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey(); + SkPicture::AccelData::Key key = SkLayerInfo::ComputeKey(); const SkPicture::AccelData* data = mainPicture->EXPERIMENTAL_getAccelData(key); if (!data) { -- cgit v1.2.3