Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use an explicit attribute to signal that a context prefers to use a d…
…iscrete GPU

https://bugs.webkit.org/show_bug.cgi?id=80639

Reviewed by Stephen White.

Source/Platform:

Adds preferDiscreteGPU attribute to WebGraphicsContext3D::Attributes. Also remove the forUseOnAnotherThread
attribute, this has been dead code for a while now.

* chromium/public/WebGraphicsContext3D.h:
(WebKit::WebGraphicsContext3D::Attributes::Attributes):
(Attributes):

Source/WebCore:

On platforms that support both integrated and discrete GPUs and can dynamically switch between the two, we
sometimes have a specific preference for a given context. Specifically, contexts used for WebGL and canvas 2d
acceleration should use the discrete GPU if available, but compositor contexts can run fine on an integrated
GPU. Instead of attempting to infer the intent from examining other context attributes, this adds an explicit
attribute to control this behavior.

* html/canvas/WebGLRenderingContext.cpp:
(WebCore):
(WebCore::WebGLRenderingContext::create):
* platform/graphics/GraphicsContext3D.h:
(WebCore::GraphicsContext3D::Attributes::Attributes):
(Attributes):
* platform/graphics/gpu/SharedGraphicsContext3D.cpp:
(WebCore::SharedGraphicsContext3D::get):

Source/WebKit/chromium:

* src/GraphicsContext3DChromium.cpp:
(WebCore::GraphicsContext3DPrivate::getContextAttributes):
(WebCore::GraphicsContext3D::create):
* src/WebViewImpl.cpp:
(WebKit::WebViewImpl::createCompositorGraphicsContext3D):

Canonical link: https://commits.webkit.org/97825@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@110227 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
jamesr committed Mar 8, 2012
1 parent ef33ca3 commit 38db308
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 26 deletions.
14 changes: 14 additions & 0 deletions Source/Platform/ChangeLog
@@ -1,3 +1,17 @@
2012-03-08 James Robinson <jamesr@chromium.org>

Use an explicit attribute to signal that a context prefers to use a discrete GPU
https://bugs.webkit.org/show_bug.cgi?id=80639

Reviewed by Stephen White.

Adds preferDiscreteGPU attribute to WebGraphicsContext3D::Attributes. Also remove the forUseOnAnotherThread
attribute, this has been dead code for a while now.

* chromium/public/WebGraphicsContext3D.h:
(WebKit::WebGraphicsContext3D::Attributes::Attributes):
(Attributes):

2012-02-24 James Robinson <jamesr@chromium.org>

[chromium] WebKit::setColorNames is a client API
Expand Down
4 changes: 2 additions & 2 deletions Source/Platform/chromium/public/WebGraphicsContext3D.h
Expand Up @@ -94,7 +94,7 @@ class WebGraphicsContext3D : public WebNonCopyable {
, canRecoverFromContextLoss(true)
, noExtensions(false)
, shareResources(true)
, forUseOnAnotherThread(false)
, preferDiscreteGPU(false)
{
}

Expand All @@ -106,7 +106,7 @@ class WebGraphicsContext3D : public WebNonCopyable {
bool canRecoverFromContextLoss;
bool noExtensions;
bool shareResources;
bool forUseOnAnotherThread;
bool preferDiscreteGPU;
};

class WebGraphicsContextLostCallback {
Expand Down
22 changes: 22 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,25 @@
2012-03-08 James Robinson <jamesr@chromium.org>

Use an explicit attribute to signal that a context prefers to use a discrete GPU
https://bugs.webkit.org/show_bug.cgi?id=80639

Reviewed by Stephen White.

On platforms that support both integrated and discrete GPUs and can dynamically switch between the two, we
sometimes have a specific preference for a given context. Specifically, contexts used for WebGL and canvas 2d
acceleration should use the discrete GPU if available, but compositor contexts can run fine on an integrated
GPU. Instead of attempting to infer the intent from examining other context attributes, this adds an explicit
attribute to control this behavior.

* html/canvas/WebGLRenderingContext.cpp:
(WebCore):
(WebCore::WebGLRenderingContext::create):
* platform/graphics/GraphicsContext3D.h:
(WebCore::GraphicsContext3D::Attributes::Attributes):
(Attributes):
* platform/graphics/gpu/SharedGraphicsContext3D.cpp:
(WebCore::SharedGraphicsContext3D::get):

2012-03-08 Andy Estes <aestes@apple.com>

NULL renderer possible in WebCore::HTMLInputElement::setCanReceiveDroppedFiles()
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/html/canvas/WebGLRenderingContext.cpp
Expand Up @@ -403,6 +403,7 @@ PassOwnPtr<WebGLRenderingContext> WebGLRenderingContext::create(HTMLCanvasElemen
#else
attributes.shareResources = false;
#endif
attributes.preferDiscreteGPU = true;


RefPtr<GraphicsContext3D> context(GraphicsContext3D::create(attributes, hostWindow));
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/platform/graphics/GraphicsContext3D.h
Expand Up @@ -443,6 +443,7 @@ class GraphicsContext3D : public RefCounted<GraphicsContext3D> {
, preserveDrawingBuffer(false)
, noExtensions(false)
, shareResources(true)
, preferDiscreteGPU(false)
{
}

Expand All @@ -455,6 +456,7 @@ class GraphicsContext3D : public RefCounted<GraphicsContext3D> {
bool preserveDrawingBuffer;
bool noExtensions;
bool shareResources;
bool preferDiscreteGPU;
};

enum RenderStyle {
Expand Down
Expand Up @@ -38,6 +38,7 @@ GraphicsContext3D* SharedGraphicsContext3D::get()
attributes.antialias = false;
attributes.canRecoverFromContextLoss = false; // Canvas contexts can not handle lost contexts.
attributes.shareResources = true;
attributes.preferDiscreteGPU = true;
static GraphicsContext3D* context = GraphicsContext3D::create(attributes, 0).leakRef();
if (context && !context->makeContextCurrent())
context = 0;
Expand Down
13 changes: 13 additions & 0 deletions Source/WebKit/chromium/ChangeLog
@@ -1,3 +1,16 @@
2012-03-08 James Robinson <jamesr@chromium.org>

Use an explicit attribute to signal that a context prefers to use a discrete GPU
https://bugs.webkit.org/show_bug.cgi?id=80639

Reviewed by Stephen White.

* src/GraphicsContext3DChromium.cpp:
(WebCore::GraphicsContext3DPrivate::getContextAttributes):
(WebCore::GraphicsContext3D::create):
* src/WebViewImpl.cpp:
(WebKit::WebViewImpl::createCompositorGraphicsContext3D):

2012-03-08 Scott Byer <scottbyer@chromium.org>

Have ScrollAnimatorNone use requestAnimationFrame
Expand Down
2 changes: 2 additions & 0 deletions Source/WebKit/chromium/src/GraphicsContext3DChromium.cpp
Expand Up @@ -573,6 +573,7 @@ GraphicsContext3D::Attributes GraphicsContext3DPrivate::getContextAttributes()
attributes.antialias = webAttributes.antialias;
attributes.premultipliedAlpha = webAttributes.premultipliedAlpha;
attributes.preserveDrawingBuffer = m_preserveDrawingBuffer;
attributes.preferDiscreteGPU = webAttributes.preferDiscreteGPU;
return attributes;
}

Expand Down Expand Up @@ -1017,6 +1018,7 @@ PassRefPtr<GraphicsContext3D> GraphicsContext3D::create(GraphicsContext3D::Attri
webAttributes.canRecoverFromContextLoss = attrs.canRecoverFromContextLoss;
webAttributes.noExtensions = attrs.noExtensions;
webAttributes.shareResources = attrs.shareResources;
webAttributes.preferDiscreteGPU = attrs.preferDiscreteGPU;

OwnPtr<WebKit::WebGraphicsContext3D> webContext = adoptPtr(WebKit::webKitPlatformSupport()->createOffscreenGraphicsContext3D(webAttributes));
if (!webContext)
Expand Down
38 changes: 14 additions & 24 deletions Source/WebKit/chromium/src/WebViewImpl.cpp
Expand Up @@ -171,27 +171,6 @@
using namespace WebCore;
using namespace std;

namespace {

WebKit::WebGraphicsContext3D::Attributes getCompositorContextAttributes(bool threaded)
{
// Explicitly disable antialiasing for the compositor. As of the time of
// this writing, the only platform that supported antialiasing for the
// compositor was Mac OS X, because the on-screen OpenGL context creation
// code paths on Windows and Linux didn't yet have multisampling support.
// Mac OS X essentially always behaves as though it's rendering offscreen.
// Multisampling has a heavy cost especially on devices with relatively low
// fill rate like most notebooks, and the Mac implementation would need to
// be optimized to resolve directly into the IOSurface shared between the
// GPU and browser processes. For these reasons and to avoid platform
// disparities we explicitly disable antialiasing.
WebKit::WebGraphicsContext3D::Attributes attributes;
attributes.antialias = false;
attributes.shareResources = true;
attributes.forUseOnAnotherThread = threaded;
return attributes;
}

// The following constants control parameters for automated scaling of webpages
// (such as due to a double tap gesture or find in page etc.). These are
// experimentally determined.
Expand All @@ -200,8 +179,6 @@ static const float minScaleDifference = 0.01;
static const float doubleTapZoomContentDefaultMargin = 5;
static const float doubleTapZoomContentMinimumMargin = 2;

} // anonymous namespace

namespace WebKit {

// Change the text zoom level by kTextSizeMultiplierRatio each time the user
Expand Down Expand Up @@ -3221,7 +3198,20 @@ void WebViewImpl::setIsAcceleratedCompositingActive(bool active)

PassOwnPtr<WebKit::WebGraphicsContext3D> WebViewImpl::createCompositorGraphicsContext3D()
{
WebKit::WebGraphicsContext3D::Attributes attributes = getCompositorContextAttributes(CCProxy::hasImplThread());
// Explicitly disable antialiasing for the compositor. As of the time of
// this writing, the only platform that supported antialiasing for the
// compositor was Mac OS X, because the on-screen OpenGL context creation
// code paths on Windows and Linux didn't yet have multisampling support.
// Mac OS X essentially always behaves as though it's rendering offscreen.
// Multisampling has a heavy cost especially on devices with relatively low
// fill rate like most notebooks, and the Mac implementation would need to
// be optimized to resolve directly into the IOSurface shared between the
// GPU and browser processes. For these reasons and to avoid platform
// disparities we explicitly disable antialiasing.
WebKit::WebGraphicsContext3D::Attributes attributes;
attributes.antialias = false;
attributes.shareResources = true;

OwnPtr<WebGraphicsContext3D> webContext = adoptPtr(client()->createGraphicsContext3D(attributes, true /* renderDirectlyToHostWindow */));
if (!webContext)
return nullptr;
Expand Down

0 comments on commit 38db308

Please sign in to comment.