Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(965)

Unified Diff: third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp

Issue 1367683002: Make 2D canvas smarter about chosing whether or not to use GPU acceleration (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added nullptr check + fixed style check errors Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp
diff --git a/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp b/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp
index cb747f8aed20efce9c18742e248ae438cffcdc54..fd24abef26f60bc73f8dcd65aaec90914575f04e 100644
--- a/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp
+++ b/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp
@@ -203,7 +203,7 @@ void WebGLRenderingContextBase::willDestroyContext(WebGLRenderingContextBase* co
deactivateContext(context);
// Try to re-enable the oldest inactive contexts.
- while(activeContexts().size() < maxGLActiveContexts && forciblyEvictedContexts().size()) {
+ while (activeContexts().size() < maxGLActiveContexts && forciblyEvictedContexts().size()) {
WebGLRenderingContextBase* evictedContext = forciblyEvictedContexts().first();
if (!evictedContext->m_restoreAllowed) {
forciblyEvictedContexts().remove(0);
@@ -866,11 +866,6 @@ static const FormatType kSupportedFormatTypesES3[] = {
} // namespace anonymous
-#define ADD_VALUES_TO_SET(set, values) \
- for (size_t i = 0; i < arraysize(values); ++i) { \
- set.insert(values[i]); \
- }
-
WebGLRenderingContextBase::WebGLRenderingContextBase(HTMLCanvasElement* passedCanvas, PassOwnPtr<WebGraphicsContext3D> context, const WebGLContextAttributes& requestedAttributes)
: CanvasRenderingContext(passedCanvas)
, m_contextLostMode(NotLostContext)
@@ -909,6 +904,11 @@ WebGLRenderingContextBase::WebGLRenderingContextBase(HTMLCanvasElement* passedCa
drawingBuffer()->bind(GL_FRAMEBUFFER);
setupFlags();
+
+#define ADD_VALUES_TO_SET(set, values) \
+ for (size_t i = 0; i < arraysize(values); ++i) { \
+ set.insert(values[i]); \
+ }
ADD_VALUES_TO_SET(m_supportedInternalFormats, kSupportedInternalFormatsES2);
ADD_VALUES_TO_SET(m_supportedFormats, kSupportedFormatsES2);
@@ -1107,9 +1107,10 @@ WebGLRenderingContextBase::~WebGLRenderingContextBase()
destroyContext();
- if (m_multisamplingObserverRegistered)
+ if (m_multisamplingObserverRegistered) {
if (Page* page = canvas()->document().page())
page->removeMultisamplingChangedObserver(this);
+ }
willDestroyContext(this);
}
@@ -4032,9 +4033,9 @@ void WebGLRenderingContextBase::texImage2DImpl(GLenum target, GLint level, GLenu
const void* imagePixelData = imageExtractor.imagePixelData();
bool needConversion = true;
- if (type == GL_UNSIGNED_BYTE && sourceDataFormat == WebGLImageConversion::DataFormatRGBA8 && format == GL_RGBA && alphaOp == WebGLImageConversion::AlphaDoNothing && !flipY)
+ if (type == GL_UNSIGNED_BYTE && sourceDataFormat == WebGLImageConversion::DataFormatRGBA8 && format == GL_RGBA && alphaOp == WebGLImageConversion::AlphaDoNothing && !flipY) {
needConversion = false;
- else {
+ } else {
if (!WebGLImageConversion::packImageData(image, imagePixelData, format, type, flipY, alphaOp, sourceDataFormat, imageExtractor.imageWidth(), imageExtractor.imageHeight(), imageExtractor.imageSourceUnpackAlignment(), data)) {
synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "packImage error");
return;
@@ -4187,9 +4188,9 @@ void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in
bool needConversion = true;
// The data from ImageData is always of format RGBA8.
// No conversion is needed if destination format is RGBA and type is USIGNED_BYTE and no Flip or Premultiply operation is required.
- if (!m_unpackFlipY && !m_unpackPremultiplyAlpha && format == GL_RGBA && type == GL_UNSIGNED_BYTE)
+ if (!m_unpackFlipY && !m_unpackPremultiplyAlpha && format == GL_RGBA && type == GL_UNSIGNED_BYTE) {
needConversion = false;
- else {
+ } else {
if (!WebGLImageConversion::extractImageData(pixels->data()->data(), pixels->size(), format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) {
synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "bad image data");
return;
@@ -4297,7 +4298,7 @@ void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in
bool isFloatType = type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_HALF_FLOAT_OES;
if (!canvas->renderingContext() || !canvas->renderingContext()->isAccelerated() || isFloatType) {
// 2D canvas has only FrontBuffer.
- texImage2DImpl(target, level, internalformat, format, type, canvas->copiedImage(FrontBuffer).get(),
+ texImage2DImpl(target, level, internalformat, format, type, canvas->copiedImage(FrontBuffer, PreferAcceleration).get(),
WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpackPremultiplyAlpha);
return;
}
@@ -4448,9 +4449,9 @@ void WebGLRenderingContextBase::texSubImage2DImpl(GLenum target, GLint level, GL
const void* imagePixelData = imageExtractor.imagePixelData();
bool needConversion = true;
- if (type == GL_UNSIGNED_BYTE && sourceDataFormat == WebGLImageConversion::DataFormatRGBA8 && format == GL_RGBA && alphaOp == WebGLImageConversion::AlphaDoNothing && !flipY)
+ if (type == GL_UNSIGNED_BYTE && sourceDataFormat == WebGLImageConversion::DataFormatRGBA8 && format == GL_RGBA && alphaOp == WebGLImageConversion::AlphaDoNothing && !flipY) {
needConversion = false;
- else {
+ } else {
if (!WebGLImageConversion::packImageData(image, imagePixelData, format, type, flipY, alphaOp, sourceDataFormat, imageExtractor.imageWidth(), imageExtractor.imageHeight(), imageExtractor.imageSourceUnpackAlignment(), data)) {
synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "bad image data");
return;
@@ -4476,10 +4477,7 @@ void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint
bool changeUnpackAlignment = false;
if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) {
if (!WebGLImageConversion::extractTextureData(width, height, format, type,
- m_unpackAlignment,
- m_unpackFlipY, m_unpackPremultiplyAlpha,
- data,
- tempData))
+ m_unpackAlignment, m_unpackFlipY, m_unpackPremultiplyAlpha, data, tempData))
return;
data = tempData.data();
changeUnpackAlignment = true;
@@ -4508,9 +4506,9 @@ void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint
bool needConversion = true;
// The data from ImageData is always of format RGBA8.
// No conversion is needed if destination format is RGBA and type is USIGNED_BYTE and no Flip or Premultiply operation is required.
- if (format == GL_RGBA && type == GL_UNSIGNED_BYTE && !m_unpackFlipY && !m_unpackPremultiplyAlpha)
+ if (format == GL_RGBA && type == GL_UNSIGNED_BYTE && !m_unpackFlipY && !m_unpackPremultiplyAlpha) {
needConversion = false;
- else {
+ } else {
if (!WebGLImageConversion::extractImageData(pixels->data()->data(), pixels->size(), format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) {
synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "bad image data");
return;
@@ -4557,7 +4555,7 @@ void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint
bool isFloatType = type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_HALF_FLOAT_OES;
if (!canvas->renderingContext() || !canvas->renderingContext()->isAccelerated() || isFloatType) {
// 2D canvas has only FrontBuffer.
- texSubImage2DImpl(target, level, xoffset, yoffset, format, type, canvas->copiedImage(FrontBuffer).get(),
+ texSubImage2DImpl(target, level, xoffset, yoffset, format, type, canvas->copiedImage(FrontBuffer, PreferAcceleration).get(),
WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpackPremultiplyAlpha);
return;
}
@@ -6556,9 +6554,9 @@ void WebGLRenderingContextBase::synthesizeGLError(GLenum error, const char* func
String message = String("WebGL: ") + errorType + ": " + String(functionName) + ": " + String(description);
printGLErrorToConsole(message);
}
- if (!isContextLost())
+ if (!isContextLost()) {
webContext()->synthesizeGLError(error);
- else {
+ } else {
if (m_lostContextErrors.find(error) == WTF::kNotFound)
m_lostContextErrors.append(error);
}
@@ -6578,15 +6576,14 @@ void WebGLRenderingContextBase::applyStencilTest()
{
bool haveStencilBuffer = false;
- if (m_framebufferBinding)
+ if (m_framebufferBinding) {
haveStencilBuffer = m_framebufferBinding->hasStencilBuffer();
- else {
+ } else {
Nullable<WebGLContextAttributes> attributes;
getContextAttributes(attributes);
haveStencilBuffer = !attributes.isNull() && attributes.get().stencil();
}
- enableOrDisable(GL_STENCIL_TEST,
- m_stencilEnabled && haveStencilBuffer);
+ enableOrDisable(GL_STENCIL_TEST, m_stencilEnabled && haveStencilBuffer);
}
void WebGLRenderingContextBase::enableOrDisable(GLenum capability, bool enable)
@@ -6602,7 +6599,7 @@ void WebGLRenderingContextBase::enableOrDisable(GLenum capability, bool enable)
IntSize WebGLRenderingContextBase::clampedCanvasSize()
{
return IntSize(clamp(canvas()->width(), 1, m_maxViewportDims[0]),
- clamp(canvas()->height(), 1, m_maxViewportDims[1]));
+ clamp(canvas()->height(), 1, m_maxViewportDims[1]));
}
GLint WebGLRenderingContextBase::maxDrawBuffers()

Powered by Google App Engine
This is Rietveld 408576698