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

Side by Side Diff: Source/core/html/canvas/WebGLRenderingContext.cpp

Issue 17230006: Implement WEBGL_shared_resources Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 25 matching lines...) Expand all
36 #include "core/html/canvas/ANGLEInstancedArrays.h" 36 #include "core/html/canvas/ANGLEInstancedArrays.h"
37 #include "core/html/canvas/EXTFragDepth.h" 37 #include "core/html/canvas/EXTFragDepth.h"
38 #include "core/html/canvas/EXTTextureFilterAnisotropic.h" 38 #include "core/html/canvas/EXTTextureFilterAnisotropic.h"
39 #include "core/html/canvas/OESElementIndexUint.h" 39 #include "core/html/canvas/OESElementIndexUint.h"
40 #include "core/html/canvas/OESStandardDerivatives.h" 40 #include "core/html/canvas/OESStandardDerivatives.h"
41 #include "core/html/canvas/OESTextureFloat.h" 41 #include "core/html/canvas/OESTextureFloat.h"
42 #include "core/html/canvas/OESTextureFloatLinear.h" 42 #include "core/html/canvas/OESTextureFloatLinear.h"
43 #include "core/html/canvas/OESTextureHalfFloat.h" 43 #include "core/html/canvas/OESTextureHalfFloat.h"
44 #include "core/html/canvas/OESTextureHalfFloatLinear.h" 44 #include "core/html/canvas/OESTextureHalfFloatLinear.h"
45 #include "core/html/canvas/OESVertexArrayObject.h" 45 #include "core/html/canvas/OESVertexArrayObject.h"
46 #include "core/html/canvas/WebGLAcquireSharedResourceCallback.h"
46 #include "core/html/canvas/WebGLActiveInfo.h" 47 #include "core/html/canvas/WebGLActiveInfo.h"
47 #include "core/html/canvas/WebGLBuffer.h" 48 #include "core/html/canvas/WebGLBuffer.h"
48 #include "core/html/canvas/WebGLCompressedTextureATC.h" 49 #include "core/html/canvas/WebGLCompressedTextureATC.h"
49 #include "core/html/canvas/WebGLCompressedTexturePVRTC.h" 50 #include "core/html/canvas/WebGLCompressedTexturePVRTC.h"
50 #include "core/html/canvas/WebGLCompressedTextureS3TC.h" 51 #include "core/html/canvas/WebGLCompressedTextureS3TC.h"
51 #include "core/html/canvas/WebGLContextAttributes.h" 52 #include "core/html/canvas/WebGLContextAttributes.h"
52 #include "core/html/canvas/WebGLContextEvent.h" 53 #include "core/html/canvas/WebGLContextEvent.h"
53 #include "core/html/canvas/WebGLContextGroup.h" 54 #include "core/html/canvas/WebGLContextGroup.h"
54 #include "core/html/canvas/WebGLDebugRendererInfo.h" 55 #include "core/html/canvas/WebGLDebugRendererInfo.h"
55 #include "core/html/canvas/WebGLDebugShaders.h" 56 #include "core/html/canvas/WebGLDebugShaders.h"
56 #include "core/html/canvas/WebGLDepthTexture.h" 57 #include "core/html/canvas/WebGLDepthTexture.h"
57 #include "core/html/canvas/WebGLDrawBuffers.h" 58 #include "core/html/canvas/WebGLDrawBuffers.h"
58 #include "core/html/canvas/WebGLFramebuffer.h" 59 #include "core/html/canvas/WebGLFramebuffer.h"
59 #include "core/html/canvas/WebGLLoseContext.h" 60 #include "core/html/canvas/WebGLLoseContext.h"
60 #include "core/html/canvas/WebGLProgram.h" 61 #include "core/html/canvas/WebGLProgram.h"
61 #include "core/html/canvas/WebGLRenderbuffer.h" 62 #include "core/html/canvas/WebGLRenderbuffer.h"
62 #include "core/html/canvas/WebGLShader.h" 63 #include "core/html/canvas/WebGLShader.h"
63 #include "core/html/canvas/WebGLShaderPrecisionFormat.h" 64 #include "core/html/canvas/WebGLShaderPrecisionFormat.h"
65 #include "core/html/canvas/WebGLShareGroup.h"
66 #include "core/html/canvas/WebGLSharedResources.h"
64 #include "core/html/canvas/WebGLTexture.h" 67 #include "core/html/canvas/WebGLTexture.h"
65 #include "core/html/canvas/WebGLUniformLocation.h" 68 #include "core/html/canvas/WebGLUniformLocation.h"
66 #include "core/inspector/InspectorInstrumentation.h" 69 #include "core/inspector/InspectorInstrumentation.h"
67 #include "core/loader/FrameLoader.h" 70 #include "core/loader/FrameLoader.h"
68 #include "core/loader/FrameLoaderClient.h" 71 #include "core/loader/FrameLoaderClient.h"
69 #include "core/loader/cache/CachedImage.h" 72 #include "core/loader/cache/CachedImage.h"
70 #include "core/page/Frame.h" 73 #include "core/page/Frame.h"
71 #include "core/page/Page.h" 74 #include "core/page/Page.h"
72 #include "core/page/Settings.h" 75 #include "core/page/Settings.h"
73 #include "core/platform/NotImplemented.h" 76 #include "core/platform/NotImplemented.h"
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 520
518 if (!context || !context->makeContextCurrent()) { 521 if (!context || !context->makeContextCurrent()) {
519 canvas->dispatchEvent(WebGLContextEvent::create(eventNames().webglcontex tcreationerrorEvent, false, true, "Could not create a WebGL context.")); 522 canvas->dispatchEvent(WebGLContextEvent::create(eventNames().webglcontex tcreationerrorEvent, false, true, "Could not create a WebGL context."));
520 return nullptr; 523 return nullptr;
521 } 524 }
522 525
523 Extensions3D* extensions = context->getExtensions(); 526 Extensions3D* extensions = context->getExtensions();
524 if (extensions->supports("GL_EXT_debug_marker")) 527 if (extensions->supports("GL_EXT_debug_marker"))
525 extensions->pushGroupMarkerEXT("WebGLRenderingContext"); 528 extensions->pushGroupMarkerEXT("WebGLRenderingContext");
526 529
527 OwnPtr<WebGLRenderingContext> renderingContext = adoptPtr(new WebGLRendering Context(canvas, context, attributes, requestedAttributes)); 530 RefPtr<WebGLContextGroup> contextGroup(attrs->group()
531 ? attrs->group()->contextGroup()
532 : WebGLContextGroup::create());
533
534 OwnPtr<WebGLRenderingContext> renderingContext = adoptPtr(new WebGLRendering Context(canvas, context, attributes, requestedAttributes, contextGroup));
528 renderingContext->suspendIfNeeded(); 535 renderingContext->suspendIfNeeded();
529 536
530 if (renderingContext->m_drawingBuffer->isZeroSized()) { 537 if (renderingContext->m_drawingBuffer->isZeroSized()) {
531 canvas->dispatchEvent(WebGLContextEvent::create(eventNames().webglcontex tcreationerrorEvent, false, true, "Could not create a WebGL context.")); 538 canvas->dispatchEvent(WebGLContextEvent::create(eventNames().webglcontex tcreationerrorEvent, false, true, "Could not create a WebGL context."));
532 return nullptr; 539 return nullptr;
533 } 540 }
534 541
535 return renderingContext.release(); 542 return renderingContext.release();
536 } 543 }
537 544
538 WebGLRenderingContext::WebGLRenderingContext(HTMLCanvasElement* passedCanvas, Pa ssRefPtr<GraphicsContext3D> context, GraphicsContext3D::Attributes attributes, G raphicsContext3D::Attributes requestedAttributes) 545 WebGLRenderingContext::WebGLRenderingContext(HTMLCanvasElement* passedCanvas, Pa ssRefPtr<GraphicsContext3D> context, GraphicsContext3D::Attributes attributes, G raphicsContext3D::Attributes requestedAttributes, PassRefPtr<WebGLContextGroup> contextGroup)
539 : CanvasRenderingContext(passedCanvas) 546 : CanvasRenderingContext(passedCanvas)
540 , ActiveDOMObject(passedCanvas->document()) 547 , ActiveDOMObject(passedCanvas->document())
541 , m_context(context) 548 , m_context(context)
549 , m_contextGroup(contextGroup)
542 , m_drawingBuffer(0) 550 , m_drawingBuffer(0)
543 , m_dispatchContextLostEventTimer(this, &WebGLRenderingContext::dispatchCont extLostEvent) 551 , m_dispatchContextLostEventTimer(this, &WebGLRenderingContext::dispatchCont extLostEvent)
544 , m_restoreAllowed(false) 552 , m_restoreAllowed(false)
545 , m_restoreTimer(this, &WebGLRenderingContext::maybeRestoreContext) 553 , m_restoreTimer(this, &WebGLRenderingContext::maybeRestoreContext)
546 , m_videoCache(4) 554 , m_videoCache(4)
547 , m_contextLost(false) 555 , m_contextLost(false)
548 , m_contextLostMode(SyntheticLostContext) 556 , m_contextLostMode(SyntheticLostContext)
549 , m_attributes(attributes) 557 , m_attributes(attributes)
550 , m_requestedAttributes(requestedAttributes) 558 , m_requestedAttributes(requestedAttributes)
551 , m_synthesizedErrorsToConsole(true) 559 , m_synthesizedErrorsToConsole(true)
552 , m_numGLErrorsToConsoleAllowed(maxGLErrorsAllowedToConsole) 560 , m_numGLErrorsToConsoleAllowed(maxGLErrorsAllowedToConsole)
553 , m_multisamplingAllowed(false) 561 , m_multisamplingAllowed(false)
554 , m_multisamplingObserverRegistered(false) 562 , m_multisamplingObserverRegistered(false)
555 { 563 {
556 ASSERT(m_context); 564 ASSERT(m_context);
557 ScriptWrappable::init(this); 565 ScriptWrappable::init(this);
558 566
559 m_contextGroup = WebGLContextGroup::create();
560 m_contextGroup->addContext(this); 567 m_contextGroup->addContext(this);
561 568
562 m_maxViewportDims[0] = m_maxViewportDims[1] = 0; 569 m_maxViewportDims[0] = m_maxViewportDims[1] = 0;
563 m_context->getIntegerv(GraphicsContext3D::MAX_VIEWPORT_DIMS, m_maxViewportDi ms); 570 m_context->getIntegerv(GraphicsContext3D::MAX_VIEWPORT_DIMS, m_maxViewportDi ms);
564 571
565 RefPtr<WebGLRenderingContextEvictionManager> contextEvictionManager = adoptR ef(new WebGLRenderingContextEvictionManager()); 572 RefPtr<WebGLRenderingContextEvictionManager> contextEvictionManager = adoptR ef(new WebGLRenderingContextEvictionManager());
566 573
567 // Create the DrawingBuffer and initialize the platform layer. 574 // Create the DrawingBuffer and initialize the platform layer.
568 DrawingBuffer::PreserveDrawingBuffer preserve = m_attributes.preserveDrawing Buffer ? DrawingBuffer::Preserve : DrawingBuffer::Discard; 575 DrawingBuffer::PreserveDrawingBuffer preserve = m_attributes.preserveDrawing Buffer ? DrawingBuffer::Preserve : DrawingBuffer::Discard;
569 m_drawingBuffer = DrawingBuffer::create(m_context.get(), clampedCanvasSize() , preserve, contextEvictionManager.release()); 576 m_drawingBuffer = DrawingBuffer::create(m_context.get(), clampedCanvasSize() , preserve, contextEvictionManager.release());
(...skipping 20 matching lines...) Expand all
590 registerExtension<WebGLCompressedTextureATC>(m_webglCompressedTextureATC, fa lse, false, true, webkitPrefix); 597 registerExtension<WebGLCompressedTextureATC>(m_webglCompressedTextureATC, fa lse, false, true, webkitPrefix);
591 registerExtension<WebGLCompressedTexturePVRTC>(m_webglCompressedTexturePVRTC , false, false, true, webkitPrefix); 598 registerExtension<WebGLCompressedTexturePVRTC>(m_webglCompressedTexturePVRTC , false, false, true, webkitPrefix);
592 registerExtension<WebGLCompressedTextureS3TC>(m_webglCompressedTextureS3TC, false, false, true, bothPrefixes); 599 registerExtension<WebGLCompressedTextureS3TC>(m_webglCompressedTextureS3TC, false, false, true, bothPrefixes);
593 registerExtension<WebGLDepthTexture>(m_webglDepthTexture, false, false, true , bothPrefixes); 600 registerExtension<WebGLDepthTexture>(m_webglDepthTexture, false, false, true , bothPrefixes);
594 registerExtension<WebGLLoseContext>(m_webglLoseContext, false, false, false, bothPrefixes); 601 registerExtension<WebGLLoseContext>(m_webglLoseContext, false, false, false, bothPrefixes);
595 602
596 // Register draft extensions. 603 // Register draft extensions.
597 registerExtension<ANGLEInstancedArrays>(m_angleInstancedArrays, false, true, false, unprefixed); 604 registerExtension<ANGLEInstancedArrays>(m_angleInstancedArrays, false, true, false, unprefixed);
598 registerExtension<EXTFragDepth>(m_extFragDepth, false, true, false, unprefix ed); 605 registerExtension<EXTFragDepth>(m_extFragDepth, false, true, false, unprefix ed);
599 registerExtension<WebGLDrawBuffers>(m_webglDrawBuffers, false, true, false, unprefixed); 606 registerExtension<WebGLDrawBuffers>(m_webglDrawBuffers, false, true, false, unprefixed);
607 registerExtension<WebGLSharedResources>(m_webglSharedResources, false, true, false, unprefixed);
600 608
601 // Register privileged extensions. 609 // Register privileged extensions.
602 registerExtension<WebGLDebugRendererInfo>(m_webglDebugRendererInfo, true, fa lse, false, unprefixed); 610 registerExtension<WebGLDebugRendererInfo>(m_webglDebugRendererInfo, true, fa lse, false, unprefixed);
603 registerExtension<WebGLDebugShaders>(m_webglDebugShaders, true, false, false , unprefixed); 611 registerExtension<WebGLDebugShaders>(m_webglDebugShaders, true, false, false , unprefixed);
604 } 612 }
605 613
606 void WebGLRenderingContext::initializeNewContext() 614 void WebGLRenderingContext::initializeNewContext()
607 { 615 {
608 ASSERT(!isContextLost()); 616 ASSERT(!isContextLost());
609 m_needsUpdate = true; 617 m_needsUpdate = true;
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 m_activeTextureUnit = texture - GraphicsContext3D::TEXTURE0; 1003 m_activeTextureUnit = texture - GraphicsContext3D::TEXTURE0;
996 m_context->activeTexture(texture); 1004 m_context->activeTexture(texture);
997 1005
998 m_drawingBuffer->setActiveTextureUnit(texture); 1006 m_drawingBuffer->setActiveTextureUnit(texture);
999 1007
1000 } 1008 }
1001 1009
1002 void WebGLRenderingContext::attachShader(WebGLProgram* program, WebGLShader* sha der, ExceptionCode& ec) 1010 void WebGLRenderingContext::attachShader(WebGLProgram* program, WebGLShader* sha der, ExceptionCode& ec)
1003 { 1011 {
1004 UNUSED_PARAM(ec); 1012 UNUSED_PARAM(ec);
1005 if (isContextLost() || !validateWebGLObject("attachShader", program) || !val idateWebGLObject("attachShader", shader)) 1013 bool boundSinceLastAcquire;
1014 bool deleted;
1015 if (isContextLost()
1016 || !validateWebGLSharedObject("attachShader", program, WebGLSharedObject ::Exclusive)
1017 || !checkSharedObjectToBeBound("attachShader", shader, deleted, boundSin ceLastAcquire)) {
1006 return; 1018 return;
1019 }
1020 if (deleted) {
1021 shader = 0;
1022 }
1007 if (!program->attachShader(shader)) { 1023 if (!program->attachShader(shader)) {
1008 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "attachShader", "shader attachment already has shader"); 1024 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "attachShader", "shader attachment already has shader");
1009 return; 1025 return;
1010 } 1026 }
1011 m_context->attachShader(objectOrZero(program), objectOrZero(shader)); 1027 m_context->attachShader(objectOrZero(program), objectOrZero(shader));
1012 shader->onAttached(); 1028 if (shader) {
1029 shader->onAttached();
1030 if (!boundSinceLastAcquire) {
1031 shader->markAsBoundSinceLastAcquireForContext(this);
1032 }
1033 }
1013 } 1034 }
1014 1035
1015 void WebGLRenderingContext::bindAttribLocation(WebGLProgram* program, GC3Duint i ndex, const String& name, ExceptionCode& ec) 1036 void WebGLRenderingContext::bindAttribLocation(WebGLProgram* program, GC3Duint i ndex, const String& name, ExceptionCode& ec)
1016 { 1037 {
1017 UNUSED_PARAM(ec); 1038 UNUSED_PARAM(ec);
1018 if (isContextLost() || !validateWebGLObject("bindAttribLocation", program)) 1039 if (isContextLost() || !validateWebGLSharedObject("bindAttribLocation", prog ram, WebGLSharedObject::Exclusive))
1019 return; 1040 return;
1020 if (!validateLocationLength("bindAttribLocation", name)) 1041 if (!validateLocationLength("bindAttribLocation", name))
1021 return; 1042 return;
1022 if (!validateString("bindAttribLocation", name)) 1043 if (!validateString("bindAttribLocation", name))
1023 return; 1044 return;
1024 if (isPrefixReserved(name)) { 1045 if (isPrefixReserved(name)) {
1025 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "bindAttribLocat ion", "reserved prefix"); 1046 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "bindAttribLocat ion", "reserved prefix");
1026 return; 1047 return;
1027 } 1048 }
1028 if (index >= m_maxVertexAttribs) { 1049 if (index >= m_maxVertexAttribs) {
1029 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "bindAttribLocation" , "index out of range"); 1050 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "bindAttribLocation" , "index out of range");
1030 return; 1051 return;
1031 } 1052 }
1032 m_context->bindAttribLocation(objectOrZero(program), index, name); 1053 m_context->bindAttribLocation(objectOrZero(program), index, name);
1033 } 1054 }
1034 1055
1035 bool WebGLRenderingContext::checkObjectToBeBound(const char* functionName, WebGL Object* object, bool& deleted) 1056 bool WebGLRenderingContext::checkContextObjectToBeBound(const char* functionName , WebGLContextObject* object, bool& deleted)
1036 { 1057 {
1037 deleted = false; 1058 deleted = false;
1038 if (isContextLost()) 1059 if (isContextLost())
1039 return false; 1060 return false;
1040 if (object) { 1061 if (object) {
1041 if (!object->validate(contextGroup(), this)) { 1062 if (!object->validate(contextGroup(), this)) {
1042 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName , "object not from this context"); 1063 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName , "object not from this share group");
1043 return false; 1064 return false;
1044 } 1065 }
1045 deleted = !object->object(); 1066 deleted = !object->object();
1067 }
1068 return true;
1069 }
1070
1071 bool WebGLRenderingContext::checkSharedObjectToBeBound(const char* functionName, WebGLSharedObject* object, bool& deleted, bool& boundSinceLastAcquire)
1072 {
1073 deleted = false;
1074 if (isContextLost())
1075 return false;
1076 if (object) {
1077 if (!object->validate(functionName, this, WebGLSharedObject::ReadOnly, f alse, &boundSinceLastAcquire)) {
1078 return false;
1079 }
1080 deleted = !object->object();
1046 } 1081 }
1047 return true; 1082 return true;
1048 } 1083 }
1049 1084
1050 void WebGLRenderingContext::bindBuffer(GC3Denum target, WebGLBuffer* buffer, Exc eptionCode& ec) 1085 void WebGLRenderingContext::bindBuffer(GC3Denum target, WebGLBuffer* buffer, Exc eptionCode& ec)
1051 { 1086 {
1052 UNUSED_PARAM(ec); 1087 UNUSED_PARAM(ec);
1053 bool deleted; 1088 bool deleted;
1054 if (!checkObjectToBeBound("bindBuffer", buffer, deleted)) 1089 bool boundSinceLastAcquire;
1090 if (!checkSharedObjectToBeBound("bindBuffer", buffer, deleted, boundSinceLas tAcquire))
1055 return; 1091 return;
1056 if (deleted) 1092 if (deleted)
1057 buffer = 0; 1093 buffer = 0;
1058 if (buffer && buffer->getTarget() && buffer->getTarget() != target) { 1094 if (buffer && buffer->getTarget() && buffer->getTarget() != target) {
1059 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "bindBuffer", "b uffers can not be used with multiple targets"); 1095 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "bindBuffer", "b uffers can not be used with multiple targets");
1060 return; 1096 return;
1061 } 1097 }
1062 if (target == GraphicsContext3D::ARRAY_BUFFER) 1098 if (target == GraphicsContext3D::ARRAY_BUFFER)
1063 m_boundArrayBuffer = buffer; 1099 m_boundArrayBuffer = buffer;
1064 else if (target == GraphicsContext3D::ELEMENT_ARRAY_BUFFER) 1100 else if (target == GraphicsContext3D::ELEMENT_ARRAY_BUFFER)
1065 m_boundVertexArrayObject->setElementArrayBuffer(buffer); 1101 m_boundVertexArrayObject->setElementArrayBuffer(buffer);
1066 else { 1102 else {
1067 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "bindBuffer", "invali d target"); 1103 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "bindBuffer", "invali d target");
1068 return; 1104 return;
1069 } 1105 }
1070 1106
1071 m_context->bindBuffer(target, objectOrZero(buffer)); 1107 m_context->bindBuffer(target, objectOrZero(buffer));
1072 if (buffer) 1108 if (buffer) {
1073 buffer->setTarget(target); 1109 buffer->setTarget(target);
1110 if (!boundSinceLastAcquire) {
1111 buffer->markAsBoundSinceLastAcquireForContext(this);
1112 }
1113 }
1074 } 1114 }
1075 1115
1076 void WebGLRenderingContext::bindFramebuffer(GC3Denum target, WebGLFramebuffer* b uffer, ExceptionCode& ec) 1116 void WebGLRenderingContext::bindFramebuffer(GC3Denum target, WebGLFramebuffer* b uffer, ExceptionCode& ec)
1077 { 1117 {
1078 UNUSED_PARAM(ec); 1118 UNUSED_PARAM(ec);
1079 bool deleted; 1119 bool deleted;
1080 if (!checkObjectToBeBound("bindFramebuffer", buffer, deleted)) 1120 if (!checkContextObjectToBeBound("bindFramebuffer", buffer, deleted))
1081 return; 1121 return;
1082 if (deleted) 1122 if (deleted)
1083 buffer = 0; 1123 buffer = 0;
1084 if (target != GraphicsContext3D::FRAMEBUFFER) { 1124 if (target != GraphicsContext3D::FRAMEBUFFER) {
1085 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "bindFramebuffer", "i nvalid target"); 1125 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "bindFramebuffer", "i nvalid target");
1086 return; 1126 return;
1087 } 1127 }
1088 m_framebufferBinding = buffer; 1128 m_framebufferBinding = buffer;
1089 m_drawingBuffer->setFramebufferBinding(objectOrZero(m_framebufferBinding.get ())); 1129 m_drawingBuffer->setFramebufferBinding(objectOrZero(m_framebufferBinding.get ()));
1090 if (!m_framebufferBinding) { 1130 if (!m_framebufferBinding) {
1091 // Instead of binding fb 0, bind the drawing buffer. 1131 // Instead of binding fb 0, bind the drawing buffer.
1092 m_drawingBuffer->bind(); 1132 m_drawingBuffer->bind();
1093 } else 1133 } else
1094 m_context->bindFramebuffer(target, objectOrZero(buffer)); 1134 m_context->bindFramebuffer(target, objectOrZero(buffer));
1095 if (buffer) 1135 if (buffer)
1096 buffer->setHasEverBeenBound(); 1136 buffer->setHasEverBeenBound();
1097 applyStencilTest(); 1137 applyStencilTest();
1098 } 1138 }
1099 1139
1100 void WebGLRenderingContext::bindRenderbuffer(GC3Denum target, WebGLRenderbuffer* renderBuffer, ExceptionCode& ec) 1140 void WebGLRenderingContext::bindRenderbuffer(GC3Denum target, WebGLRenderbuffer* renderBuffer, ExceptionCode& ec)
1101 { 1141 {
1102 UNUSED_PARAM(ec); 1142 UNUSED_PARAM(ec);
1103 bool deleted; 1143 bool deleted;
1104 if (!checkObjectToBeBound("bindRenderbuffer", renderBuffer, deleted)) 1144 bool boundSinceLastAcquire;
1145 if (!checkSharedObjectToBeBound("bindRenderbuffer", renderBuffer, deleted, b oundSinceLastAcquire))
1105 return; 1146 return;
1106 if (deleted) 1147 if (deleted)
1107 renderBuffer = 0; 1148 renderBuffer = 0;
1108 if (target != GraphicsContext3D::RENDERBUFFER) { 1149 if (target != GraphicsContext3D::RENDERBUFFER) {
1109 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "bindRenderbuffer", " invalid target"); 1150 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "bindRenderbuffer", " invalid target");
1110 return; 1151 return;
1111 } 1152 }
1112 m_renderbufferBinding = renderBuffer; 1153 m_renderbufferBinding = renderBuffer;
1113 m_context->bindRenderbuffer(target, objectOrZero(renderBuffer)); 1154 m_context->bindRenderbuffer(target, objectOrZero(renderBuffer));
1114 if (renderBuffer) 1155 if (renderBuffer) {
1115 renderBuffer->setHasEverBeenBound(); 1156 renderBuffer->setHasEverBeenBound();
1157 if (!boundSinceLastAcquire) {
1158 renderBuffer->markAsBoundSinceLastAcquireForContext(this);
1159 }
1160 }
1116 } 1161 }
1117 1162
1118 void WebGLRenderingContext::bindTexture(GC3Denum target, WebGLTexture* texture, ExceptionCode& ec) 1163 void WebGLRenderingContext::bindTexture(GC3Denum target, WebGLTexture* texture, ExceptionCode& ec)
1119 { 1164 {
1120 UNUSED_PARAM(ec); 1165 UNUSED_PARAM(ec);
1121 bool deleted; 1166 bool deleted;
1122 if (!checkObjectToBeBound("bindTexture", texture, deleted)) 1167 bool boundSinceLastAcquire;
1168 if (!checkSharedObjectToBeBound("bindTexture", texture, deleted, boundSinceL astAcquire))
1123 return; 1169 return;
1124 if (deleted) 1170 if (deleted)
1125 texture = 0; 1171 texture = 0;
1126 if (texture && texture->getTarget() && texture->getTarget() != target) { 1172 if (texture && texture->getTarget() && texture->getTarget() != target) {
1127 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "bindTexture", " textures can not be used with multiple targets"); 1173 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "bindTexture", " textures can not be used with multiple targets");
1128 return; 1174 return;
1129 } 1175 }
1130 GC3Dint maxLevel = 0; 1176 GC3Dint maxLevel = 0;
1131 if (target == GraphicsContext3D::TEXTURE_2D) { 1177 if (target == GraphicsContext3D::TEXTURE_2D) {
1132 m_textureUnits[m_activeTextureUnit].m_texture2DBinding = texture; 1178 m_textureUnits[m_activeTextureUnit].m_texture2DBinding = texture;
1133 maxLevel = m_maxTextureLevel; 1179 maxLevel = m_maxTextureLevel;
1134 1180
1135 if (!m_activeTextureUnit) 1181 if (!m_activeTextureUnit)
1136 m_drawingBuffer->setTexture2DBinding(objectOrZero(texture)); 1182 m_drawingBuffer->setTexture2DBinding(objectOrZero(texture));
1137 1183
1138 } else if (target == GraphicsContext3D::TEXTURE_CUBE_MAP) { 1184 } else if (target == GraphicsContext3D::TEXTURE_CUBE_MAP) {
1139 m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding = texture; 1185 m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding = texture;
1140 maxLevel = m_maxCubeMapTextureLevel; 1186 maxLevel = m_maxCubeMapTextureLevel;
1141 } else { 1187 } else {
1142 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "bindTexture", "inval id target"); 1188 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "bindTexture", "inval id target");
1143 return; 1189 return;
1144 } 1190 }
1145 m_context->bindTexture(target, objectOrZero(texture)); 1191 m_context->bindTexture(target, objectOrZero(texture));
1146 if (texture) 1192 if (texture) {
1147 texture->setTarget(target, maxLevel); 1193 texture->setTarget(target, maxLevel);
1194 if (!boundSinceLastAcquire) {
1195 texture->markAsBoundSinceLastAcquireForContext(this);
1196 }
1197 }
1148 1198
1149 // Note: previously we used to automatically set the TEXTURE_WRAP_R 1199 // Note: previously we used to automatically set the TEXTURE_WRAP_R
1150 // repeat mode to CLAMP_TO_EDGE for cube map textures, because OpenGL 1200 // repeat mode to CLAMP_TO_EDGE for cube map textures, because OpenGL
1151 // ES 2.0 doesn't expose this flag (a bug in the specification) and 1201 // ES 2.0 doesn't expose this flag (a bug in the specification) and
1152 // otherwise the application has no control over the seams in this 1202 // otherwise the application has no control over the seams in this
1153 // dimension. However, it appears that supporting this properly on all 1203 // dimension. However, it appears that supporting this properly on all
1154 // platforms is fairly involved (will require a HashMap from texture ID 1204 // platforms is fairly involved (will require a HashMap from texture ID
1155 // in all ports), and we have not had any complaints, so the logic has 1205 // in all ports), and we have not had any complaints, so the logic has
1156 // been removed. 1206 // been removed.
1157 1207
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1278 if (!data) 1328 if (!data)
1279 return; 1329 return;
1280 1330
1281 m_context->bufferSubData(target, static_cast<GC3Dintptr>(offset), data->byte Length(), data->baseAddress()); 1331 m_context->bufferSubData(target, static_cast<GC3Dintptr>(offset), data->byte Length(), data->baseAddress());
1282 } 1332 }
1283 1333
1284 GC3Denum WebGLRenderingContext::checkFramebufferStatus(GC3Denum target) 1334 GC3Denum WebGLRenderingContext::checkFramebufferStatus(GC3Denum target)
1285 { 1335 {
1286 if (isContextLost()) 1336 if (isContextLost())
1287 return GraphicsContext3D::FRAMEBUFFER_UNSUPPORTED; 1337 return GraphicsContext3D::FRAMEBUFFER_UNSUPPORTED;
1288 if (target != GraphicsContext3D::FRAMEBUFFER) { 1338 switch (target) {
1339 case GraphicsContext3D::FRAMEBUFFER:
1340 case Extensions3D::READ_FRAMEBUFFER:
1341 case Extensions3D::DRAW_FRAMEBUFFER:
1342 break;
1343 default:
1289 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "checkFramebufferStat us", "invalid target"); 1344 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "checkFramebufferStat us", "invalid target");
1290 return 0; 1345 return 0;
1291 } 1346 }
1292 if (!m_framebufferBinding || !m_framebufferBinding->object()) 1347 if (!m_framebufferBinding || !m_framebufferBinding->object())
1293 return GraphicsContext3D::FRAMEBUFFER_COMPLETE; 1348 return GraphicsContext3D::FRAMEBUFFER_COMPLETE;
1294 const char* reason = "framebuffer incomplete"; 1349 const char* reason = "framebuffer incomplete";
1295 GC3Denum result = m_framebufferBinding->checkStatus(&reason); 1350 WebGLSharedObject::AcquireMode neededAccessMode = (target == Extensions3D::R EAD_FRAMEBUFFER) ? WebGLSharedObject::ReadOnly : WebGLSharedObject::Exclusive;
1351 GC3Denum result = m_framebufferBinding->checkStatus(this, neededAccessMode, &reason);
1296 if (result != GraphicsContext3D::FRAMEBUFFER_COMPLETE) { 1352 if (result != GraphicsContext3D::FRAMEBUFFER_COMPLETE) {
1297 printGLWarningToConsole("checkFramebufferStatus", reason); 1353 printGLWarningToConsole("checkFramebufferStatus", reason);
1298 return result; 1354 return result;
1299 } 1355 }
1300 result = m_context->checkFramebufferStatus(target); 1356 result = m_context->checkFramebufferStatus(target);
1301 return result; 1357 return result;
1302 } 1358 }
1303 1359
1304 void WebGLRenderingContext::clear(GC3Dbitfield mask) 1360 void WebGLRenderingContext::clear(GC3Dbitfield mask)
1305 { 1361 {
1306 if (isContextLost()) 1362 if (isContextLost())
1307 return; 1363 return;
1308 if (mask & ~(GraphicsContext3D::COLOR_BUFFER_BIT | GraphicsContext3D::DEPTH_ BUFFER_BIT | GraphicsContext3D::STENCIL_BUFFER_BIT)) { 1364 if (mask & ~(GraphicsContext3D::COLOR_BUFFER_BIT | GraphicsContext3D::DEPTH_ BUFFER_BIT | GraphicsContext3D::STENCIL_BUFFER_BIT)) {
1309 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "clear", "invalid ma sk"); 1365 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "clear", "invalid ma sk");
1310 return; 1366 return;
1311 } 1367 }
1312 const char* reason = "framebuffer incomplete"; 1368 const char* reason = "framebuffer incomplete";
1313 if (m_framebufferBinding && !m_framebufferBinding->onAccess(graphicsContext3 D(), &reason)) { 1369 if (m_framebufferBinding && !m_framebufferBinding->onAccess(this, WebGLShare dObject::Exclusive, &reason)) {
1314 synthesizeGLError(GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION, "cle ar", reason); 1370 synthesizeGLError(GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION, "cle ar", reason);
1315 return; 1371 return;
1316 } 1372 }
1317 if (!clearIfComposited(mask)) 1373 if (!clearIfComposited(mask))
1318 m_context->clear(mask); 1374 m_context->clear(mask);
1319 markContextChanged(); 1375 markContextChanged();
1320 } 1376 }
1321 1377
1322 void WebGLRenderingContext::clearColor(GC3Dfloat r, GC3Dfloat g, GC3Dfloat b, GC 3Dfloat a) 1378 void WebGLRenderingContext::clearColor(GC3Dfloat r, GC3Dfloat g, GC3Dfloat b, GC 3Dfloat a)
1323 { 1379 {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1361 m_colorMask[0] = red; 1417 m_colorMask[0] = red;
1362 m_colorMask[1] = green; 1418 m_colorMask[1] = green;
1363 m_colorMask[2] = blue; 1419 m_colorMask[2] = blue;
1364 m_colorMask[3] = alpha; 1420 m_colorMask[3] = alpha;
1365 m_context->colorMask(red, green, blue, alpha); 1421 m_context->colorMask(red, green, blue, alpha);
1366 } 1422 }
1367 1423
1368 void WebGLRenderingContext::compileShader(WebGLShader* shader, ExceptionCode& ec ) 1424 void WebGLRenderingContext::compileShader(WebGLShader* shader, ExceptionCode& ec )
1369 { 1425 {
1370 UNUSED_PARAM(ec); 1426 UNUSED_PARAM(ec);
1371 if (isContextLost() || !validateWebGLObject("compileShader", shader)) 1427 if (isContextLost() || !validateWebGLSharedObject("compileShader", shader, W ebGLSharedObject::Exclusive))
1372 return; 1428 return;
1373 m_context->compileShader(objectOrZero(shader)); 1429 m_context->compileShader(objectOrZero(shader));
1374 } 1430 }
1375 1431
1376 void WebGLRenderingContext::compressedTexImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, 1432 void WebGLRenderingContext::compressedTexImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width,
1377 GC3Dsizei height, GC3Dint borde r, ArrayBufferView* data) 1433 GC3Dsizei height, GC3Dint borde r, ArrayBufferView* data)
1378 { 1434 {
1379 if (isContextLost()) 1435 if (isContextLost())
1380 return; 1436 return;
1381 if (!validateTexFuncLevel("compressedTexImage2D", target, level)) 1437 if (!validateTexFuncLevel("compressedTexImage2D", target, level))
1382 return; 1438 return;
1383 1439
1384 if (!validateCompressedTexFormat(internalformat)) { 1440 if (!validateCompressedTexFormat(internalformat)) {
1385 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "compressedTexImage2D ", "invalid internalformat"); 1441 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "compressedTexImage2D ", "invalid internalformat");
1386 return; 1442 return;
1387 } 1443 }
1388 if (border) { 1444 if (border) {
1389 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "compressedTexImage2 D", "border not 0"); 1445 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "compressedTexImage2 D", "border not 0");
1390 return; 1446 return;
1391 } 1447 }
1392 if (!validateCompressedTexDimensions("compressedTexImage2D", level, width, h eight, internalformat)) 1448 if (!validateCompressedTexDimensions("compressedTexImage2D", level, width, h eight, internalformat))
1393 return; 1449 return;
1394 if (!validateCompressedTexFuncData("compressedTexImage2D", width, height, in ternalformat, data)) 1450 if (!validateCompressedTexFuncData("compressedTexImage2D", width, height, in ternalformat, data))
1395 return; 1451 return;
1396 1452
1397 WebGLTexture* tex = validateTextureBinding("compressedTexImage2D", target, t rue); 1453 WebGLTexture* tex = validateTextureBinding("compressedTexImage2D", target, t rue, WebGLSharedObject::Exclusive);
1398 if (!tex) 1454 if (!tex)
1399 return; 1455 return;
1400 if (!isGLES2NPOTStrict()) { 1456 if (!isGLES2NPOTStrict()) {
1401 if (level && WebGLTexture::isNPOT(width, height)) { 1457 if (level && WebGLTexture::isNPOT(width, height)) {
1402 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "compressedTexIm age2D", "level > 0 not power of 2"); 1458 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "compressedTexIm age2D", "level > 0 not power of 2");
1403 return; 1459 return;
1404 } 1460 }
1405 } 1461 }
1406 graphicsContext3D()->compressedTexImage2D(target, level, internalformat, wid th, height, 1462 graphicsContext3D()->compressedTexImage2D(target, level, internalformat, wid th, height,
1407 border, data->byteLength(), data-> baseAddress()); 1463 border, data->byteLength(), data-> baseAddress());
1408 tex->setLevelInfo(target, level, internalformat, width, height, GraphicsCont ext3D::UNSIGNED_BYTE); 1464 tex->setLevelInfo(target, level, internalformat, width, height, GraphicsCont ext3D::UNSIGNED_BYTE);
1409 } 1465 }
1410 1466
1411 void WebGLRenderingContext::compressedTexSubImage2D(GC3Denum target, GC3Dint lev el, GC3Dint xoffset, GC3Dint yoffset, 1467 void WebGLRenderingContext::compressedTexSubImage2D(GC3Denum target, GC3Dint lev el, GC3Dint xoffset, GC3Dint yoffset,
1412 GC3Dsizei width, GC3Dsizei h eight, GC3Denum format, ArrayBufferView* data) 1468 GC3Dsizei width, GC3Dsizei h eight, GC3Denum format, ArrayBufferView* data)
1413 { 1469 {
1414 if (isContextLost()) 1470 if (isContextLost())
1415 return; 1471 return;
1416 if (!validateTexFuncLevel("compressedTexSubImage2D", target, level)) 1472 if (!validateTexFuncLevel("compressedTexSubImage2D", target, level))
1417 return; 1473 return;
1418 if (!validateCompressedTexFormat(format)) { 1474 if (!validateCompressedTexFormat(format)) {
1419 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "compressedTexSubImag e2D", "invalid format"); 1475 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "compressedTexSubImag e2D", "invalid format");
1420 return; 1476 return;
1421 } 1477 }
1422 if (!validateCompressedTexFuncData("compressedTexSubImage2D", width, height, format, data)) 1478 if (!validateCompressedTexFuncData("compressedTexSubImage2D", width, height, format, data))
1423 return; 1479 return;
1424 1480
1425 WebGLTexture* tex = validateTextureBinding("compressedTexSubImage2D", target , true); 1481 WebGLTexture* tex = validateTextureBinding("compressedTexSubImage2D", target , true, WebGLSharedObject::Exclusive);
1426 if (!tex) 1482 if (!tex)
1427 return; 1483 return;
1428 1484
1429 if (format != tex->getInternalFormat(target, level)) { 1485 if (format != tex->getInternalFormat(target, level)) {
1430 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "compressedTexSu bImage2D", "format does not match texture format"); 1486 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "compressedTexSu bImage2D", "format does not match texture format");
1431 return; 1487 return;
1432 } 1488 }
1433 1489
1434 if (!validateCompressedTexSubDimensions("compressedTexSubImage2D", target, l evel, xoffset, yoffset, width, height, format, tex)) 1490 if (!validateCompressedTexSubDimensions("compressedTexSubImage2D", target, l evel, xoffset, yoffset, width, height, format, tex))
1435 return; 1491 return;
(...skipping 12 matching lines...) Expand all
1448 } 1504 }
1449 1505
1450 void WebGLRenderingContext::copyTexImage2D(GC3Denum target, GC3Dint level, GC3De num internalformat, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3 Dint border) 1506 void WebGLRenderingContext::copyTexImage2D(GC3Denum target, GC3Dint level, GC3De num internalformat, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3 Dint border)
1451 { 1507 {
1452 if (isContextLost()) 1508 if (isContextLost())
1453 return; 1509 return;
1454 if (!validateTexFuncParameters("copyTexImage2D", NotTexSubImage2D, target, l evel, internalformat, width, height, border, internalformat, GraphicsContext3D:: UNSIGNED_BYTE)) 1510 if (!validateTexFuncParameters("copyTexImage2D", NotTexSubImage2D, target, l evel, internalformat, width, height, border, internalformat, GraphicsContext3D:: UNSIGNED_BYTE))
1455 return; 1511 return;
1456 if (!validateSettableTexFormat("copyTexImage2D", internalformat)) 1512 if (!validateSettableTexFormat("copyTexImage2D", internalformat))
1457 return; 1513 return;
1458 WebGLTexture* tex = validateTextureBinding("copyTexImage2D", target, true); 1514 WebGLTexture* tex = validateTextureBinding("copyTexImage2D", target, true, W ebGLSharedObject::Exclusive);
1459 if (!tex) 1515 if (!tex)
1460 return; 1516 return;
1461 if (!isTexInternalFormatColorBufferCombinationValid(internalformat, getBound FramebufferColorFormat())) { 1517 if (!isTexInternalFormatColorBufferCombinationValid(internalformat, getBound FramebufferColorFormat())) {
1462 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "copyTexImage2D" , "framebuffer is incompatible format"); 1518 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "copyTexImage2D" , "framebuffer is incompatible format");
1463 return; 1519 return;
1464 } 1520 }
1465 if (!isGLES2NPOTStrict() && level && WebGLTexture::isNPOT(width, height)) { 1521 if (!isGLES2NPOTStrict() && level && WebGLTexture::isNPOT(width, height)) {
1466 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "copyTexImage2D", "l evel > 0 not power of 2"); 1522 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "copyTexImage2D", "l evel > 0 not power of 2");
1467 return; 1523 return;
1468 } 1524 }
1469 const char* reason = "framebuffer incomplete"; 1525 const char* reason = "framebuffer incomplete";
1470 if (m_framebufferBinding && !m_framebufferBinding->onAccess(graphicsContext3 D(), &reason)) { 1526 if (m_framebufferBinding && !m_framebufferBinding->onAccess(this, WebGLShare dObject::ReadOnly, &reason)) {
1471 synthesizeGLError(GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION, "cop yTexImage2D", reason); 1527 synthesizeGLError(GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION, "cop yTexImage2D", reason);
1472 return; 1528 return;
1473 } 1529 }
1474 clearIfComposited(); 1530 clearIfComposited();
1475 ScopedDrawingBufferBinder binder(m_drawingBuffer.get(), m_framebufferBinding .get()); 1531 ScopedDrawingBufferBinder binder(m_drawingBuffer.get(), m_framebufferBinding .get());
1476 m_context->copyTexImage2D(target, level, internalformat, x, y, width, height , border); 1532 m_context->copyTexImage2D(target, level, internalformat, x, y, width, height , border);
1477 // FIXME: if the framebuffer is not complete, none of the below should be ex ecuted. 1533 // FIXME: if the framebuffer is not complete, none of the below should be ex ecuted.
1478 tex->setLevelInfo(target, level, internalformat, width, height, GraphicsCont ext3D::UNSIGNED_BYTE); 1534 tex->setLevelInfo(target, level, internalformat, width, height, GraphicsCont ext3D::UNSIGNED_BYTE);
1479 } 1535 }
1480 1536
1481 void WebGLRenderingContext::copyTexSubImage2D(GC3Denum target, GC3Dint level, GC 3Dint xoffset, GC3Dint yoffset, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height) 1537 void WebGLRenderingContext::copyTexSubImage2D(GC3Denum target, GC3Dint level, GC 3Dint xoffset, GC3Dint yoffset, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height)
1482 { 1538 {
1483 if (isContextLost()) 1539 if (isContextLost())
1484 return; 1540 return;
1485 if (!validateTexFuncLevel("copyTexSubImage2D", target, level)) 1541 if (!validateTexFuncLevel("copyTexSubImage2D", target, level))
1486 return; 1542 return;
1487 WebGLTexture* tex = validateTextureBinding("copyTexSubImage2D", target, true ); 1543 WebGLTexture* tex = validateTextureBinding("copyTexSubImage2D", target, true , WebGLSharedObject::Exclusive);
1488 if (!tex) 1544 if (!tex)
1489 return; 1545 return;
1490 if (!validateSize("copyTexSubImage2D", xoffset, yoffset) || !validateSize("c opyTexSubImage2D", width, height)) 1546 if (!validateSize("copyTexSubImage2D", xoffset, yoffset) || !validateSize("c opyTexSubImage2D", width, height))
1491 return; 1547 return;
1492 // Before checking if it is in the range, check if overflow happens first. 1548 // Before checking if it is in the range, check if overflow happens first.
1493 if (xoffset + width < 0 || yoffset + height < 0) { 1549 if (xoffset + width < 0 || yoffset + height < 0) {
1494 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "copyTexSubImage2D", "bad dimensions"); 1550 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "copyTexSubImage2D", "bad dimensions");
1495 return; 1551 return;
1496 } 1552 }
1497 if (xoffset + width > tex->getWidth(target, level) || yoffset + height > tex ->getHeight(target, level)) { 1553 if (xoffset + width > tex->getWidth(target, level) || yoffset + height > tex ->getHeight(target, level)) {
1498 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "copyTexSubImage2D", "rectangle out of range"); 1554 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "copyTexSubImage2D", "rectangle out of range");
1499 return; 1555 return;
1500 } 1556 }
1501 GC3Denum internalformat = tex->getInternalFormat(target, level); 1557 GC3Denum internalformat = tex->getInternalFormat(target, level);
1502 if (!validateSettableTexFormat("copyTexSubImage2D", internalformat)) 1558 if (!validateSettableTexFormat("copyTexSubImage2D", internalformat))
1503 return; 1559 return;
1504 if (!isTexInternalFormatColorBufferCombinationValid(internalformat, getBound FramebufferColorFormat())) { 1560 if (!isTexInternalFormatColorBufferCombinationValid(internalformat, getBound FramebufferColorFormat())) {
1505 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "copyTexSubImage 2D", "framebuffer is incompatible format"); 1561 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "copyTexSubImage 2D", "framebuffer is incompatible format");
1506 return; 1562 return;
1507 } 1563 }
1508 const char* reason = "framebuffer incomplete"; 1564 const char* reason = "framebuffer incomplete";
1509 if (m_framebufferBinding && !m_framebufferBinding->onAccess(graphicsContext3 D(), &reason)) { 1565 if (m_framebufferBinding && !m_framebufferBinding->onAccess(this, WebGLShare dObject::ReadOnly, &reason)) {
1510 synthesizeGLError(GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION, "cop yTexSubImage2D", reason); 1566 synthesizeGLError(GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION, "cop yTexSubImage2D", reason);
1511 return; 1567 return;
1512 } 1568 }
1513 clearIfComposited(); 1569 clearIfComposited();
1514 ScopedDrawingBufferBinder binder(m_drawingBuffer.get(), m_framebufferBinding .get()); 1570 ScopedDrawingBufferBinder binder(m_drawingBuffer.get(), m_framebufferBinding .get());
1515 m_context->copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, h eight); 1571 m_context->copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, h eight);
1516 } 1572 }
1517 1573
1518 PassRefPtr<WebGLBuffer> WebGLRenderingContext::createBuffer() 1574 PassRefPtr<WebGLBuffer> WebGLRenderingContext::createBuffer()
1519 { 1575 {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1587 return o; 1643 return o;
1588 } 1644 }
1589 1645
1590 void WebGLRenderingContext::cullFace(GC3Denum mode) 1646 void WebGLRenderingContext::cullFace(GC3Denum mode)
1591 { 1647 {
1592 if (isContextLost()) 1648 if (isContextLost())
1593 return; 1649 return;
1594 m_context->cullFace(mode); 1650 m_context->cullFace(mode);
1595 } 1651 }
1596 1652
1597 bool WebGLRenderingContext::deleteObject(WebGLObject* object) 1653 bool WebGLRenderingContext::deleteContextObject(const char* functionName, WebGLC ontextObject* object)
1598 { 1654 {
1599 if (isContextLost() || !object) 1655 if (isContextLost() || !object)
1600 return false; 1656 return false;
1601 if (!object->validate(contextGroup(), this)) { 1657 if (!object->validate(contextGroup(), this)) {
1602 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "delete", "objec t does not belong to this context"); 1658 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "o bject does not belong to this share group");
1659 return false;
1660 }
1661 if (object->object()) {
1662 // We need to pass in context here because we want
1663 // things in this context unbound.
1664 object->deleteObject(graphicsContext3D());
1665 }
1666 return true;
1667 }
1668
1669 bool WebGLRenderingContext::deleteSharedObject(const char* functionName, WebGLSh aredObject* object)
1670 {
1671 if (isContextLost() || !object)
1672 return false;
1673 if (!object->validate(functionName, this, WebGLSharedObject::Exclusive, true , 0)) {
Ken Russell (switch to Gerrit) 2013/06/19 03:51:24 What happens if the implementation tries to force
greggman 2013/06/21 19:54:21 I don't think so. context lost doesn't go through
1603 return false; 1674 return false;
1604 } 1675 }
1605 if (object->object()) 1676 if (object->object())
1606 // We need to pass in context here because we want 1677 // We need to pass in context here because we want
1607 // things in this context unbound. 1678 // things in this context unbound.
1608 object->deleteObject(graphicsContext3D()); 1679 object->deleteObject(graphicsContext3D());
1609 return true; 1680 return true;
1610 } 1681 }
1611 1682
1612 void WebGLRenderingContext::deleteBuffer(WebGLBuffer* buffer) 1683 void WebGLRenderingContext::deleteBuffer(WebGLBuffer* buffer)
1613 { 1684 {
1614 if (!deleteObject(buffer)) 1685 if (!deleteSharedObject("deleteBuffer", buffer))
1615 return; 1686 return;
1616 if (m_boundArrayBuffer == buffer) 1687 if (m_boundArrayBuffer == buffer)
1617 m_boundArrayBuffer = 0; 1688 m_boundArrayBuffer = 0;
1618 1689
1619 m_boundVertexArrayObject->unbindBuffer(buffer); 1690 m_boundVertexArrayObject->unbindBuffer(buffer);
1620 } 1691 }
1621 1692
1622 void WebGLRenderingContext::deleteFramebuffer(WebGLFramebuffer* framebuffer) 1693 void WebGLRenderingContext::deleteFramebuffer(WebGLFramebuffer* framebuffer)
1623 { 1694 {
1624 if (!deleteObject(framebuffer)) 1695 if (!deleteContextObject("deleteFramebuffer", framebuffer))
1625 return; 1696 return;
1626 if (framebuffer == m_framebufferBinding) { 1697 if (framebuffer == m_framebufferBinding) {
1627 m_framebufferBinding = 0; 1698 m_framebufferBinding = 0;
1628 m_drawingBuffer->setFramebufferBinding(0); 1699 m_drawingBuffer->setFramebufferBinding(0);
1629 // Have to call bindFramebuffer here to bind back to internal fbo. 1700 // Have to call bindFramebuffer here to bind back to internal fbo.
1630 m_drawingBuffer->bind(); 1701 m_drawingBuffer->bind();
1631 } 1702 }
1632 } 1703 }
1633 1704
1634 void WebGLRenderingContext::deleteProgram(WebGLProgram* program) 1705 void WebGLRenderingContext::deleteProgram(WebGLProgram* program)
1635 { 1706 {
1636 deleteObject(program); 1707 deleteSharedObject("deleteProgram", program);
1637 // We don't reset m_currentProgram to 0 here because the deletion of the 1708 // We don't reset m_currentProgram to 0 here because the deletion of the
1638 // current program is delayed. 1709 // current program is delayed.
1639 } 1710 }
1640 1711
1641 void WebGLRenderingContext::deleteRenderbuffer(WebGLRenderbuffer* renderbuffer) 1712 void WebGLRenderingContext::deleteRenderbuffer(WebGLRenderbuffer* renderbuffer)
1642 { 1713 {
1643 if (!deleteObject(renderbuffer)) 1714 if (!deleteSharedObject("deleteRenderbuffer", renderbuffer))
1644 return; 1715 return;
1645 if (renderbuffer == m_renderbufferBinding) 1716 if (renderbuffer == m_renderbufferBinding)
1646 m_renderbufferBinding = 0; 1717 m_renderbufferBinding = 0;
1647 if (m_framebufferBinding) 1718 if (m_framebufferBinding)
1648 m_framebufferBinding->removeAttachmentFromBoundFramebuffer(renderbuffer) ; 1719 m_framebufferBinding->removeAttachmentFromBoundFramebuffer(renderbuffer) ;
1649 } 1720 }
1650 1721
1651 void WebGLRenderingContext::deleteShader(WebGLShader* shader) 1722 void WebGLRenderingContext::deleteShader(WebGLShader* shader)
1652 { 1723 {
1653 deleteObject(shader); 1724 deleteSharedObject("deleteShader", shader);
1654 } 1725 }
1655 1726
1656 void WebGLRenderingContext::deleteTexture(WebGLTexture* texture) 1727 void WebGLRenderingContext::deleteTexture(WebGLTexture* texture)
1657 { 1728 {
1658 if (!deleteObject(texture)) 1729 if (!deleteSharedObject("deleteTexture", texture))
1659 return; 1730 return;
1660 for (size_t i = 0; i < m_textureUnits.size(); ++i) { 1731 for (size_t i = 0; i < m_textureUnits.size(); ++i) {
1661 if (texture == m_textureUnits[i].m_texture2DBinding) 1732 if (texture == m_textureUnits[i].m_texture2DBinding)
1662 m_textureUnits[i].m_texture2DBinding = 0; 1733 m_textureUnits[i].m_texture2DBinding = 0;
1663 if (texture == m_textureUnits[i].m_textureCubeMapBinding) 1734 if (texture == m_textureUnits[i].m_textureCubeMapBinding)
1664 m_textureUnits[i].m_textureCubeMapBinding = 0; 1735 m_textureUnits[i].m_textureCubeMapBinding = 0;
1665 } 1736 }
1666 if (m_framebufferBinding) 1737 if (m_framebufferBinding)
1667 m_framebufferBinding->removeAttachmentFromBoundFramebuffer(texture); 1738 m_framebufferBinding->removeAttachmentFromBoundFramebuffer(texture);
1668 } 1739 }
(...skipping 20 matching lines...) Expand all
1689 if (zNear > zFar) { 1760 if (zNear > zFar) {
1690 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "depthRange", "z Near > zFar"); 1761 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "depthRange", "z Near > zFar");
1691 return; 1762 return;
1692 } 1763 }
1693 m_context->depthRange(zNear, zFar); 1764 m_context->depthRange(zNear, zFar);
1694 } 1765 }
1695 1766
1696 void WebGLRenderingContext::detachShader(WebGLProgram* program, WebGLShader* sha der, ExceptionCode& ec) 1767 void WebGLRenderingContext::detachShader(WebGLProgram* program, WebGLShader* sha der, ExceptionCode& ec)
1697 { 1768 {
1698 UNUSED_PARAM(ec); 1769 UNUSED_PARAM(ec);
1699 if (isContextLost() || !validateWebGLObject("detachShader", program) || !val idateWebGLObject("detachShader", shader)) 1770 bool boundSinceLastAcquire;
1771 bool deleted;
1772 // NOTE: We explicitly don't check the shader has been bound since the only way to mark a shader as bound is to attach it which means
1773 // there would be no way to detach a shader in context other than the one
1774 // that attached it.
1775 if (isContextLost()
1776 || !validateWebGLSharedObject("detachShader", program, WebGLSharedObject ::Exclusive)
1777 || !checkSharedObjectToBeBound("detachShader", shader, deleted, boundSin ceLastAcquire)) {
1700 return; 1778 return;
1779 }
1780 if (deleted) {
1781 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "detachShader", "shader deleted");
1782 return;
1783 }
1701 if (!program->detachShader(shader)) { 1784 if (!program->detachShader(shader)) {
1702 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "detachShader", "shader not attached"); 1785 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "detachShader", "shader not attached");
1703 return; 1786 return;
1704 } 1787 }
1705 m_context->detachShader(objectOrZero(program), objectOrZero(shader)); 1788 m_context->detachShader(objectOrZero(program), objectOrZero(shader));
1706 shader->onDetached(graphicsContext3D()); 1789 shader->onDetached(graphicsContext3D());
1707 } 1790 }
1708 1791
1709 void WebGLRenderingContext::disable(GC3Denum cap) 1792 void WebGLRenderingContext::disable(GC3Denum cap)
1710 { 1793 {
(...skipping 19 matching lines...) Expand all
1730 if (index >= m_maxVertexAttribs) { 1813 if (index >= m_maxVertexAttribs) {
1731 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "disableVertexAttrib Array", "index out of range"); 1814 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "disableVertexAttrib Array", "index out of range");
1732 return; 1815 return;
1733 } 1816 }
1734 1817
1735 WebGLVertexArrayObjectOES::VertexAttribState& state = m_boundVertexArrayObje ct->getVertexAttribState(index); 1818 WebGLVertexArrayObjectOES::VertexAttribState& state = m_boundVertexArrayObje ct->getVertexAttribState(index);
1736 state.enabled = false; 1819 state.enabled = false;
1737 m_context->disableVertexAttribArray(index); 1820 m_context->disableVertexAttribArray(index);
1738 } 1821 }
1739 1822
1740 bool WebGLRenderingContext::validateRenderingState() 1823 bool WebGLRenderingContext::validateRenderingState(const char* functionName)
1741 { 1824 {
1742 if (!m_currentProgram) 1825 if (!m_currentProgram)
1743 return false; 1826 return false;
1744 1827
1828 if (!isAcquiredForReading(functionName, m_currentProgram.get())) {
1829 return false;
1830 }
1831
1745 // Look in each enabled vertex attrib and check if they've been bound to a b uffer. 1832 // Look in each enabled vertex attrib and check if they've been bound to a b uffer.
1746 for (unsigned i = 0; i < m_maxVertexAttribs; ++i) { 1833 for (unsigned i = 0; i < m_maxVertexAttribs; ++i) {
1747 const WebGLVertexArrayObjectOES::VertexAttribState& state = m_boundVerte xArrayObject->getVertexAttribState(i); 1834 WebGLVertexArrayObjectOES::VertexAttribState& state = m_boundVertexArray Object->getVertexAttribState(i);
1748 if (state.enabled 1835 if (state.enabled) {
1749 && (!state.bufferBinding || !state.bufferBinding->object())) 1836 if (!state.bufferBinding || !state.bufferBinding->object()) {
1750 return false; 1837 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, function Name, "attribs enabled with no buffer bound");
1838 return false;
1839 }
1840 if (!isAcquiredForReading(functionName, state.bufferBinding.get())) {
1841 return false;
1842 }
1843 }
1751 } 1844 }
1752 1845
1753 return true; 1846 return true;
1754 } 1847 }
1755 1848
1756 bool WebGLRenderingContext::validateWebGLObject(const char* functionName, WebGLO bject* object) 1849 bool WebGLRenderingContext::isAcquiredForModification(const char* functionName, WebGLSharedObject* object)
1850 {
1851 return validateWebGLSharedObject(functionName, object, WebGLSharedObject::Ex clusive);
1852 }
1853
1854 bool WebGLRenderingContext::isAcquiredForReading(const char* functionName, WebGL SharedObject* object)
1855 {
1856 return validateWebGLSharedObject(functionName, object, WebGLSharedObject::Re adOnly);
1857 }
1858
1859 bool WebGLRenderingContext::validateWebGLSharedObject(const char* functionName, WebGLSharedObject* object, WebGLSharedObject::AcquireMode acquireMode)
1757 { 1860 {
1758 if (!object || !object->object()) { 1861 if (!object || !object->object()) {
1759 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no ob ject or object deleted"); 1862 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no ob ject or object deleted");
1760 return false; 1863 return false;
1761 } 1864 }
1762 if (!object->validate(contextGroup(), this)) { 1865 if (!object->validate(functionName, this, acquireMode, true, 0)) {
1763 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "o bject does not belong to this context");
1764 return false; 1866 return false;
1765 } 1867 }
1766 return true; 1868 return true;
1767 } 1869 }
1768 1870
1871 long WebGLRenderingContext::acquireSharedResource(WebGLSharedObject* object, Web GLSharedObject::AcquireMode desiredMode, PassRefPtr<WebGLAcquireSharedResourceCa llback> callback, ExceptionCode& ec)
1872 {
1873 UNUSED_PARAM(ec);
1874 if (!object) {
1875 return 0;
1876 }
1877
1878 long id;
1879 if (!object->addAcquireRequest(this, desiredMode, callback, id)) {
1880 return 0;
1881 }
1882
1883 return id;
1884 }
1885
1886 void WebGLRenderingContext::releaseSharedResource(WebGLSharedObject* object, Exc eptionCode& ec)
1887 {
1888 UNUSED_PARAM(ec);
1889
1890 if (!object) {
1891 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "releaseSharedRe source", "no resource");
1892 return;
1893 }
1894
1895 if (!object->release(this)) {
1896 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "releaseSharedRe source", "resource not acquired");
1897 }
1898 }
1899
1900 void WebGLRenderingContext::cancelAcquireSharedResource(long id)
1901 {
1902 m_contextGroup->cancelAcquireSharedResource(this, id);
1903 }
1904
1769 void WebGLRenderingContext::drawArrays(GC3Denum mode, GC3Dint first, GC3Dsizei c ount, ExceptionCode& ec) 1905 void WebGLRenderingContext::drawArrays(GC3Denum mode, GC3Dint first, GC3Dsizei c ount, ExceptionCode& ec)
1770 { 1906 {
1771 UNUSED_PARAM(ec); 1907 UNUSED_PARAM(ec);
1772 1908
1773 if (!validateDrawArrays("drawArrays", mode, first, count)) 1909 if (!validateDrawArrays("drawArrays", mode, first, count))
1774 return; 1910 return;
1775 1911
1776 clearIfComposited(); 1912 bool texturesReplaced;
1777 1913 if (handleTextureCompleteness("drawArrays", true, &texturesReplaced)) {
1778 handleTextureCompleteness("drawArrays", true); 1914 clearIfComposited();
1779 m_context->drawArrays(mode, first, count); 1915 m_context->drawArrays(mode, first, count);
1780 handleTextureCompleteness("drawArrays", false); 1916 markContextChanged();
1781 markContextChanged(); 1917 }
1918 if (texturesReplaced) {
1919 handleTextureCompleteness("drawArrays", false, 0);
1920 }
1782 } 1921 }
1783 1922
1784 void WebGLRenderingContext::drawElements(GC3Denum mode, GC3Dsizei count, GC3Denu m type, long long offset, ExceptionCode& ec) 1923 void WebGLRenderingContext::drawElements(GC3Denum mode, GC3Dsizei count, GC3Denu m type, long long offset, ExceptionCode& ec)
1785 { 1924 {
1786 UNUSED_PARAM(ec); 1925 UNUSED_PARAM(ec);
1787 1926
1788 if (!validateDrawElements("drawElements", mode, count, type, offset)) 1927 if (!validateDrawElements("drawElements", mode, count, type, offset))
1789 return; 1928 return;
1790 1929
1791 clearIfComposited(); 1930 bool texturesReplaced;
1792 1931 if (handleTextureCompleteness("drawElements", true, &texturesReplaced)) {
1793 handleTextureCompleteness("drawElements", true); 1932 clearIfComposited();
1794 m_context->drawElements(mode, count, type, static_cast<GC3Dintptr>(offset)); 1933 m_context->drawElements(mode, count, type, static_cast<GC3Dintptr>(offse t));
1795 handleTextureCompleteness("drawElements", false); 1934 markContextChanged();
1796 markContextChanged(); 1935 }
1936 if (texturesReplaced) {
1937 handleTextureCompleteness("drawElements", false, 0);
1938 }
1797 } 1939 }
1798 1940
1799 void WebGLRenderingContext::drawArraysInstancedANGLE(GC3Denum mode, GC3Dint firs t, GC3Dsizei count, GC3Dsizei primcount) 1941 void WebGLRenderingContext::drawArraysInstancedANGLE(GC3Denum mode, GC3Dint firs t, GC3Dsizei count, GC3Dsizei primcount)
1800 { 1942 {
1801 if (!validateDrawArrays("drawArraysInstancedANGLE", mode, first, count)) 1943 if (!validateDrawArrays("drawArraysInstancedANGLE", mode, first, count))
1802 return; 1944 return;
1803 1945
1804 if (!validateDrawInstanced("drawArraysInstancedANGLE", primcount)) 1946 if (!validateDrawInstanced("drawArraysInstancedANGLE", primcount))
1805 return; 1947 return;
1806 1948
1807 clearIfComposited(); 1949 bool texturesReplaced;
1808 1950 if (handleTextureCompleteness("drawArraysInstancedANGLE", true, &texturesRep laced)) {
1809 handleTextureCompleteness("drawArraysInstancedANGLE", true); 1951 clearIfComposited();
1810 m_context->getExtensions()->drawArraysInstancedANGLE(mode, first, count, pri mcount); 1952 m_context->getExtensions()->drawArraysInstancedANGLE(mode, first, count, primcount);
1811 handleTextureCompleteness("drawArraysInstancedANGLE", false); 1953 markContextChanged();
1812 markContextChanged(); 1954 }
1955 if (texturesReplaced) {
1956 handleTextureCompleteness("drawArraysInstancedANGLE", false, 0);
1957 }
1813 } 1958 }
1814 1959
1815 void WebGLRenderingContext::drawElementsInstancedANGLE(GC3Denum mode, GC3Dsizei count, GC3Denum type, GC3Dintptr offset, GC3Dsizei primcount) 1960 void WebGLRenderingContext::drawElementsInstancedANGLE(GC3Denum mode, GC3Dsizei count, GC3Denum type, GC3Dintptr offset, GC3Dsizei primcount)
1816 { 1961 {
1817 if (!validateDrawElements("drawElementsInstancedANGLE", mode, count, type, o ffset)) 1962 if (!validateDrawElements("drawElementsInstancedANGLE", mode, count, type, o ffset))
1818 return; 1963 return;
1819 1964
1820 if (!validateDrawInstanced("drawElementsInstancedANGLE", primcount)) 1965 if (!validateDrawInstanced("drawElementsInstancedANGLE", primcount))
1821 return; 1966 return;
1822 1967
1823 clearIfComposited(); 1968 bool texturesReplaced;
1824 1969 if (handleTextureCompleteness("drawElementsInstancedANGLE", true, &texturesR eplaced)) {
1825 handleTextureCompleteness("drawElementsInstancedANGLE", true); 1970 clearIfComposited();
1826 m_context->getExtensions()->drawElementsInstancedANGLE(mode, count, type, st atic_cast<GC3Dintptr>(offset), primcount); 1971 m_context->getExtensions()->drawElementsInstancedANGLE(mode, count, type , static_cast<GC3Dintptr>(offset), primcount);
1827 handleTextureCompleteness("drawElementsInstancedANGLE", false); 1972 markContextChanged();
1828 markContextChanged(); 1973 }
1974 if (texturesReplaced) {
1975 handleTextureCompleteness("drawElementsInstancedANGLE", false, 0);
1976 }
1829 } 1977 }
1830 1978
1831 void WebGLRenderingContext::enable(GC3Denum cap) 1979 void WebGLRenderingContext::enable(GC3Denum cap)
1832 { 1980 {
1833 if (isContextLost() || !validateCapability("enable", cap)) 1981 if (isContextLost() || !validateCapability("enable", cap))
1834 return; 1982 return;
1835 if (cap == GraphicsContext3D::STENCIL_TEST) { 1983 if (cap == GraphicsContext3D::STENCIL_TEST) {
1836 m_stencilEnabled = true; 1984 m_stencilEnabled = true;
1837 applyStencilTest(); 1985 applyStencilTest();
1838 return; 1986 return;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1876 2024
1877 void WebGLRenderingContext::framebufferRenderbuffer(GC3Denum target, GC3Denum at tachment, GC3Denum renderbuffertarget, WebGLRenderbuffer* buffer, ExceptionCode& ec) 2025 void WebGLRenderingContext::framebufferRenderbuffer(GC3Denum target, GC3Denum at tachment, GC3Denum renderbuffertarget, WebGLRenderbuffer* buffer, ExceptionCode& ec)
1878 { 2026 {
1879 UNUSED_PARAM(ec); 2027 UNUSED_PARAM(ec);
1880 if (isContextLost() || !validateFramebufferFuncParameters("framebufferRender buffer", target, attachment)) 2028 if (isContextLost() || !validateFramebufferFuncParameters("framebufferRender buffer", target, attachment))
1881 return; 2029 return;
1882 if (renderbuffertarget != GraphicsContext3D::RENDERBUFFER) { 2030 if (renderbuffertarget != GraphicsContext3D::RENDERBUFFER) {
1883 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "framebufferRenderbuf fer", "invalid target"); 2031 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "framebufferRenderbuf fer", "invalid target");
1884 return; 2032 return;
1885 } 2033 }
1886 if (buffer && !buffer->validate(contextGroup(), this)) { 2034 bool hasBeenBoundSinceLastAcquire;
1887 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "framebufferRend erbuffer", "no buffer or buffer not from this context"); 2035 if (buffer && !buffer->validate("framebufferRenderbuffer", this, WebGLShared Object::ReadOnly, false, &hasBeenBoundSinceLastAcquire)) {
1888 return; 2036 return;
1889 } 2037 }
1890 // Don't allow the default framebuffer to be mutated; all current 2038 // Don't allow the default framebuffer to be mutated; all current
1891 // implementations use an FBO internally in place of the default 2039 // implementations use an FBO internally in place of the default
1892 // FBO. 2040 // FBO.
1893 if (!m_framebufferBinding || !m_framebufferBinding->object()) { 2041 if (!m_framebufferBinding || !m_framebufferBinding->object()) {
1894 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "framebufferRend erbuffer", "no framebuffer bound"); 2042 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "framebufferRend erbuffer", "no framebuffer bound");
1895 return; 2043 return;
1896 } 2044 }
1897 Platform3DObject bufferObject = objectOrZero(buffer); 2045 Platform3DObject bufferObject = objectOrZero(buffer);
2046 if (buffer && !hasBeenBoundSinceLastAcquire) {
2047 buffer->markAsBoundSinceLastAcquireForContext(this);
2048 }
1898 switch (attachment) { 2049 switch (attachment) {
1899 case GraphicsContext3D::DEPTH_STENCIL_ATTACHMENT: 2050 case GraphicsContext3D::DEPTH_STENCIL_ATTACHMENT:
1900 if (isDepthStencilSupported() || !buffer) { 2051 if (isDepthStencilSupported() || !buffer) {
1901 m_context->framebufferRenderbuffer(target, GraphicsContext3D::DEPTH_ ATTACHMENT, renderbuffertarget, bufferObject); 2052 m_context->framebufferRenderbuffer(target, GraphicsContext3D::DEPTH_ ATTACHMENT, renderbuffertarget, bufferObject);
1902 m_context->framebufferRenderbuffer(target, GraphicsContext3D::STENCI L_ATTACHMENT, renderbuffertarget, bufferObject); 2053 m_context->framebufferRenderbuffer(target, GraphicsContext3D::STENCI L_ATTACHMENT, renderbuffertarget, bufferObject);
1903 } else { 2054 } else {
1904 WebGLRenderbuffer* emulatedStencilBuffer = ensureEmulatedStencilBuff er(renderbuffertarget, buffer); 2055 WebGLRenderbuffer* emulatedStencilBuffer = ensureEmulatedStencilBuff er(renderbuffertarget, buffer);
1905 if (!emulatedStencilBuffer) { 2056 if (!emulatedStencilBuffer) {
1906 synthesizeGLError(GraphicsContext3D::OUT_OF_MEMORY, "framebuffer Renderbuffer", "out of memory"); 2057 synthesizeGLError(GraphicsContext3D::OUT_OF_MEMORY, "framebuffer Renderbuffer", "out of memory");
1907 return; 2058 return;
(...skipping 11 matching lines...) Expand all
1919 2070
1920 void WebGLRenderingContext::framebufferTexture2D(GC3Denum target, GC3Denum attac hment, GC3Denum textarget, WebGLTexture* texture, GC3Dint level, ExceptionCode& ec) 2071 void WebGLRenderingContext::framebufferTexture2D(GC3Denum target, GC3Denum attac hment, GC3Denum textarget, WebGLTexture* texture, GC3Dint level, ExceptionCode& ec)
1921 { 2072 {
1922 UNUSED_PARAM(ec); 2073 UNUSED_PARAM(ec);
1923 if (isContextLost() || !validateFramebufferFuncParameters("framebufferTextur e2D", target, attachment)) 2074 if (isContextLost() || !validateFramebufferFuncParameters("framebufferTextur e2D", target, attachment))
1924 return; 2075 return;
1925 if (level) { 2076 if (level) {
1926 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "framebufferTexture2 D", "level not 0"); 2077 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "framebufferTexture2 D", "level not 0");
1927 return; 2078 return;
1928 } 2079 }
1929 if (texture && !texture->validate(contextGroup(), this)) { 2080 bool hasBeenBoundSinceLastAcquire;
1930 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "framebufferText ure2D", "no texture or texture not from this context"); 2081 if (texture && !texture->validate("framebufferTexture2D", this, WebGLSharedO bject::ReadOnly, false, &hasBeenBoundSinceLastAcquire)) {
1931 return; 2082 return;
1932 } 2083 }
1933 // Don't allow the default framebuffer to be mutated; all current 2084 // Don't allow the default framebuffer to be mutated; all current
1934 // implementations use an FBO internally in place of the default 2085 // implementations use an FBO internally in place of the default
1935 // FBO. 2086 // FBO.
1936 if (!m_framebufferBinding || !m_framebufferBinding->object()) { 2087 if (!m_framebufferBinding || !m_framebufferBinding->object()) {
1937 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "framebufferText ure2D", "no framebuffer bound"); 2088 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "framebufferText ure2D", "no framebuffer bound");
1938 return; 2089 return;
1939 } 2090 }
1940 Platform3DObject textureObject = objectOrZero(texture); 2091 Platform3DObject textureObject = objectOrZero(texture);
2092 if (texture && !hasBeenBoundSinceLastAcquire) {
2093 texture->markAsBoundSinceLastAcquireForContext(this);
2094 }
1941 switch (attachment) { 2095 switch (attachment) {
1942 case GraphicsContext3D::DEPTH_STENCIL_ATTACHMENT: 2096 case GraphicsContext3D::DEPTH_STENCIL_ATTACHMENT:
1943 m_context->framebufferTexture2D(target, GraphicsContext3D::DEPTH_ATTACHM ENT, textarget, textureObject, level); 2097 m_context->framebufferTexture2D(target, GraphicsContext3D::DEPTH_ATTACHM ENT, textarget, textureObject, level);
1944 m_context->framebufferTexture2D(target, GraphicsContext3D::STENCIL_ATTAC HMENT, textarget, textureObject, level); 2098 m_context->framebufferTexture2D(target, GraphicsContext3D::STENCIL_ATTAC HMENT, textarget, textureObject, level);
1945 break; 2099 break;
1946 case GraphicsContext3D::DEPTH_ATTACHMENT: 2100 case GraphicsContext3D::DEPTH_ATTACHMENT:
1947 m_context->framebufferTexture2D(target, attachment, textarget, textureOb ject, level); 2101 m_context->framebufferTexture2D(target, attachment, textarget, textureOb ject, level);
1948 break; 2102 break;
1949 case GraphicsContext3D::STENCIL_ATTACHMENT: 2103 case GraphicsContext3D::STENCIL_ATTACHMENT:
1950 m_context->framebufferTexture2D(target, attachment, textarget, textureOb ject, level); 2104 m_context->framebufferTexture2D(target, attachment, textarget, textureOb ject, level);
1951 break; 2105 break;
1952 default: 2106 default:
1953 m_context->framebufferTexture2D(target, attachment, textarget, textureOb ject, level); 2107 m_context->framebufferTexture2D(target, attachment, textarget, textureOb ject, level);
1954 } 2108 }
1955 m_framebufferBinding->setAttachmentForBoundFramebuffer(attachment, textarget , texture, level); 2109 m_framebufferBinding->setAttachmentForBoundFramebuffer(attachment, textarget , texture, level);
1956 applyStencilTest(); 2110 applyStencilTest();
1957 } 2111 }
1958 2112
1959 void WebGLRenderingContext::frontFace(GC3Denum mode) 2113 void WebGLRenderingContext::frontFace(GC3Denum mode)
1960 { 2114 {
1961 if (isContextLost()) 2115 if (isContextLost())
1962 return; 2116 return;
1963 m_context->frontFace(mode); 2117 m_context->frontFace(mode);
1964 } 2118 }
1965 2119
1966 void WebGLRenderingContext::generateMipmap(GC3Denum target) 2120 void WebGLRenderingContext::generateMipmap(GC3Denum target)
1967 { 2121 {
1968 if (isContextLost()) 2122 if (isContextLost())
1969 return; 2123 return;
1970 WebGLTexture* tex = validateTextureBinding("generateMipmap", target, false); 2124 WebGLTexture* tex = validateTextureBinding("generateMipmap", target, false, WebGLSharedObject::Exclusive);
1971 if (!tex) 2125 if (!tex)
1972 return; 2126 return;
1973 if (!tex->canGenerateMipmaps()) { 2127 if (!tex->canGenerateMipmaps()) {
1974 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "generateMipmap" , "level 0 not power of 2 or not all the same size"); 2128 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "generateMipmap" , "level 0 not power of 2 or not all the same size");
1975 return; 2129 return;
1976 } 2130 }
1977 if (!validateSettableTexFormat("generateMipmap", tex->getInternalFormat(targ et, 0))) 2131 if (!validateSettableTexFormat("generateMipmap", tex->getInternalFormat(targ et, 0)))
1978 return; 2132 return;
1979 2133
1980 // generateMipmap won't work properly if minFilter is not NEAREST_MIPMAP_LIN EAR 2134 // generateMipmap won't work properly if minFilter is not NEAREST_MIPMAP_LIN EAR
1981 // on Mac. Remove the hack once this driver bug is fixed. 2135 // on Mac. Remove the hack once this driver bug is fixed.
1982 #if OS(DARWIN) 2136 #if OS(DARWIN)
1983 bool needToResetMinFilter = false; 2137 bool needToResetMinFilter = false;
1984 if (tex->getMinFilter() != GraphicsContext3D::NEAREST_MIPMAP_LINEAR) { 2138 if (tex->getMinFilter() != GraphicsContext3D::NEAREST_MIPMAP_LINEAR) {
1985 m_context->texParameteri(target, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::NEAREST_MIPMAP_LINEAR); 2139 m_context->texParameteri(target, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::NEAREST_MIPMAP_LINEAR);
1986 needToResetMinFilter = true; 2140 needToResetMinFilter = true;
1987 } 2141 }
1988 #endif 2142 #endif
1989 m_context->generateMipmap(target); 2143 m_context->generateMipmap(target);
1990 #if OS(DARWIN) 2144 #if OS(DARWIN)
1991 if (needToResetMinFilter) 2145 if (needToResetMinFilter)
1992 m_context->texParameteri(target, GraphicsContext3D::TEXTURE_MIN_FILTER, tex->getMinFilter()); 2146 m_context->texParameteri(target, GraphicsContext3D::TEXTURE_MIN_FILTER, tex->getMinFilter());
1993 #endif 2147 #endif
1994 tex->generateMipmapLevelInfo(); 2148 tex->generateMipmapLevelInfo();
1995 } 2149 }
1996 2150
1997 PassRefPtr<WebGLActiveInfo> WebGLRenderingContext::getActiveAttrib(WebGLProgram* program, GC3Duint index, ExceptionCode& ec) 2151 PassRefPtr<WebGLActiveInfo> WebGLRenderingContext::getActiveAttrib(WebGLProgram* program, GC3Duint index, ExceptionCode& ec)
1998 { 2152 {
1999 UNUSED_PARAM(ec); 2153 UNUSED_PARAM(ec);
2000 if (isContextLost() || !validateWebGLObject("getActiveAttrib", program)) 2154 if (isContextLost() || !validateWebGLSharedObject("getActiveAttrib", program , WebGLSharedObject::ReadOnly))
2001 return 0; 2155 return 0;
2002 ActiveInfo info; 2156 ActiveInfo info;
2003 if (!m_context->getActiveAttrib(objectOrZero(program), index, info)) 2157 if (!m_context->getActiveAttrib(objectOrZero(program), index, info))
2004 return 0; 2158 return 0;
2005 return WebGLActiveInfo::create(info.name, info.type, info.size); 2159 return WebGLActiveInfo::create(info.name, info.type, info.size);
2006 } 2160 }
2007 2161
2008 PassRefPtr<WebGLActiveInfo> WebGLRenderingContext::getActiveUniform(WebGLProgram * program, GC3Duint index, ExceptionCode& ec) 2162 PassRefPtr<WebGLActiveInfo> WebGLRenderingContext::getActiveUniform(WebGLProgram * program, GC3Duint index, ExceptionCode& ec)
2009 { 2163 {
2010 UNUSED_PARAM(ec); 2164 UNUSED_PARAM(ec);
2011 if (isContextLost() || !validateWebGLObject("getActiveUniform", program)) 2165 if (isContextLost() || !validateWebGLSharedObject("getActiveUniform", progra m, WebGLSharedObject::ReadOnly))
2012 return 0; 2166 return 0;
2013 ActiveInfo info; 2167 ActiveInfo info;
2014 if (!m_context->getActiveUniform(objectOrZero(program), index, info)) 2168 if (!m_context->getActiveUniform(objectOrZero(program), index, info))
2015 return 0; 2169 return 0;
2016 return WebGLActiveInfo::create(info.name, info.type, info.size); 2170 return WebGLActiveInfo::create(info.name, info.type, info.size);
2017 } 2171 }
2018 2172
2019 bool WebGLRenderingContext::getAttachedShaders(WebGLProgram* program, Vector<Ref Ptr<WebGLShader> >& shaderObjects, ExceptionCode& ec) 2173 bool WebGLRenderingContext::getAttachedShaders(WebGLProgram* program, Vector<Ref Ptr<WebGLShader> >& shaderObjects, ExceptionCode& ec)
2020 { 2174 {
2021 UNUSED_PARAM(ec); 2175 UNUSED_PARAM(ec);
2022 shaderObjects.clear(); 2176 shaderObjects.clear();
2023 if (isContextLost() || !validateWebGLObject("getAttachedShaders", program)) 2177 if (isContextLost() || !validateWebGLSharedObject("getAttachedShaders", prog ram, WebGLSharedObject::ReadOnly))
2024 return false; 2178 return false;
2025 2179
2026 const GC3Denum shaderType[] = { 2180 const GC3Denum shaderType[] = {
2027 GraphicsContext3D::VERTEX_SHADER, 2181 GraphicsContext3D::VERTEX_SHADER,
2028 GraphicsContext3D::FRAGMENT_SHADER 2182 GraphicsContext3D::FRAGMENT_SHADER
2029 }; 2183 };
2030 for (unsigned i = 0; i < sizeof(shaderType) / sizeof(GC3Denum); ++i) { 2184 for (unsigned i = 0; i < sizeof(shaderType) / sizeof(GC3Denum); ++i) {
2031 WebGLShader* shader = program->getAttachedShader(shaderType[i]); 2185 WebGLShader* shader = program->getAttachedShader(shaderType[i]);
2032 if (shader) 2186 if (shader)
2033 shaderObjects.append(shader); 2187 shaderObjects.append(shader);
2034 } 2188 }
2035 return true; 2189 return true;
2036 } 2190 }
2037 2191
2038 GC3Dint WebGLRenderingContext::getAttribLocation(WebGLProgram* program, const St ring& name) 2192 GC3Dint WebGLRenderingContext::getAttribLocation(WebGLProgram* program, const St ring& name)
2039 { 2193 {
2040 if (isContextLost() || !validateWebGLObject("getAttribLocation", program)) 2194 if (isContextLost() || !validateWebGLSharedObject("getAttribLocation", progr am, WebGLSharedObject::ReadOnly))
2041 return -1; 2195 return -1;
2042 if (!validateLocationLength("getAttribLocation", name)) 2196 if (!validateLocationLength("getAttribLocation", name))
2043 return -1; 2197 return -1;
2044 if (!validateString("getAttribLocation", name)) 2198 if (!validateString("getAttribLocation", name))
2045 return -1; 2199 return -1;
2046 if (isPrefixReserved(name)) 2200 if (isPrefixReserved(name))
2047 return -1; 2201 return -1;
2048 if (!program->getLinkStatus()) { 2202 if (!program->getLinkStatus(this)) {
2049 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "getAttribLocati on", "program not linked"); 2203 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "getAttribLocati on", "program not linked");
2050 return 0; 2204 return 0;
2051 } 2205 }
2052 return m_context->getAttribLocation(objectOrZero(program), name); 2206 return m_context->getAttribLocation(objectOrZero(program), name);
2053 } 2207 }
2054 2208
2055 WebGLGetInfo WebGLRenderingContext::getBufferParameter(GC3Denum target, GC3Denum pname, ExceptionCode& ec) 2209 WebGLGetInfo WebGLRenderingContext::getBufferParameter(GC3Denum target, GC3Denum pname, ExceptionCode& ec)
2056 { 2210 {
2057 UNUSED_PARAM(ec); 2211 UNUSED_PARAM(ec);
2058 if (isContextLost()) 2212 if (isContextLost())
2059 return WebGLGetInfo(); 2213 return WebGLGetInfo();
2060 if (target != GraphicsContext3D::ARRAY_BUFFER && target != GraphicsContext3D ::ELEMENT_ARRAY_BUFFER) { 2214
2061 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getBufferParameter", "invalid target"); 2215 WebGLBuffer* buffer = getBufferForTarget("getBufferParameter", target);
2216 if (!buffer) {
2062 return WebGLGetInfo(); 2217 return WebGLGetInfo();
2063 } 2218 }
2064 2219
2065 if (pname != GraphicsContext3D::BUFFER_SIZE && pname != GraphicsContext3D::B UFFER_USAGE) { 2220 if (pname != GraphicsContext3D::BUFFER_SIZE && pname != GraphicsContext3D::B UFFER_USAGE) {
2066 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getBufferParameter", "invalid parameter name"); 2221 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getBufferParameter", "invalid parameter name");
2067 return WebGLGetInfo(); 2222 return WebGLGetInfo();
2068 } 2223 }
2069 2224
2225 if (!isAcquiredForReading("getBufferParameter", buffer)) {
2226 return WebGLGetInfo();
2227 }
2228
2070 GC3Dint value = 0; 2229 GC3Dint value = 0;
2071 m_context->getBufferParameteriv(target, pname, &value); 2230 m_context->getBufferParameteriv(target, pname, &value);
2072 if (pname == GraphicsContext3D::BUFFER_SIZE) 2231 if (pname == GraphicsContext3D::BUFFER_SIZE)
2073 return WebGLGetInfo(value); 2232 return WebGLGetInfo(value);
2074 return WebGLGetInfo(static_cast<unsigned int>(value)); 2233 return WebGLGetInfo(static_cast<unsigned int>(value));
2075 } 2234 }
2076 2235
2077 PassRefPtr<WebGLContextAttributes> WebGLRenderingContext::getContextAttributes() 2236 PassRefPtr<WebGLContextAttributes> WebGLRenderingContext::getContextAttributes()
2078 { 2237 {
2079 if (isContextLost()) 2238 if (isContextLost())
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
2428 return WebGLGetInfo(value); 2587 return WebGLGetInfo(value);
2429 } 2588 }
2430 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getParameter", "inva lid parameter name"); 2589 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getParameter", "inva lid parameter name");
2431 return WebGLGetInfo(); 2590 return WebGLGetInfo();
2432 } 2591 }
2433 } 2592 }
2434 2593
2435 WebGLGetInfo WebGLRenderingContext::getProgramParameter(WebGLProgram* program, G C3Denum pname, ExceptionCode& ec) 2594 WebGLGetInfo WebGLRenderingContext::getProgramParameter(WebGLProgram* program, G C3Denum pname, ExceptionCode& ec)
2436 { 2595 {
2437 UNUSED_PARAM(ec); 2596 UNUSED_PARAM(ec);
2438 if (isContextLost() || !validateWebGLObject("getProgramParameter", program)) 2597 if (isContextLost() || !validateWebGLSharedObject("getProgramParameter", pro gram, WebGLSharedObject::ReadOnly))
2439 return WebGLGetInfo(); 2598 return WebGLGetInfo();
2440 2599
2441 GC3Dint value = 0; 2600 GC3Dint value = 0;
2442 switch (pname) { 2601 switch (pname) {
2443 case GraphicsContext3D::DELETE_STATUS: 2602 case GraphicsContext3D::DELETE_STATUS:
2444 return WebGLGetInfo(program->isDeleted()); 2603 return WebGLGetInfo(program->isDeleted());
2445 case GraphicsContext3D::VALIDATE_STATUS: 2604 case GraphicsContext3D::VALIDATE_STATUS:
2446 m_context->getProgramiv(objectOrZero(program), pname, &value); 2605 m_context->getProgramiv(objectOrZero(program), pname, &value);
2447 return WebGLGetInfo(static_cast<bool>(value)); 2606 return WebGLGetInfo(static_cast<bool>(value));
2448 case GraphicsContext3D::LINK_STATUS: 2607 case GraphicsContext3D::LINK_STATUS:
2449 return WebGLGetInfo(program->getLinkStatus()); 2608 return WebGLGetInfo(program->getLinkStatus(this));
2450 case GraphicsContext3D::ATTACHED_SHADERS: 2609 case GraphicsContext3D::ATTACHED_SHADERS:
2451 case GraphicsContext3D::ACTIVE_ATTRIBUTES: 2610 case GraphicsContext3D::ACTIVE_ATTRIBUTES:
2452 case GraphicsContext3D::ACTIVE_UNIFORMS: 2611 case GraphicsContext3D::ACTIVE_UNIFORMS:
2453 m_context->getProgramiv(objectOrZero(program), pname, &value); 2612 m_context->getProgramiv(objectOrZero(program), pname, &value);
2454 return WebGLGetInfo(value); 2613 return WebGLGetInfo(value);
2455 default: 2614 default:
2456 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getProgramParameter" , "invalid parameter name"); 2615 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getProgramParameter" , "invalid parameter name");
2457 return WebGLGetInfo(); 2616 return WebGLGetInfo();
2458 } 2617 }
2459 } 2618 }
2460 2619
2461 String WebGLRenderingContext::getProgramInfoLog(WebGLProgram* program, Exception Code& ec) 2620 String WebGLRenderingContext::getProgramInfoLog(WebGLProgram* program, Exception Code& ec)
2462 { 2621 {
2463 UNUSED_PARAM(ec); 2622 UNUSED_PARAM(ec);
2464 if (isContextLost()) 2623 if (isContextLost())
2465 return String(); 2624 return String();
2466 if (!validateWebGLObject("getProgramInfoLog", program)) 2625 if (!validateWebGLSharedObject("getProgramInfoLog", program, WebGLSharedObje ct::ReadOnly))
2467 return ""; 2626 return "";
2468 return ensureNotNull(m_context->getProgramInfoLog(objectOrZero(program))); 2627 return ensureNotNull(m_context->getProgramInfoLog(objectOrZero(program)));
2469 } 2628 }
2470 2629
2471 WebGLGetInfo WebGLRenderingContext::getRenderbufferParameter(GC3Denum target, GC 3Denum pname, ExceptionCode& ec) 2630 WebGLGetInfo WebGLRenderingContext::getRenderbufferParameter(GC3Denum target, GC 3Denum pname, ExceptionCode& ec)
2472 { 2631 {
2473 UNUSED_PARAM(ec); 2632 UNUSED_PARAM(ec);
2474 if (isContextLost()) 2633 if (isContextLost())
2475 return WebGLGetInfo(); 2634 return WebGLGetInfo();
2476 if (target != GraphicsContext3D::RENDERBUFFER) { 2635 if (target != GraphicsContext3D::RENDERBUFFER) {
2477 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getRenderbufferParam eter", "invalid target"); 2636 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getRenderbufferParam eter", "invalid target");
2478 return WebGLGetInfo(); 2637 return WebGLGetInfo();
2479 } 2638 }
2480 if (!m_renderbufferBinding || !m_renderbufferBinding->object()) { 2639 if (!m_renderbufferBinding || !m_renderbufferBinding->object()) {
2481 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "getRenderbuffer Parameter", "no renderbuffer bound"); 2640 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "getRenderbuffer Parameter", "no renderbuffer bound");
2482 return WebGLGetInfo(); 2641 return WebGLGetInfo();
2483 } 2642 }
2484 2643
2644 if (!isAcquiredForReading("getRenderbufferParameter", m_renderbufferBinding. get())) {
2645 return WebGLGetInfo();
2646 }
2647
2485 GC3Dint value = 0; 2648 GC3Dint value = 0;
2486 switch (pname) { 2649 switch (pname) {
2487 case GraphicsContext3D::RENDERBUFFER_WIDTH: 2650 case GraphicsContext3D::RENDERBUFFER_WIDTH:
2488 case GraphicsContext3D::RENDERBUFFER_HEIGHT: 2651 case GraphicsContext3D::RENDERBUFFER_HEIGHT:
2489 case GraphicsContext3D::RENDERBUFFER_RED_SIZE: 2652 case GraphicsContext3D::RENDERBUFFER_RED_SIZE:
2490 case GraphicsContext3D::RENDERBUFFER_GREEN_SIZE: 2653 case GraphicsContext3D::RENDERBUFFER_GREEN_SIZE:
2491 case GraphicsContext3D::RENDERBUFFER_BLUE_SIZE: 2654 case GraphicsContext3D::RENDERBUFFER_BLUE_SIZE:
2492 case GraphicsContext3D::RENDERBUFFER_ALPHA_SIZE: 2655 case GraphicsContext3D::RENDERBUFFER_ALPHA_SIZE:
2493 case GraphicsContext3D::RENDERBUFFER_DEPTH_SIZE: 2656 case GraphicsContext3D::RENDERBUFFER_DEPTH_SIZE:
2494 m_context->getRenderbufferParameteriv(target, pname, &value); 2657 m_context->getRenderbufferParameteriv(target, pname, &value);
(...skipping 11 matching lines...) Expand all
2506 return WebGLGetInfo(m_renderbufferBinding->getInternalFormat()); 2669 return WebGLGetInfo(m_renderbufferBinding->getInternalFormat());
2507 default: 2670 default:
2508 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getRenderbufferParam eter", "invalid parameter name"); 2671 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getRenderbufferParam eter", "invalid parameter name");
2509 return WebGLGetInfo(); 2672 return WebGLGetInfo();
2510 } 2673 }
2511 } 2674 }
2512 2675
2513 WebGLGetInfo WebGLRenderingContext::getShaderParameter(WebGLShader* shader, GC3D enum pname, ExceptionCode& ec) 2676 WebGLGetInfo WebGLRenderingContext::getShaderParameter(WebGLShader* shader, GC3D enum pname, ExceptionCode& ec)
2514 { 2677 {
2515 UNUSED_PARAM(ec); 2678 UNUSED_PARAM(ec);
2516 if (isContextLost() || !validateWebGLObject("getShaderParameter", shader)) 2679 if (isContextLost() || !validateWebGLSharedObject("getShaderParameter", shad er, WebGLSharedObject::ReadOnly))
2517 return WebGLGetInfo(); 2680 return WebGLGetInfo();
2518 GC3Dint value = 0; 2681 GC3Dint value = 0;
2519 switch (pname) { 2682 switch (pname) {
2520 case GraphicsContext3D::DELETE_STATUS: 2683 case GraphicsContext3D::DELETE_STATUS:
2521 return WebGLGetInfo(shader->isDeleted()); 2684 return WebGLGetInfo(shader->isDeleted());
2522 case GraphicsContext3D::COMPILE_STATUS: 2685 case GraphicsContext3D::COMPILE_STATUS:
2523 m_context->getShaderiv(objectOrZero(shader), pname, &value); 2686 m_context->getShaderiv(objectOrZero(shader), pname, &value);
2524 return WebGLGetInfo(static_cast<bool>(value)); 2687 return WebGLGetInfo(static_cast<bool>(value));
2525 case GraphicsContext3D::SHADER_TYPE: 2688 case GraphicsContext3D::SHADER_TYPE:
2526 m_context->getShaderiv(objectOrZero(shader), pname, &value); 2689 m_context->getShaderiv(objectOrZero(shader), pname, &value);
2527 return WebGLGetInfo(static_cast<unsigned int>(value)); 2690 return WebGLGetInfo(static_cast<unsigned int>(value));
2528 default: 2691 default:
2529 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getShaderParameter", "invalid parameter name"); 2692 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getShaderParameter", "invalid parameter name");
2530 return WebGLGetInfo(); 2693 return WebGLGetInfo();
2531 } 2694 }
2532 } 2695 }
2533 2696
2534 String WebGLRenderingContext::getShaderInfoLog(WebGLShader* shader, ExceptionCod e& ec) 2697 String WebGLRenderingContext::getShaderInfoLog(WebGLShader* shader, ExceptionCod e& ec)
2535 { 2698 {
2536 UNUSED_PARAM(ec); 2699 UNUSED_PARAM(ec);
2537 if (isContextLost()) 2700 if (isContextLost())
2538 return String(); 2701 return String();
2539 if (!validateWebGLObject("getShaderInfoLog", shader)) 2702 if (!validateWebGLSharedObject("getShaderInfoLog", shader, WebGLSharedObject ::ReadOnly))
2540 return ""; 2703 return "";
2541 return ensureNotNull(m_context->getShaderInfoLog(objectOrZero(shader))); 2704 return ensureNotNull(m_context->getShaderInfoLog(objectOrZero(shader)));
2542 } 2705 }
2543 2706
2544 PassRefPtr<WebGLShaderPrecisionFormat> WebGLRenderingContext::getShaderPrecision Format(GC3Denum shaderType, GC3Denum precisionType, ExceptionCode& ec) 2707 PassRefPtr<WebGLShaderPrecisionFormat> WebGLRenderingContext::getShaderPrecision Format(GC3Denum shaderType, GC3Denum precisionType, ExceptionCode& ec)
2545 { 2708 {
2546 UNUSED_PARAM(ec); 2709 UNUSED_PARAM(ec);
2547 if (isContextLost()) 2710 if (isContextLost())
2548 return 0; 2711 return 0;
2549 switch (shaderType) { 2712 switch (shaderType) {
(...skipping 21 matching lines...) Expand all
2571 GC3Dint precision = 0; 2734 GC3Dint precision = 0;
2572 m_context->getShaderPrecisionFormat(shaderType, precisionType, range, &preci sion); 2735 m_context->getShaderPrecisionFormat(shaderType, precisionType, range, &preci sion);
2573 return WebGLShaderPrecisionFormat::create(range[0], range[1], precision); 2736 return WebGLShaderPrecisionFormat::create(range[0], range[1], precision);
2574 } 2737 }
2575 2738
2576 String WebGLRenderingContext::getShaderSource(WebGLShader* shader, ExceptionCode & ec) 2739 String WebGLRenderingContext::getShaderSource(WebGLShader* shader, ExceptionCode & ec)
2577 { 2740 {
2578 UNUSED_PARAM(ec); 2741 UNUSED_PARAM(ec);
2579 if (isContextLost()) 2742 if (isContextLost())
2580 return String(); 2743 return String();
2581 if (!validateWebGLObject("getShaderSource", shader)) 2744 if (!validateWebGLSharedObject("getShaderSource", shader, WebGLSharedObject: :ReadOnly))
2582 return ""; 2745 return "";
2583 return ensureNotNull(shader->getSource()); 2746 return ensureNotNull(shader->getSource());
2584 } 2747 }
2585 2748
2586 Vector<String> WebGLRenderingContext::getSupportedExtensions() 2749 Vector<String> WebGLRenderingContext::getSupportedExtensions()
2587 { 2750 {
2588 Vector<String> result; 2751 Vector<String> result;
2589 if (isContextLost()) 2752 if (isContextLost())
2590 return result; 2753 return result;
2591 2754
2592 for (size_t i = 0; i < m_extensions.size(); ++i) { 2755 for (size_t i = 0; i < m_extensions.size(); ++i) {
2593 ExtensionTracker* tracker = m_extensions[i]; 2756 ExtensionTracker* tracker = m_extensions[i];
2594 if (tracker->getPrivileged() && !allowPrivilegedExtensions()) 2757 if (tracker->getPrivileged() && !allowPrivilegedExtensions())
2595 continue; 2758 continue;
2596 if (tracker->getDraft() && !RuntimeEnabledFeatures::webGLDraftExtensions Enabled()) 2759 if (tracker->getDraft() && !RuntimeEnabledFeatures::webGLDraftExtensions Enabled())
2597 continue; 2760 continue;
2598 if (tracker->supported(this)) 2761 if (tracker->supported(this))
2599 result.append(String(tracker->getPrefixed() ? "WEBKIT_" : "") + tra cker->getExtensionName()); 2762 result.append(String(tracker->getPrefixed() ? "WEBKIT_" : "") + tra cker->getExtensionName());
2600 } 2763 }
2601 2764
2602 return result; 2765 return result;
2603 } 2766 }
2604 2767
2605 WebGLGetInfo WebGLRenderingContext::getTexParameter(GC3Denum target, GC3Denum pn ame, ExceptionCode& ec) 2768 WebGLGetInfo WebGLRenderingContext::getTexParameter(GC3Denum target, GC3Denum pn ame, ExceptionCode& ec)
2606 { 2769 {
2607 UNUSED_PARAM(ec); 2770 UNUSED_PARAM(ec);
2608 if (isContextLost()) 2771 if (isContextLost())
2609 return WebGLGetInfo(); 2772 return WebGLGetInfo();
2610 WebGLTexture* tex = validateTextureBinding("getTexParameter", target, false) ; 2773 WebGLTexture* tex = validateTextureBinding("getTexParameter", target, false, WebGLSharedObject::ReadOnly);
2611 if (!tex) 2774 if (!tex)
2612 return WebGLGetInfo(); 2775 return WebGLGetInfo();
2613 GC3Dint value = 0; 2776 GC3Dint value = 0;
2614 switch (pname) { 2777 switch (pname) {
2615 case GraphicsContext3D::TEXTURE_MAG_FILTER: 2778 case GraphicsContext3D::TEXTURE_MAG_FILTER:
2616 case GraphicsContext3D::TEXTURE_MIN_FILTER: 2779 case GraphicsContext3D::TEXTURE_MIN_FILTER:
2617 case GraphicsContext3D::TEXTURE_WRAP_S: 2780 case GraphicsContext3D::TEXTURE_WRAP_S:
2618 case GraphicsContext3D::TEXTURE_WRAP_T: 2781 case GraphicsContext3D::TEXTURE_WRAP_T:
2619 m_context->getTexParameteriv(target, pname, &value); 2782 m_context->getTexParameteriv(target, pname, &value);
2620 return WebGLGetInfo(static_cast<unsigned int>(value)); 2783 return WebGLGetInfo(static_cast<unsigned int>(value));
2621 case Extensions3D::TEXTURE_MAX_ANISOTROPY_EXT: // EXT_texture_filter_anisotr opic 2784 case Extensions3D::TEXTURE_MAX_ANISOTROPY_EXT: // EXT_texture_filter_anisotr opic
2622 if (m_extTextureFilterAnisotropic) { 2785 if (m_extTextureFilterAnisotropic) {
2623 m_context->getTexParameteriv(target, pname, &value); 2786 m_context->getTexParameteriv(target, pname, &value);
2624 return WebGLGetInfo(static_cast<unsigned int>(value)); 2787 return WebGLGetInfo(static_cast<unsigned int>(value));
2625 } 2788 }
2626 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getTexParameter", "i nvalid parameter name, EXT_texture_filter_anisotropic not enabled"); 2789 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getTexParameter", "i nvalid parameter name, EXT_texture_filter_anisotropic not enabled");
2627 return WebGLGetInfo(); 2790 return WebGLGetInfo();
2628 default: 2791 default:
2629 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getTexParameter", "i nvalid parameter name"); 2792 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getTexParameter", "i nvalid parameter name");
2630 return WebGLGetInfo(); 2793 return WebGLGetInfo();
2631 } 2794 }
2632 } 2795 }
2633 2796
2634 WebGLGetInfo WebGLRenderingContext::getUniform(WebGLProgram* program, const WebG LUniformLocation* uniformLocation, ExceptionCode& ec) 2797 WebGLGetInfo WebGLRenderingContext::getUniform(WebGLProgram* program, const WebG LUniformLocation* uniformLocation, ExceptionCode& ec)
2635 { 2798 {
2636 UNUSED_PARAM(ec); 2799 UNUSED_PARAM(ec);
2637 if (isContextLost() || !validateWebGLObject("getUniform", program)) 2800 if (isContextLost() || !validateWebGLSharedObject("getUniform", program, Web GLSharedObject::ReadOnly))
2638 return WebGLGetInfo(); 2801 return WebGLGetInfo();
2639 if (!uniformLocation || uniformLocation->program() != program) { 2802 if (!uniformLocation || uniformLocation->program() != program) {
2640 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "getUniform", "n o uniformlocation or not valid for this program"); 2803 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "getUniform", "n o uniformlocation or not valid for this program");
2641 return WebGLGetInfo(); 2804 return WebGLGetInfo();
2642 } 2805 }
2643 GC3Dint location = uniformLocation->location(); 2806 GC3Dint location = uniformLocation->location();
2644 2807
2645 // FIXME: make this more efficient using WebGLUniformLocation and caching ty pes in it 2808 // FIXME: make this more efficient using WebGLUniformLocation and caching ty pes in it
2646 GC3Dint activeUniforms = 0; 2809 GC3Dint activeUniforms = 0;
2647 m_context->getProgramiv(objectOrZero(program), GraphicsContext3D::ACTIVE_UNI FORMS, &activeUniforms); 2810 m_context->getProgramiv(objectOrZero(program), GraphicsContext3D::ACTIVE_UNI FORMS, &activeUniforms);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
2770 } 2933 }
2771 } 2934 }
2772 // If we get here, something went wrong in our unfortunately complex logic a bove 2935 // If we get here, something went wrong in our unfortunately complex logic a bove
2773 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "getUniform", "unknown e rror"); 2936 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "getUniform", "unknown e rror");
2774 return WebGLGetInfo(); 2937 return WebGLGetInfo();
2775 } 2938 }
2776 2939
2777 PassRefPtr<WebGLUniformLocation> WebGLRenderingContext::getUniformLocation(WebGL Program* program, const String& name, ExceptionCode& ec) 2940 PassRefPtr<WebGLUniformLocation> WebGLRenderingContext::getUniformLocation(WebGL Program* program, const String& name, ExceptionCode& ec)
2778 { 2941 {
2779 UNUSED_PARAM(ec); 2942 UNUSED_PARAM(ec);
2780 if (isContextLost() || !validateWebGLObject("getUniformLocation", program)) 2943 if (isContextLost() || !validateWebGLSharedObject("getUniformLocation", prog ram, WebGLSharedObject::ReadOnly))
2781 return 0; 2944 return 0;
2782 if (!validateLocationLength("getUniformLocation", name)) 2945 if (!validateLocationLength("getUniformLocation", name))
2783 return 0; 2946 return 0;
2784 if (!validateString("getUniformLocation", name)) 2947 if (!validateString("getUniformLocation", name))
2785 return 0; 2948 return 0;
2786 if (isPrefixReserved(name)) 2949 if (isPrefixReserved(name))
2787 return 0; 2950 return 0;
2788 if (!program->getLinkStatus()) { 2951 if (!program->getLinkStatus(this)) {
2789 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "getUniformLocat ion", "program not linked"); 2952 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "getUniformLocat ion", "program not linked");
2790 return 0; 2953 return 0;
2791 } 2954 }
2792 GC3Dint uniformLocation = m_context->getUniformLocation(objectOrZero(program ), name); 2955 GC3Dint uniformLocation = m_context->getUniformLocation(objectOrZero(program ), name);
2793 if (uniformLocation == -1) 2956 if (uniformLocation == -1)
2794 return 0; 2957 return 0;
2795 return WebGLUniformLocation::create(program, uniformLocation); 2958 return WebGLUniformLocation::create(program, uniformLocation);
2796 } 2959 }
2797 2960
2798 WebGLGetInfo WebGLRenderingContext::getVertexAttrib(GC3Duint index, GC3Denum pna me, ExceptionCode& ec) 2961 WebGLGetInfo WebGLRenderingContext::getVertexAttrib(GC3Duint index, GC3Denum pna me, ExceptionCode& ec)
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
2865 { 3028 {
2866 if (!buffer || isContextLost()) 3029 if (!buffer || isContextLost())
2867 return 0; 3030 return 0;
2868 3031
2869 if (!buffer->hasEverBeenBound()) 3032 if (!buffer->hasEverBeenBound())
2870 return 0; 3033 return 0;
2871 3034
2872 return m_context->isBuffer(buffer->object()); 3035 return m_context->isBuffer(buffer->object());
2873 } 3036 }
2874 3037
2875 bool WebGLRenderingContext::isContextLost() 3038 bool WebGLRenderingContext::isContextLost() const
2876 { 3039 {
2877 return m_contextLost; 3040 return m_contextLost;
2878 } 3041 }
2879 3042
2880 GC3Dboolean WebGLRenderingContext::isEnabled(GC3Denum cap) 3043 GC3Dboolean WebGLRenderingContext::isEnabled(GC3Denum cap)
2881 { 3044 {
2882 if (isContextLost() || !validateCapability("isEnabled", cap)) 3045 if (isContextLost() || !validateCapability("isEnabled", cap))
2883 return 0; 3046 return 0;
2884 if (cap == GraphicsContext3D::STENCIL_TEST) 3047 if (cap == GraphicsContext3D::STENCIL_TEST)
2885 return m_stencilEnabled; 3048 return m_stencilEnabled;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
2938 void WebGLRenderingContext::lineWidth(GC3Dfloat width) 3101 void WebGLRenderingContext::lineWidth(GC3Dfloat width)
2939 { 3102 {
2940 if (isContextLost()) 3103 if (isContextLost())
2941 return; 3104 return;
2942 m_context->lineWidth(width); 3105 m_context->lineWidth(width);
2943 } 3106 }
2944 3107
2945 void WebGLRenderingContext::linkProgram(WebGLProgram* program, ExceptionCode& ec ) 3108 void WebGLRenderingContext::linkProgram(WebGLProgram* program, ExceptionCode& ec )
2946 { 3109 {
2947 UNUSED_PARAM(ec); 3110 UNUSED_PARAM(ec);
2948 if (isContextLost() || !validateWebGLObject("linkProgram", program)) 3111 if (isContextLost() || !validateWebGLSharedObject("linkProgram", program, We bGLSharedObject::Exclusive))
2949 return; 3112 return;
2950 3113
2951 m_context->linkProgram(objectOrZero(program)); 3114 m_context->linkProgram(objectOrZero(program));
2952 program->increaseLinkCount(); 3115 program->increaseLinkCount();
2953 } 3116 }
2954 3117
2955 void WebGLRenderingContext::pixelStorei(GC3Denum pname, GC3Dint param) 3118 void WebGLRenderingContext::pixelStorei(GC3Denum pname, GC3Dint param)
2956 { 3119 {
2957 if (isContextLost()) 3120 if (isContextLost())
2958 return; 3121 return;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
3031 if (format != GraphicsContext3D::RGBA || type != GraphicsContext3D::UNSIGNED _BYTE) { 3194 if (format != GraphicsContext3D::RGBA || type != GraphicsContext3D::UNSIGNED _BYTE) {
3032 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "readPixels", "f ormat not RGBA or type not UNSIGNED_BYTE"); 3195 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "readPixels", "f ormat not RGBA or type not UNSIGNED_BYTE");
3033 return; 3196 return;
3034 } 3197 }
3035 // Validate array type against pixel type. 3198 // Validate array type against pixel type.
3036 if (pixels->getType() != ArrayBufferView::TypeUint8) { 3199 if (pixels->getType() != ArrayBufferView::TypeUint8) {
3037 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "readPixels", "A rrayBufferView not Uint8Array"); 3200 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "readPixels", "A rrayBufferView not Uint8Array");
3038 return; 3201 return;
3039 } 3202 }
3040 const char* reason = "framebuffer incomplete"; 3203 const char* reason = "framebuffer incomplete";
3041 if (m_framebufferBinding && !m_framebufferBinding->onAccess(graphicsContext3 D(), &reason)) { 3204 if (m_framebufferBinding && !m_framebufferBinding->onAccess(this, WebGLShare dObject::ReadOnly, &reason)) {
3042 synthesizeGLError(GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION, "rea dPixels", reason); 3205 synthesizeGLError(GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION, "rea dPixels", reason);
3043 return; 3206 return;
3044 } 3207 }
3045 // Calculate array size, taking into consideration of PACK_ALIGNMENT. 3208 // Calculate array size, taking into consideration of PACK_ALIGNMENT.
3046 unsigned int totalBytesRequired = 0; 3209 unsigned int totalBytesRequired = 0;
3047 unsigned int padding = 0; 3210 unsigned int padding = 0;
3048 GC3Denum error = m_context->computeImageSizeInBytes(format, type, width, hei ght, m_packAlignment, &totalBytesRequired, &padding); 3211 GC3Denum error = m_context->computeImageSizeInBytes(format, type, width, hei ght, m_packAlignment, &totalBytesRequired, &padding);
3049 if (error != GraphicsContext3D::NO_ERROR) { 3212 if (error != GraphicsContext3D::NO_ERROR) {
3050 synthesizeGLError(error, "readPixels", "invalid dimensions"); 3213 synthesizeGLError(error, "readPixels", "invalid dimensions");
3051 return; 3214 return;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
3084 if (isContextLost()) 3247 if (isContextLost())
3085 return; 3248 return;
3086 if (target != GraphicsContext3D::RENDERBUFFER) { 3249 if (target != GraphicsContext3D::RENDERBUFFER) {
3087 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "renderbufferStorage" , "invalid target"); 3250 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "renderbufferStorage" , "invalid target");
3088 return; 3251 return;
3089 } 3252 }
3090 if (!m_renderbufferBinding || !m_renderbufferBinding->object()) { 3253 if (!m_renderbufferBinding || !m_renderbufferBinding->object()) {
3091 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "renderbufferSto rage", "no bound renderbuffer"); 3254 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "renderbufferSto rage", "no bound renderbuffer");
3092 return; 3255 return;
3093 } 3256 }
3257 if (!isAcquiredForModification("renderbufferStorage", m_renderbufferBinding. get()))
3258 return;
3094 if (!validateSize("renderbufferStorage", width, height)) 3259 if (!validateSize("renderbufferStorage", width, height))
3095 return; 3260 return;
3096 switch (internalformat) { 3261 switch (internalformat) {
3097 case GraphicsContext3D::DEPTH_COMPONENT16: 3262 case GraphicsContext3D::DEPTH_COMPONENT16:
3098 case GraphicsContext3D::RGBA4: 3263 case GraphicsContext3D::RGBA4:
3099 case GraphicsContext3D::RGB5_A1: 3264 case GraphicsContext3D::RGB5_A1:
3100 case GraphicsContext3D::RGB565: 3265 case GraphicsContext3D::RGB565:
3101 case GraphicsContext3D::STENCIL_INDEX8: 3266 case GraphicsContext3D::STENCIL_INDEX8:
3102 m_context->renderbufferStorage(target, internalformat, width, height); 3267 m_context->renderbufferStorage(target, internalformat, width, height);
3103 m_renderbufferBinding->setInternalFormat(internalformat); 3268 m_renderbufferBinding->setInternalFormat(internalformat);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
3142 if (isContextLost()) 3307 if (isContextLost())
3143 return; 3308 return;
3144 if (!validateSize("scissor", width, height)) 3309 if (!validateSize("scissor", width, height))
3145 return; 3310 return;
3146 m_context->scissor(x, y, width, height); 3311 m_context->scissor(x, y, width, height);
3147 } 3312 }
3148 3313
3149 void WebGLRenderingContext::shaderSource(WebGLShader* shader, const String& stri ng, ExceptionCode& ec) 3314 void WebGLRenderingContext::shaderSource(WebGLShader* shader, const String& stri ng, ExceptionCode& ec)
3150 { 3315 {
3151 UNUSED_PARAM(ec); 3316 UNUSED_PARAM(ec);
3152 if (isContextLost() || !validateWebGLObject("shaderSource", shader)) 3317 if (isContextLost() || !validateWebGLSharedObject("shaderSource", shader, We bGLSharedObject::Exclusive))
3153 return; 3318 return;
3154 String stringWithoutComments = StripComments(string).result(); 3319 String stringWithoutComments = StripComments(string).result();
3155 if (!validateString("shaderSource", stringWithoutComments)) 3320 if (!validateString("shaderSource", stringWithoutComments))
3156 return; 3321 return;
3157 shader->setSource(string); 3322 shader->setSource(string);
3158 m_context->shaderSource(objectOrZero(shader), stringWithoutComments); 3323 m_context->shaderSource(objectOrZero(shader), stringWithoutComments);
3159 } 3324 }
3160 3325
3161 void WebGLRenderingContext::stencilFunc(GC3Denum func, GC3Dint ref, GC3Duint mas k) 3326 void WebGLRenderingContext::stencilFunc(GC3Denum func, GC3Dint ref, GC3Duint mas k)
3162 { 3327 {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
3242 if (isContextLost()) 3407 if (isContextLost())
3243 return; 3408 return;
3244 m_context->stencilOpSeparate(face, fail, zfail, zpass); 3409 m_context->stencilOpSeparate(face, fail, zfail, zpass);
3245 } 3410 }
3246 3411
3247 void WebGLRenderingContext::texImage2DBase(GC3Denum target, GC3Dint level, GC3De num internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type, const void* pixels, ExceptionCode& ec) 3412 void WebGLRenderingContext::texImage2DBase(GC3Denum target, GC3Dint level, GC3De num internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type, const void* pixels, ExceptionCode& ec)
3248 { 3413 {
3249 // All calling functions check isContextLost, so a duplicate check is not ne eded here. 3414 // All calling functions check isContextLost, so a duplicate check is not ne eded here.
3250 // FIXME: For now we ignore any errors returned 3415 // FIXME: For now we ignore any errors returned
3251 ec = 0; 3416 ec = 0;
3252 WebGLTexture* tex = validateTextureBinding("texImage2D", target, true); 3417 WebGLTexture* tex = validateTextureBinding("texImage2D", target, true, WebGL SharedObject::Exclusive);
3253 ASSERT(validateTexFuncParameters("texImage2D", NotTexSubImage2D, target, lev el, internalformat, width, height, border, format, type)); 3418 ASSERT(validateTexFuncParameters("texImage2D", NotTexSubImage2D, target, lev el, internalformat, width, height, border, format, type));
3254 ASSERT(tex); 3419 ASSERT(tex);
3255 ASSERT(!level || !WebGLTexture::isNPOT(width, height)); 3420 ASSERT(!level || !WebGLTexture::isNPOT(width, height));
3256 ASSERT(!pixels || validateSettableTexFormat("texImage2D", internalformat)); 3421 ASSERT(!pixels || validateSettableTexFormat("texImage2D", internalformat));
3257 m_context->texImage2D(target, level, internalformat, width, height, 3422 m_context->texImage2D(target, level, internalformat, width, height,
3258 border, format, type, pixels); 3423 border, format, type, pixels);
3259 tex->setLevelInfo(target, level, internalformat, width, height, type); 3424 tex->setLevelInfo(target, level, internalformat, width, height, type);
3260 } 3425 }
3261 3426
3262 void WebGLRenderingContext::texImage2DImpl(GC3Denum target, GC3Dint level, GC3De num internalformat, GC3Denum format, GC3Denum type, Image* image, GraphicsContex t3D::ImageHtmlDomSource domSource, bool flipY, bool premultiplyAlpha, ExceptionC ode& ec) 3427 void WebGLRenderingContext::texImage2DImpl(GC3Denum target, GC3Dint level, GC3De num internalformat, GC3Denum format, GC3Denum type, Image* image, GraphicsContex t3D::ImageHtmlDomSource domSource, bool flipY, bool premultiplyAlpha, ExceptionC ode& ec)
(...skipping 25 matching lines...) Expand all
3288 texImage2DBase(target, level, internalformat, image->width(), image->height( ), 0, format, type, needConversion ? data.data() : imagePixelData, ec); 3453 texImage2DBase(target, level, internalformat, image->width(), image->height( ), 0, format, type, needConversion ? data.data() : imagePixelData, ec);
3289 if (m_unpackAlignment != 1) 3454 if (m_unpackAlignment != 1)
3290 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, m_unpackAlig nment); 3455 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, m_unpackAlig nment);
3291 } 3456 }
3292 3457
3293 bool WebGLRenderingContext::validateTexFunc(const char* functionName, TexFuncVal idationFunctionType functionType, TexFuncValidationSourceType sourceType, GC3Den um target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei he ight, GC3Dint border, GC3Denum format, GC3Denum type, GC3Dint xoffset, GC3Dint y offset) 3458 bool WebGLRenderingContext::validateTexFunc(const char* functionName, TexFuncVal idationFunctionType functionType, TexFuncValidationSourceType sourceType, GC3Den um target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei he ight, GC3Dint border, GC3Denum format, GC3Denum type, GC3Dint xoffset, GC3Dint y offset)
3294 { 3459 {
3295 if (!validateTexFuncParameters(functionName, functionType, target, level, in ternalformat, width, height, border, format, type)) 3460 if (!validateTexFuncParameters(functionName, functionType, target, level, in ternalformat, width, height, border, format, type))
3296 return false; 3461 return false;
3297 3462
3298 WebGLTexture* texture = validateTextureBinding(functionName, target, true); 3463 WebGLTexture* texture = validateTextureBinding(functionName, target, true, W ebGLSharedObject::Exclusive);
3299 if (!texture) 3464 if (!texture)
3300 return false; 3465 return false;
3301 3466
3302 if (functionType == NotTexSubImage2D) { 3467 if (functionType == NotTexSubImage2D) {
3303 if (level && WebGLTexture::isNPOT(width, height)) { 3468 if (level && WebGLTexture::isNPOT(width, height)) {
3304 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "l evel > 0 not power of 2"); 3469 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "l evel > 0 not power of 2");
3305 return false; 3470 return false;
3306 } 3471 }
3307 // For SourceArrayBufferView, function validateTexFuncData() would handl e whether to validate the SettableTexFormat 3472 // For SourceArrayBufferView, function validateTexFuncData() would handl e whether to validate the SettableTexFormat
3308 // by checking if the ArrayBufferView is null or not. 3473 // by checking if the ArrayBufferView is null or not.
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
3399 texImage2DImpl(target, level, internalformat, format, type, imageForRender, GraphicsContext3D::HtmlDomImage, m_unpackFlipY, m_unpackPremultiplyAlpha, ec); 3564 texImage2DImpl(target, level, internalformat, format, type, imageForRender, GraphicsContext3D::HtmlDomImage, m_unpackFlipY, m_unpackPremultiplyAlpha, ec);
3400 } 3565 }
3401 3566
3402 void WebGLRenderingContext::texImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, 3567 void WebGLRenderingContext::texImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat,
3403 GC3Denum format, GC3Denum type, HTMLCanva sElement* canvas, ExceptionCode& ec) 3568 GC3Denum format, GC3Denum type, HTMLCanva sElement* canvas, ExceptionCode& ec)
3404 { 3569 {
3405 ec = 0; 3570 ec = 0;
3406 if (isContextLost() || !validateHTMLCanvasElement("texImage2D", canvas, ec) || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLCanvasElement, tar get, level, internalformat, canvas->width(), canvas->height(), 0, format, type, 0, 0)) 3571 if (isContextLost() || !validateHTMLCanvasElement("texImage2D", canvas, ec) || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLCanvasElement, tar get, level, internalformat, canvas->width(), canvas->height(), 0, format, type, 0, 0))
3407 return; 3572 return;
3408 3573
3409 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true); 3574 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true, W ebGLSharedObject::Exclusive);
3410 // If possible, copy from the canvas element directly to the texture 3575 // If possible, copy from the canvas element directly to the texture
3411 // via the GPU, without a read-back to system memory. 3576 // via the GPU, without a read-back to system memory.
3412 if (GraphicsContext3D::TEXTURE_2D == target && texture) { 3577 if (GraphicsContext3D::TEXTURE_2D == target && texture) {
3413 ImageBuffer* buffer = canvas->buffer(); 3578 ImageBuffer* buffer = canvas->buffer();
3414 if (buffer && buffer->copyToPlatformTexture(*m_context.get(), texture->o bject(), internalformat, type, level, m_unpackPremultiplyAlpha, m_unpackFlipY)) { 3579 if (buffer && buffer->copyToPlatformTexture(*m_context.get(), texture->o bject(), internalformat, type, level, m_unpackPremultiplyAlpha, m_unpackFlipY)) {
3415 texture->setLevelInfo(target, level, internalformat, canvas->width() , canvas->height(), type); 3580 texture->setLevelInfo(target, level, internalformat, canvas->width() , canvas->height(), type);
3416 return; 3581 return;
3417 } 3582 }
3418 } 3583 }
3419 3584
(...skipping 21 matching lines...) Expand all
3441 void WebGLRenderingContext::texImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, 3606 void WebGLRenderingContext::texImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat,
3442 GC3Denum format, GC3Denum type, HTMLVideo Element* video, ExceptionCode& ec) 3607 GC3Denum format, GC3Denum type, HTMLVideo Element* video, ExceptionCode& ec)
3443 { 3608 {
3444 ec = 0; 3609 ec = 0;
3445 if (isContextLost() || !validateHTMLVideoElement("texImage2D", video, ec) 3610 if (isContextLost() || !validateHTMLVideoElement("texImage2D", video, ec)
3446 || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLVideoEleme nt, target, level, internalformat, video->videoWidth(), video->videoHeight(), 0, format, type, 0, 0)) 3611 || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLVideoEleme nt, target, level, internalformat, video->videoWidth(), video->videoHeight(), 0, format, type, 0, 0))
3447 return; 3612 return;
3448 3613
3449 // Go through the fast path doing a GPU-GPU textures copy without a readback to system memory if possible. 3614 // Go through the fast path doing a GPU-GPU textures copy without a readback to system memory if possible.
3450 // Otherwise, it will fall back to the normal SW path. 3615 // Otherwise, it will fall back to the normal SW path.
3451 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true); 3616 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true, W ebGLSharedObject::Exclusive);
3452 if (GraphicsContext3D::TEXTURE_2D == target && texture) { 3617 if (GraphicsContext3D::TEXTURE_2D == target && texture) {
3453 if (video->copyVideoTextureToPlatformTexture(m_context.get(), texture->o bject(), level, type, internalformat, m_unpackPremultiplyAlpha, m_unpackFlipY)) { 3618 if (video->copyVideoTextureToPlatformTexture(m_context.get(), texture->o bject(), level, type, internalformat, m_unpackPremultiplyAlpha, m_unpackFlipY)) {
3454 texture->setLevelInfo(target, level, internalformat, video->videoWid th(), video->videoHeight(), type); 3619 texture->setLevelInfo(target, level, internalformat, video->videoWid th(), video->videoHeight(), type);
3455 return; 3620 return;
3456 } 3621 }
3457 } 3622 }
3458 3623
3459 // Normal pure SW path. 3624 // Normal pure SW path.
3460 RefPtr<Image> image = videoFrameToImage(video, ImageBuffer::fastCopyImageMod e(), ec); 3625 RefPtr<Image> image = videoFrameToImage(video, ImageBuffer::fastCopyImageMod e(), ec);
3461 if (!image) 3626 if (!image)
3462 return; 3627 return;
3463 texImage2DImpl(target, level, internalformat, format, type, image.get(), Gra phicsContext3D::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha, ec); 3628 texImage2DImpl(target, level, internalformat, format, type, image.get(), Gra phicsContext3D::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha, ec);
3464 } 3629 }
3465 3630
3466 void WebGLRenderingContext::texParameter(GC3Denum target, GC3Denum pname, GC3Dfl oat paramf, GC3Dint parami, bool isFloat) 3631 void WebGLRenderingContext::texParameter(GC3Denum target, GC3Denum pname, GC3Dfl oat paramf, GC3Dint parami, bool isFloat)
3467 { 3632 {
3468 if (isContextLost()) 3633 if (isContextLost())
3469 return; 3634 return;
3470 WebGLTexture* tex = validateTextureBinding("texParameter", target, false); 3635 WebGLTexture* tex = validateTextureBinding("texParameter", target, false, We bGLSharedObject::Exclusive);
3471 if (!tex) 3636 if (!tex)
3472 return; 3637 return;
3473 switch (pname) { 3638 switch (pname) {
3474 case GraphicsContext3D::TEXTURE_MIN_FILTER: 3639 case GraphicsContext3D::TEXTURE_MIN_FILTER:
3475 case GraphicsContext3D::TEXTURE_MAG_FILTER: 3640 case GraphicsContext3D::TEXTURE_MAG_FILTER:
3476 break; 3641 break;
3477 case GraphicsContext3D::TEXTURE_WRAP_S: 3642 case GraphicsContext3D::TEXTURE_WRAP_S:
3478 case GraphicsContext3D::TEXTURE_WRAP_T: 3643 case GraphicsContext3D::TEXTURE_WRAP_T:
3479 if ((isFloat && paramf != GraphicsContext3D::CLAMP_TO_EDGE && paramf != GraphicsContext3D::MIRRORED_REPEAT && paramf != GraphicsContext3D::REPEAT) 3644 if ((isFloat && paramf != GraphicsContext3D::CLAMP_TO_EDGE && paramf != GraphicsContext3D::MIRRORED_REPEAT && paramf != GraphicsContext3D::REPEAT)
3480 || (!isFloat && parami != GraphicsContext3D::CLAMP_TO_EDGE && parami != GraphicsContext3D::MIRRORED_REPEAT && parami != GraphicsContext3D::REPEAT)) { 3645 || (!isFloat && parami != GraphicsContext3D::CLAMP_TO_EDGE && parami != GraphicsContext3D::MIRRORED_REPEAT && parami != GraphicsContext3D::REPEAT)) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
3512 } 3677 }
3513 3678
3514 void WebGLRenderingContext::texSubImage2DBase(GC3Denum target, GC3Dint level, GC 3Dint xoffset, GC3Dint yoffset, GC3Dsizei width, GC3Dsizei height, GC3Denum form at, GC3Denum type, const void* pixels, ExceptionCode& ec) 3679 void WebGLRenderingContext::texSubImage2DBase(GC3Denum target, GC3Dint level, GC 3Dint xoffset, GC3Dint yoffset, GC3Dsizei width, GC3Dsizei height, GC3Denum form at, GC3Denum type, const void* pixels, ExceptionCode& ec)
3515 { 3680 {
3516 // FIXME: For now we ignore any errors returned 3681 // FIXME: For now we ignore any errors returned
3517 ec = 0; 3682 ec = 0;
3518 ASSERT(!isContextLost()); 3683 ASSERT(!isContextLost());
3519 ASSERT(validateTexFuncParameters("texSubImage2D", TexSubImage2D, target, lev el, format, width, height, 0, format, type)); 3684 ASSERT(validateTexFuncParameters("texSubImage2D", TexSubImage2D, target, lev el, format, width, height, 0, format, type));
3520 ASSERT(validateSize("texSubImage2D", xoffset, yoffset)); 3685 ASSERT(validateSize("texSubImage2D", xoffset, yoffset));
3521 ASSERT(validateSettableTexFormat("texSubImage2D", format)); 3686 ASSERT(validateSettableTexFormat("texSubImage2D", format));
3522 WebGLTexture* tex = validateTextureBinding("texSubImage2D", target, true); 3687 WebGLTexture* tex = validateTextureBinding("texSubImage2D", target, true, We bGLSharedObject::Exclusive);
3523 if (!tex) { 3688 if (!tex) {
3524 ASSERT_NOT_REACHED(); 3689 ASSERT_NOT_REACHED();
3525 return; 3690 return;
3526 } 3691 }
3527 ASSERT((xoffset + width) >= 0); 3692 ASSERT((xoffset + width) >= 0);
3528 ASSERT((yoffset + height) >= 0); 3693 ASSERT((yoffset + height) >= 0);
3529 ASSERT(tex->getWidth(target, level) >= (xoffset + width)); 3694 ASSERT(tex->getWidth(target, level) >= (xoffset + width));
3530 ASSERT(tex->getHeight(target, level) >= (yoffset + height)); 3695 ASSERT(tex->getHeight(target, level) >= (yoffset + height));
3531 ASSERT(tex->getInternalFormat(target, level) == format); 3696 ASSERT(tex->getInternalFormat(target, level) == format);
3532 ASSERT(tex->getType(target, level) == type); 3697 ASSERT(tex->getType(target, level) == type);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
3655 3820
3656 RefPtr<Image> image = videoFrameToImage(video, ImageBuffer::fastCopyImageMod e(), ec); 3821 RefPtr<Image> image = videoFrameToImage(video, ImageBuffer::fastCopyImageMod e(), ec);
3657 if (!image) 3822 if (!image)
3658 return; 3823 return;
3659 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, image.get() , GraphicsContext3D::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha, ec); 3824 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, image.get() , GraphicsContext3D::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha, ec);
3660 } 3825 }
3661 3826
3662 void WebGLRenderingContext::uniform1f(const WebGLUniformLocation* location, GC3D float x, ExceptionCode& ec) 3827 void WebGLRenderingContext::uniform1f(const WebGLUniformLocation* location, GC3D float x, ExceptionCode& ec)
3663 { 3828 {
3664 UNUSED_PARAM(ec); 3829 UNUSED_PARAM(ec);
3665 if (isContextLost() || !location) 3830 if (!validateUniformParameters("uniform1f", location))
3666 return; 3831 return;
3667 3832
3668 if (location->program() != m_currentProgram) { 3833 if (location->program() != m_currentProgram) {
3669 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "uniform1f", "lo cation not for current program"); 3834 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "uniform1f", "lo cation not for current program");
3670 return; 3835 return;
3671 } 3836 }
3672 3837
3673 m_context->uniform1f(location->location(), x); 3838 m_context->uniform1f(location->location(), x);
3674 } 3839 }
3675 3840
3676 void WebGLRenderingContext::uniform1fv(const WebGLUniformLocation* location, Flo at32Array* v, ExceptionCode& ec) 3841 void WebGLRenderingContext::uniform1fv(const WebGLUniformLocation* location, Flo at32Array* v, ExceptionCode& ec)
3677 { 3842 {
3678 UNUSED_PARAM(ec); 3843 UNUSED_PARAM(ec);
3679 if (isContextLost() || !validateUniformParameters("uniform1fv", location, v, 1)) 3844 if (!validateUniformParameters("uniform1fv", location, v, 1))
3680 return; 3845 return;
3681 3846
3682 m_context->uniform1fv(location->location(), v->length(), v->data()); 3847 m_context->uniform1fv(location->location(), v->length(), v->data());
3683 } 3848 }
3684 3849
3685 void WebGLRenderingContext::uniform1fv(const WebGLUniformLocation* location, GC3 Dfloat* v, GC3Dsizei size, ExceptionCode& ec) 3850 void WebGLRenderingContext::uniform1fv(const WebGLUniformLocation* location, GC3 Dfloat* v, GC3Dsizei size, ExceptionCode& ec)
3686 { 3851 {
3687 UNUSED_PARAM(ec); 3852 UNUSED_PARAM(ec);
3688 if (isContextLost() || !validateUniformParameters("uniform1fv", location, v, size, 1)) 3853 if (!validateUniformParameters("uniform1fv", location, v, size, 1))
3689 return; 3854 return;
3690 3855
3691 m_context->uniform1fv(location->location(), size, v); 3856 m_context->uniform1fv(location->location(), size, v);
3692 } 3857 }
3693 3858
3694 void WebGLRenderingContext::uniform1i(const WebGLUniformLocation* location, GC3D int x, ExceptionCode& ec) 3859 void WebGLRenderingContext::uniform1i(const WebGLUniformLocation* location, GC3D int x, ExceptionCode& ec)
3695 { 3860 {
3696 UNUSED_PARAM(ec); 3861 UNUSED_PARAM(ec);
3697 if (isContextLost() || !location) 3862 if (!validateUniformParameters("uniform1i", location))
3698 return; 3863 return;
3699 3864
3700 if (location->program() != m_currentProgram) { 3865 if (location->program() != m_currentProgram) {
3701 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "uniform1i", "lo cation not for current program"); 3866 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "uniform1i", "lo cation not for current program");
3702 return; 3867 return;
3703 } 3868 }
3704 3869
3870 m_currentProgram->setSampler(this, location->location(), 1, &x);
3705 m_context->uniform1i(location->location(), x); 3871 m_context->uniform1i(location->location(), x);
3706 } 3872 }
3707 3873
3708 void WebGLRenderingContext::uniform1iv(const WebGLUniformLocation* location, Int 32Array* v, ExceptionCode& ec) 3874 void WebGLRenderingContext::uniform1iv(const WebGLUniformLocation* location, Int 32Array* v, ExceptionCode& ec)
3709 { 3875 {
3710 UNUSED_PARAM(ec); 3876 UNUSED_PARAM(ec);
3711 if (isContextLost() || !validateUniformParameters("uniform1iv", location, v, 1)) 3877 if (!validateUniformParameters("uniform1iv", location, v, 1))
3712 return; 3878 return;
3713 3879
3880 m_currentProgram->setSampler(this, location->location(), v->length(), v->dat a());
3714 m_context->uniform1iv(location->location(), v->length(), v->data()); 3881 m_context->uniform1iv(location->location(), v->length(), v->data());
3715 } 3882 }
3716 3883
3717 void WebGLRenderingContext::uniform1iv(const WebGLUniformLocation* location, GC3 Dint* v, GC3Dsizei size, ExceptionCode& ec) 3884 void WebGLRenderingContext::uniform1iv(const WebGLUniformLocation* location, GC3 Dint* v, GC3Dsizei size, ExceptionCode& ec)
3718 { 3885 {
3719 UNUSED_PARAM(ec); 3886 UNUSED_PARAM(ec);
3720 if (isContextLost() || !validateUniformParameters("uniform1iv", location, v, size, 1)) 3887 if (!validateUniformParameters("uniform1iv", location, v, size, 1))
3721 return; 3888 return;
3722 3889
3890 m_currentProgram->setSampler(this, location->location(), size, v);
3723 m_context->uniform1iv(location->location(), size, v); 3891 m_context->uniform1iv(location->location(), size, v);
3724 } 3892 }
3725 3893
3726 void WebGLRenderingContext::uniform2f(const WebGLUniformLocation* location, GC3D float x, GC3Dfloat y, ExceptionCode& ec) 3894 void WebGLRenderingContext::uniform2f(const WebGLUniformLocation* location, GC3D float x, GC3Dfloat y, ExceptionCode& ec)
3727 { 3895 {
3728 UNUSED_PARAM(ec); 3896 UNUSED_PARAM(ec);
3729 if (isContextLost() || !location) 3897 if (!validateUniformParameters("uniform2f", location))
3730 return; 3898 return;
3731 3899
3732 if (location->program() != m_currentProgram) {
3733 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "uniform2f", "lo cation not for current program");
3734 return;
3735 }
3736
3737 m_context->uniform2f(location->location(), x, y); 3900 m_context->uniform2f(location->location(), x, y);
3738 } 3901 }
3739 3902
3740 void WebGLRenderingContext::uniform2fv(const WebGLUniformLocation* location, Flo at32Array* v, ExceptionCode& ec) 3903 void WebGLRenderingContext::uniform2fv(const WebGLUniformLocation* location, Flo at32Array* v, ExceptionCode& ec)
3741 { 3904 {
3742 UNUSED_PARAM(ec); 3905 UNUSED_PARAM(ec);
3743 if (isContextLost() || !validateUniformParameters("uniform2fv", location, v, 2)) 3906 if (!validateUniformParameters("uniform2fv", location, v, 2))
3744 return; 3907 return;
3745 3908
3746 m_context->uniform2fv(location->location(), v->length() / 2, v->data()); 3909 m_context->uniform2fv(location->location(), v->length() / 2, v->data());
3747 } 3910 }
3748 3911
3749 void WebGLRenderingContext::uniform2fv(const WebGLUniformLocation* location, GC3 Dfloat* v, GC3Dsizei size, ExceptionCode& ec) 3912 void WebGLRenderingContext::uniform2fv(const WebGLUniformLocation* location, GC3 Dfloat* v, GC3Dsizei size, ExceptionCode& ec)
3750 { 3913 {
3751 UNUSED_PARAM(ec); 3914 UNUSED_PARAM(ec);
3752 if (isContextLost() || !validateUniformParameters("uniform2fv", location, v, size, 2)) 3915 if (!validateUniformParameters("uniform2fv", location, v, size, 2))
3753 return; 3916 return;
3754 3917
3755 m_context->uniform2fv(location->location(), size / 2, v); 3918 m_context->uniform2fv(location->location(), size / 2, v);
3756 } 3919 }
3757 3920
3758 void WebGLRenderingContext::uniform2i(const WebGLUniformLocation* location, GC3D int x, GC3Dint y, ExceptionCode& ec) 3921 void WebGLRenderingContext::uniform2i(const WebGLUniformLocation* location, GC3D int x, GC3Dint y, ExceptionCode& ec)
3759 { 3922 {
3760 UNUSED_PARAM(ec); 3923 UNUSED_PARAM(ec);
3761 if (isContextLost() || !location) 3924 if (!validateUniformParameters("uniform2i", location))
3762 return; 3925 return;
3763 3926
3764 if (location->program() != m_currentProgram) {
3765 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "uniform2i", "lo cation not for current program");
3766 return;
3767 }
3768
3769 m_context->uniform2i(location->location(), x, y); 3927 m_context->uniform2i(location->location(), x, y);
3770 } 3928 }
3771 3929
3772 void WebGLRenderingContext::uniform2iv(const WebGLUniformLocation* location, Int 32Array* v, ExceptionCode& ec) 3930 void WebGLRenderingContext::uniform2iv(const WebGLUniformLocation* location, Int 32Array* v, ExceptionCode& ec)
3773 { 3931 {
3774 UNUSED_PARAM(ec); 3932 UNUSED_PARAM(ec);
3775 if (isContextLost() || !validateUniformParameters("uniform2iv", location, v, 2)) 3933 if (!validateUniformParameters("uniform2iv", location, v, 2))
3776 return; 3934 return;
3777 3935
3778 m_context->uniform2iv(location->location(), v->length() / 2, v->data()); 3936 m_context->uniform2iv(location->location(), v->length() / 2, v->data());
3779 } 3937 }
3780 3938
3781 void WebGLRenderingContext::uniform2iv(const WebGLUniformLocation* location, GC3 Dint* v, GC3Dsizei size, ExceptionCode& ec) 3939 void WebGLRenderingContext::uniform2iv(const WebGLUniformLocation* location, GC3 Dint* v, GC3Dsizei size, ExceptionCode& ec)
3782 { 3940 {
3783 UNUSED_PARAM(ec); 3941 UNUSED_PARAM(ec);
3784 if (isContextLost() || !validateUniformParameters("uniform2iv", location, v, size, 2)) 3942 if (!validateUniformParameters("uniform2iv", location, v, size, 2))
3785 return; 3943 return;
3786 3944
3787 m_context->uniform2iv(location->location(), size / 2, v); 3945 m_context->uniform2iv(location->location(), size / 2, v);
3788 } 3946 }
3789 3947
3790 void WebGLRenderingContext::uniform3f(const WebGLUniformLocation* location, GC3D float x, GC3Dfloat y, GC3Dfloat z, ExceptionCode& ec) 3948 void WebGLRenderingContext::uniform3f(const WebGLUniformLocation* location, GC3D float x, GC3Dfloat y, GC3Dfloat z, ExceptionCode& ec)
3791 { 3949 {
3792 UNUSED_PARAM(ec); 3950 UNUSED_PARAM(ec);
3793 if (isContextLost() || !location) 3951 if (!validateUniformParameters("uniform3f", location))
3794 return; 3952 return;
3795 3953
3796 if (location->program() != m_currentProgram) {
3797 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "uniform3f", "lo cation not for current program");
3798 return;
3799 }
3800
3801 m_context->uniform3f(location->location(), x, y, z); 3954 m_context->uniform3f(location->location(), x, y, z);
3802 } 3955 }
3803 3956
3804 void WebGLRenderingContext::uniform3fv(const WebGLUniformLocation* location, Flo at32Array* v, ExceptionCode& ec) 3957 void WebGLRenderingContext::uniform3fv(const WebGLUniformLocation* location, Flo at32Array* v, ExceptionCode& ec)
3805 { 3958 {
3806 UNUSED_PARAM(ec); 3959 UNUSED_PARAM(ec);
3807 if (isContextLost() || !validateUniformParameters("uniform3fv", location, v, 3)) 3960 if (!validateUniformParameters("uniform3fv", location, v, 3))
3808 return; 3961 return;
3809 3962
3810 m_context->uniform3fv(location->location(), v->length() / 3, v->data()); 3963 m_context->uniform3fv(location->location(), v->length() / 3, v->data());
3811 } 3964 }
3812 3965
3813 void WebGLRenderingContext::uniform3fv(const WebGLUniformLocation* location, GC3 Dfloat* v, GC3Dsizei size, ExceptionCode& ec) 3966 void WebGLRenderingContext::uniform3fv(const WebGLUniformLocation* location, GC3 Dfloat* v, GC3Dsizei size, ExceptionCode& ec)
3814 { 3967 {
3815 UNUSED_PARAM(ec); 3968 UNUSED_PARAM(ec);
3816 if (isContextLost() || !validateUniformParameters("uniform3fv", location, v, size, 3)) 3969 if (!validateUniformParameters("uniform3fv", location, v, size, 3))
3817 return; 3970 return;
3818 3971
3819 m_context->uniform3fv(location->location(), size / 3, v); 3972 m_context->uniform3fv(location->location(), size / 3, v);
3820 } 3973 }
3821 3974
3822 void WebGLRenderingContext::uniform3i(const WebGLUniformLocation* location, GC3D int x, GC3Dint y, GC3Dint z, ExceptionCode& ec) 3975 void WebGLRenderingContext::uniform3i(const WebGLUniformLocation* location, GC3D int x, GC3Dint y, GC3Dint z, ExceptionCode& ec)
3823 { 3976 {
3824 UNUSED_PARAM(ec); 3977 UNUSED_PARAM(ec);
3825 if (isContextLost() || !location) 3978 if (!validateUniformParameters("uniform3i", location))
3826 return; 3979 return;
3827 3980
3828 if (location->program() != m_currentProgram) {
3829 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "uniform3i", "lo cation not for current program");
3830 return;
3831 }
3832
3833 m_context->uniform3i(location->location(), x, y, z); 3981 m_context->uniform3i(location->location(), x, y, z);
3834 } 3982 }
3835 3983
3836 void WebGLRenderingContext::uniform3iv(const WebGLUniformLocation* location, Int 32Array* v, ExceptionCode& ec) 3984 void WebGLRenderingContext::uniform3iv(const WebGLUniformLocation* location, Int 32Array* v, ExceptionCode& ec)
3837 { 3985 {
3838 UNUSED_PARAM(ec); 3986 UNUSED_PARAM(ec);
3839 if (isContextLost() || !validateUniformParameters("uniform3iv", location, v, 3)) 3987 if (!validateUniformParameters("uniform3iv", location, v, 3))
3840 return; 3988 return;
3841 3989
3842 m_context->uniform3iv(location->location(), v->length() / 3, v->data()); 3990 m_context->uniform3iv(location->location(), v->length() / 3, v->data());
3843 } 3991 }
3844 3992
3845 void WebGLRenderingContext::uniform3iv(const WebGLUniformLocation* location, GC3 Dint* v, GC3Dsizei size, ExceptionCode& ec) 3993 void WebGLRenderingContext::uniform3iv(const WebGLUniformLocation* location, GC3 Dint* v, GC3Dsizei size, ExceptionCode& ec)
3846 { 3994 {
3847 UNUSED_PARAM(ec); 3995 UNUSED_PARAM(ec);
3848 if (isContextLost() || !validateUniformParameters("uniform3iv", location, v, size, 3)) 3996 if (!validateUniformParameters("uniform3iv", location, v, size, 3))
3849 return; 3997 return;
3850 3998
3851 m_context->uniform3iv(location->location(), size / 3, v); 3999 m_context->uniform3iv(location->location(), size / 3, v);
3852 } 4000 }
3853 4001
3854 void WebGLRenderingContext::uniform4f(const WebGLUniformLocation* location, GC3D float x, GC3Dfloat y, GC3Dfloat z, GC3Dfloat w, ExceptionCode& ec) 4002 void WebGLRenderingContext::uniform4f(const WebGLUniformLocation* location, GC3D float x, GC3Dfloat y, GC3Dfloat z, GC3Dfloat w, ExceptionCode& ec)
3855 { 4003 {
3856 UNUSED_PARAM(ec); 4004 UNUSED_PARAM(ec);
3857 if (isContextLost() || !location) 4005 if (!validateUniformParameters("uniform4f", location))
3858 return; 4006 return;
3859 4007
3860 if (location->program() != m_currentProgram) {
3861 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "uniform4f", "lo cation not for current program");
3862 return;
3863 }
3864
3865 m_context->uniform4f(location->location(), x, y, z, w); 4008 m_context->uniform4f(location->location(), x, y, z, w);
3866 } 4009 }
3867 4010
3868 void WebGLRenderingContext::uniform4fv(const WebGLUniformLocation* location, Flo at32Array* v, ExceptionCode& ec) 4011 void WebGLRenderingContext::uniform4fv(const WebGLUniformLocation* location, Flo at32Array* v, ExceptionCode& ec)
3869 { 4012 {
3870 UNUSED_PARAM(ec); 4013 UNUSED_PARAM(ec);
3871 if (isContextLost() || !validateUniformParameters("uniform4fv", location, v, 4)) 4014 if (!validateUniformParameters("uniform4fv", location, v, 4))
3872 return; 4015 return;
3873 4016
3874 m_context->uniform4fv(location->location(), v->length() / 4, v->data()); 4017 m_context->uniform4fv(location->location(), v->length() / 4, v->data());
3875 } 4018 }
3876 4019
3877 void WebGLRenderingContext::uniform4fv(const WebGLUniformLocation* location, GC3 Dfloat* v, GC3Dsizei size, ExceptionCode& ec) 4020 void WebGLRenderingContext::uniform4fv(const WebGLUniformLocation* location, GC3 Dfloat* v, GC3Dsizei size, ExceptionCode& ec)
3878 { 4021 {
3879 UNUSED_PARAM(ec); 4022 UNUSED_PARAM(ec);
3880 if (isContextLost() || !validateUniformParameters("uniform4fv", location, v, size, 4)) 4023 if (!validateUniformParameters("uniform4fv", location, v, size, 4))
3881 return; 4024 return;
3882 4025
3883 m_context->uniform4fv(location->location(), size / 4, v); 4026 m_context->uniform4fv(location->location(), size / 4, v);
3884 } 4027 }
3885 4028
3886 void WebGLRenderingContext::uniform4i(const WebGLUniformLocation* location, GC3D int x, GC3Dint y, GC3Dint z, GC3Dint w, ExceptionCode& ec) 4029 void WebGLRenderingContext::uniform4i(const WebGLUniformLocation* location, GC3D int x, GC3Dint y, GC3Dint z, GC3Dint w, ExceptionCode& ec)
3887 { 4030 {
3888 UNUSED_PARAM(ec); 4031 UNUSED_PARAM(ec);
3889 if (isContextLost() || !location) 4032 if (!validateUniformParameters("uniform4i", location))
3890 return; 4033 return;
3891 4034
3892 if (location->program() != m_currentProgram) {
3893 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "uniform4i", "lo cation not for current program");
3894 return;
3895 }
3896
3897 m_context->uniform4i(location->location(), x, y, z, w); 4035 m_context->uniform4i(location->location(), x, y, z, w);
3898 } 4036 }
3899 4037
3900 void WebGLRenderingContext::uniform4iv(const WebGLUniformLocation* location, Int 32Array* v, ExceptionCode& ec) 4038 void WebGLRenderingContext::uniform4iv(const WebGLUniformLocation* location, Int 32Array* v, ExceptionCode& ec)
3901 { 4039 {
3902 UNUSED_PARAM(ec); 4040 UNUSED_PARAM(ec);
3903 if (isContextLost() || !validateUniformParameters("uniform4iv", location, v, 4)) 4041 if (!validateUniformParameters("uniform4iv", location, v, 4))
3904 return; 4042 return;
3905 4043
3906 m_context->uniform4iv(location->location(), v->length() / 4, v->data()); 4044 m_context->uniform4iv(location->location(), v->length() / 4, v->data());
3907 } 4045 }
3908 4046
3909 void WebGLRenderingContext::uniform4iv(const WebGLUniformLocation* location, GC3 Dint* v, GC3Dsizei size, ExceptionCode& ec) 4047 void WebGLRenderingContext::uniform4iv(const WebGLUniformLocation* location, GC3 Dint* v, GC3Dsizei size, ExceptionCode& ec)
3910 { 4048 {
3911 UNUSED_PARAM(ec); 4049 UNUSED_PARAM(ec);
3912 if (isContextLost() || !validateUniformParameters("uniform4iv", location, v, size, 4)) 4050 if (!validateUniformParameters("uniform4iv", location, v, size, 4))
3913 return; 4051 return;
3914 4052
3915 m_context->uniform4iv(location->location(), size / 4, v); 4053 m_context->uniform4iv(location->location(), size / 4, v);
3916 } 4054 }
3917 4055
3918 void WebGLRenderingContext::uniformMatrix2fv(const WebGLUniformLocation* locatio n, GC3Dboolean transpose, Float32Array* v, ExceptionCode& ec) 4056 void WebGLRenderingContext::uniformMatrix2fv(const WebGLUniformLocation* locatio n, GC3Dboolean transpose, Float32Array* v, ExceptionCode& ec)
3919 { 4057 {
3920 UNUSED_PARAM(ec); 4058 UNUSED_PARAM(ec);
3921 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix2fv", location, transpose, v, 4)) 4059 if (!validateUniformMatrixParameters("uniformMatrix2fv", location, transpose , v, 4))
3922 return; 4060 return;
3923 m_context->uniformMatrix2fv(location->location(), v->length() / 4, transpose , v->data()); 4061 m_context->uniformMatrix2fv(location->location(), v->length() / 4, transpose , v->data());
3924 } 4062 }
3925 4063
3926 void WebGLRenderingContext::uniformMatrix2fv(const WebGLUniformLocation* locatio n, GC3Dboolean transpose, GC3Dfloat* v, GC3Dsizei size, ExceptionCode& ec) 4064 void WebGLRenderingContext::uniformMatrix2fv(const WebGLUniformLocation* locatio n, GC3Dboolean transpose, GC3Dfloat* v, GC3Dsizei size, ExceptionCode& ec)
3927 { 4065 {
3928 UNUSED_PARAM(ec); 4066 UNUSED_PARAM(ec);
3929 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix2fv", location, transpose, v, size, 4)) 4067 if (!validateUniformMatrixParameters("uniformMatrix2fv", location, transpose , v, size, 4))
3930 return; 4068 return;
3931 m_context->uniformMatrix2fv(location->location(), size / 4, transpose, v); 4069 m_context->uniformMatrix2fv(location->location(), size / 4, transpose, v);
3932 } 4070 }
3933 4071
3934 void WebGLRenderingContext::uniformMatrix3fv(const WebGLUniformLocation* locatio n, GC3Dboolean transpose, Float32Array* v, ExceptionCode& ec) 4072 void WebGLRenderingContext::uniformMatrix3fv(const WebGLUniformLocation* locatio n, GC3Dboolean transpose, Float32Array* v, ExceptionCode& ec)
3935 { 4073 {
3936 UNUSED_PARAM(ec); 4074 UNUSED_PARAM(ec);
3937 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix3fv", location, transpose, v, 9)) 4075 if (!validateUniformMatrixParameters("uniformMatrix3fv", location, transpose , v, 9))
3938 return; 4076 return;
3939 m_context->uniformMatrix3fv(location->location(), v->length() / 9, transpose , v->data()); 4077 m_context->uniformMatrix3fv(location->location(), v->length() / 9, transpose , v->data());
3940 } 4078 }
3941 4079
3942 void WebGLRenderingContext::uniformMatrix3fv(const WebGLUniformLocation* locatio n, GC3Dboolean transpose, GC3Dfloat* v, GC3Dsizei size, ExceptionCode& ec) 4080 void WebGLRenderingContext::uniformMatrix3fv(const WebGLUniformLocation* locatio n, GC3Dboolean transpose, GC3Dfloat* v, GC3Dsizei size, ExceptionCode& ec)
3943 { 4081 {
3944 UNUSED_PARAM(ec); 4082 UNUSED_PARAM(ec);
3945 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix3fv", location, transpose, v, size, 9)) 4083 if (!validateUniformMatrixParameters("uniformMatrix3fv", location, transpose , v, size, 9))
3946 return; 4084 return;
3947 m_context->uniformMatrix3fv(location->location(), size / 9, transpose, v); 4085 m_context->uniformMatrix3fv(location->location(), size / 9, transpose, v);
3948 } 4086 }
3949 4087
3950 void WebGLRenderingContext::uniformMatrix4fv(const WebGLUniformLocation* locatio n, GC3Dboolean transpose, Float32Array* v, ExceptionCode& ec) 4088 void WebGLRenderingContext::uniformMatrix4fv(const WebGLUniformLocation* locatio n, GC3Dboolean transpose, Float32Array* v, ExceptionCode& ec)
3951 { 4089 {
3952 UNUSED_PARAM(ec); 4090 UNUSED_PARAM(ec);
3953 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix4fv", location, transpose, v, 16)) 4091 if (!validateUniformMatrixParameters("uniformMatrix4fv", location, transpose , v, 16))
3954 return; 4092 return;
3955 m_context->uniformMatrix4fv(location->location(), v->length() / 16, transpos e, v->data()); 4093 m_context->uniformMatrix4fv(location->location(), v->length() / 16, transpos e, v->data());
3956 } 4094 }
3957 4095
3958 void WebGLRenderingContext::uniformMatrix4fv(const WebGLUniformLocation* locatio n, GC3Dboolean transpose, GC3Dfloat* v, GC3Dsizei size, ExceptionCode& ec) 4096 void WebGLRenderingContext::uniformMatrix4fv(const WebGLUniformLocation* locatio n, GC3Dboolean transpose, GC3Dfloat* v, GC3Dsizei size, ExceptionCode& ec)
3959 { 4097 {
3960 UNUSED_PARAM(ec); 4098 UNUSED_PARAM(ec);
3961 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix4fv", location, transpose, v, size, 16)) 4099 if (!validateUniformMatrixParameters("uniformMatrix4fv", location, transpose , v, size, 16))
3962 return; 4100 return;
3963 m_context->uniformMatrix4fv(location->location(), size / 16, transpose, v); 4101 m_context->uniformMatrix4fv(location->location(), size / 16, transpose, v);
3964 } 4102 }
3965 4103
3966 void WebGLRenderingContext::useProgram(WebGLProgram* program, ExceptionCode& ec) 4104 void WebGLRenderingContext::useProgram(WebGLProgram* program, ExceptionCode& ec)
3967 { 4105 {
3968 UNUSED_PARAM(ec); 4106 UNUSED_PARAM(ec);
3969 bool deleted; 4107 bool deleted;
3970 if (!checkObjectToBeBound("useProgram", program, deleted)) 4108 bool boundSinceLastAcquire;
4109 if (!checkSharedObjectToBeBound("useProgram", program, deleted, boundSinceLa stAcquire))
3971 return; 4110 return;
3972 if (deleted) 4111 if (deleted)
3973 program = 0; 4112 program = 0;
3974 if (program && !program->getLinkStatus()) { 4113 if (program && !program->getLinkStatus(this)) {
3975 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "useProgram", "p rogram not valid"); 4114 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "useProgram", "p rogram not valid");
3976 return; 4115 return;
3977 } 4116 }
3978 if (m_currentProgram != program) { 4117 if (m_currentProgram != program) {
3979 if (m_currentProgram) 4118 if (m_currentProgram)
3980 m_currentProgram->onDetached(graphicsContext3D()); 4119 m_currentProgram->onDetached(graphicsContext3D());
3981 m_currentProgram = program; 4120 m_currentProgram = program;
3982 m_context->useProgram(objectOrZero(program)); 4121 m_context->useProgram(objectOrZero(program));
3983 if (program) 4122 if (program)
3984 program->onAttached(); 4123 program->onAttached();
3985 } 4124 }
4125 if (program && !boundSinceLastAcquire) {
4126 program->markAsBoundSinceLastAcquireForContext(this);
4127 }
3986 } 4128 }
3987 4129
3988 void WebGLRenderingContext::validateProgram(WebGLProgram* program, ExceptionCode & ec) 4130 void WebGLRenderingContext::validateProgram(WebGLProgram* program, ExceptionCode & ec)
3989 { 4131 {
3990 UNUSED_PARAM(ec); 4132 UNUSED_PARAM(ec);
3991 if (isContextLost() || !validateWebGLObject("validateProgram", program)) 4133 if (isContextLost() || !validateWebGLSharedObject("validateProgram", program , WebGLSharedObject::ReadOnly))
3992 return; 4134 return;
3993 m_context->validateProgram(objectOrZero(program)); 4135 m_context->validateProgram(objectOrZero(program));
3994 } 4136 }
3995 4137
3996 void WebGLRenderingContext::vertexAttrib1f(GC3Duint index, GC3Dfloat v0) 4138 void WebGLRenderingContext::vertexAttrib1f(GC3Duint index, GC3Dfloat v0)
3997 { 4139 {
3998 vertexAttribfImpl("vertexAttrib1f", index, 1, v0, 0.0f, 0.0f, 1.0f); 4140 vertexAttribfImpl("vertexAttrib1f", index, 1, v0, 0.0f, 0.0f, 1.0f);
3999 } 4141 }
4000 4142
4001 void WebGLRenderingContext::vertexAttrib1fv(GC3Duint index, Float32Array* v) 4143 void WebGLRenderingContext::vertexAttrib1fv(GC3Duint index, Float32Array* v)
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
4086 if (!typeSize) { 4228 if (!typeSize) {
4087 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "vertexAttribPointer" , "invalid type"); 4229 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "vertexAttribPointer" , "invalid type");
4088 return; 4230 return;
4089 } 4231 }
4090 if ((stride % typeSize) || (static_cast<GC3Dintptr>(offset) % typeSize)) { 4232 if ((stride % typeSize) || (static_cast<GC3Dintptr>(offset) % typeSize)) {
4091 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "vertexAttribPoi nter", "stride or offset not valid for type"); 4233 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "vertexAttribPoi nter", "stride or offset not valid for type");
4092 return; 4234 return;
4093 } 4235 }
4094 GC3Dsizei bytesPerElement = size * typeSize; 4236 GC3Dsizei bytesPerElement = size * typeSize;
4095 4237
4238 if (!isAcquiredForReading("vertexAttribPointer", m_boundArrayBuffer.get())) {
4239 return;
4240 }
4096 m_boundVertexArrayObject->setVertexAttribState(index, bytesPerElement, size, type, normalized, stride, static_cast<GC3Dintptr>(offset), m_boundArrayBuffer); 4241 m_boundVertexArrayObject->setVertexAttribState(index, bytesPerElement, size, type, normalized, stride, static_cast<GC3Dintptr>(offset), m_boundArrayBuffer);
4097 m_context->vertexAttribPointer(index, size, type, normalized, stride, static _cast<GC3Dintptr>(offset)); 4242 m_context->vertexAttribPointer(index, size, type, normalized, stride, static _cast<GC3Dintptr>(offset));
4098 } 4243 }
4099 4244
4100 void WebGLRenderingContext::vertexAttribDivisorANGLE(GC3Duint index, GC3Duint di visor) 4245 void WebGLRenderingContext::vertexAttribDivisorANGLE(GC3Duint index, GC3Duint di visor)
4101 { 4246 {
4102 if (isContextLost()) 4247 if (isContextLost())
4103 return; 4248 return;
4104 4249
4105 if (index >= m_maxVertexAttribs) { 4250 if (index >= m_maxVertexAttribs) {
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
4323 case GraphicsContext3D::SCISSOR_BOX: 4468 case GraphicsContext3D::SCISSOR_BOX:
4324 case GraphicsContext3D::VIEWPORT: 4469 case GraphicsContext3D::VIEWPORT:
4325 length = 4; 4470 length = 4;
4326 break; 4471 break;
4327 default: 4472 default:
4328 notImplemented(); 4473 notImplemented();
4329 } 4474 }
4330 return WebGLGetInfo(Int32Array::create(value, length)); 4475 return WebGLGetInfo(Int32Array::create(value, length));
4331 } 4476 }
4332 4477
4333 void WebGLRenderingContext::handleTextureCompleteness(const char* functionName, bool prepareToDraw) 4478 bool WebGLRenderingContext::handleTextureCompleteness(const char* functionName, bool prepareToDraw, bool* texturesReplaced)
4334 { 4479 {
4480 if (texturesReplaced) {
4481 *texturesReplaced = false;
4482 }
4335 // All calling functions check isContextLost, so a duplicate check is not ne eded here. 4483 // All calling functions check isContextLost, so a duplicate check is not ne eded here.
4336 bool resetActiveUnit = false; 4484 bool resetActiveUnit = false;
4337 WebGLTexture::TextureExtensionFlag flag = static_cast<WebGLTexture::TextureE xtensionFlag>((m_oesTextureFloatLinear ? WebGLTexture::TextureFloatLinearExtensi onEnabled : 0) 4485 WebGLTexture::TextureExtensionFlag flag = static_cast<WebGLTexture::TextureE xtensionFlag>((m_oesTextureFloatLinear ? WebGLTexture::TextureFloatLinearExtensi onEnabled : 0)
4338 | (m_oesTextureHalfFloatLinear ? WebGLTexture::TextureHalfFloatLinearExt ensionEnabled : 0)); 4486 | (m_oesTextureHalfFloatLinear ? WebGLTexture::TextureHalfFloatLinearExt ensionEnabled : 0));
4339 for (unsigned ii = 0; ii < m_textureUnits.size(); ++ii) { 4487
4340 if ((m_textureUnits[ii].m_texture2DBinding.get() && m_textureUnits[ii].m _texture2DBinding->needToUseBlackTexture(flag)) 4488 const WebGLProgram::SamplerTextureUnitMap& samplerMap = m_currentProgram->sa mplerLocationTextureUnitMap();
4341 || (m_textureUnits[ii].m_textureCubeMapBinding.get() && m_textureUni ts[ii].m_textureCubeMapBinding->needToUseBlackTexture(flag))) { 4489 for (WebGLProgram::SamplerTextureUnitMap::const_iterator it = samplerMap.beg in(); it != samplerMap.end(); ++it) {
4342 if (ii != m_activeTextureUnit) { 4490 GC3Dint unit = it->value.unit;
4343 m_context->activeTexture(ii); 4491 GC3Denum type = it->value.type;
4344 resetActiveUnit = true; 4492 WebGLTexture* texture;
4345 } else if (resetActiveUnit) { 4493 WebGLTexture* blackTexture;
4346 m_context->activeTexture(ii); 4494 GC3Denum target;
4347 resetActiveUnit = false; 4495 switch (it->value.type) {
4496 case GraphicsContext3D::SAMPLER_2D:
4497 target = GraphicsContext3D::TEXTURE_2D;
4498 texture = m_textureUnits[unit].m_texture2DBinding.get();
4499 blackTexture = m_blackTexture2D.get();
4500 break;
4501 case GraphicsContext3D::SAMPLER_CUBE:
4502 target = GraphicsContext3D::TEXTURE_CUBE_MAP;
4503 texture = m_textureUnits[unit].m_textureCubeMapBinding.get();
4504 blackTexture = m_blackTextureCubeMap.get();
4505 break;
4506 default:
4507 notImplemented();
4508 }
4509
4510 if (!texture) {
4511 continue;
4512 }
4513
4514 if (prepareToDraw && !isAcquiredForReading(functionName, texture)) {
4515 return false;
Ken Russell (switch to Gerrit) 2013/06/19 03:51:24 The code associated with resetActiveUnit isn't run
greggman 2013/06/21 19:54:21 Yes, added a comment
4516 }
4517
4518 if (texture->needToUseBlackTexture(flag)) {
4519 if (texturesReplaced) {
4520 *texturesReplaced = true;
4348 } 4521 }
4349 WebGLTexture* tex2D; 4522 m_context->activeTexture(GraphicsContext3D::TEXTURE0 + unit);
4350 WebGLTexture* texCubeMap; 4523 resetActiveUnit = true;
4524 WebGLTexture* tex;
4351 if (prepareToDraw) { 4525 if (prepareToDraw) {
4352 String msg(String("texture bound to texture unit ") + String::nu mber(ii) 4526 String msg(String("texture bound to texture unit ") + String::nu mber(unit)
4353 + " is not renderable. It maybe non-power-of-2 and have inco mpatible texture filtering or is not 'texture complete'." 4527 + " is not renderable. It maybe non-power-of-2 and have inco mpatible texture filtering or is not 'texture complete'."
4354 + " Or the texture is Float or Half Float type with linear f iltering while OES_float_linear or OES_half_float_linear extension is not enable d."); 4528 + " Or the texture is Float or Half Float type with linear f iltering while OES_float_linear or OES_half_float_linear extension is not enable d.");
4355 printGLWarningToConsole(functionName, msg.utf8().data()); 4529 printGLWarningToConsole(functionName, msg.utf8().data());
4356 tex2D = m_blackTexture2D.get(); 4530 tex = blackTexture;
4357 texCubeMap = m_blackTextureCubeMap.get();
4358 } else { 4531 } else {
4359 tex2D = m_textureUnits[ii].m_texture2DBinding.get(); 4532 tex = texture;
4360 texCubeMap = m_textureUnits[ii].m_textureCubeMapBinding.get();
4361 } 4533 }
4362 if (m_textureUnits[ii].m_texture2DBinding && m_textureUnits[ii].m_te xture2DBinding->needToUseBlackTexture(flag)) 4534 m_context->bindTexture(target, objectOrZero(tex));
4363 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, objectOrZe ro(tex2D));
4364 if (m_textureUnits[ii].m_textureCubeMapBinding && m_textureUnits[ii] .m_textureCubeMapBinding->needToUseBlackTexture(flag))
4365 m_context->bindTexture(GraphicsContext3D::TEXTURE_CUBE_MAP, obje ctOrZero(texCubeMap));
4366 } 4535 }
4367 } 4536 }
4368 if (resetActiveUnit) 4537 if (resetActiveUnit)
4369 m_context->activeTexture(m_activeTextureUnit); 4538 m_context->activeTexture(m_activeTextureUnit);
4539
4540 return true;
4370 } 4541 }
4371 4542
4372 void WebGLRenderingContext::createFallbackBlackTextures1x1() 4543 void WebGLRenderingContext::createFallbackBlackTextures1x1()
4373 { 4544 {
4374 // All calling functions check isContextLost, so a duplicate check is not ne eded here. 4545 // All calling functions check isContextLost, so a duplicate check is not ne eded here.
4375 unsigned char black[] = {0, 0, 0, 255}; 4546 unsigned char black[] = {0, 0, 0, 255};
4376 m_blackTexture2D = createTexture(); 4547 m_blackTexture2D = createTexture();
4377 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_blackTexture2D->obje ct()); 4548 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_blackTexture2D->obje ct());
4378 m_context->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, GraphicsContext3D::R GBA, 1, 1, 4549 m_context->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, GraphicsContext3D::R GBA, 1, 1,
4379 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNE D_BYTE, black); 4550 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNE D_BYTE, black);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
4419 return m_drawingBuffer->size().width(); 4590 return m_drawingBuffer->size().width();
4420 } 4591 }
4421 4592
4422 int WebGLRenderingContext::getBoundFramebufferHeight() 4593 int WebGLRenderingContext::getBoundFramebufferHeight()
4423 { 4594 {
4424 if (m_framebufferBinding && m_framebufferBinding->object()) 4595 if (m_framebufferBinding && m_framebufferBinding->object())
4425 return m_framebufferBinding->getColorBufferHeight(); 4596 return m_framebufferBinding->getColorBufferHeight();
4426 return m_drawingBuffer->size().height(); 4597 return m_drawingBuffer->size().height();
4427 } 4598 }
4428 4599
4429 WebGLTexture* WebGLRenderingContext::validateTextureBinding(const char* function Name, GC3Denum target, bool useSixEnumsForCubeMap) 4600 WebGLTexture* WebGLRenderingContext::validateTextureBinding(const char* function Name, GC3Denum target, bool useSixEnumsForCubeMap, WebGLSharedObject::AcquireMod e mode)
4430 { 4601 {
4431 WebGLTexture* tex = 0; 4602 WebGLTexture* tex = 0;
4432 switch (target) { 4603 switch (target) {
4433 case GraphicsContext3D::TEXTURE_2D: 4604 case GraphicsContext3D::TEXTURE_2D:
4434 tex = m_textureUnits[m_activeTextureUnit].m_texture2DBinding.get(); 4605 tex = m_textureUnits[m_activeTextureUnit].m_texture2DBinding.get();
4435 break; 4606 break;
4436 case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_X: 4607 case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_X:
4437 case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_X: 4608 case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_X:
4438 case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Y: 4609 case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Y:
4439 case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Y: 4610 case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Y:
(...skipping 11 matching lines...) Expand all
4451 return 0; 4622 return 0;
4452 } 4623 }
4453 tex = m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding.get(); 4624 tex = m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding.get();
4454 break; 4625 break;
4455 default: 4626 default:
4456 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, "invali d texture target"); 4627 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, "invali d texture target");
4457 return 0; 4628 return 0;
4458 } 4629 }
4459 if (!tex) 4630 if (!tex)
4460 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "n o texture"); 4631 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "n o texture");
4632 switch (mode) {
4633 case WebGLSharedObject::ReadOnly:
4634 if (!isAcquiredForReading(functionName, tex)) {
4635 return 0;
4636 }
4637 break;
4638 case WebGLSharedObject::Exclusive:
4639 if (!isAcquiredForModification(functionName, tex)) {
4640 return 0;
4641 }
4642 break;
4643 default:
4644 notImplemented();
4645 break;
4646 }
4461 return tex; 4647 return tex;
4462 } 4648 }
4463 4649
4464 bool WebGLRenderingContext::validateLocationLength(const char* functionName, con st String& string) 4650 bool WebGLRenderingContext::validateLocationLength(const char* functionName, con st String& string)
4465 { 4651 {
4466 const unsigned maxWebGLLocationLength = 256; 4652 const unsigned maxWebGLLocationLength = 256;
4467 if (string.length() > maxWebGLLocationLength) { 4653 if (string.length() > maxWebGLLocationLength) {
4468 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "locat ion length > 256"); 4654 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "locat ion length > 256");
4469 return false; 4655 return false;
4470 } 4656 }
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
5029 case GraphicsContext3D::SAMPLE_COVERAGE: 5215 case GraphicsContext3D::SAMPLE_COVERAGE:
5030 case GraphicsContext3D::SCISSOR_TEST: 5216 case GraphicsContext3D::SCISSOR_TEST:
5031 case GraphicsContext3D::STENCIL_TEST: 5217 case GraphicsContext3D::STENCIL_TEST:
5032 return true; 5218 return true;
5033 default: 5219 default:
5034 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, "invali d capability"); 5220 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, "invali d capability");
5035 return false; 5221 return false;
5036 } 5222 }
5037 } 5223 }
5038 5224
5039 bool WebGLRenderingContext::validateUniformParameters(const char* functionName, const WebGLUniformLocation* location, Float32Array* v, GC3Dsizei requiredMinSize ) 5225 bool WebGLRenderingContext::validateUniformParameters(const char* functionName, const WebGLUniformLocation* location)
5226 {
5227 if (isContextLost() || !location) {
5228 return false;
5229 }
5230
5231 if (location->program() != m_currentProgram) {
5232 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "l ocation is not from current program");
5233 return false;
5234 }
5235
5236 if (!isAcquiredForModification(functionName, m_currentProgram.get())) {
5237 return false;
5238 }
5239
5240 return true;
5241 }
5242
5243 bool WebGLRenderingContext::validateUniformParameters(const char* functionName, const WebGLUniformLocation* location, Int32Array* v, GC3Dsizei requiredMinSize)
5040 { 5244 {
5041 if (!v) { 5245 if (!v) {
5042 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no ar ray"); 5246 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no ar ray");
5043 return false; 5247 return false;
5044 } 5248 }
5045 return validateUniformMatrixParameters(functionName, location, false, v->dat a(), v->length(), requiredMinSize); 5249 return validateUniformMatrixParameters(functionName, location, false, v->dat a(), v->length(), requiredMinSize);
5046 } 5250 }
5047 5251
5048 bool WebGLRenderingContext::validateUniformParameters(const char* functionName, const WebGLUniformLocation* location, Int32Array* v, GC3Dsizei requiredMinSize) 5252 bool WebGLRenderingContext::validateUniformParameters(const char* functionName, const WebGLUniformLocation* location, Float32Array* v, GC3Dsizei requiredMinSize )
5049 { 5253 {
5050 if (!v) { 5254 if (!v) {
5051 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no ar ray"); 5255 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no ar ray");
5052 return false; 5256 return false;
5053 } 5257 }
5054 return validateUniformMatrixParameters(functionName, location, false, v->dat a(), v->length(), requiredMinSize); 5258 return validateUniformMatrixParameters(functionName, location, false, v->dat a(), v->length(), requiredMinSize);
5055 } 5259 }
5056 5260
5057 bool WebGLRenderingContext::validateUniformParameters(const char* functionName, const WebGLUniformLocation* location, void* v, GC3Dsizei size, GC3Dsizei require dMinSize) 5261 bool WebGLRenderingContext::validateUniformParameters(const char* functionName, const WebGLUniformLocation* location, void* v, GC3Dsizei size, GC3Dsizei require dMinSize)
5058 { 5262 {
5059 return validateUniformMatrixParameters(functionName, location, false, v, siz e, requiredMinSize); 5263 return validateUniformMatrixParameters(functionName, location, false, v, siz e, requiredMinSize);
5060 } 5264 }
5061 5265
5062 bool WebGLRenderingContext::validateUniformMatrixParameters(const char* function Name, const WebGLUniformLocation* location, GC3Dboolean transpose, Float32Array* v, GC3Dsizei requiredMinSize) 5266 bool WebGLRenderingContext::validateUniformMatrixParameters(const char* function Name, const WebGLUniformLocation* location, GC3Dboolean transpose, Float32Array* v, GC3Dsizei requiredMinSize)
5063 { 5267 {
5064 if (!v) { 5268 if (!v) {
5065 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no ar ray"); 5269 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no ar ray");
5066 return false; 5270 return false;
5067 } 5271 }
5068 return validateUniformMatrixParameters(functionName, location, transpose, v- >data(), v->length(), requiredMinSize); 5272 return validateUniformMatrixParameters(functionName, location, transpose, v- >data(), v->length(), requiredMinSize);
5069 } 5273 }
5070 5274
5071 bool WebGLRenderingContext::validateUniformMatrixParameters(const char* function Name, const WebGLUniformLocation* location, GC3Dboolean transpose, void* v, GC3D sizei size, GC3Dsizei requiredMinSize) 5275 bool WebGLRenderingContext::validateUniformMatrixParameters(const char* function Name, const WebGLUniformLocation* location, GC3Dboolean transpose, void* v, GC3D sizei size, GC3Dsizei requiredMinSize)
5072 { 5276 {
5073 if (!location) 5277 if (isContextLost() || !location)
5074 return false; 5278 return false;
5075 if (location->program() != m_currentProgram) { 5279 if (location->program() != m_currentProgram) {
5076 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "l ocation is not from current program"); 5280 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "l ocation is not from current program");
5077 return false; 5281 return false;
5078 } 5282 }
5283 if (!isAcquiredForModification(functionName, m_currentProgram.get())) {
5284 return false;
5285 }
5286
5079 if (!v) { 5287 if (!v) {
5080 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no ar ray"); 5288 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no ar ray");
5081 return false; 5289 return false;
5082 } 5290 }
5083 if (transpose) { 5291 if (transpose) {
5084 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "trans pose not FALSE"); 5292 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "trans pose not FALSE");
5085 return false; 5293 return false;
5086 } 5294 }
5087 if (size < requiredMinSize || (size % requiredMinSize)) { 5295 if (size < requiredMinSize || (size % requiredMinSize)) {
5088 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "inval id size"); 5296 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "inval id size");
5089 return false; 5297 return false;
5090 } 5298 }
5091 return true; 5299 return true;
5092 } 5300 }
5093 5301
5094 WebGLBuffer* WebGLRenderingContext::validateBufferDataParameters(const char* fun ctionName, GC3Denum target, GC3Denum usage) 5302 WebGLBuffer* WebGLRenderingContext::getBufferForTarget(const char* functionName, GC3Denum target)
5095 { 5303 {
5096 WebGLBuffer* buffer = 0; 5304 WebGLBuffer* buffer = 0;
5097 switch (target) { 5305 switch (target) {
5098 case GraphicsContext3D::ELEMENT_ARRAY_BUFFER: 5306 case GraphicsContext3D::ELEMENT_ARRAY_BUFFER:
5099 buffer = m_boundVertexArrayObject->getElementArrayBuffer().get(); 5307 buffer = m_boundVertexArrayObject->getElementArrayBuffer().get();
5100 break; 5308 break;
5101 case GraphicsContext3D::ARRAY_BUFFER: 5309 case GraphicsContext3D::ARRAY_BUFFER:
5102 buffer = m_boundArrayBuffer.get(); 5310 buffer = m_boundArrayBuffer.get();
5103 break; 5311 break;
5104 default: 5312 default:
5105 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, "invali d target"); 5313 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, "invali d target");
5106 return 0; 5314 return 0;
5107 } 5315 }
5108 if (!buffer) { 5316 if (!buffer) {
5109 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "n o buffer"); 5317 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "n o buffer");
5110 return 0; 5318 return 0;
5111 } 5319 }
5320 return buffer;
5321 }
5322
5323 WebGLBuffer* WebGLRenderingContext::validateBufferDataParameters(const char* fun ctionName, GC3Denum target, GC3Denum usage)
5324 {
5325 WebGLBuffer* buffer = getBufferForTarget(functionName, target);
5326 if (!buffer) {
5327 return 0;
5328 }
5329
5330 if (!isAcquiredForModification(functionName, buffer))
5331 return 0;
5112 switch (usage) { 5332 switch (usage) {
5113 case GraphicsContext3D::STREAM_DRAW: 5333 case GraphicsContext3D::STREAM_DRAW:
5114 case GraphicsContext3D::STATIC_DRAW: 5334 case GraphicsContext3D::STATIC_DRAW:
5115 case GraphicsContext3D::DYNAMIC_DRAW: 5335 case GraphicsContext3D::DYNAMIC_DRAW:
5116 return buffer; 5336 return buffer;
5117 } 5337 }
5118 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, "invalid us age"); 5338 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, "invalid us age");
5119 return 0; 5339 return 0;
5120 } 5340 }
5121 5341
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
5174 if (first < 0 || count < 0) { 5394 if (first < 0 || count < 0) {
5175 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "first or count < 0"); 5395 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "first or count < 0");
5176 return false; 5396 return false;
5177 } 5397 }
5178 5398
5179 if (!count) { 5399 if (!count) {
5180 markContextChanged(); 5400 markContextChanged();
5181 return false; 5401 return false;
5182 } 5402 }
5183 5403
5184 if (!validateRenderingState()) { 5404 if (!validateRenderingState(functionName)) {
5185 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "a ttribs not setup correctly");
5186 return false; 5405 return false;
5187 } 5406 }
5188 5407
5189 const char* reason = "framebuffer incomplete"; 5408 const char* reason = "framebuffer incomplete";
5190 if (m_framebufferBinding && !m_framebufferBinding->onAccess(graphicsContext3 D(), &reason)) { 5409 if (m_framebufferBinding && !m_framebufferBinding->onAccess(this, WebGLShare dObject::Exclusive, &reason)) {
5191 synthesizeGLError(GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION, func tionName, reason); 5410 synthesizeGLError(GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION, func tionName, reason);
5192 return false; 5411 return false;
5193 } 5412 }
5194 5413
5195 return true; 5414 return true;
5196 } 5415 }
5197 5416
5198 bool WebGLRenderingContext::validateDrawElements(const char* functionName, GC3De num mode, GC3Dsizei count, GC3Denum type, long long offset) 5417 bool WebGLRenderingContext::validateDrawElements(const char* functionName, GC3De num mode, GC3Dsizei count, GC3Denum type, long long offset)
5199 { 5418 {
5200 if (isContextLost() || !validateDrawMode(functionName, mode)) 5419 if (isContextLost() || !validateDrawMode(functionName, mode))
(...skipping 24 matching lines...) Expand all
5225 if (!count) { 5444 if (!count) {
5226 markContextChanged(); 5445 markContextChanged();
5227 return false; 5446 return false;
5228 } 5447 }
5229 5448
5230 if (!m_boundVertexArrayObject->getElementArrayBuffer()) { 5449 if (!m_boundVertexArrayObject->getElementArrayBuffer()) {
5231 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "n o ELEMENT_ARRAY_BUFFER bound"); 5450 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "n o ELEMENT_ARRAY_BUFFER bound");
5232 return false; 5451 return false;
5233 } 5452 }
5234 5453
5235 if (!validateRenderingState()) { 5454 if (!isAcquiredForReading(functionName, m_boundVertexArrayObject->getElement ArrayBuffer().get())) {
5236 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "a ttribs not setup correctly"); 5455 return false;
5456 }
5457
5458 if (!validateRenderingState(functionName)) {
5237 return false; 5459 return false;
5238 } 5460 }
5239 5461
5240 const char* reason = "framebuffer incomplete"; 5462 const char* reason = "framebuffer incomplete";
5241 if (m_framebufferBinding && !m_framebufferBinding->onAccess(graphicsContext3 D(), &reason)) { 5463 if (m_framebufferBinding && !m_framebufferBinding->onAccess(this, WebGLShare dObject::Exclusive, &reason)) {
5242 synthesizeGLError(GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION, func tionName, reason); 5464 synthesizeGLError(GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION, func tionName, reason);
5243 return false; 5465 return false;
5244 } 5466 }
5245 5467
5246 return true; 5468 return true;
5247 } 5469 }
5248 5470
5249 // Helper function to validate draw*Instanced calls 5471 // Helper function to validate draw*Instanced calls
5250 bool WebGLRenderingContext::validateDrawInstanced(const char* functionName, GC3D sizei primcount) 5472 bool WebGLRenderingContext::validateDrawInstanced(const char* functionName, GC3D sizei primcount)
5251 { 5473 {
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
5576 5798
5577 void WebGLRenderingContext::multisamplingChanged(bool enabled) 5799 void WebGLRenderingContext::multisamplingChanged(bool enabled)
5578 { 5800 {
5579 if (m_multisamplingAllowed != enabled) { 5801 if (m_multisamplingAllowed != enabled) {
5580 m_multisamplingAllowed = enabled; 5802 m_multisamplingAllowed = enabled;
5581 forceLostContext(WebGLRenderingContext::AutoRecoverSyntheticLostContext) ; 5803 forceLostContext(WebGLRenderingContext::AutoRecoverSyntheticLostContext) ;
5582 } 5804 }
5583 } 5805 }
5584 5806
5585 } // namespace WebCore 5807 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698