Add standalone drawText for GrTextContext.
This unifies the interface between GrBitmapTextContext and
GrDistanceFieldTextContext so that they don't need special case code.
The future GrNVPRTextContext will also use this interface.
BUG=skia:2018
R=bsalomon@google.com, reed@google.com
Author: jvanverth@google.com
Review URL: https://codereview.chromium.org/141863005
git-svn-id: http://skia.googlecode.com/svn/trunk@13227 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/gpu/GrTextContext.h b/include/gpu/GrTextContext.h
index 1539df0..a8c0df0 100644
--- a/include/gpu/GrTextContext.h
+++ b/include/gpu/GrTextContext.h
@@ -8,9 +8,10 @@
#ifndef GrTextContext_DEFINED
#define GrTextContext_DEFINED
-#include "GrContext.h"
+#include "GrPoint.h"
#include "GrGlyph.h"
#include "GrPaint.h"
+#include "SkDeviceProperties.h"
#include "SkPostConfig.h"
@@ -24,18 +25,25 @@
class GrTextContext {
public:
virtual ~GrTextContext() {}
- virtual void drawPackedGlyph(GrGlyph::PackedID, GrFixed left, GrFixed top,
- GrFontScaler*) = 0;
+ virtual void drawText(const char text[], size_t byteLength, SkScalar x, SkScalar y) = 0;
+ virtual void drawPosText(const char text[], size_t byteLength,
+ const SkScalar pos[], SkScalar constY,
+ int scalarsPerPosition) = 0;
protected:
- GrTextContext(GrContext*, const GrPaint&, const SkPaint&);
+ GrTextContext(GrContext*, const GrPaint&, const SkPaint&, const SkDeviceProperties&);
- GrPaint fPaint;
- SkPaint fSkPaint;
- GrContext* fContext;
- GrDrawTarget* fDrawTarget;
+ static GrFontScaler* GetGrFontScaler(SkGlyphCache* cache);
+ static void MeasureText(SkGlyphCache* cache, SkDrawCacheProc glyphCacheProc,
+ const char text[], size_t byteLength, SkVector* stopVector);
+
+ GrContext* fContext;
+ GrPaint fPaint;
+ SkPaint fSkPaint;
+ SkDeviceProperties fDeviceProperties;
+ GrDrawTarget* fDrawTarget;
- SkIRect fClipRect;
+ SkIRect fClipRect;
};
/*
@@ -45,8 +53,8 @@
class GrTextContextManager {
public:
virtual ~GrTextContextManager() {}
- virtual GrTextContext* create(GrContext* context, const GrPaint& grPaint,
- const SkPaint& skPaint) = 0;
+ virtual GrTextContext* create(GrContext* grContext, const GrPaint& grPaint,
+ const SkPaint& skPaint, const SkDeviceProperties& props) = 0;
};
template <class TextContextClass>
@@ -54,13 +62,14 @@
private:
class ManagedTextContext : public TextContextClass {
public:
- ~ManagedTextContext() {}
+ virtual ~ManagedTextContext() {}
- ManagedTextContext(GrContext* context,
+ ManagedTextContext(GrContext* grContext,
const GrPaint& grPaint,
const SkPaint& skPaint,
+ const SkDeviceProperties& properties,
GrTTextContextManager<TextContextClass>* manager) :
- TextContextClass(context, grPaint, skPaint) {
+ TextContextClass(grContext, grPaint, skPaint, properties) {
fManager = manager;
}
@@ -84,17 +93,19 @@
fUsed = false;
}
- ~GrTTextContextManager() {
+ virtual ~GrTTextContextManager() {
SkASSERT(!fUsed);
sk_free(fAllocation);
}
- GrTextContext* create(GrContext* context, const GrPaint& grPaint,
- const SkPaint& skPaint) {
+ virtual GrTextContext* create(GrContext* grContext, const GrPaint& grPaint,
+ const SkPaint& skPaint, const SkDeviceProperties& properties)
+ SK_OVERRIDE {
// add check for usePath here?
SkASSERT(!fUsed);
ManagedTextContext* obj = SkNEW_PLACEMENT_ARGS(fAllocation, ManagedTextContext,
- (context, grPaint, skPaint, this));
+ (grContext, grPaint, skPaint, properties,
+ this));
fUsed = true;
return obj;
}