Add isMultisampled() to GrRenderTarget. Cleanup MSAA vs smooth lines logic in GrGpuGL.

Skia issue: 178

Review URL: http://codereview.appspot.com/4382041/



git-svn-id: http://skia.googlecode.com/svn/trunk@1067 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
bsalomon@google.com 2011-04-06 17:50:02 +00:00
Родитель 7cf3dcd902
Коммит f954d8dd9a
9 изменённых файлов: 80 добавлений и 34 удалений

Просмотреть файл

@ -164,11 +164,14 @@ public:
* id.
* @param stencilBits the number of stencil bits that the render
* target has.
* @param isMultisampled specify whether the render target is
* multisampled.
* @param width width of the render target.
* @param height height of the render target.
*/
GrRenderTarget* createPlatformRenderTarget(intptr_t platformRenderTarget,
int stencilBits,
bool isMultisampled,
int width, int height);
/**

Просмотреть файл

@ -64,13 +64,14 @@ protected:
GrGLuint fTexFBOID;
GrGLuint fStencilRenderbufferID;
GrGLuint fMSColorRenderbufferID;
bool fOwnIDs;
bool fOwnIDs;
};
GrGLRenderTarget(GrGpuGL* gpu,
const GLRenderTargetIDs& ids,
GrGLTexID* texID,
GrGLuint stencilBits,
bool isMultisampled,
const GrGLIRect& fViewport,
GrGLTexture* texture);

Просмотреть файл

@ -188,12 +188,14 @@ public:
* underlying 3D API. Interpretation depends on
* GrGpu subclass in use.
* @param stencilBits number of stencil bits the target has
* @param isMultisampled specify whether the RT is multisampled
* @param width width of the render target
* @param height height of the render target
*/
virtual GrRenderTarget* createPlatformRenderTarget(
intptr_t platformRenderTarget,
int stencilBits,
bool isMultisampled,
int width, int height);
/**
@ -486,6 +488,7 @@ protected:
virtual GrRenderTarget* createPlatformRenderTargetHelper(
intptr_t platformRenderTarget,
int stencilBits,
bool isMultisampled,
int width, int height) = 0;
virtual GrRenderTarget* createRenderTargetFrom3DApiStateHelper() = 0;
virtual GrVertexBuffer* createVertexBufferHelper(uint32_t size,

Просмотреть файл

@ -53,6 +53,11 @@ public:
*/
GrTexture* asTexture() {return fTexture;}
/**
* @return true if the render target is multisampled, false otherwise
*/
bool isMultisampled() { return fIsMultisampled; }
/**
* Reads a rectangle of pixels from the render target.
* @param left left edge of the rectangle to read (inclusive)
@ -73,12 +78,14 @@ protected:
GrTexture* texture,
int width,
int height,
int stencilBits)
int stencilBits,
bool isMultisampled)
: INHERITED(gpu)
, fTexture(texture)
, fWidth(width)
, fHeight(height)
, fStencilBits(stencilBits)
, fIsMultisampled(isMultisampled)
{}
friend class GrTexture;
@ -96,6 +103,7 @@ protected:
int fWidth;
int fHeight;
int fStencilBits;
bool fIsMultisampled;
private:
// GrGpu keeps a cached clip in the render target to avoid redundantly

Просмотреть файл

@ -270,8 +270,10 @@ int GrContext::getMaxTextureDimension() {
GrRenderTarget* GrContext::createPlatformRenderTarget(
intptr_t platformRenderTarget,
int stencilBits,
bool isMultisampled,
int width, int height) {
return fGpu->createPlatformRenderTarget(platformRenderTarget, stencilBits,
isMultisampled,
width, height);
}

Просмотреть файл

@ -24,9 +24,11 @@ GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu,
const GLRenderTargetIDs& ids,
GrGLTexID* texID,
GrGLuint stencilBits,
bool isMultisampled,
const GrGLIRect& viewport,
GrGLTexture* texture)
: INHERITED(gpu, texture, viewport.fWidth, viewport.fHeight, stencilBits) {
: INHERITED(gpu, texture, viewport.fWidth,
viewport.fHeight, stencilBits, isMultisampled) {
fRTFBOID = ids.fRTFBOID;
fTexFBOID = ids.fTexFBOID;
fStencilRenderbufferID = ids.fStencilRenderbufferID;
@ -96,7 +98,6 @@ const GrGLenum* GrGLTexture::WrapMode2GLWrap() {
}
};
GrGLTexture::GrGLTexture(GrGpuGL* gpu,
const GLTextureDesc& textureDesc,
const GLRenderTargetIDs& rtIDs,
@ -131,6 +132,7 @@ GrGLTexture::GrGLTexture(GrGpuGL* gpu,
fRenderTarget = new GrGLRenderTarget(gpu, rtIDs, fTexIDObj,
textureDesc.fStencilBits,
rtIDs.fRTFBOID != rtIDs.fTexFBOID,
vp, this);
}
}

Просмотреть файл

@ -144,10 +144,12 @@ GrTexture* GrGpu::createTexture(const TextureDesc& desc,
GrRenderTarget* GrGpu::createPlatformRenderTarget(intptr_t platformRenderTarget,
int stencilBits,
bool isMultisampled,
int width, int height) {
this->handleDirtyContext();
return this->createPlatformRenderTargetHelper(platformRenderTarget,
stencilBits,
isMultisampled,
width, height);
}

Просмотреть файл

@ -481,6 +481,8 @@ void GrGpuGL::resetContext() {
GR_GL(Disable(GR_GL_LINE_SMOOTH));
GR_GL(Disable(GR_GL_POINT_SMOOTH));
GR_GL(Disable(GR_GL_MULTISAMPLE));
fHWAAState.fMSAAEnabled = false;
fHWAAState.fSmoothLineEnabled = false;
}
GR_GL(ColorMask(GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE));
@ -534,6 +536,7 @@ void GrGpuGL::resetContext() {
GrRenderTarget* GrGpuGL::createPlatformRenderTargetHelper(
intptr_t platformRenderTarget,
int stencilBits,
bool isMultisampled,
int width,
int height) {
GrGLRenderTarget::GLRenderTargetIDs rtIDs;
@ -552,7 +555,8 @@ GrRenderTarget* GrGpuGL::createPlatformRenderTargetHelper(
rtIDs.fRTFBOID = (GrGLuint)platformRenderTarget;
rtIDs.fTexFBOID = (GrGLuint)platformRenderTarget;
return new GrGLRenderTarget(this, rtIDs, NULL, stencilBits, viewport, NULL);
return new GrGLRenderTarget(this, rtIDs, NULL, stencilBits,
isMultisampled, viewport, NULL);
}
GrRenderTarget* GrGpuGL::createRenderTargetFrom3DApiStateHelper() {
@ -569,9 +573,13 @@ GrRenderTarget* GrGpuGL::createRenderTargetFrom3DApiStateHelper() {
GrGLuint stencilBits;
GR_GL_GetIntegerv(GR_GL_STENCIL_BITS, (GrGLint*)&stencilBits);
GrGLint samples;
GR_GL_GetIntegerv(GR_GL_SAMPLES, &samples);
rtIDs.fOwnIDs = false;
return new GrGLRenderTarget(this, rtIDs, NULL, stencilBits, viewport, NULL);
return new GrGLRenderTarget(this, rtIDs, NULL, stencilBits,
(samples > 0), viewport, NULL);
}
///////////////////////////////////////////////////////////////////////////////
@ -1518,6 +1526,42 @@ void GrGpuGL::flushStencil() {
}
}
void GrGpuGL::flushAAState(GrPrimitiveType type) {
if (GR_GL_SUPPORT_DESKTOP) {
// ES doesn't support toggling GL_MULTISAMPLE and doesn't have
// smooth lines.
// we prefer smooth lines over multisampled lines
// msaa should be disabled if drawing smooth lines.
if (kLines_PrimitiveType == type) {
if (!fHWAAState.fSmoothLineEnabled &&
(kAntialias_StateBit & fCurrDrawState.fFlagBits)) {
GR_GL(Enable(GR_GL_LINE_SMOOTH));
fHWAAState.fSmoothLineEnabled = true;
} else if (fHWAAState.fSmoothLineEnabled &&
!(kAntialias_StateBit & fCurrDrawState.fFlagBits)) {
GR_GL(Disable(GR_GL_LINE_SMOOTH));
fHWAAState.fSmoothLineEnabled = false;
}
if (fCurrDrawState.fRenderTarget->isMultisampled() &&
fHWAAState.fMSAAEnabled) {
GR_GL(Disable(GR_GL_MULTISAMPLE));
fHWAAState.fMSAAEnabled = false;
}
} else if (fCurrDrawState.fRenderTarget->isMultisampled() &&
!!(kAntialias_StateBit & fCurrDrawState.fFlagBits) !=
fHWAAState.fMSAAEnabled) {
if (fHWAAState.fMSAAEnabled) {
GR_GL(Disable(GR_GL_MULTISAMPLE));
fHWAAState.fMSAAEnabled = false;
} else {
GR_GL(Enable(GR_GL_MULTISAMPLE));
fHWAAState.fMSAAEnabled = true;
}
}
}
}
bool GrGpuGL::flushGLStateCommon(GrPrimitiveType type) {
// GrGpu::setupClipAndFlushState should have already checked this
@ -1595,6 +1639,8 @@ bool GrGpuGL::flushGLStateCommon(GrPrimitiveType type) {
flushRenderTarget();
flushAAState(type);
if ((fCurrDrawState.fFlagBits & kDither_StateBit) !=
(fHWDrawState.fFlagBits & kDither_StateBit)) {
if (fCurrDrawState.fFlagBits & kDither_StateBit) {
@ -1615,34 +1661,6 @@ bool GrGpuGL::flushGLStateCommon(GrPrimitiveType type) {
GR_GL(ColorMask(mask, mask, mask, mask));
}
if (GR_GL_SUPPORT_DESKTOP) {
// ES doesn't support toggling GL_MULTISAMPLE and doesn't have
// smooth lines.
if (fDirtyFlags.fRenderTargetChanged ||
(fCurrDrawState.fFlagBits & kAntialias_StateBit) !=
(fHWDrawState.fFlagBits & kAntialias_StateBit)) {
GrGLint msaa = 0;
// only perform query if we know MSAA is supported.
// calling on non-MSAA target caused a crash in one environment,
// though I don't think it should.
if (fAASamples[kHigh_AALevel]) {
GR_GL_GetIntegerv(GR_GL_SAMPLE_BUFFERS, &msaa);
}
if (fCurrDrawState.fFlagBits & kAntialias_StateBit) {
if (msaa) {
GR_GL(Enable(GR_GL_MULTISAMPLE));
} else {
GR_GL(Enable(GR_GL_LINE_SMOOTH));
}
} else {
if (msaa) {
GR_GL(Disable(GR_GL_MULTISAMPLE));
}
GR_GL(Disable(GR_GL_LINE_SMOOTH));
}
}
}
bool blendOff = canDisableBlend();
if (fHWBlendDisabled != blendOff) {
if (blendOff) {

Просмотреть файл

@ -39,6 +39,11 @@ protected:
bool fArrayPtrsDirty;
} fHWGeometryState;
struct AAState {
bool fMSAAEnabled;
bool fSmoothLineEnabled;
} fHWAAState;
DrState fHWDrawState;
bool fHWStencilClip;
@ -78,6 +83,7 @@ protected:
virtual GrRenderTarget* createPlatformRenderTargetHelper(
intptr_t platformRenderTarget,
int stencilBits,
bool isMultisampled,
int width, int height);
virtual GrRenderTarget* createRenderTargetFrom3DApiStateHelper();
@ -147,6 +153,7 @@ private:
void flushRenderTarget();
void flushStencil();
void flushAAState(GrPrimitiveType type);
void resolveTextureRenderTarget(GrGLTexture* texture);
bool canBeTexture(GrPixelConfig config,