f4a9c82918
This is a step towards enabling alternate text rendering code paths (GLyphy in particular) Committed on behalf of baranowski@chromium.org Review URL: http://codereview.appspot.com/5796071/ git-svn-id: http://skia.googlecode.com/svn/trunk@3412 2bbb7eff-a529-9590-31e7-b0007b416f81
111 lines
2.6 KiB
C++
111 lines
2.6 KiB
C++
|
|
/*
|
|
* Copyright 2010 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GrTextContext_DEFINED
|
|
#define GrTextContext_DEFINED
|
|
|
|
#include "GrGlyph.h"
|
|
#include "GrMatrix.h"
|
|
#include "GrRefCnt.h"
|
|
|
|
class GrContext;
|
|
class GrFontScaler;
|
|
class GrPaint;
|
|
|
|
class SkGpuDevice;
|
|
class SkPaint;
|
|
|
|
class GrTextContext: public GrRefCnt {
|
|
protected:
|
|
GrContext* fContext;
|
|
|
|
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;
|
|
};
|
|
|
|
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;
|
|
}
|
|
|
|
private:
|
|
typedef GrRefCnt INHERITED;
|
|
};
|
|
|
|
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
|