aboutsummaryrefslogtreecommitdiffhomepage
path: root/gpu
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-04-06 17:50:02 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-04-06 17:50:02 +0000
commitf954d8dd9a4e75aa97e7da79692f5a7add039e68 (patch)
treea4d0cbc377940968a589c018cbb6616aaa105e72 /gpu
parent7cf3dcd90275dcd23fa0d9230e144ee71852ef3a (diff)
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
Diffstat (limited to 'gpu')
-rw-r--r--gpu/include/GrContext.h3
-rw-r--r--gpu/include/GrGLTexture.h3
-rw-r--r--gpu/include/GrGpu.h3
-rw-r--r--gpu/include/GrTexture.h10
-rw-r--r--gpu/src/GrContext.cpp2
-rw-r--r--gpu/src/GrGLTexture.cpp6
-rw-r--r--gpu/src/GrGpu.cpp2
-rw-r--r--gpu/src/GrGpuGL.cpp78
-rw-r--r--gpu/src/GrGpuGL.h7
9 files changed, 80 insertions, 34 deletions
diff --git a/gpu/include/GrContext.h b/gpu/include/GrContext.h
index c178ed68dc..675965447c 100644
--- a/gpu/include/GrContext.h
+++ b/gpu/include/GrContext.h
@@ -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);
/**
diff --git a/gpu/include/GrGLTexture.h b/gpu/include/GrGLTexture.h
index 7924cc3f00..94ae7b49d5 100644
--- a/gpu/include/GrGLTexture.h
+++ b/gpu/include/GrGLTexture.h
@@ -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);
diff --git a/gpu/include/GrGpu.h b/gpu/include/GrGpu.h
index cbe3e95e33..ebf28b12c2 100644
--- a/gpu/include/GrGpu.h
+++ b/gpu/include/GrGpu.h
@@ -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,
diff --git a/gpu/include/GrTexture.h b/gpu/include/GrTexture.h
index 8f9952a851..493bb8d672 100644
--- a/gpu/include/GrTexture.h
+++ b/gpu/include/GrTexture.h
@@ -54,6 +54,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)
* @param top top 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
diff --git a/gpu/src/GrContext.cpp b/gpu/src/GrContext.cpp
index a0f5c51f9b..b17a238c86 100644
--- a/gpu/src/GrContext.cpp
+++ b/gpu/src/GrContext.cpp
@@ -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);
}
diff --git a/gpu/src/GrGLTexture.cpp b/gpu/src/GrGLTexture.cpp
index ce9345b7ed..6a5a005142 100644
--- a/gpu/src/GrGLTexture.cpp
+++ b/gpu/src/GrGLTexture.cpp
@@ -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);
}
}
diff --git a/gpu/src/GrGpu.cpp b/gpu/src/GrGpu.cpp
index 06de3ac53c..4aaed7943b 100644
--- a/gpu/src/GrGpu.cpp
+++ b/gpu/src/GrGpu.cpp
@@ -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);
}
diff --git a/gpu/src/GrGpuGL.cpp b/gpu/src/GrGpuGL.cpp
index e5f9fa23a1..a9e0e1d187 100644
--- a/gpu/src/GrGpuGL.cpp
+++ b/gpu/src/GrGpuGL.cpp
@@ -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) {
diff --git a/gpu/src/GrGpuGL.h b/gpu/src/GrGpuGL.h
index 3eedabf353..6d600e0cf5 100644
--- a/gpu/src/GrGpuGL.h
+++ b/gpu/src/GrGpuGL.h
@@ -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,