Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(253)

Unified Diff: src/gpu/GrRecordReplaceDraw.h

Issue 607763008: Update GrRecordReplaceDraw to use SkTDynamicHash & add ReplaceDraw (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Re-add missing header Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/GrLayerHoister.cpp ('k') | src/gpu/GrRecordReplaceDraw.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrRecordReplaceDraw.h
diff --git a/src/gpu/GrRecordReplaceDraw.h b/src/gpu/GrRecordReplaceDraw.h
index 4900e0d2417ec7d34d3faf58866814b2a1929b27..b47b0774155aa62847150deab85330da686640a1 100644
--- a/src/gpu/GrRecordReplaceDraw.h
+++ b/src/gpu/GrRecordReplaceDraw.h
@@ -8,9 +8,11 @@
#ifndef GrRecordReplaceDraw_DEFINED
#define GrRecordReplaceDraw_DEFINED
+#include "SkChecksum.h"
#include "SkDrawPictureCallback.h"
+#include "SkImage.h"
#include "SkRect.h"
-#include "SkTDArray.h"
+#include "SkTDynamicHash.h"
class SkBBoxHierarchy;
class SkBitmap;
@@ -26,9 +28,53 @@ class SkRecord;
class GrReplacements {
public:
// All the operations between fStart and fStop (inclusive) will be replaced with
- // a single drawBitmap call using fPos, fBM and fPaint.
- struct ReplacementInfo {
- unsigned fStart;
+ // a single drawBitmap call using fPos, fImage and fPaint.
+ class ReplacementInfo {
+ public:
+ struct Key {
+ Key(uint32_t pictureID, unsigned int start, const SkMatrix& ctm)
+ : fPictureID(pictureID)
+ , fStart(start)
+ , fCTM(ctm) {
+ fCTM.getType(); // force initialization of type so hashes match
+
+ // Key needs to be tightly packed.
+ GR_STATIC_ASSERT(sizeof(Key) == sizeof(uint32_t) + // picture ID
+ sizeof(int) + // start
+ 9 * sizeof(SkScalar) // 3x3 from CTM
+ +sizeof(uint32_t)); // matrix's type
+ }
+
+ bool operator==(const Key& other) const {
+ return fPictureID == other.fPictureID &&
+ fStart == other.fStart &&
+ fCTM.cheapEqualTo(other.fCTM); // TODO: should be fuzzy
+ }
+
+ uint32_t pictureID() const { return fPictureID; }
+ unsigned int start() const { return fStart; }
+
+ private:
+ const uint32_t fPictureID;
+ const unsigned int fStart;
+ const SkMatrix fCTM;
+ };
+
+ static const Key& GetKey(const ReplacementInfo& layer) { return layer.fKey; }
+ static uint32_t Hash(const Key& key) {
+ return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(&key), sizeof(Key));
+ }
+
+ ReplacementInfo(uint32_t pictureID, unsigned int start, const SkMatrix& ctm)
+ : fKey(pictureID, start, ctm)
+ , fImage(NULL)
+ , fPaint(NULL) {
+ }
+ ~ReplacementInfo() { fImage->unref(); SkDELETE(fPaint); }
+
+ unsigned int start() const { return fKey.start(); }
+
+ const Key fKey;
unsigned fStop;
SkIPoint fPos;
SkImage* fImage; // Owns a ref
@@ -39,25 +85,18 @@ public:
~GrReplacements() { this->freeAll(); }
- // Add a new replacement range. The replacement ranges should be
- // sorted in increasing order and non-overlapping (esp. no nested
- // saveLayers).
- ReplacementInfo* push();
+ // Add a new replacement range.
+ ReplacementInfo* newReplacement(uint32_t pictureID, unsigned int start, const SkMatrix& ctm);
- // look up a replacement range by its start offset.
- // lastLookedUp is an in/out parameter that is used to speed up the search.
- // It should be initialized to 0 on the first call and then passed back in
- // unmodified on subsequent calls.
- const ReplacementInfo* lookupByStart(size_t start, int* lastLookedUp) const;
+ // look up a replacement range by its pictureID, start offset and the CTM
+ // TODO: also need to add clip to lookup
+ const ReplacementInfo* lookupByStart(uint32_t pictureID, size_t start,
+ const SkMatrix& ctm) const;
private:
- SkTDArray<ReplacementInfo> fReplacements;
+ SkTDynamicHash<ReplacementInfo, ReplacementInfo::Key> fReplacementHash;
void freeAll();
-
-#ifdef SK_DEBUG
- void validate() const;
-#endif
};
// Draw an SkPicture into an SkCanvas replacing saveLayer/restore blocks with
@@ -65,7 +104,7 @@ private:
void GrRecordReplaceDraw(const SkPicture*,
SkCanvas*,
const GrReplacements*,
- const SkMatrix&,
+ const SkMatrix& initialMatrix,
SkDrawPictureCallback*);
#endif // GrRecordReplaceDraw_DEFINED
« no previous file with comments | « src/gpu/GrLayerHoister.cpp ('k') | src/gpu/GrRecordReplaceDraw.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698