2010-12-22 21:39:39 +00:00
|
|
|
|
2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2010 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2010-12-22 21:39:39 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2011-07-28 14:26:00 +00:00
|
|
|
|
2010-12-22 21:39:39 +00:00
|
|
|
#ifndef GrTextContext_DEFINED
|
|
|
|
#define GrTextContext_DEFINED
|
|
|
|
|
|
|
|
#include "GrGlyph.h"
|
2011-05-10 13:52:42 +00:00
|
|
|
#include "GrMatrix.h"
|
2012-03-16 14:02:46 +00:00
|
|
|
#include "GrRefCnt.h"
|
2010-12-22 21:39:39 +00:00
|
|
|
|
|
|
|
class GrContext;
|
|
|
|
class GrFontScaler;
|
2012-03-16 14:02:46 +00:00
|
|
|
class GrPaint;
|
2010-12-22 21:39:39 +00:00
|
|
|
|
2012-03-16 14:02:46 +00:00
|
|
|
class SkGpuDevice;
|
|
|
|
class SkPaint;
|
2010-12-22 21:39:39 +00:00
|
|
|
|
2012-05-10 12:40:40 +00:00
|
|
|
/**
|
|
|
|
* Derived classes can use stages GrPaint::kTotalStages through
|
|
|
|
* GrDrawState::kNumStages-1. The stages before GrPaint::kTotalStages
|
|
|
|
* are reserved for setting up the draw (i.e., textures and filter masks).
|
|
|
|
*/
|
2012-03-16 14:02:46 +00:00
|
|
|
class GrTextContext: public GrRefCnt {
|
|
|
|
protected:
|
2010-12-22 21:39:39 +00:00
|
|
|
GrContext* fContext;
|
|
|
|
|
2012-03-16 14:02:46 +00:00
|
|
|
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;
|
2010-12-22 21:39:39 +00:00
|
|
|
};
|
|
|
|
|
2012-03-16 14:02:46 +00:00
|
|
|
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;
|
|
|
|
}
|
2010-12-22 21:39:39 +00:00
|
|
|
|
2012-03-16 14:02:46 +00:00
|
|
|
private:
|
|
|
|
typedef GrRefCnt INHERITED;
|
2010-12-22 21:39:39 +00:00
|
|
|
};
|
|
|
|
|
2012-03-16 14:02:46 +00:00
|
|
|
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;
|
|
|
|
}
|
2010-12-22 21:39:39 +00:00
|
|
|
|
2012-03-16 14:02:46 +00:00
|
|
|
#endif
|