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

Unified Diff: src/gpu/GrStencilAndCoverTextContext.h

Issue 1381073002: Implement cached nvpr text blobs (Closed) Base URL: https://skia.googlesource.com/skia.git@upload3_fallbackblob
Patch Set: Created 5 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 | « include/core/SkTextBlob.h ('k') | src/gpu/GrStencilAndCoverTextContext.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrStencilAndCoverTextContext.h
diff --git a/src/gpu/GrStencilAndCoverTextContext.h b/src/gpu/GrStencilAndCoverTextContext.h
index 9e85e89c8820a1c9576f12abac0452f72799f1fb..008f61ee5fde11859e84a27c57c003591f25daef 100644
--- a/src/gpu/GrStencilAndCoverTextContext.h
+++ b/src/gpu/GrStencilAndCoverTextContext.h
@@ -11,6 +11,9 @@
#include "GrTextContext.h"
#include "GrDrawTarget.h"
#include "GrStrokeInfo.h"
+#include "SkTHash.h"
+#include "SkTInternalLList.h"
+#include "SkTLList.h"
class GrTextStrike;
class GrPath;
@@ -31,19 +34,24 @@ public:
private:
GrStencilAndCoverTextContext(GrContext*, const SkSurfaceProps&);
- bool canDraw(const GrRenderTarget*, const GrClip&, const GrPaint&,
- const SkPaint&, const SkMatrix& viewMatrix) override;
+ bool canDraw(const GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint& skPaint,
+ const SkMatrix&) override { return this->internalCanDraw(skPaint); }
+
+ bool internalCanDraw(const SkPaint&);
void onDrawText(GrDrawContext*, GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&,
const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
- SkScalar x, SkScalar y, const SkIRect& regionClipBounds) override;
+ SkScalar x, SkScalar y, const SkIRect& clipBounds) override;
void onDrawPosText(GrDrawContext*, GrRenderTarget*,
const GrClip&, const GrPaint&, const SkPaint&,
const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
const SkScalar pos[], int scalarsPerPosition,
- const SkPoint& offset, const SkIRect& regionClipBounds) override;
+ const SkPoint& offset, const SkIRect& clipBounds) override;
+ void drawTextBlob(GrDrawContext*, GrRenderTarget*, const GrClip&, const SkPaint&,
+ const SkMatrix& viewMatrix, const SkTextBlob*, SkScalar x, SkScalar y,
+ SkDrawFilter*, const SkIRect& clipBounds) override;
class FallbackBlobBuilder;
@@ -59,9 +67,11 @@ private:
const SkScalar pos[], int scalarsPerPosition, const SkPoint& offset,
GrContext*, const SkSurfaceProps*);
- void draw(GrDrawContext*, GrRenderTarget*, const GrClip&, const GrPaint&, const SkMatrix&,
- const SkIRect& regionClipBounds, GrTextContext* fallbackTextContext,
- const SkPaint& originalSkPaint) const;
+ void draw(GrDrawContext*, GrPipelineBuilder*, GrColor, const SkMatrix&,
+ SkScalar x, SkScalar y, const SkIRect& clipBounds,
+ GrTextContext* fallbackTextContext, const SkPaint& originalSkPaint) const;
+
+ int cpuMemorySize() const;
private:
GrPathRange* createGlyphs(GrContext*, SkGlyphCache*);
@@ -72,12 +82,59 @@ private:
SkPaint fFont;
SkScalar fTextRatio;
float fTextInverseRatio;
- SkMatrix fLocalMatrix;
bool fUsingRawGlyphPaths;
+ int fTotalGlyphCount;
SkAutoTUnref<GrPathRangeDraw> fDraw;
SkAutoTUnref<const SkTextBlob> fFallbackTextBlob;
+ mutable SkMatrix fLocalMatrixTemplate;
+ };
+
+ // Text blobs/caches.
+
+ class TextBlob : public SkTLList<TextRun> {
+ public:
+ typedef SkTArray<uint32_t, true> Key;
+
+ static const Key& GetKey(const TextBlob* blob) { return blob->key(); }
+
+ static uint32_t Hash(const Key& key) {
+ SkASSERT(key.count() > 1); // 1-length keys should be using the blob-id hash map.
+ return SkChecksum::Murmur3(key.begin(), sizeof(uint32_t) * key.count());
+ }
+
+ TextBlob(uint32_t blobId, const SkTextBlob* skBlob, const SkPaint& skPaint,
+ GrContext* ctx, const SkSurfaceProps* props)
+ : fKey(&blobId, 1) { this->init(skBlob, skPaint, ctx, props); }
+
+ TextBlob(const Key& key, const SkTextBlob* skBlob, const SkPaint& skPaint,
+ GrContext* ctx, const SkSurfaceProps* props)
+ : fKey(key) {
+ // 1-length keys are unterstood to be the blob id and must use the other constructor.
+ SkASSERT(fKey.count() > 1);
+ this->init(skBlob, skPaint, ctx, props);
+ }
+
+ const Key& key() const { return fKey; }
+
+ int cpuMemorySize() const { return fCpuMemorySize; }
+
+ private:
+ void init(const SkTextBlob*, const SkPaint&, GrContext*, const SkSurfaceProps*);
+
+ const SkSTArray<1, uint32_t, true> fKey;
+ int fCpuMemorySize;
+
+ SK_DECLARE_INTERNAL_LLIST_INTERFACE(TextBlob);
};
+ const TextBlob& findOrCreateTextBlob(const SkTextBlob*, const SkPaint&);
+ void purgeToFit(const TextBlob&);
+
+ SkTHashMap<uint32_t, TextBlob*> fBlobIdCache;
+ SkTHashTable<TextBlob*, const TextBlob::Key&, TextBlob> fBlobKeyCache;
+ SkTInternalLList<TextBlob> fLRUList;
+ int fCacheSize;
+
typedef GrTextContext INHERITED;
};
« no previous file with comments | « include/core/SkTextBlob.h ('k') | src/gpu/GrStencilAndCoverTextContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698