aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/gpu/GrTextContext.h122
-rw-r--r--include/gpu/SkGpuDevice.h7
2 files changed, 89 insertions, 40 deletions
diff --git a/include/gpu/GrTextContext.h b/include/gpu/GrTextContext.h
index 5983e358c8..588ae6ee34 100644
--- a/include/gpu/GrTextContext.h
+++ b/include/gpu/GrTextContext.h
@@ -12,57 +12,99 @@
#define GrTextContext_DEFINED
#include "GrGlyph.h"
-#include "GrPaint.h"
#include "GrMatrix.h"
+#include "GrRefCnt.h"
-struct GrGpuTextVertex;
class GrContext;
-class GrTextStrike;
class GrFontScaler;
-class GrDrawTarget;
+class GrPaint;
-class GrTextContext {
-public:
- GrTextContext(GrContext*,
- const GrPaint& paint,
- const GrMatrix* extMatrix = NULL);
- ~GrTextContext();
-
- void drawPackedGlyph(GrGlyph::PackedID, GrFixed left, GrFixed top,
- GrFontScaler*);
-
- void flush(); // optional; automatically called by destructor
+class SkGpuDevice;
+class SkPaint;
-private:
- GrPaint fPaint;
- GrVertexLayout fVertexLayout;
+class GrTextContext: public GrRefCnt {
+protected:
GrContext* fContext;
- GrDrawTarget* fDrawTarget;
-
- GrMatrix fExtMatrix;
- GrFontScaler* fScaler;
- GrTextStrike* fStrike;
-
- inline void flushGlyphs();
- void setupDrawTarget();
- enum {
- kMinRequestedGlyphs = 1,
- kDefaultRequestedGlyphs = 64,
- kMinRequestedVerts = kMinRequestedGlyphs * 4,
- kDefaultRequestedVerts = kDefaultRequestedGlyphs * 4,
+public:
+ /**
+ * To use a text context it must be wrapped in an AutoFinish. AutoFinish's
+ * destructor ensures all drawing is flushed to the GrContext.
+ */
+ class AutoFinish {
+ public:
+ AutoFinish(GrTextContext* textContext, GrContext* context,
+ const GrPaint&, const GrMatrix* extMatrix);
+ ~AutoFinish();
+ GrTextContext* getTextContext() const;
+
+ private:
+ GrTextContext* fTextContext;
};
- GrGpuTextVertex* fVertices;
-
- int32_t fMaxVertices;
- GrTexture* fCurrTexture;
- int fCurrVertex;
+ virtual void drawPackedGlyph(GrGlyph::PackedID, GrFixed left, GrFixed top,
+ GrFontScaler*) = 0;
+
+ virtual ~GrTextContext() {}
+
+protected:
+ GrTextContext() {
+ fContext = NULL;
+ }
+
+ bool isValid() const {
+ return (NULL != fContext);
+ }
+
+ /**
+ * Initialize the object.
+ *
+ * Before call to this method, the instance is considered to be in
+ * invalid state. I.e. call to any method other than isValid will result in
+ * undefined behaviour.
+ *
+ * @see finish
+ */
+ virtual void init(GrContext* context, const GrPaint&,
+ const GrMatrix* extMatrix) {
+ fContext = context;
+ }
+
+ /**
+ * Reset the object to invalid state.
+ *
+ * After call to this method, the instance is considered to be in
+ * invalid state.
+ *
+ * It might be brought back to a valid state by calling init.
+ *
+ * @see init
+ */
+ virtual void finish() {
+ fContext = NULL;
+ }
- GrIRect fClipRect;
- GrMatrix fOrigViewMatrix; // restore previous viewmatrix
+private:
+ typedef GrRefCnt INHERITED;
};
-#endif
-
+inline GrTextContext::AutoFinish::AutoFinish(GrTextContext* textContext,
+ GrContext* context,
+ const GrPaint& grPaint,
+ const GrMatrix* extMatrix) {
+ GrAssert(NULL != textContext);
+ fTextContext = textContext;
+ fTextContext->ref();
+ fTextContext->init(context, grPaint, extMatrix);
+}
+
+inline GrTextContext::AutoFinish::~AutoFinish() {
+ fTextContext->finish();
+ fTextContext->unref();
+}
+
+inline GrTextContext* GrTextContext::AutoFinish::getTextContext() const {
+ return fTextContext;
+}
+#endif
diff --git a/include/gpu/SkGpuDevice.h b/include/gpu/SkGpuDevice.h
index 46c15d6ce7..24e6e5adb1 100644
--- a/include/gpu/SkGpuDevice.h
+++ b/include/gpu/SkGpuDevice.h
@@ -147,6 +147,8 @@ private:
bool fNeedClear;
bool fNeedPrepareRenderTarget;
+ GrTextContext* fTextContext;
+
// called from rt and tex cons
void initFromRenderTarget(GrContext*, GrRenderTarget*);
@@ -167,6 +169,11 @@ private:
void internalDrawBitmap(const SkDraw&, const SkBitmap&,
const SkIRect&, const SkMatrix&, GrPaint* grPaint);
+ /**
+ * Returns non-initialized instance.
+ */
+ GrTextContext* getTextContext();
+
typedef SkDevice INHERITED;
};