зеркало из https://github.com/mozilla/moz-skia.git
Increase number of stages from 1 to 2
Move GrTextContext from stage 0 to stage 1 so it doesn't conflict with GrPaint (allow textured text) Switch to dynamically generated shaders git-svn-id: http://skia.googlecode.com/svn/trunk@721 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
Родитель
1a2e8d233d
Коммит
7d34d2eecc
|
@ -50,7 +50,7 @@ public:
|
||||||
|
|
||||||
// Currently there is just one stage but this will be changed soon.
|
// Currently there is just one stage but this will be changed soon.
|
||||||
enum {
|
enum {
|
||||||
kNumStages = 1,
|
kNumStages = 2,
|
||||||
kMaxTexCoords = kNumStages
|
kMaxTexCoords = kNumStages
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,8 @@ public:
|
||||||
void flush(); // optional; automatically called by destructor
|
void flush(); // optional; automatically called by destructor
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const GrPaint& fPaint;
|
GrPaint fPaint;
|
||||||
|
GrVertexLayout fVertexLayout;
|
||||||
GrContext* fContext;
|
GrContext* fContext;
|
||||||
GrDrawTarget* fDrawTarget;
|
GrDrawTarget* fDrawTarget;
|
||||||
|
|
||||||
|
|
|
@ -472,9 +472,14 @@ void GrDrawTarget::setIndexSourceToBuffer(const GrIndexBuffer* buffer) {
|
||||||
|
|
||||||
GrDrawTarget::AutoStateRestore::AutoStateRestore(GrDrawTarget* target) {
|
GrDrawTarget::AutoStateRestore::AutoStateRestore(GrDrawTarget* target) {
|
||||||
fDrawTarget = target;
|
fDrawTarget = target;
|
||||||
fDrawTarget->saveCurrentDrawState(&fDrawState);
|
if (NULL != fDrawTarget) {
|
||||||
|
fDrawTarget->saveCurrentDrawState(&fDrawState);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GrDrawTarget::AutoStateRestore::~AutoStateRestore() {
|
GrDrawTarget::AutoStateRestore::~AutoStateRestore() {
|
||||||
fDrawTarget->restoreDrawState(fDrawState);
|
if (NULL != fDrawTarget) {
|
||||||
|
fDrawTarget->restoreDrawState(fDrawState);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,9 @@ void GrGpu::resetContext() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrGpu::unimpl(const char msg[]) {
|
void GrGpu::unimpl(const char msg[]) {
|
||||||
// GrPrintf("--- GrGpu unimplemented(\"%s\")\n", msg);
|
#if GR_DEBUG
|
||||||
|
GrPrintf("--- GrGpu unimplemented(\"%s\")\n", msg);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -108,7 +110,7 @@ bool GrGpu::canDisableBlend() const {
|
||||||
if (VertexUsesStage(s, fGeometrySrc.fVertexLayout)) {
|
if (VertexUsesStage(s, fGeometrySrc.fVertexLayout)) {
|
||||||
GrAssert(NULL != fCurrDrawState.fTextures[s]);
|
GrAssert(NULL != fCurrDrawState.fTextures[s]);
|
||||||
GrTexture::PixelConfig config = fCurrDrawState.fTextures[s]->config();
|
GrTexture::PixelConfig config = fCurrDrawState.fTextures[s]->config();
|
||||||
|
|
||||||
if (GrTexture::kRGB_565_PixelConfig != config &&
|
if (GrTexture::kRGB_565_PixelConfig != config &&
|
||||||
GrTexture::kRGBX_8888_PixelConfig != config) {
|
GrTexture::kRGBX_8888_PixelConfig != config) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
#include "GrGLConfig.h"
|
#include "GrGLConfig.h"
|
||||||
|
|
||||||
#define GR_USE_GLSHADERS2 0
|
#define GR_USE_GLSHADERS2 1
|
||||||
|
|
||||||
#if GR_SUPPORT_GLES1 || GR_SUPPORT_GLDESKTOP
|
#if GR_SUPPORT_GLES1 || GR_SUPPORT_GLDESKTOP
|
||||||
#include "GrGpuGLFixed.h"
|
#include "GrGpuGLFixed.h"
|
||||||
|
|
|
@ -1019,9 +1019,13 @@ void GrGpuGL::flushScissor(const GrIRect* rect) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrGpuGL::eraseColor(GrColor color) {
|
void GrGpuGL::eraseColor(GrColor color) {
|
||||||
|
if (NULL == fCurrDrawState.fRenderTarget) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
flushRenderTarget();
|
flushRenderTarget();
|
||||||
if (fHWBounds.fScissorEnabled) {
|
if (fHWBounds.fScissorEnabled) {
|
||||||
GR_GL(Disable(GL_SCISSOR_TEST));
|
GR_GL(Disable(GL_SCISSOR_TEST));
|
||||||
|
fHWBounds.fScissorEnabled = false;
|
||||||
}
|
}
|
||||||
GR_GL(ColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE));
|
GR_GL(ColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE));
|
||||||
GR_GL(ClearColor(GrColorUnpackR(color)/255.f,
|
GR_GL(ClearColor(GrColorUnpackR(color)/255.f,
|
||||||
|
@ -1029,19 +1033,21 @@ void GrGpuGL::eraseColor(GrColor color) {
|
||||||
GrColorUnpackB(color)/255.f,
|
GrColorUnpackB(color)/255.f,
|
||||||
GrColorUnpackA(color)/255.f));
|
GrColorUnpackA(color)/255.f));
|
||||||
GR_GL(Clear(GL_COLOR_BUFFER_BIT));
|
GR_GL(Clear(GL_COLOR_BUFFER_BIT));
|
||||||
fHWBounds.fScissorEnabled = false;
|
|
||||||
fWriteMaskChanged = true;
|
fWriteMaskChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrGpuGL::eraseStencil(uint32_t value, uint32_t mask) {
|
void GrGpuGL::eraseStencil(uint32_t value, uint32_t mask) {
|
||||||
|
if (NULL == fCurrDrawState.fRenderTarget) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
flushRenderTarget();
|
flushRenderTarget();
|
||||||
if (fHWBounds.fScissorEnabled) {
|
if (fHWBounds.fScissorEnabled) {
|
||||||
GR_GL(Disable(GL_SCISSOR_TEST));
|
GR_GL(Disable(GL_SCISSOR_TEST));
|
||||||
|
fHWBounds.fScissorEnabled = false;
|
||||||
}
|
}
|
||||||
GR_GL(StencilMask(mask));
|
GR_GL(StencilMask(mask));
|
||||||
GR_GL(ClearStencil(value));
|
GR_GL(ClearStencil(value));
|
||||||
GR_GL(Clear(GL_STENCIL_BUFFER_BIT));
|
GR_GL(Clear(GL_STENCIL_BUFFER_BIT));
|
||||||
fHWBounds.fScissorEnabled = false;
|
|
||||||
fWriteMaskChanged = true;
|
fWriteMaskChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -236,13 +236,17 @@ static uint32_t ror(uint32_t x) {
|
||||||
return (x >> 8) | (x << 24);
|
return (x >> 8) | (x << 24);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint32_t rol(uint32_t x) {
|
||||||
|
return (x << 8) | (x >> 24);
|
||||||
|
}
|
||||||
|
|
||||||
GrGpuGLShaders2::ProgramCache::HashKey::HashKey(const ProgramDesc& desc) {
|
GrGpuGLShaders2::ProgramCache::HashKey::HashKey(const ProgramDesc& desc) {
|
||||||
fDesc = desc;
|
fDesc = desc;
|
||||||
// if you change the size of the desc, need to update the hash function
|
// if you change the size of the desc, need to update the hash function
|
||||||
GR_STATIC_ASSERT(8 == sizeof(ProgramDesc));
|
GR_STATIC_ASSERT(12 == sizeof(ProgramDesc));
|
||||||
|
|
||||||
uint32_t* d = (uint32_t*) &fDesc;
|
uint32_t* d = (uint32_t*) &fDesc;
|
||||||
fHash = d[0] ^ ror(d[1]);
|
fHash = d[0] ^ ror(d[1]) ^ rol(d[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GrGpuGLShaders2::ProgramCache::HashKey::EQ(const Entry& entry,
|
bool GrGpuGLShaders2::ProgramCache::HashKey::EQ(const Entry& entry,
|
||||||
|
@ -267,7 +271,6 @@ uint32_t GrGpuGLShaders2::ProgramCache::HashKey::getHash() const {
|
||||||
return fHash;
|
return fHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct GrGpuGLShaders2::ShaderCodeSegments {
|
struct GrGpuGLShaders2::ShaderCodeSegments {
|
||||||
GrSStringBuilder<256> fVSUnis;
|
GrSStringBuilder<256> fVSUnis;
|
||||||
GrSStringBuilder<256> fVSAttrs;
|
GrSStringBuilder<256> fVSAttrs;
|
||||||
|
|
|
@ -23,9 +23,11 @@
|
||||||
#include "GrTextStrike_impl.h"
|
#include "GrTextStrike_impl.h"
|
||||||
#include "GrFontScaler.h"
|
#include "GrFontScaler.h"
|
||||||
|
|
||||||
static const GrVertexLayout VLAYOUT =
|
static const int TEXT_STAGE = 1;
|
||||||
GrDrawTarget::kTextFormat_VertexLayoutBit |
|
|
||||||
GrDrawTarget::StageTexCoordVertexLayoutBit(0,0);
|
static const GrVertexLayout BASE_VLAYOUT =
|
||||||
|
GrDrawTarget::kTextFormat_VertexLayoutBit |
|
||||||
|
GrDrawTarget::StageTexCoordVertexLayoutBit(TEXT_STAGE,0);
|
||||||
|
|
||||||
void GrTextContext::flushGlyphs() {
|
void GrTextContext::flushGlyphs() {
|
||||||
if (fCurrVertex > 0) {
|
if (fCurrVertex > 0) {
|
||||||
|
@ -36,18 +38,17 @@ void GrTextContext::flushGlyphs() {
|
||||||
GrSamplerState sampler(GrSamplerState::kRepeat_WrapMode,
|
GrSamplerState sampler(GrSamplerState::kRepeat_WrapMode,
|
||||||
GrSamplerState::kRepeat_WrapMode,
|
GrSamplerState::kRepeat_WrapMode,
|
||||||
!fExtMatrix.isIdentity());
|
!fExtMatrix.isIdentity());
|
||||||
fDrawTarget->setSamplerState(0, sampler);
|
fDrawTarget->setSamplerState(TEXT_STAGE, sampler);
|
||||||
|
|
||||||
GrAssert(GrIsALIGN4(fCurrVertex));
|
GrAssert(GrIsALIGN4(fCurrVertex));
|
||||||
int nIndices = fCurrVertex + (fCurrVertex >> 1);
|
int nIndices = fCurrVertex + (fCurrVertex >> 1);
|
||||||
GrAssert(fCurrTexture);
|
GrAssert(fCurrTexture);
|
||||||
fDrawTarget->setTexture(0, fCurrTexture);
|
fDrawTarget->setTexture(TEXT_STAGE, fCurrTexture);
|
||||||
fDrawTarget->setTextureMatrix(0, GrMatrix::I());
|
fDrawTarget->setTextureMatrix(TEXT_STAGE, GrMatrix::I());
|
||||||
fDrawTarget->setIndexSourceToBuffer(fContext->quadIndexBuffer());
|
fDrawTarget->setIndexSourceToBuffer(fContext->quadIndexBuffer());
|
||||||
|
|
||||||
fDrawTarget->drawIndexed(GrDrawTarget::kTriangles_PrimitiveType,
|
fDrawTarget->drawIndexed(GrDrawTarget::kTriangles_PrimitiveType,
|
||||||
0, 0, fCurrVertex, nIndices);
|
0, 0, fCurrVertex, nIndices);
|
||||||
|
|
||||||
fDrawTarget->releaseReservedGeometry();
|
fDrawTarget->releaseReservedGeometry();
|
||||||
fVertices = NULL;
|
fVertices = NULL;
|
||||||
fMaxVertices = 0;
|
fMaxVertices = 0;
|
||||||
|
@ -82,9 +83,20 @@ GrTextContext::GrTextContext(GrContext* context,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// save the context's original matrix off and restore in destructor
|
||||||
|
// this must be done before getTextTarget.
|
||||||
fOrigViewMatrix = fContext->getMatrix();
|
fOrigViewMatrix = fContext->getMatrix();
|
||||||
fContext->setMatrix(fExtMatrix);
|
fContext->setMatrix(fExtMatrix);
|
||||||
|
|
||||||
|
fVertexLayout = BASE_VLAYOUT;
|
||||||
|
if (NULL != paint.getTexture()) {
|
||||||
|
fVertexLayout |= GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(0);
|
||||||
|
GrMatrix inverseViewMatrix;
|
||||||
|
if (fOrigViewMatrix.invert(&inverseViewMatrix)) {
|
||||||
|
fPaint.fTextureMatrix.preConcat(inverseViewMatrix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fVertices = NULL;
|
fVertices = NULL;
|
||||||
fMaxVertices = 0;
|
fMaxVertices = 0;
|
||||||
fDrawTarget = fContext->getTextTarget(fPaint);
|
fDrawTarget = fContext->getTextTarget(fPaint);
|
||||||
|
@ -191,7 +203,7 @@ HAS_ATLAS:
|
||||||
// If we need to reserve vertices allow the draw target to suggest
|
// If we need to reserve vertices allow the draw target to suggest
|
||||||
// a number of verts to reserve and whether to perform a flush.
|
// a number of verts to reserve and whether to perform a flush.
|
||||||
fMaxVertices = kMinRequestedVerts;
|
fMaxVertices = kMinRequestedVerts;
|
||||||
bool flush = fDrawTarget->geometryHints(VLAYOUT,
|
bool flush = fDrawTarget->geometryHints(fVertexLayout,
|
||||||
&fMaxVertices,
|
&fMaxVertices,
|
||||||
NULL);
|
NULL);
|
||||||
if (flush) {
|
if (flush) {
|
||||||
|
@ -200,7 +212,7 @@ HAS_ATLAS:
|
||||||
fDrawTarget = fContext->getTextTarget(fPaint);
|
fDrawTarget = fContext->getTextTarget(fPaint);
|
||||||
fMaxVertices = kDefaultRequestedVerts;
|
fMaxVertices = kDefaultRequestedVerts;
|
||||||
// ignore return, no point in flushing again.
|
// ignore return, no point in flushing again.
|
||||||
fDrawTarget->geometryHints(VLAYOUT,
|
fDrawTarget->geometryHints(fVertexLayout,
|
||||||
&fMaxVertices,
|
&fMaxVertices,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
@ -211,7 +223,7 @@ HAS_ATLAS:
|
||||||
// don't exceed the limit of the index buffer
|
// don't exceed the limit of the index buffer
|
||||||
fMaxVertices = (fContext->maxQuadsInIndexBuffer() * 4);
|
fMaxVertices = (fContext->maxQuadsInIndexBuffer() * 4);
|
||||||
}
|
}
|
||||||
bool success = fDrawTarget->reserveAndLockGeometry(VLAYOUT,
|
bool success = fDrawTarget->reserveAndLockGeometry(fVertexLayout,
|
||||||
fMaxVertices, 0,
|
fMaxVertices, 0,
|
||||||
GrTCast<void**>(&fVertices),
|
GrTCast<void**>(&fVertices),
|
||||||
NULL);
|
NULL);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче