| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 #include "platform/CheckedInt.h" | 89 #include "platform/CheckedInt.h" |
| 90 #include "platform/RuntimeEnabledFeatures.h" | 90 #include "platform/RuntimeEnabledFeatures.h" |
| 91 #include "platform/geometry/IntSize.h" | 91 #include "platform/geometry/IntSize.h" |
| 92 #include "platform/graphics/GraphicsContext.h" | 92 #include "platform/graphics/GraphicsContext.h" |
| 93 #include "platform/graphics/UnacceleratedImageBufferSurface.h" | 93 #include "platform/graphics/UnacceleratedImageBufferSurface.h" |
| 94 #include "platform/graphics/gpu/AcceleratedImageBufferSurface.h" | 94 #include "platform/graphics/gpu/AcceleratedImageBufferSurface.h" |
| 95 #include "platform/graphics/gpu/DrawingBuffer.h" | 95 #include "platform/graphics/gpu/DrawingBuffer.h" |
| 96 #include "public/platform/Platform.h" | 96 #include "public/platform/Platform.h" |
| 97 #include "public/platform/WebGraphicsContext3D.h" | 97 #include "public/platform/WebGraphicsContext3D.h" |
| 98 #include "public/platform/WebGraphicsContext3DProvider.h" | 98 #include "public/platform/WebGraphicsContext3DProvider.h" |
| 99 #include "public/platform/callback/WebClosure.h" | 99 #include "public/platform/functional/WebFunction.h" |
| 100 #include "wtf/Functional.h" | 100 #include "wtf/Functional.h" |
| 101 #include "wtf/PassOwnPtr.h" | 101 #include "wtf/PassOwnPtr.h" |
| 102 #include "wtf/text/StringBuilder.h" | 102 #include "wtf/text/StringBuilder.h" |
| 103 #include "wtf/text/StringUTF8Adaptor.h" | 103 #include "wtf/text/StringUTF8Adaptor.h" |
| 104 #include "wtf/typed_arrays/ArrayBufferContents.h" | 104 #include "wtf/typed_arrays/ArrayBufferContents.h" |
| 105 | 105 |
| 106 namespace blink { | 106 namespace blink { |
| 107 | 107 |
| 108 namespace { | 108 namespace { |
| 109 | 109 |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 | 475 |
| 476 ~ScopedFramebufferRestorer() | 476 ~ScopedFramebufferRestorer() |
| 477 { | 477 { |
| 478 m_context->restoreCurrentFramebuffer(); | 478 m_context->restoreCurrentFramebuffer(); |
| 479 } | 479 } |
| 480 | 480 |
| 481 private: | 481 private: |
| 482 Member<WebGLRenderingContextBase> m_context; | 482 Member<WebGLRenderingContextBase> m_context; |
| 483 }; | 483 }; |
| 484 | 484 |
| 485 class WebGLRenderingContextErrorMessageCallback final : public GarbageCollectedF
inalized<WebGLRenderingContextErrorMessageCallback>, public WebGraphicsContext3D
::WebGraphicsErrorMessageCallback { | |
| 486 public: | |
| 487 static WebGLRenderingContextErrorMessageCallback* create(WebGLRenderingConte
xtBase* context) | |
| 488 { | |
| 489 return new WebGLRenderingContextErrorMessageCallback(context); | |
| 490 } | |
| 491 | |
| 492 ~WebGLRenderingContextErrorMessageCallback() override { } | |
| 493 | |
| 494 virtual void onErrorMessage(const WebString& message, GLint) | |
| 495 { | |
| 496 if (m_context->m_synthesizedErrorsToConsole) | |
| 497 m_context->printGLErrorToConsole(message); | |
| 498 InspectorInstrumentation::didFireWebGLErrorOrWarning(m_context->canvas()
, message); | |
| 499 } | |
| 500 | |
| 501 DEFINE_INLINE_TRACE() | |
| 502 { | |
| 503 visitor->trace(m_context); | |
| 504 } | |
| 505 | |
| 506 private: | |
| 507 explicit WebGLRenderingContextErrorMessageCallback(WebGLRenderingContextBase
* context) | |
| 508 : m_context(context) { } | |
| 509 | |
| 510 Member<WebGLRenderingContextBase> m_context; | |
| 511 }; | |
| 512 | |
| 513 static void formatWebGLStatusString(const String& glInfo, const String& infostri
ng, String& statusMessage) | 485 static void formatWebGLStatusString(const String& glInfo, const String& infostri
ng, String& statusMessage) |
| 514 { | 486 { |
| 515 if (!infostring.isEmpty()) | 487 if (!infostring.isEmpty()) |
| 516 statusMessage.append(", " + glInfo + " = " + infostring); | 488 statusMessage.append(", " + glInfo + " = " + infostring); |
| 517 } | 489 } |
| 518 | 490 |
| 519 static String extractWebGLContextCreationError(const Platform::GraphicsInfo& inf
o) | 491 static String extractWebGLContextCreationError(const Platform::GraphicsInfo& inf
o) |
| 520 { | 492 { |
| 521 String statusMessage("Could not create a WebGL context"); | 493 String statusMessage("Could not create a WebGL context"); |
| 522 formatWebGLStatusString("VENDOR", info.vendorId ? String::format("0x%04x", i
nfo.vendorId).utf8().data() : "0xffff", statusMessage); | 494 formatWebGLStatusString("VENDOR", info.vendorId ? String::format("0x%04x", i
nfo.vendorId).utf8().data() : "0xffff", statusMessage); |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 956 // for the default VAO. (This object is never exposed to JavaScript, but we
need to link other | 928 // for the default VAO. (This object is never exposed to JavaScript, but we
need to link other |
| 957 // JavaScript wrappers to it.) | 929 // JavaScript wrappers to it.) |
| 958 m_preservedDefaultVAOObjectWrapper = false; | 930 m_preservedDefaultVAOObjectWrapper = false; |
| 959 m_boundVertexArrayObject = m_defaultVertexArrayObject; | 931 m_boundVertexArrayObject = m_defaultVertexArrayObject; |
| 960 | 932 |
| 961 m_vertexAttribType.resize(m_maxVertexAttribs); | 933 m_vertexAttribType.resize(m_maxVertexAttribs); |
| 962 | 934 |
| 963 contextGL()->Viewport(0, 0, drawingBufferWidth(), drawingBufferHeight()); | 935 contextGL()->Viewport(0, 0, drawingBufferWidth(), drawingBufferHeight()); |
| 964 contextGL()->Scissor(0, 0, drawingBufferWidth(), drawingBufferHeight()); | 936 contextGL()->Scissor(0, 0, drawingBufferWidth(), drawingBufferHeight()); |
| 965 | 937 |
| 966 m_errorMessageCallbackAdapter = WebGLRenderingContextErrorMessageCallback::c
reate(this); | 938 drawingBuffer()->contextProvider()->setLostContextCallback( |
| 967 | 939 WebClosure(bind( |
| 968 drawingBuffer()->contextProvider()->setLostContextCallback(WebClosure(WTF::b
ind(&WebGLRenderingContextBase::forceLostContext, createWeakThisPointer(), WebGL
RenderingContextBase::RealLostContext, WebGLRenderingContextBase::Auto))); | 940 &WebGLRenderingContextBase::forceLostContext, |
| 969 webContext()->setErrorMessageCallback(m_errorMessageCallbackAdapter.get()); | 941 createWeakThisPointer(), |
| 942 WebGLRenderingContextBase::RealLostContext, |
| 943 WebGLRenderingContextBase::Auto))); |
| 944 drawingBuffer()->contextProvider()->setErrorMessageCallback( |
| 945 WebFunction<void(const char*, int32_t)>(bind<const char*, int32_t>( |
| 946 &WebGLRenderingContextBase::onErrorMessage, |
| 947 createWeakThisPointer()))); |
| 970 | 948 |
| 971 // If WebGL 2, the PRIMITIVE_RESTART_FIXED_INDEX should be always enabled. | 949 // If WebGL 2, the PRIMITIVE_RESTART_FIXED_INDEX should be always enabled. |
| 972 // See the section <Primitive Restart is Always Enabled> in WebGL 2 spec: | 950 // See the section <Primitive Restart is Always Enabled> in WebGL 2 spec: |
| 973 // https://www.khronos.org/registry/webgl/specs/latest/2.0/#4.1.4 | 951 // https://www.khronos.org/registry/webgl/specs/latest/2.0/#4.1.4 |
| 974 if (isWebGL2OrHigher()) | 952 if (isWebGL2OrHigher()) |
| 975 contextGL()->Enable(GL_PRIMITIVE_RESTART_FIXED_INDEX); | 953 contextGL()->Enable(GL_PRIMITIVE_RESTART_FIXED_INDEX); |
| 976 | 954 |
| 977 // This ensures that the context has a valid "lastFlushID" and won't be mist
akenly identified as the "least recently used" context. | 955 // This ensures that the context has a valid "lastFlushID" and won't be mist
akenly identified as the "least recently used" context. |
| 978 contextGL()->Flush(); | 956 contextGL()->Flush(); |
| 979 | 957 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1068 } | 1046 } |
| 1069 | 1047 |
| 1070 void WebGLRenderingContextBase::destroyContext() | 1048 void WebGLRenderingContextBase::destroyContext() |
| 1071 { | 1049 { |
| 1072 if (!drawingBuffer()) | 1050 if (!drawingBuffer()) |
| 1073 return; | 1051 return; |
| 1074 | 1052 |
| 1075 m_extensionsUtil.clear(); | 1053 m_extensionsUtil.clear(); |
| 1076 | 1054 |
| 1077 drawingBuffer()->contextProvider()->setLostContextCallback(WebClosure()); | 1055 drawingBuffer()->contextProvider()->setLostContextCallback(WebClosure()); |
| 1078 webContext()->setErrorMessageCallback(nullptr); | 1056 drawingBuffer()->contextProvider()->setErrorMessageCallback(WebFunction<void
(const char*, int32_t)>()); |
| 1079 | 1057 |
| 1080 ASSERT(drawingBuffer()); | 1058 ASSERT(drawingBuffer()); |
| 1081 m_drawingBuffer->beginDestruction(); | 1059 m_drawingBuffer->beginDestruction(); |
| 1082 m_drawingBuffer.clear(); | 1060 m_drawingBuffer.clear(); |
| 1083 } | 1061 } |
| 1084 | 1062 |
| 1085 void WebGLRenderingContextBase::markContextChanged(ContentChangeType changeType) | 1063 void WebGLRenderingContextBase::markContextChanged(ContentChangeType changeType) |
| 1086 { | 1064 { |
| 1087 if (m_framebufferBinding || isContextLost()) | 1065 if (m_framebufferBinding || isContextLost()) |
| 1088 return; | 1066 return; |
| 1089 | 1067 |
| 1090 drawingBuffer()->markContentsChanged(); | 1068 drawingBuffer()->markContentsChanged(); |
| 1091 | 1069 |
| 1092 LayoutBox* layoutBox = canvas()->layoutBox(); | 1070 LayoutBox* layoutBox = canvas()->layoutBox(); |
| 1093 if (layoutBox && layoutBox->hasAcceleratedCompositing()) { | 1071 if (layoutBox && layoutBox->hasAcceleratedCompositing()) { |
| 1094 m_markedCanvasDirty = true; | 1072 m_markedCanvasDirty = true; |
| 1095 canvas()->clearCopiedImage(); | 1073 canvas()->clearCopiedImage(); |
| 1096 layoutBox->contentChanged(changeType); | 1074 layoutBox->contentChanged(changeType); |
| 1097 } else { | 1075 } else { |
| 1098 if (!m_markedCanvasDirty) { | 1076 if (!m_markedCanvasDirty) { |
| 1099 m_markedCanvasDirty = true; | 1077 m_markedCanvasDirty = true; |
| 1100 canvas()->didDraw(FloatRect(FloatPoint(0, 0), FloatSize(clampedCanva
sSize()))); | 1078 canvas()->didDraw(FloatRect(FloatPoint(0, 0), FloatSize(clampedCanva
sSize()))); |
| 1101 } | 1079 } |
| 1102 } | 1080 } |
| 1103 } | 1081 } |
| 1104 | 1082 |
| 1083 void WebGLRenderingContextBase::onErrorMessage(const char* message, int32_t id) |
| 1084 { |
| 1085 if (m_synthesizedErrorsToConsole) |
| 1086 printGLErrorToConsole(message); |
| 1087 InspectorInstrumentation::didFireWebGLErrorOrWarning(canvas(), message); |
| 1088 } |
| 1089 |
| 1105 void WebGLRenderingContextBase::notifyCanvasContextChanged() | 1090 void WebGLRenderingContextBase::notifyCanvasContextChanged() |
| 1106 { | 1091 { |
| 1107 if (!canvas()) | 1092 if (!canvas()) |
| 1108 return; | 1093 return; |
| 1109 | 1094 |
| 1110 canvas()->notifyListenersCanvasChanged(); | 1095 canvas()->notifyListenersCanvasChanged(); |
| 1111 } | 1096 } |
| 1112 | 1097 |
| 1113 WebGLRenderingContextBase::HowToClear WebGLRenderingContextBase::clearIfComposit
ed(GLbitfield mask) | 1098 WebGLRenderingContextBase::HowToClear WebGLRenderingContextBase::clearIfComposit
ed(GLbitfield mask) |
| 1114 { | 1099 { |
| (...skipping 5134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6249 { | 6234 { |
| 6250 visitor->trace(m_texture2DBinding); | 6235 visitor->trace(m_texture2DBinding); |
| 6251 visitor->trace(m_textureCubeMapBinding); | 6236 visitor->trace(m_textureCubeMapBinding); |
| 6252 visitor->trace(m_texture3DBinding); | 6237 visitor->trace(m_texture3DBinding); |
| 6253 visitor->trace(m_texture2DArrayBinding); | 6238 visitor->trace(m_texture2DArrayBinding); |
| 6254 } | 6239 } |
| 6255 | 6240 |
| 6256 DEFINE_TRACE(WebGLRenderingContextBase) | 6241 DEFINE_TRACE(WebGLRenderingContextBase) |
| 6257 { | 6242 { |
| 6258 visitor->trace(m_contextObjects); | 6243 visitor->trace(m_contextObjects); |
| 6259 visitor->trace(m_errorMessageCallbackAdapter); | |
| 6260 visitor->trace(m_boundArrayBuffer); | 6244 visitor->trace(m_boundArrayBuffer); |
| 6261 visitor->trace(m_defaultVertexArrayObject); | 6245 visitor->trace(m_defaultVertexArrayObject); |
| 6262 visitor->trace(m_boundVertexArrayObject); | 6246 visitor->trace(m_boundVertexArrayObject); |
| 6263 visitor->trace(m_currentProgram); | 6247 visitor->trace(m_currentProgram); |
| 6264 visitor->trace(m_framebufferBinding); | 6248 visitor->trace(m_framebufferBinding); |
| 6265 visitor->trace(m_renderbufferBinding); | 6249 visitor->trace(m_renderbufferBinding); |
| 6266 visitor->trace(m_valuebufferBinding); | 6250 visitor->trace(m_valuebufferBinding); |
| 6267 visitor->trace(m_textureUnits); | 6251 visitor->trace(m_textureUnits); |
| 6268 visitor->trace(m_extensions); | 6252 visitor->trace(m_extensions); |
| 6269 CanvasRenderingContext::trace(visitor); | 6253 CanvasRenderingContext::trace(visitor); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6306 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1); | 6290 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 6307 } | 6291 } |
| 6308 | 6292 |
| 6309 void WebGLRenderingContextBase::restoreUnpackParameters() | 6293 void WebGLRenderingContextBase::restoreUnpackParameters() |
| 6310 { | 6294 { |
| 6311 if (m_unpackAlignment != 1) | 6295 if (m_unpackAlignment != 1) |
| 6312 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); | 6296 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); |
| 6313 } | 6297 } |
| 6314 | 6298 |
| 6315 } // namespace blink | 6299 } // namespace blink |
| OLD | NEW |