aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/gpu/GrContext.h13
-rw-r--r--src/gpu/GrContext.cpp17
2 files changed, 30 insertions, 0 deletions
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index ad3789b1a8..1834586578 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -306,6 +306,19 @@ public:
*/
int getMaxSampleCount() const;
+ /**
+ * Returns the recommended sample count for a render target when using this
+ * context.
+ *
+ * @param config the configuration of the render target.
+ * @param dpi the display density in dots per inch.
+ *
+ * @return sample count that should be perform well and have good enough
+ * rendering quality for the display. Alternatively returns 0 if
+ * MSAA is not supported or recommended to be used by default.
+ */
+ int getRecommendedSampleCount(GrPixelConfig config, SkScalar dpi) const;
+
///////////////////////////////////////////////////////////////////////////
// Backend Surfaces
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index bb0f4fa9fa..c7e3433938 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -1703,6 +1703,23 @@ bool GrContext::isConfigRenderable(GrPixelConfig config, bool withMSAA) const {
return fGpu->caps()->isConfigRenderable(config, withMSAA);
}
+int GrContext::getRecommendedSampleCount(GrPixelConfig config,
+ SkScalar dpi) const {
+ if (!this->isConfigRenderable(config, true)) {
+ return 0;
+ }
+ int chosenSampleCount = 0;
+ if (fGpu->caps()->pathRenderingSupport()) {
+ if (dpi >= 250.0f) {
+ chosenSampleCount = 4;
+ } else {
+ chosenSampleCount = 16;
+ }
+ }
+ return chosenSampleCount <= fGpu->caps()->maxSampleCount() ?
+ chosenSampleCount : 0;
+}
+
void GrContext::setupDrawBuffer() {
SkASSERT(NULL == fDrawBuffer);
SkASSERT(NULL == fDrawBufferVBAllocPool);