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

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

Issue 24096029: Moved the majority of WebGL functionality into WebGLRenderingContextBase (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Re-wrote patch by hand (too much to rebase) Created 6 years, 10 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 // Copyright 2014 The Chromium Authors. All rights reserved.
2 * Copyright (C) 2009 Apple Inc. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be
3 * 3 // found in the LICENSE file.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25 4
26 #include "config.h" 5 #include "config.h"
27 #include "core/html/canvas/WebGLRenderingContext.h" 6 #include "core/html/canvas/WebGLRenderingContextBase.h"
28 7
29 #include "RuntimeEnabledFeatures.h" 8 #include "RuntimeEnabledFeatures.h"
30 #include "bindings/v8/ExceptionMessages.h" 9 #include "bindings/v8/ExceptionMessages.h"
31 #include "bindings/v8/ExceptionState.h" 10 #include "bindings/v8/ExceptionState.h"
32 #include "core/dom/ExceptionCode.h" 11 #include "core/dom/ExceptionCode.h"
33 #include "core/fetch/ImageResource.h" 12 #include "core/fetch/ImageResource.h"
34 #include "core/html/HTMLCanvasElement.h" 13 #include "core/html/HTMLCanvasElement.h"
35 #include "core/html/HTMLImageElement.h" 14 #include "core/html/HTMLImageElement.h"
36 #include "core/html/HTMLVideoElement.h" 15 #include "core/html/HTMLVideoElement.h"
37 #include "core/html/ImageData.h" 16 #include "core/html/ImageData.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 #include "wtf/PassOwnPtr.h" 60 #include "wtf/PassOwnPtr.h"
82 #include "wtf/Uint32Array.h" 61 #include "wtf/Uint32Array.h"
83 #include "wtf/text/StringBuilder.h" 62 #include "wtf/text/StringBuilder.h"
84 63
85 namespace WebCore { 64 namespace WebCore {
86 65
87 const double secondsBetweenRestoreAttempts = 1.0; 66 const double secondsBetweenRestoreAttempts = 1.0;
88 const int maxGLErrorsAllowedToConsole = 256; 67 const int maxGLErrorsAllowedToConsole = 256;
89 const unsigned maxGLActiveContexts = 16; 68 const unsigned maxGLActiveContexts = 16;
90 69
91 Vector<WebGLRenderingContext*>& WebGLRenderingContext::activeContexts() 70 Vector<WebGLRenderingContextBase*>& WebGLRenderingContextBase::activeContexts()
92 { 71 {
93 DEFINE_STATIC_LOCAL(Vector<WebGLRenderingContext*>, activeContexts, ()); 72 DEFINE_STATIC_LOCAL(Vector<WebGLRenderingContextBase*>, activeContexts, ());
94 return activeContexts; 73 return activeContexts;
95 } 74 }
96 75
97 Vector<WebGLRenderingContext*>& WebGLRenderingContext::forciblyEvictedContexts() 76 Vector<WebGLRenderingContextBase*>& WebGLRenderingContextBase::forciblyEvictedCo ntexts()
98 { 77 {
99 DEFINE_STATIC_LOCAL(Vector<WebGLRenderingContext*>, forciblyEvictedContexts, ()); 78 DEFINE_STATIC_LOCAL(Vector<WebGLRenderingContextBase*>, forciblyEvictedConte xts, ());
100 return forciblyEvictedContexts; 79 return forciblyEvictedContexts;
101 } 80 }
102 81
103 void WebGLRenderingContext::forciblyLoseOldestContext(const String& reason) 82 void WebGLRenderingContextBase::forciblyLoseOldestContext(const String& reason)
104 { 83 {
105 size_t candidateID = oldestContextIndex(); 84 size_t candidateID = oldestContextIndex();
106 if (candidateID >= activeContexts().size()) 85 if (candidateID >= activeContexts().size())
107 return; 86 return;
108 87
109 WebGLRenderingContext* candidate = activeContexts()[candidateID]; 88 WebGLRenderingContextBase* candidate = activeContexts()[candidateID];
110 89
111 activeContexts().remove(candidateID); 90 activeContexts().remove(candidateID);
112 91
113 candidate->printWarningToConsole(reason); 92 candidate->printWarningToConsole(reason);
114 InspectorInstrumentation::didFireWebGLWarning(candidate->canvas()); 93 InspectorInstrumentation::didFireWebGLWarning(candidate->canvas());
115 94
116 // This will call deactivateContext once the context has actually been lost. 95 // This will call deactivateContext once the context has actually been lost.
117 candidate->forceLostContext(WebGLRenderingContext::SyntheticLostContext); 96 candidate->forceLostContext(WebGLRenderingContextBase::SyntheticLostContext) ;
118 } 97 }
119 98
120 size_t WebGLRenderingContext::oldestContextIndex() 99 size_t WebGLRenderingContextBase::oldestContextIndex()
121 { 100 {
122 if (!activeContexts().size()) 101 if (!activeContexts().size())
123 return maxGLActiveContexts; 102 return maxGLActiveContexts;
124 103
125 WebGLRenderingContext* candidate = activeContexts().first(); 104 WebGLRenderingContextBase* candidate = activeContexts().first();
126 size_t candidateID = 0; 105 size_t candidateID = 0;
127 for (size_t ii = 1; ii < activeContexts().size(); ++ii) { 106 for (size_t ii = 1; ii < activeContexts().size(); ++ii) {
128 WebGLRenderingContext* context = activeContexts()[ii]; 107 WebGLRenderingContextBase* context = activeContexts()[ii];
129 if (context->webGraphicsContext3D() && candidate->webGraphicsContext3D() && context->webGraphicsContext3D()->lastFlushID() < candidate->webGraphicsConte xt3D()->lastFlushID()) { 108 if (context->webGraphicsContext3D() && candidate->webGraphicsContext3D() && context->webGraphicsContext3D()->lastFlushID() < candidate->webGraphicsConte xt3D()->lastFlushID()) {
130 candidate = context; 109 candidate = context;
131 candidateID = ii; 110 candidateID = ii;
132 } 111 }
133 } 112 }
134 113
135 return candidateID; 114 return candidateID;
136 } 115 }
137 116
138 IntSize WebGLRenderingContext::oldestContextSize() 117 IntSize WebGLRenderingContextBase::oldestContextSize()
139 { 118 {
140 IntSize size; 119 IntSize size;
141 120
142 size_t candidateID = oldestContextIndex(); 121 size_t candidateID = oldestContextIndex();
143 if (candidateID < activeContexts().size()) { 122 if (candidateID < activeContexts().size()) {
144 WebGLRenderingContext* candidate = activeContexts()[candidateID]; 123 WebGLRenderingContextBase* candidate = activeContexts()[candidateID];
145 size.setWidth(candidate->drawingBufferWidth()); 124 size.setWidth(candidate->drawingBufferWidth());
146 size.setHeight(candidate->drawingBufferHeight()); 125 size.setHeight(candidate->drawingBufferHeight());
147 } 126 }
148 127
149 return size; 128 return size;
150 } 129 }
151 130
152 void WebGLRenderingContext::activateContext(WebGLRenderingContext* context) 131 void WebGLRenderingContextBase::activateContext(WebGLRenderingContextBase* conte xt)
153 { 132 {
154 unsigned removedContexts = 0; 133 unsigned removedContexts = 0;
155 while (activeContexts().size() >= maxGLActiveContexts && removedContexts < m axGLActiveContexts) { 134 while (activeContexts().size() >= maxGLActiveContexts && removedContexts < m axGLActiveContexts) {
156 forciblyLoseOldestContext("WARNING: Too many active WebGL contexts. Olde st context will be lost."); 135 forciblyLoseOldestContext("WARNING: Too many active WebGL contexts. Olde st context will be lost.");
157 removedContexts++; 136 removedContexts++;
158 } 137 }
159 138
160 if (!activeContexts().contains(context)) 139 if (!activeContexts().contains(context))
161 activeContexts().append(context); 140 activeContexts().append(context);
162 } 141 }
163 142
164 void WebGLRenderingContext::deactivateContext(WebGLRenderingContext* context, bo ol addToEvictedList) 143 void WebGLRenderingContextBase::deactivateContext(WebGLRenderingContextBase* con text, bool addToEvictedList)
165 { 144 {
166 size_t position = activeContexts().find(context); 145 size_t position = activeContexts().find(context);
167 if (position != WTF::kNotFound) 146 if (position != WTF::kNotFound)
168 activeContexts().remove(position); 147 activeContexts().remove(position);
169 148
170 if (addToEvictedList && !forciblyEvictedContexts().contains(context)) 149 if (addToEvictedList && !forciblyEvictedContexts().contains(context))
171 forciblyEvictedContexts().append(context); 150 forciblyEvictedContexts().append(context);
172 } 151 }
173 152
174 void WebGLRenderingContext::willDestroyContext(WebGLRenderingContext* context) 153 void WebGLRenderingContextBase::willDestroyContext(WebGLRenderingContextBase* co ntext)
175 { 154 {
176 size_t position = forciblyEvictedContexts().find(context); 155 size_t position = forciblyEvictedContexts().find(context);
177 if (position != WTF::kNotFound) 156 if (position != WTF::kNotFound)
178 forciblyEvictedContexts().remove(position); 157 forciblyEvictedContexts().remove(position);
179 158
180 deactivateContext(context, false); 159 deactivateContext(context, false);
181 160
182 // Try to re-enable the oldest inactive contexts. 161 // Try to re-enable the oldest inactive contexts.
183 while(activeContexts().size() < maxGLActiveContexts && forciblyEvictedContex ts().size()) { 162 while(activeContexts().size() < maxGLActiveContexts && forciblyEvictedContex ts().size()) {
184 WebGLRenderingContext* evictedContext = forciblyEvictedContexts().first( ); 163 WebGLRenderingContextBase* evictedContext = forciblyEvictedContexts().fi rst();
185 if (!evictedContext->m_restoreAllowed) { 164 if (!evictedContext->m_restoreAllowed) {
186 forciblyEvictedContexts().remove(0); 165 forciblyEvictedContexts().remove(0);
187 continue; 166 continue;
188 } 167 }
189 168
190 IntSize desiredSize = evictedContext->m_drawingBuffer->adjustSize(evicte dContext->clampedCanvasSize()); 169 IntSize desiredSize = evictedContext->m_drawingBuffer->adjustSize(evicte dContext->clampedCanvasSize());
191 170
192 // If there's room in the pixel budget for this context, restore it. 171 // If there's room in the pixel budget for this context, restore it.
193 if (!desiredSize.isEmpty()) { 172 if (!desiredSize.isEmpty()) {
194 forciblyEvictedContexts().remove(0); 173 forciblyEvictedContexts().remove(0);
195 evictedContext->forceRestoreContext(); 174 evictedContext->forceRestoreContext();
196 activeContexts().append(evictedContext); 175 activeContexts().append(evictedContext);
197 } 176 }
198 break; 177 break;
199 } 178 }
200 } 179 }
201 180
202 class WebGLRenderingContextEvictionManager : public ContextEvictionManager { 181 class WebGLRenderingContextEvictionManager : public ContextEvictionManager {
203 public: 182 public:
204 void forciblyLoseOldestContext(const String& reason) { 183 void forciblyLoseOldestContext(const String& reason) {
205 WebGLRenderingContext::forciblyLoseOldestContext(reason); 184 WebGLRenderingContextBase::forciblyLoseOldestContext(reason);
206 }; 185 };
207 IntSize oldestContextSize() { 186 IntSize oldestContextSize() {
208 return WebGLRenderingContext::oldestContextSize(); 187 return WebGLRenderingContextBase::oldestContextSize();
209 }; 188 };
210 }; 189 };
211 190
212 namespace { 191 namespace {
213 192
214 class ScopedDrawingBufferBinder { 193 class ScopedDrawingBufferBinder {
215 public: 194 public:
216 ScopedDrawingBufferBinder(DrawingBuffer* drawingBuffer, WebGLFramebuffer * framebufferBinding) 195 ScopedDrawingBufferBinder(DrawingBuffer* drawingBuffer, WebGLFramebuffer * framebufferBinding)
217 : m_drawingBuffer(drawingBuffer) 196 : m_drawingBuffer(drawingBuffer)
218 , m_framebufferBinding(framebufferBinding) 197 , m_framebufferBinding(framebufferBinding)
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 // want or need to just emit a space per character to try 430 // want or need to just emit a space per character to try
452 // to preserve column numbers for debugging purposes. 431 // to preserve column numbers for debugging purposes.
453 break; 432 break;
454 } 433 }
455 } 434 }
456 } // namespace anonymous 435 } // namespace anonymous
457 436
458 class WebGLRenderingContextLostCallback : public blink::WebGraphicsContext3D::We bGraphicsContextLostCallback { 437 class WebGLRenderingContextLostCallback : public blink::WebGraphicsContext3D::We bGraphicsContextLostCallback {
459 WTF_MAKE_FAST_ALLOCATED; 438 WTF_MAKE_FAST_ALLOCATED;
460 public: 439 public:
461 explicit WebGLRenderingContextLostCallback(WebGLRenderingContext* cb) : m_co ntext(cb) { } 440 explicit WebGLRenderingContextLostCallback(WebGLRenderingContextBase* cb) : m_context(cb) { }
462 virtual void onContextLost() { m_context->forceLostContext(WebGLRenderingCon text::RealLostContext); } 441 virtual void onContextLost() { m_context->forceLostContext(WebGLRenderingCon textBase::RealLostContext); }
463 virtual ~WebGLRenderingContextLostCallback() {} 442 virtual ~WebGLRenderingContextLostCallback() {}
464 private: 443 private:
465 WebGLRenderingContext* m_context; 444 WebGLRenderingContextBase* m_context;
466 }; 445 };
467 446
468 class WebGLRenderingContextErrorMessageCallback : public blink::WebGraphicsConte xt3D::WebGraphicsErrorMessageCallback { 447 class WebGLRenderingContextErrorMessageCallback : public blink::WebGraphicsConte xt3D::WebGraphicsErrorMessageCallback {
469 WTF_MAKE_FAST_ALLOCATED; 448 WTF_MAKE_FAST_ALLOCATED;
470 public: 449 public:
471 explicit WebGLRenderingContextErrorMessageCallback(WebGLRenderingContext* cb ) : m_context(cb) { } 450 explicit WebGLRenderingContextErrorMessageCallback(WebGLRenderingContextBase * cb) : m_context(cb) { }
472 virtual void onErrorMessage(const blink::WebString& message, blink::WGC3Dint ) 451 virtual void onErrorMessage(const blink::WebString& message, blink::WGC3Dint )
473 { 452 {
474 if (m_context->m_synthesizedErrorsToConsole) 453 if (m_context->m_synthesizedErrorsToConsole)
475 m_context->printGLErrorToConsole(message); 454 m_context->printGLErrorToConsole(message);
476 InspectorInstrumentation::didFireWebGLErrorOrWarning(m_context->canvas() , message); 455 InspectorInstrumentation::didFireWebGLErrorOrWarning(m_context->canvas() , message);
477 } 456 }
478 virtual ~WebGLRenderingContextErrorMessageCallback() { } 457 virtual ~WebGLRenderingContextErrorMessageCallback() { }
479 private: 458 private:
480 WebGLRenderingContext* m_context; 459 WebGLRenderingContextBase* m_context;
481 }; 460 };
482 461
483 PassOwnPtr<WebGLRenderingContext> WebGLRenderingContext::create(HTMLCanvasElemen t* canvas, WebGLContextAttributes* attrs) 462 WebGLRenderingContextBase::WebGLRenderingContextBase(HTMLCanvasElement* passedCa nvas, PassOwnPtr<blink::WebGraphicsContext3D> context, WebGLContextAttributes* r equestedAttributes)
484 {
485 Document& document = canvas->document();
486 Frame* frame = document.frame();
487 if (!frame)
488 return nullptr;
489 Settings* settings = frame->settings();
490
491 // The FrameLoaderClient might block creation of a new WebGL context despite the page settings; in
492 // particular, if WebGL contexts were lost one or more times via the GL_ARB_ robustness extension.
493 if (!frame->loader().client()->allowWebGL(settings && settings->webGLEnabled ())) {
494 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Web page was not allowed to create a WebGL cont ext."));
495 return nullptr;
496 }
497
498 // The only situation that attrs is null is through Document::getCSSCanvasCo ntext().
499 RefPtr<WebGLContextAttributes> defaultAttrs;
500 if (!attrs) {
501 defaultAttrs = WebGLContextAttributes::create();
502 attrs = defaultAttrs.get();
503 }
504 blink::WebGraphicsContext3D::Attributes attributes = attrs->attributes(docum ent.topDocument()->url().string(), settings);
505 OwnPtr<blink::WebGraphicsContext3D> context = adoptPtr(blink::Platform::curr ent()->createOffscreenGraphicsContext3D(attributes));
506 if (!context || !context->makeContextCurrent()) {
507 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Could not create a WebGL context."));
508 return nullptr;
509 }
510
511 Extensions3DUtil extensionsUtil(context.get());
512 if (extensionsUtil.supportsExtension("GL_EXT_debug_marker"))
513 context->pushGroupMarkerEXT("WebGLRenderingContext");
514
515 OwnPtr<WebGLRenderingContext> renderingContext = adoptPtr(new WebGLRendering Context(canvas, context.release(), attrs));
516 renderingContext->suspendIfNeeded();
517
518 if (renderingContext->m_drawingBuffer->isZeroSized()) {
519 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Could not create a WebGL context."));
520 return nullptr;
521 }
522
523 return renderingContext.release();
524 }
525
526 WebGLRenderingContext::WebGLRenderingContext(HTMLCanvasElement* passedCanvas, Pa ssOwnPtr<blink::WebGraphicsContext3D> context, WebGLContextAttributes* requested Attributes)
527 : CanvasRenderingContext(passedCanvas) 463 : CanvasRenderingContext(passedCanvas)
528 , ActiveDOMObject(&passedCanvas->document()) 464 , ActiveDOMObject(&passedCanvas->document())
529 , m_context(context) 465 , m_context(context)
530 , m_drawingBuffer(0) 466 , m_drawingBuffer(0)
531 , m_dispatchContextLostEventTimer(this, &WebGLRenderingContext::dispatchCont extLostEvent) 467 , m_dispatchContextLostEventTimer(this, &WebGLRenderingContextBase::dispatch ContextLostEvent)
532 , m_restoreAllowed(false) 468 , m_restoreAllowed(false)
533 , m_restoreTimer(this, &WebGLRenderingContext::maybeRestoreContext) 469 , m_restoreTimer(this, &WebGLRenderingContextBase::maybeRestoreContext)
534 , m_generatedImageCache(4) 470 , m_generatedImageCache(4)
535 , m_contextLost(false) 471 , m_contextLost(false)
536 , m_contextLostMode(SyntheticLostContext) 472 , m_contextLostMode(SyntheticLostContext)
537 , m_requestedAttributes(requestedAttributes->clone()) 473 , m_requestedAttributes(requestedAttributes->clone())
538 , m_synthesizedErrorsToConsole(true) 474 , m_synthesizedErrorsToConsole(true)
539 , m_numGLErrorsToConsoleAllowed(maxGLErrorsAllowedToConsole) 475 , m_numGLErrorsToConsoleAllowed(maxGLErrorsAllowedToConsole)
540 , m_multisamplingAllowed(false) 476 , m_multisamplingAllowed(false)
541 , m_multisamplingObserverRegistered(false) 477 , m_multisamplingObserverRegistered(false)
542 , m_onePlusMaxEnabledAttribIndex(0) 478 , m_onePlusMaxEnabledAttribIndex(0)
543 , m_onePlusMaxNonDefaultTextureUnit(0) 479 , m_onePlusMaxNonDefaultTextureUnit(0)
(...skipping 11 matching lines...) Expand all
555 491
556 // Create the DrawingBuffer and initialize the platform layer. 492 // Create the DrawingBuffer and initialize the platform layer.
557 DrawingBuffer::PreserveDrawingBuffer preserve = requestedAttributes->preserv eDrawingBuffer() ? DrawingBuffer::Preserve : DrawingBuffer::Discard; 493 DrawingBuffer::PreserveDrawingBuffer preserve = requestedAttributes->preserv eDrawingBuffer() ? DrawingBuffer::Preserve : DrawingBuffer::Discard;
558 m_drawingBuffer = DrawingBuffer::create(m_context.get(), clampedCanvasSize() , preserve, contextEvictionManager.release()); 494 m_drawingBuffer = DrawingBuffer::create(m_context.get(), clampedCanvasSize() , preserve, contextEvictionManager.release());
559 495
560 if (!m_drawingBuffer->isZeroSized()) { 496 if (!m_drawingBuffer->isZeroSized()) {
561 m_drawingBuffer->bind(); 497 m_drawingBuffer->bind();
562 setupFlags(); 498 setupFlags();
563 initializeNewContext(); 499 initializeNewContext();
564 } 500 }
565
566 // Register extensions.
567 static const char* const webkitPrefix[] = { "WEBKIT_", 0, };
568 static const char* const bothPrefixes[] = { "", "WEBKIT_", 0, };
569
570 registerExtension<ANGLEInstancedArrays>(m_angleInstancedArrays);
571 registerExtension<EXTTextureFilterAnisotropic>(m_extTextureFilterAnisotropic , PrefixedExtension, webkitPrefix);
572 registerExtension<OESElementIndexUint>(m_oesElementIndexUint);
573 registerExtension<OESStandardDerivatives>(m_oesStandardDerivatives);
574 registerExtension<OESTextureFloat>(m_oesTextureFloat);
575 registerExtension<OESTextureFloatLinear>(m_oesTextureFloatLinear);
576 registerExtension<OESTextureHalfFloat>(m_oesTextureHalfFloat);
577 registerExtension<OESTextureHalfFloatLinear>(m_oesTextureHalfFloatLinear);
578 registerExtension<OESVertexArrayObject>(m_oesVertexArrayObject);
579 registerExtension<WebGLCompressedTextureATC>(m_webglCompressedTextureATC, Pr efixedExtension, webkitPrefix);
580 registerExtension<WebGLCompressedTexturePVRTC>(m_webglCompressedTexturePVRTC , PrefixedExtension, webkitPrefix);
581 registerExtension<WebGLCompressedTextureS3TC>(m_webglCompressedTextureS3TC, PrefixedExtension, bothPrefixes);
582 registerExtension<WebGLDepthTexture>(m_webglDepthTexture, PrefixedExtension, bothPrefixes);
583 registerExtension<WebGLDrawBuffers>(m_webglDrawBuffers);
584 registerExtension<WebGLLoseContext>(m_webglLoseContext, ApprovedExtension, b othPrefixes);
585
586 // Register draft extensions.
587 registerExtension<EXTFragDepth>(m_extFragDepth, DraftExtension);
588
589 // Register privileged extensions.
590 registerExtension<WebGLDebugRendererInfo>(m_webglDebugRendererInfo, WebGLDeb ugRendererInfoExtension);
591 registerExtension<WebGLDebugShaders>(m_webglDebugShaders, PrivilegedExtensio n);
592 } 501 }
593 502
594 void WebGLRenderingContext::initializeNewContext() 503 void WebGLRenderingContextBase::initializeNewContext()
595 { 504 {
596 ASSERT(!isContextLost()); 505 ASSERT(!isContextLost());
597 m_needsUpdate = true; 506 m_needsUpdate = true;
598 m_markedCanvasDirty = false; 507 m_markedCanvasDirty = false;
599 m_activeTextureUnit = 0; 508 m_activeTextureUnit = 0;
600 m_packAlignment = 4; 509 m_packAlignment = 4;
601 m_unpackAlignment = 4; 510 m_unpackAlignment = 4;
602 m_unpackFlipY = false; 511 m_unpackFlipY = false;
603 m_unpackPremultiplyAlpha = false; 512 m_unpackPremultiplyAlpha = false;
604 m_unpackColorspaceConversion = GC3D_BROWSER_DEFAULT_WEBGL; 513 m_unpackColorspaceConversion = GC3D_BROWSER_DEFAULT_WEBGL;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 572
664 m_contextLostCallbackAdapter = adoptPtr(new WebGLRenderingContextLostCallbac k(this)); 573 m_contextLostCallbackAdapter = adoptPtr(new WebGLRenderingContextLostCallbac k(this));
665 m_errorMessageCallbackAdapter = adoptPtr(new WebGLRenderingContextErrorMessa geCallback(this)); 574 m_errorMessageCallbackAdapter = adoptPtr(new WebGLRenderingContextErrorMessa geCallback(this));
666 575
667 m_context->setContextLostCallback(m_contextLostCallbackAdapter.get()); 576 m_context->setContextLostCallback(m_contextLostCallbackAdapter.get());
668 m_context->setErrorMessageCallback(m_errorMessageCallbackAdapter.get()); 577 m_context->setErrorMessageCallback(m_errorMessageCallbackAdapter.get());
669 578
670 // This ensures that the context has a valid "lastFlushID" and won't be mist akenly identified as the "least recently used" context. 579 // This ensures that the context has a valid "lastFlushID" and won't be mist akenly identified as the "least recently used" context.
671 m_context->flush(); 580 m_context->flush();
672 581
582 for (int i = 0; i < WebGLExtensionNameCount; ++i)
583 m_extensionEnabled[i] = false;
584
673 activateContext(this); 585 activateContext(this);
674 } 586 }
675 587
676 void WebGLRenderingContext::setupFlags() 588 void WebGLRenderingContextBase::setupFlags()
677 { 589 {
678 ASSERT(m_context); 590 ASSERT(m_context);
679 if (Page* p = canvas()->document().page()) { 591 if (Page* p = canvas()->document().page()) {
680 m_synthesizedErrorsToConsole = p->settings().webGLErrorsToConsoleEnabled (); 592 m_synthesizedErrorsToConsole = p->settings().webGLErrorsToConsoleEnabled ();
681 593
682 if (!m_multisamplingObserverRegistered && m_requestedAttributes->antiali as()) { 594 if (!m_multisamplingObserverRegistered && m_requestedAttributes->antiali as()) {
683 m_multisamplingAllowed = m_drawingBuffer->multisample(); 595 m_multisamplingAllowed = m_drawingBuffer->multisample();
684 p->addMultisamplingChangedObserver(this); 596 p->addMultisamplingChangedObserver(this);
685 m_multisamplingObserverRegistered = true; 597 m_multisamplingObserverRegistered = true;
686 } 598 }
687 } 599 }
688 600
689 m_isGLES2NPOTStrict = !extensionsUtil()->isExtensionEnabled("GL_OES_texture_ npot"); 601 m_isGLES2NPOTStrict = !extensionsUtil()->isExtensionEnabled("GL_OES_texture_ npot");
690 m_isDepthStencilSupported = extensionsUtil()->isExtensionEnabled("GL_OES_pac ked_depth_stencil"); 602 m_isDepthStencilSupported = extensionsUtil()->isExtensionEnabled("GL_OES_pac ked_depth_stencil");
691 } 603 }
692 604
693 bool WebGLRenderingContext::allowPrivilegedExtensions() const 605 bool WebGLRenderingContextBase::allowPrivilegedExtensions() const
694 { 606 {
695 if (Page* p = canvas()->document().page()) 607 if (Page* p = canvas()->document().page())
696 return p->settings().privilegedWebGLExtensionsEnabled(); 608 return p->settings().privilegedWebGLExtensionsEnabled();
697 return false; 609 return false;
698 } 610 }
699 611
700 bool WebGLRenderingContext::allowWebGLDebugRendererInfo() const 612 bool WebGLRenderingContextBase::allowWebGLDebugRendererInfo() const
701 { 613 {
702 return true; 614 return true;
703 } 615 }
704 616
705 void WebGLRenderingContext::addCompressedTextureFormat(GLenum format) 617 void WebGLRenderingContextBase::addCompressedTextureFormat(GLenum format)
706 { 618 {
707 if (!m_compressedTextureFormats.contains(format)) 619 if (!m_compressedTextureFormats.contains(format))
708 m_compressedTextureFormats.append(format); 620 m_compressedTextureFormats.append(format);
709 } 621 }
710 622
711 void WebGLRenderingContext::removeAllCompressedTextureFormats() 623 void WebGLRenderingContextBase::removeAllCompressedTextureFormats()
712 { 624 {
713 m_compressedTextureFormats.clear(); 625 m_compressedTextureFormats.clear();
714 } 626 }
715 627
716 WebGLRenderingContext::~WebGLRenderingContext() 628 // Helper function for V8 bindings to identify what version of WebGL a CanvasRen deringContext supports.
629 unsigned WebGLRenderingContextBase::getWebGLVersion(CanvasRenderingContext* cont ext)
630 {
631 if (!context->is3d())
632 return 0;
633 return static_cast<WebGLRenderingContextBase*>(context)->version();
634 }
635
636 WebGLRenderingContextBase::~WebGLRenderingContextBase()
717 { 637 {
718 // Remove all references to WebGLObjects so if they are the last reference 638 // Remove all references to WebGLObjects so if they are the last reference
719 // they will be freed before the last context is removed from the context gr oup. 639 // they will be freed before the last context is removed from the context gr oup.
720 m_boundArrayBuffer = 0; 640 m_boundArrayBuffer = 0;
721 m_defaultVertexArrayObject = 0; 641 m_defaultVertexArrayObject = 0;
722 m_boundVertexArrayObject = 0; 642 m_boundVertexArrayObject = 0;
723 m_vertexAttrib0Buffer = 0; 643 m_vertexAttrib0Buffer = 0;
724 m_currentProgram = 0; 644 m_currentProgram = 0;
725 m_framebufferBinding = 0; 645 m_framebufferBinding = 0;
726 m_renderbufferBinding = 0; 646 m_renderbufferBinding = 0;
(...skipping 20 matching lines...) Expand all
747 667
748 if (m_multisamplingObserverRegistered) { 668 if (m_multisamplingObserverRegistered) {
749 Page* page = canvas()->document().page(); 669 Page* page = canvas()->document().page();
750 if (page) 670 if (page)
751 page->removeMultisamplingChangedObserver(this); 671 page->removeMultisamplingChangedObserver(this);
752 } 672 }
753 673
754 willDestroyContext(this); 674 willDestroyContext(this);
755 } 675 }
756 676
757 void WebGLRenderingContext::destroyContext() 677 void WebGLRenderingContextBase::destroyContext()
758 { 678 {
759 m_contextLost = true; 679 m_contextLost = true;
760 680
761 // The drawing buffer holds a context reference. It must also be destroyed 681 // The drawing buffer holds a context reference. It must also be destroyed
762 // in order for the context to be released. 682 // in order for the context to be released.
763 m_drawingBuffer->releaseResources(); 683 m_drawingBuffer->releaseResources();
764 684
765 m_extensionsUtil.clear(); 685 m_extensionsUtil.clear();
766 686
767 if (m_context) { 687 if (m_context) {
768 m_context->setContextLostCallback(0); 688 m_context->setContextLostCallback(0);
769 m_context->setErrorMessageCallback(0); 689 m_context->setErrorMessageCallback(0);
770 m_context.clear(); 690 m_context.clear();
771 } 691 }
772 } 692 }
773 693
774 void WebGLRenderingContext::markContextChanged() 694 void WebGLRenderingContextBase::markContextChanged()
775 { 695 {
776 if (m_framebufferBinding || isContextLost()) 696 if (m_framebufferBinding || isContextLost())
777 return; 697 return;
778 698
779 m_drawingBuffer->markContentsChanged(); 699 m_drawingBuffer->markContentsChanged();
780 700
781 m_layerCleared = false; 701 m_layerCleared = false;
782 RenderBox* renderBox = canvas()->renderBox(); 702 RenderBox* renderBox = canvas()->renderBox();
783 if (renderBox && renderBox->hasAcceleratedCompositing()) { 703 if (renderBox && renderBox->hasAcceleratedCompositing()) {
784 m_markedCanvasDirty = true; 704 m_markedCanvasDirty = true;
785 canvas()->clearCopiedImage(); 705 canvas()->clearCopiedImage();
786 renderBox->contentChanged(CanvasChanged); 706 renderBox->contentChanged(CanvasChanged);
787 } else { 707 } else {
788 if (!m_markedCanvasDirty) { 708 if (!m_markedCanvasDirty) {
789 m_markedCanvasDirty = true; 709 m_markedCanvasDirty = true;
790 canvas()->didDraw(FloatRect(FloatPoint(0, 0), clampedCanvasSize())); 710 canvas()->didDraw(FloatRect(FloatPoint(0, 0), clampedCanvasSize()));
791 } 711 }
792 } 712 }
793 } 713 }
794 714
795 bool WebGLRenderingContext::clearIfComposited(GLbitfield mask) 715 bool WebGLRenderingContextBase::clearIfComposited(GLbitfield mask)
796 { 716 {
797 if (isContextLost()) 717 if (isContextLost())
798 return false; 718 return false;
799 719
800 if (!m_drawingBuffer->layerComposited() || m_layerCleared 720 if (!m_drawingBuffer->layerComposited() || m_layerCleared
801 || m_requestedAttributes->preserveDrawingBuffer() || (mask && m_framebuf ferBinding)) 721 || m_requestedAttributes->preserveDrawingBuffer() || (mask && m_framebuf ferBinding))
802 return false; 722 return false;
803 723
804 RefPtr<WebGLContextAttributes> contextAttributes = getContextAttributes(); 724 RefPtr<WebGLContextAttributes> contextAttributes = getContextAttributes();
805 725
(...skipping 28 matching lines...) Expand all
834 m_drawingBuffer->clearFramebuffers(clearMask); 754 m_drawingBuffer->clearFramebuffers(clearMask);
835 755
836 restoreStateAfterClear(); 756 restoreStateAfterClear();
837 if (m_framebufferBinding) 757 if (m_framebufferBinding)
838 m_context->bindFramebuffer(GL_FRAMEBUFFER, objectOrZero(m_framebufferBin ding.get())); 758 m_context->bindFramebuffer(GL_FRAMEBUFFER, objectOrZero(m_framebufferBin ding.get()));
839 m_layerCleared = true; 759 m_layerCleared = true;
840 760
841 return combinedClear; 761 return combinedClear;
842 } 762 }
843 763
844 void WebGLRenderingContext::restoreStateAfterClear() 764 void WebGLRenderingContextBase::restoreStateAfterClear()
845 { 765 {
846 if (isContextLost()) 766 if (isContextLost())
847 return; 767 return;
848 768
849 // Restore the state that the context set. 769 // Restore the state that the context set.
850 if (m_scissorEnabled) 770 if (m_scissorEnabled)
851 m_context->enable(GL_SCISSOR_TEST); 771 m_context->enable(GL_SCISSOR_TEST);
852 m_context->clearColor(m_clearColor[0], m_clearColor[1], 772 m_context->clearColor(m_clearColor[0], m_clearColor[1],
853 m_clearColor[2], m_clearColor[3]); 773 m_clearColor[2], m_clearColor[3]);
854 m_context->colorMask(m_colorMask[0], m_colorMask[1], 774 m_context->colorMask(m_colorMask[0], m_colorMask[1],
855 m_colorMask[2], m_colorMask[3]); 775 m_colorMask[2], m_colorMask[3]);
856 m_context->clearDepth(m_clearDepth); 776 m_context->clearDepth(m_clearDepth);
857 m_context->clearStencil(m_clearStencil); 777 m_context->clearStencil(m_clearStencil);
858 m_context->stencilMaskSeparate(GL_FRONT, m_stencilMask); 778 m_context->stencilMaskSeparate(GL_FRONT, m_stencilMask);
859 m_context->depthMask(m_depthMask); 779 m_context->depthMask(m_depthMask);
860 } 780 }
861 781
862 void WebGLRenderingContext::markLayerComposited() 782 void WebGLRenderingContextBase::markLayerComposited()
863 { 783 {
864 if (!isContextLost()) 784 if (!isContextLost())
865 m_drawingBuffer->markLayerComposited(); 785 m_drawingBuffer->markLayerComposited();
866 } 786 }
867 787
868 void WebGLRenderingContext::paintRenderingResultsToCanvas() 788 void WebGLRenderingContextBase::paintRenderingResultsToCanvas()
869 { 789 {
870 if (isContextLost()) { 790 if (isContextLost()) {
871 canvas()->clearPresentationCopy(); 791 canvas()->clearPresentationCopy();
872 return; 792 return;
873 } 793 }
874 794
875 if (canvas()->document().printing()) 795 if (canvas()->document().printing())
876 canvas()->clearPresentationCopy(); 796 canvas()->clearPresentationCopy();
877 797
878 // Until the canvas is written to by the application, the clear that 798 // Until the canvas is written to by the application, the clear that
(...skipping 18 matching lines...) Expand all
897 if (canvas()->hasImageBuffer()) 817 if (canvas()->hasImageBuffer())
898 m_drawingBuffer->paintRenderingResultsToCanvas(canvas()->buffer()); 818 m_drawingBuffer->paintRenderingResultsToCanvas(canvas()->buffer());
899 } 819 }
900 820
901 if (m_framebufferBinding) 821 if (m_framebufferBinding)
902 m_context->bindFramebuffer(GL_FRAMEBUFFER, objectOrZero(m_framebufferBin ding.get())); 822 m_context->bindFramebuffer(GL_FRAMEBUFFER, objectOrZero(m_framebufferBin ding.get()));
903 else 823 else
904 m_drawingBuffer->bind(); 824 m_drawingBuffer->bind();
905 } 825 }
906 826
907 PassRefPtr<ImageData> WebGLRenderingContext::paintRenderingResultsToImageData() 827 PassRefPtr<ImageData> WebGLRenderingContextBase::paintRenderingResultsToImageDat a()
908 { 828 {
909 if (isContextLost()) 829 if (isContextLost())
910 return 0; 830 return 0;
911 831
912 clearIfComposited(); 832 clearIfComposited();
913 m_drawingBuffer->commit(); 833 m_drawingBuffer->commit();
914 int width, height; 834 int width, height;
915 RefPtr<Uint8ClampedArray> imageDataPixels = m_drawingBuffer->paintRenderingR esultsToImageData(width, height); 835 RefPtr<Uint8ClampedArray> imageDataPixels = m_drawingBuffer->paintRenderingR esultsToImageData(width, height);
916 if (!imageDataPixels) 836 if (!imageDataPixels)
917 return 0; 837 return 0;
918 838
919 if (m_framebufferBinding) 839 if (m_framebufferBinding)
920 m_context->bindFramebuffer(GL_FRAMEBUFFER, objectOrZero(m_framebufferBin ding.get())); 840 m_context->bindFramebuffer(GL_FRAMEBUFFER, objectOrZero(m_framebufferBin ding.get()));
921 else 841 else
922 m_drawingBuffer->bind(); 842 m_drawingBuffer->bind();
923 843
924 return ImageData::create(IntSize(width, height), imageDataPixels); 844 return ImageData::create(IntSize(width, height), imageDataPixels);
925 } 845 }
926 846
927 void WebGLRenderingContext::reshape(int width, int height) 847 void WebGLRenderingContextBase::reshape(int width, int height)
928 { 848 {
929 if (isContextLost()) 849 if (isContextLost())
930 return; 850 return;
931 851
932 // This is an approximation because at WebGLRenderingContext level we don't 852 // This is an approximation because at WebGLRenderingContextBase level we do n't
933 // know if the underlying FBO uses textures or renderbuffers. 853 // know if the underlying FBO uses textures or renderbuffers.
934 GLint maxSize = std::min(m_maxTextureSize, m_maxRenderbufferSize); 854 GLint maxSize = std::min(m_maxTextureSize, m_maxRenderbufferSize);
935 // Limit drawing buffer size to 4k to avoid memory exhaustion. 855 // Limit drawing buffer size to 4k to avoid memory exhaustion.
936 const int sizeUpperLimit = 4096; 856 const int sizeUpperLimit = 4096;
937 maxSize = std::min(maxSize, sizeUpperLimit); 857 maxSize = std::min(maxSize, sizeUpperLimit);
938 GLint maxWidth = std::min(maxSize, m_maxViewportDims[0]); 858 GLint maxWidth = std::min(maxSize, m_maxViewportDims[0]);
939 GLint maxHeight = std::min(maxSize, m_maxViewportDims[1]); 859 GLint maxHeight = std::min(maxSize, m_maxViewportDims[1]);
940 width = clamp(width, 1, maxWidth); 860 width = clamp(width, 1, maxWidth);
941 height = clamp(height, 1, maxHeight); 861 height = clamp(height, 1, maxHeight);
942 862
943 if (m_needsUpdate) { 863 if (m_needsUpdate) {
944 RenderBox* renderBox = canvas()->renderBox(); 864 RenderBox* renderBox = canvas()->renderBox();
945 if (renderBox && renderBox->hasAcceleratedCompositing()) 865 if (renderBox && renderBox->hasAcceleratedCompositing())
946 renderBox->contentChanged(CanvasChanged); 866 renderBox->contentChanged(CanvasChanged);
947 m_needsUpdate = false; 867 m_needsUpdate = false;
948 } 868 }
949 869
950 // We don't have to mark the canvas as dirty, since the newly created image buffer will also start off 870 // We don't have to mark the canvas as dirty, since the newly created image buffer will also start off
951 // clear (and this matches what reshape will do). 871 // clear (and this matches what reshape will do).
952 m_drawingBuffer->reset(IntSize(width, height)); 872 m_drawingBuffer->reset(IntSize(width, height));
953 restoreStateAfterClear(); 873 restoreStateAfterClear();
954 874
955 m_context->bindTexture(GL_TEXTURE_2D, objectOrZero(m_textureUnits[m_activeTe xtureUnit].m_texture2DBinding.get())); 875 m_context->bindTexture(GL_TEXTURE_2D, objectOrZero(m_textureUnits[m_activeTe xtureUnit].m_texture2DBinding.get()));
956 m_context->bindRenderbuffer(GL_RENDERBUFFER, objectOrZero(m_renderbufferBind ing.get())); 876 m_context->bindRenderbuffer(GL_RENDERBUFFER, objectOrZero(m_renderbufferBind ing.get()));
957 if (m_framebufferBinding) 877 if (m_framebufferBinding)
958 m_context->bindFramebuffer(GL_FRAMEBUFFER, objectOrZero(m_framebufferBin ding.get())); 878 m_context->bindFramebuffer(GL_FRAMEBUFFER, objectOrZero(m_framebufferBin ding.get()));
959 } 879 }
960 880
961 int WebGLRenderingContext::drawingBufferWidth() const 881 int WebGLRenderingContextBase::drawingBufferWidth() const
962 { 882 {
963 return m_drawingBuffer->size().width(); 883 return m_drawingBuffer->size().width();
964 } 884 }
965 885
966 int WebGLRenderingContext::drawingBufferHeight() const 886 int WebGLRenderingContextBase::drawingBufferHeight() const
967 { 887 {
968 return m_drawingBuffer->size().height(); 888 return m_drawingBuffer->size().height();
969 } 889 }
970 890
971 unsigned WebGLRenderingContext::sizeInBytes(GLenum type) 891 unsigned WebGLRenderingContextBase::sizeInBytes(GLenum type)
972 { 892 {
973 switch (type) { 893 switch (type) {
974 case GL_BYTE: 894 case GL_BYTE:
975 return sizeof(GLbyte); 895 return sizeof(GLbyte);
976 case GL_UNSIGNED_BYTE: 896 case GL_UNSIGNED_BYTE:
977 return sizeof(GLubyte); 897 return sizeof(GLubyte);
978 case GL_SHORT: 898 case GL_SHORT:
979 return sizeof(GLshort); 899 return sizeof(GLshort);
980 case GL_UNSIGNED_SHORT: 900 case GL_UNSIGNED_SHORT:
981 return sizeof(GLushort); 901 return sizeof(GLushort);
982 case GL_INT: 902 case GL_INT:
983 return sizeof(GLint); 903 return sizeof(GLint);
984 case GL_UNSIGNED_INT: 904 case GL_UNSIGNED_INT:
985 return sizeof(GLuint); 905 return sizeof(GLuint);
986 case GL_FLOAT: 906 case GL_FLOAT:
987 return sizeof(GLfloat); 907 return sizeof(GLfloat);
988 } 908 }
989 ASSERT_NOT_REACHED(); 909 ASSERT_NOT_REACHED();
990 return 0; 910 return 0;
991 } 911 }
992 912
993 void WebGLRenderingContext::activeTexture(GLenum texture) 913 void WebGLRenderingContextBase::activeTexture(GLenum texture)
994 { 914 {
995 if (isContextLost()) 915 if (isContextLost())
996 return; 916 return;
997 if (texture - GL_TEXTURE0 >= m_textureUnits.size()) { 917 if (texture - GL_TEXTURE0 >= m_textureUnits.size()) {
998 synthesizeGLError(GL_INVALID_ENUM, "activeTexture", "texture unit out of range"); 918 synthesizeGLError(GL_INVALID_ENUM, "activeTexture", "texture unit out of range");
999 return; 919 return;
1000 } 920 }
1001 m_activeTextureUnit = texture - GL_TEXTURE0; 921 m_activeTextureUnit = texture - GL_TEXTURE0;
1002 m_context->activeTexture(texture); 922 m_context->activeTexture(texture);
1003 923
1004 m_drawingBuffer->setActiveTextureUnit(texture); 924 m_drawingBuffer->setActiveTextureUnit(texture);
1005 925
1006 } 926 }
1007 927
1008 void WebGLRenderingContext::attachShader(WebGLProgram* program, WebGLShader* sha der) 928 void WebGLRenderingContextBase::attachShader(WebGLProgram* program, WebGLShader* shader)
1009 { 929 {
1010 if (isContextLost() || !validateWebGLObject("attachShader", program) || !val idateWebGLObject("attachShader", shader)) 930 if (isContextLost() || !validateWebGLObject("attachShader", program) || !val idateWebGLObject("attachShader", shader))
1011 return; 931 return;
1012 if (!program->attachShader(shader)) { 932 if (!program->attachShader(shader)) {
1013 synthesizeGLError(GL_INVALID_OPERATION, "attachShader", "shader attachme nt already has shader"); 933 synthesizeGLError(GL_INVALID_OPERATION, "attachShader", "shader attachme nt already has shader");
1014 return; 934 return;
1015 } 935 }
1016 m_context->attachShader(objectOrZero(program), objectOrZero(shader)); 936 m_context->attachShader(objectOrZero(program), objectOrZero(shader));
1017 shader->onAttached(); 937 shader->onAttached();
1018 } 938 }
1019 939
1020 void WebGLRenderingContext::bindAttribLocation(WebGLProgram* program, GLuint ind ex, const String& name) 940 void WebGLRenderingContextBase::bindAttribLocation(WebGLProgram* program, GLuint index, const String& name)
1021 { 941 {
1022 if (isContextLost() || !validateWebGLObject("bindAttribLocation", program)) 942 if (isContextLost() || !validateWebGLObject("bindAttribLocation", program))
1023 return; 943 return;
1024 if (!validateLocationLength("bindAttribLocation", name)) 944 if (!validateLocationLength("bindAttribLocation", name))
1025 return; 945 return;
1026 if (!validateString("bindAttribLocation", name)) 946 if (!validateString("bindAttribLocation", name))
1027 return; 947 return;
1028 if (isPrefixReserved(name)) { 948 if (isPrefixReserved(name)) {
1029 synthesizeGLError(GL_INVALID_OPERATION, "bindAttribLocation", "reserved prefix"); 949 synthesizeGLError(GL_INVALID_OPERATION, "bindAttribLocation", "reserved prefix");
1030 return; 950 return;
1031 } 951 }
1032 if (index >= m_maxVertexAttribs) { 952 if (index >= m_maxVertexAttribs) {
1033 synthesizeGLError(GL_INVALID_VALUE, "bindAttribLocation", "index out of range"); 953 synthesizeGLError(GL_INVALID_VALUE, "bindAttribLocation", "index out of range");
1034 return; 954 return;
1035 } 955 }
1036 m_context->bindAttribLocation(objectOrZero(program), index, name.utf8().data ()); 956 m_context->bindAttribLocation(objectOrZero(program), index, name.utf8().data ());
1037 } 957 }
1038 958
1039 bool WebGLRenderingContext::checkObjectToBeBound(const char* functionName, WebGL Object* object, bool& deleted) 959 bool WebGLRenderingContextBase::checkObjectToBeBound(const char* functionName, W ebGLObject* object, bool& deleted)
1040 { 960 {
1041 deleted = false; 961 deleted = false;
1042 if (isContextLost()) 962 if (isContextLost())
1043 return false; 963 return false;
1044 if (object) { 964 if (object) {
1045 if (!object->validate(contextGroup(), this)) { 965 if (!object->validate(contextGroup(), this)) {
1046 synthesizeGLError(GL_INVALID_OPERATION, functionName, "object not fr om this context"); 966 synthesizeGLError(GL_INVALID_OPERATION, functionName, "object not fr om this context");
1047 return false; 967 return false;
1048 } 968 }
1049 deleted = !object->object(); 969 deleted = !object->object();
1050 } 970 }
1051 return true; 971 return true;
1052 } 972 }
1053 973
1054 void WebGLRenderingContext::bindBuffer(GLenum target, WebGLBuffer* buffer) 974 void WebGLRenderingContextBase::bindBuffer(GLenum target, WebGLBuffer* buffer)
1055 { 975 {
1056 bool deleted; 976 bool deleted;
1057 if (!checkObjectToBeBound("bindBuffer", buffer, deleted)) 977 if (!checkObjectToBeBound("bindBuffer", buffer, deleted))
1058 return; 978 return;
1059 if (deleted) 979 if (deleted)
1060 buffer = 0; 980 buffer = 0;
1061 if (buffer && buffer->getTarget() && buffer->getTarget() != target) { 981 if (buffer && buffer->getTarget() && buffer->getTarget() != target) {
1062 synthesizeGLError(GL_INVALID_OPERATION, "bindBuffer", "buffers can not b e used with multiple targets"); 982 synthesizeGLError(GL_INVALID_OPERATION, "bindBuffer", "buffers can not b e used with multiple targets");
1063 return; 983 return;
1064 } 984 }
1065 if (target == GL_ARRAY_BUFFER) 985 if (target == GL_ARRAY_BUFFER)
1066 m_boundArrayBuffer = buffer; 986 m_boundArrayBuffer = buffer;
1067 else if (target == GL_ELEMENT_ARRAY_BUFFER) 987 else if (target == GL_ELEMENT_ARRAY_BUFFER)
1068 m_boundVertexArrayObject->setElementArrayBuffer(buffer); 988 m_boundVertexArrayObject->setElementArrayBuffer(buffer);
1069 else { 989 else {
1070 synthesizeGLError(GL_INVALID_ENUM, "bindBuffer", "invalid target"); 990 synthesizeGLError(GL_INVALID_ENUM, "bindBuffer", "invalid target");
1071 return; 991 return;
1072 } 992 }
1073 993
1074 m_context->bindBuffer(target, objectOrZero(buffer)); 994 m_context->bindBuffer(target, objectOrZero(buffer));
1075 if (buffer) 995 if (buffer)
1076 buffer->setTarget(target); 996 buffer->setTarget(target);
1077 } 997 }
1078 998
1079 void WebGLRenderingContext::bindFramebuffer(GLenum target, WebGLFramebuffer* buf fer) 999 void WebGLRenderingContextBase::bindFramebuffer(GLenum target, WebGLFramebuffer* buffer)
1080 { 1000 {
1081 bool deleted; 1001 bool deleted;
1082 if (!checkObjectToBeBound("bindFramebuffer", buffer, deleted)) 1002 if (!checkObjectToBeBound("bindFramebuffer", buffer, deleted))
1083 return; 1003 return;
1084 if (deleted) 1004 if (deleted)
1085 buffer = 0; 1005 buffer = 0;
1086 if (target != GL_FRAMEBUFFER) { 1006 if (target != GL_FRAMEBUFFER) {
1087 synthesizeGLError(GL_INVALID_ENUM, "bindFramebuffer", "invalid target"); 1007 synthesizeGLError(GL_INVALID_ENUM, "bindFramebuffer", "invalid target");
1088 return; 1008 return;
1089 } 1009 }
1090 m_framebufferBinding = buffer; 1010 m_framebufferBinding = buffer;
1091 m_drawingBuffer->setFramebufferBinding(objectOrZero(m_framebufferBinding.get ())); 1011 m_drawingBuffer->setFramebufferBinding(objectOrZero(m_framebufferBinding.get ()));
1092 if (!m_framebufferBinding) { 1012 if (!m_framebufferBinding) {
1093 // Instead of binding fb 0, bind the drawing buffer. 1013 // Instead of binding fb 0, bind the drawing buffer.
1094 m_drawingBuffer->bind(); 1014 m_drawingBuffer->bind();
1095 } else 1015 } else
1096 m_context->bindFramebuffer(target, objectOrZero(buffer)); 1016 m_context->bindFramebuffer(target, objectOrZero(buffer));
1097 if (buffer) 1017 if (buffer)
1098 buffer->setHasEverBeenBound(); 1018 buffer->setHasEverBeenBound();
1099 applyStencilTest(); 1019 applyStencilTest();
1100 } 1020 }
1101 1021
1102 void WebGLRenderingContext::bindRenderbuffer(GLenum target, WebGLRenderbuffer* r enderBuffer) 1022 void WebGLRenderingContextBase::bindRenderbuffer(GLenum target, WebGLRenderbuffe r* renderBuffer)
1103 { 1023 {
1104 bool deleted; 1024 bool deleted;
1105 if (!checkObjectToBeBound("bindRenderbuffer", renderBuffer, deleted)) 1025 if (!checkObjectToBeBound("bindRenderbuffer", renderBuffer, deleted))
1106 return; 1026 return;
1107 if (deleted) 1027 if (deleted)
1108 renderBuffer = 0; 1028 renderBuffer = 0;
1109 if (target != GL_RENDERBUFFER) { 1029 if (target != GL_RENDERBUFFER) {
1110 synthesizeGLError(GL_INVALID_ENUM, "bindRenderbuffer", "invalid target") ; 1030 synthesizeGLError(GL_INVALID_ENUM, "bindRenderbuffer", "invalid target") ;
1111 return; 1031 return;
1112 } 1032 }
1113 m_renderbufferBinding = renderBuffer; 1033 m_renderbufferBinding = renderBuffer;
1114 m_context->bindRenderbuffer(target, objectOrZero(renderBuffer)); 1034 m_context->bindRenderbuffer(target, objectOrZero(renderBuffer));
1115 if (renderBuffer) 1035 if (renderBuffer)
1116 renderBuffer->setHasEverBeenBound(); 1036 renderBuffer->setHasEverBeenBound();
1117 } 1037 }
1118 1038
1119 void WebGLRenderingContext::bindTexture(GLenum target, WebGLTexture* texture) 1039 void WebGLRenderingContextBase::bindTexture(GLenum target, WebGLTexture* texture )
1120 { 1040 {
1121 bool deleted; 1041 bool deleted;
1122 if (!checkObjectToBeBound("bindTexture", texture, deleted)) 1042 if (!checkObjectToBeBound("bindTexture", texture, deleted))
1123 return; 1043 return;
1124 if (deleted) 1044 if (deleted)
1125 texture = 0; 1045 texture = 0;
1126 if (texture && texture->getTarget() && texture->getTarget() != target) { 1046 if (texture && texture->getTarget() && texture->getTarget() != target) {
1127 synthesizeGLError(GL_INVALID_OPERATION, "bindTexture", "textures can not be used with multiple targets"); 1047 synthesizeGLError(GL_INVALID_OPERATION, "bindTexture", "textures can not be used with multiple targets");
1128 return; 1048 return;
1129 } 1049 }
(...skipping 28 matching lines...) Expand all
1158 // repeat mode to CLAMP_TO_EDGE for cube map textures, because OpenGL 1078 // repeat mode to CLAMP_TO_EDGE for cube map textures, because OpenGL
1159 // ES 2.0 doesn't expose this flag (a bug in the specification) and 1079 // ES 2.0 doesn't expose this flag (a bug in the specification) and
1160 // otherwise the application has no control over the seams in this 1080 // otherwise the application has no control over the seams in this
1161 // dimension. However, it appears that supporting this properly on all 1081 // dimension. However, it appears that supporting this properly on all
1162 // platforms is fairly involved (will require a HashMap from texture ID 1082 // platforms is fairly involved (will require a HashMap from texture ID
1163 // in all ports), and we have not had any complaints, so the logic has 1083 // in all ports), and we have not had any complaints, so the logic has
1164 // been removed. 1084 // been removed.
1165 1085
1166 } 1086 }
1167 1087
1168 void WebGLRenderingContext::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) 1088 void WebGLRenderingContextBase::blendColor(GLfloat red, GLfloat green, GLfloat b lue, GLfloat alpha)
1169 { 1089 {
1170 if (isContextLost()) 1090 if (isContextLost())
1171 return; 1091 return;
1172 m_context->blendColor(red, green, blue, alpha); 1092 m_context->blendColor(red, green, blue, alpha);
1173 } 1093 }
1174 1094
1175 void WebGLRenderingContext::blendEquation(GLenum mode) 1095 void WebGLRenderingContextBase::blendEquation(GLenum mode)
1176 { 1096 {
1177 if (isContextLost() || !validateBlendEquation("blendEquation", mode)) 1097 if (isContextLost() || !validateBlendEquation("blendEquation", mode))
1178 return; 1098 return;
1179 m_context->blendEquation(mode); 1099 m_context->blendEquation(mode);
1180 } 1100 }
1181 1101
1182 void WebGLRenderingContext::blendEquationSeparate(GLenum modeRGB, GLenum modeAlp ha) 1102 void WebGLRenderingContextBase::blendEquationSeparate(GLenum modeRGB, GLenum mod eAlpha)
1183 { 1103 {
1184 if (isContextLost() || !validateBlendEquation("blendEquationSeparate", modeR GB) || !validateBlendEquation("blendEquationSeparate", modeAlpha)) 1104 if (isContextLost() || !validateBlendEquation("blendEquationSeparate", modeR GB) || !validateBlendEquation("blendEquationSeparate", modeAlpha))
1185 return; 1105 return;
1186 m_context->blendEquationSeparate(modeRGB, modeAlpha); 1106 m_context->blendEquationSeparate(modeRGB, modeAlpha);
1187 } 1107 }
1188 1108
1189 1109
1190 void WebGLRenderingContext::blendFunc(GLenum sfactor, GLenum dfactor) 1110 void WebGLRenderingContextBase::blendFunc(GLenum sfactor, GLenum dfactor)
1191 { 1111 {
1192 if (isContextLost() || !validateBlendFuncFactors("blendFunc", sfactor, dfact or)) 1112 if (isContextLost() || !validateBlendFuncFactors("blendFunc", sfactor, dfact or))
1193 return; 1113 return;
1194 m_context->blendFunc(sfactor, dfactor); 1114 m_context->blendFunc(sfactor, dfactor);
1195 } 1115 }
1196 1116
1197 void WebGLRenderingContext::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLen um srcAlpha, GLenum dstAlpha) 1117 void WebGLRenderingContextBase::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
1198 { 1118 {
1199 // Note: Alpha does not have the same restrictions as RGB. 1119 // Note: Alpha does not have the same restrictions as RGB.
1200 if (isContextLost() || !validateBlendFuncFactors("blendFuncSeparate", srcRGB , dstRGB)) 1120 if (isContextLost() || !validateBlendFuncFactors("blendFuncSeparate", srcRGB , dstRGB))
1201 return; 1121 return;
1202 m_context->blendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha); 1122 m_context->blendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
1203 } 1123 }
1204 1124
1205 void WebGLRenderingContext::bufferData(GLenum target, long long size, GLenum usa ge) 1125 void WebGLRenderingContextBase::bufferData(GLenum target, long long size, GLenum usage)
1206 { 1126 {
1207 if (isContextLost()) 1127 if (isContextLost())
1208 return; 1128 return;
1209 WebGLBuffer* buffer = validateBufferDataParameters("bufferData", target, usa ge); 1129 WebGLBuffer* buffer = validateBufferDataParameters("bufferData", target, usa ge);
1210 if (!buffer) 1130 if (!buffer)
1211 return; 1131 return;
1212 if (size < 0) { 1132 if (size < 0) {
1213 synthesizeGLError(GL_INVALID_VALUE, "bufferData", "size < 0"); 1133 synthesizeGLError(GL_INVALID_VALUE, "bufferData", "size < 0");
1214 return; 1134 return;
1215 } 1135 }
1216 if (!size) { 1136 if (!size) {
1217 synthesizeGLError(GL_INVALID_VALUE, "bufferData", "size == 0"); 1137 synthesizeGLError(GL_INVALID_VALUE, "bufferData", "size == 0");
1218 return; 1138 return;
1219 } 1139 }
1220 1140
1221 m_context->bufferData(target, static_cast<GLsizeiptr>(size), 0, usage); 1141 m_context->bufferData(target, static_cast<GLsizeiptr>(size), 0, usage);
1222 } 1142 }
1223 1143
1224 void WebGLRenderingContext::bufferData(GLenum target, ArrayBuffer* data, GLenum usage) 1144 void WebGLRenderingContextBase::bufferData(GLenum target, ArrayBuffer* data, GLe num usage)
1225 { 1145 {
1226 if (isContextLost()) 1146 if (isContextLost())
1227 return; 1147 return;
1228 WebGLBuffer* buffer = validateBufferDataParameters("bufferData", target, usa ge); 1148 WebGLBuffer* buffer = validateBufferDataParameters("bufferData", target, usa ge);
1229 if (!buffer) 1149 if (!buffer)
1230 return; 1150 return;
1231 if (!data) { 1151 if (!data) {
1232 synthesizeGLError(GL_INVALID_VALUE, "bufferData", "no data"); 1152 synthesizeGLError(GL_INVALID_VALUE, "bufferData", "no data");
1233 return; 1153 return;
1234 } 1154 }
1235 m_context->bufferData(target, data->byteLength(), data->data(), usage); 1155 m_context->bufferData(target, data->byteLength(), data->data(), usage);
1236 } 1156 }
1237 1157
1238 void WebGLRenderingContext::bufferData(GLenum target, ArrayBufferView* data, GLe num usage) 1158 void WebGLRenderingContextBase::bufferData(GLenum target, ArrayBufferView* data, GLenum usage)
1239 { 1159 {
1240 if (isContextLost()) 1160 if (isContextLost())
1241 return; 1161 return;
1242 WebGLBuffer* buffer = validateBufferDataParameters("bufferData", target, usa ge); 1162 WebGLBuffer* buffer = validateBufferDataParameters("bufferData", target, usa ge);
1243 if (!buffer) 1163 if (!buffer)
1244 return; 1164 return;
1245 if (!data) { 1165 if (!data) {
1246 synthesizeGLError(GL_INVALID_VALUE, "bufferData", "no data"); 1166 synthesizeGLError(GL_INVALID_VALUE, "bufferData", "no data");
1247 return; 1167 return;
1248 } 1168 }
1249 1169
1250 m_context->bufferData(target, data->byteLength(), data->baseAddress(), usage ); 1170 m_context->bufferData(target, data->byteLength(), data->baseAddress(), usage );
1251 } 1171 }
1252 1172
1253 void WebGLRenderingContext::bufferSubData(GLenum target, long long offset, Array Buffer* data) 1173 void WebGLRenderingContextBase::bufferSubData(GLenum target, long long offset, A rrayBuffer* data)
1254 { 1174 {
1255 if (isContextLost()) 1175 if (isContextLost())
1256 return; 1176 return;
1257 WebGLBuffer* buffer = validateBufferDataParameters("bufferSubData", target, GL_STATIC_DRAW); 1177 WebGLBuffer* buffer = validateBufferDataParameters("bufferSubData", target, GL_STATIC_DRAW);
1258 if (!buffer) 1178 if (!buffer)
1259 return; 1179 return;
1260 if (offset < 0) { 1180 if (offset < 0) {
1261 synthesizeGLError(GL_INVALID_VALUE, "bufferSubData", "offset < 0"); 1181 synthesizeGLError(GL_INVALID_VALUE, "bufferSubData", "offset < 0");
1262 return; 1182 return;
1263 } 1183 }
1264 if (!data) 1184 if (!data)
1265 return; 1185 return;
1266 1186
1267 m_context->bufferSubData(target, static_cast<GLintptr>(offset), data->byteLe ngth(), data->data()); 1187 m_context->bufferSubData(target, static_cast<GLintptr>(offset), data->byteLe ngth(), data->data());
1268 } 1188 }
1269 1189
1270 void WebGLRenderingContext::bufferSubData(GLenum target, long long offset, Array BufferView* data) 1190 void WebGLRenderingContextBase::bufferSubData(GLenum target, long long offset, A rrayBufferView* data)
1271 { 1191 {
1272 if (isContextLost()) 1192 if (isContextLost())
1273 return; 1193 return;
1274 WebGLBuffer* buffer = validateBufferDataParameters("bufferSubData", target, GL_STATIC_DRAW); 1194 WebGLBuffer* buffer = validateBufferDataParameters("bufferSubData", target, GL_STATIC_DRAW);
1275 if (!buffer) 1195 if (!buffer)
1276 return; 1196 return;
1277 if (offset < 0) { 1197 if (offset < 0) {
1278 synthesizeGLError(GL_INVALID_VALUE, "bufferSubData", "offset < 0"); 1198 synthesizeGLError(GL_INVALID_VALUE, "bufferSubData", "offset < 0");
1279 return; 1199 return;
1280 } 1200 }
1281 if (!data) 1201 if (!data)
1282 return; 1202 return;
1283 1203
1284 m_context->bufferSubData(target, static_cast<GLintptr>(offset), data->byteLe ngth(), data->baseAddress()); 1204 m_context->bufferSubData(target, static_cast<GLintptr>(offset), data->byteLe ngth(), data->baseAddress());
1285 } 1205 }
1286 1206
1287 GLenum WebGLRenderingContext::checkFramebufferStatus(GLenum target) 1207 GLenum WebGLRenderingContextBase::checkFramebufferStatus(GLenum target)
1288 { 1208 {
1289 if (isContextLost()) 1209 if (isContextLost())
1290 return GL_FRAMEBUFFER_UNSUPPORTED; 1210 return GL_FRAMEBUFFER_UNSUPPORTED;
1291 if (target != GL_FRAMEBUFFER) { 1211 if (target != GL_FRAMEBUFFER) {
1292 synthesizeGLError(GL_INVALID_ENUM, "checkFramebufferStatus", "invalid ta rget"); 1212 synthesizeGLError(GL_INVALID_ENUM, "checkFramebufferStatus", "invalid ta rget");
1293 return 0; 1213 return 0;
1294 } 1214 }
1295 if (!m_framebufferBinding || !m_framebufferBinding->object()) 1215 if (!m_framebufferBinding || !m_framebufferBinding->object())
1296 return GL_FRAMEBUFFER_COMPLETE; 1216 return GL_FRAMEBUFFER_COMPLETE;
1297 const char* reason = "framebuffer incomplete"; 1217 const char* reason = "framebuffer incomplete";
1298 GLenum result = m_framebufferBinding->checkStatus(&reason); 1218 GLenum result = m_framebufferBinding->checkStatus(&reason);
1299 if (result != GL_FRAMEBUFFER_COMPLETE) { 1219 if (result != GL_FRAMEBUFFER_COMPLETE) {
1300 emitGLWarning("checkFramebufferStatus", reason); 1220 emitGLWarning("checkFramebufferStatus", reason);
1301 return result; 1221 return result;
1302 } 1222 }
1303 result = m_context->checkFramebufferStatus(target); 1223 result = m_context->checkFramebufferStatus(target);
1304 return result; 1224 return result;
1305 } 1225 }
1306 1226
1307 void WebGLRenderingContext::clear(GLbitfield mask) 1227 void WebGLRenderingContextBase::clear(GLbitfield mask)
1308 { 1228 {
1309 if (isContextLost()) 1229 if (isContextLost())
1310 return; 1230 return;
1311 if (mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_B IT)) { 1231 if (mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_B IT)) {
1312 synthesizeGLError(GL_INVALID_VALUE, "clear", "invalid mask"); 1232 synthesizeGLError(GL_INVALID_VALUE, "clear", "invalid mask");
1313 return; 1233 return;
1314 } 1234 }
1315 const char* reason = "framebuffer incomplete"; 1235 const char* reason = "framebuffer incomplete";
1316 if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context.get(), &reason)) { 1236 if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context.get(), &reason)) {
1317 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "clear", reason); 1237 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "clear", reason);
1318 return; 1238 return;
1319 } 1239 }
1320 if (!clearIfComposited(mask)) 1240 if (!clearIfComposited(mask))
1321 m_context->clear(mask); 1241 m_context->clear(mask);
1322 markContextChanged(); 1242 markContextChanged();
1323 } 1243 }
1324 1244
1325 void WebGLRenderingContext::clearColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a) 1245 void WebGLRenderingContextBase::clearColor(GLfloat r, GLfloat g, GLfloat b, GLfl oat a)
1326 { 1246 {
1327 if (isContextLost()) 1247 if (isContextLost())
1328 return; 1248 return;
1329 if (std::isnan(r)) 1249 if (std::isnan(r))
1330 r = 0; 1250 r = 0;
1331 if (std::isnan(g)) 1251 if (std::isnan(g))
1332 g = 0; 1252 g = 0;
1333 if (std::isnan(b)) 1253 if (std::isnan(b))
1334 b = 0; 1254 b = 0;
1335 if (std::isnan(a)) 1255 if (std::isnan(a))
1336 a = 1; 1256 a = 1;
1337 m_clearColor[0] = r; 1257 m_clearColor[0] = r;
1338 m_clearColor[1] = g; 1258 m_clearColor[1] = g;
1339 m_clearColor[2] = b; 1259 m_clearColor[2] = b;
1340 m_clearColor[3] = a; 1260 m_clearColor[3] = a;
1341 m_context->clearColor(r, g, b, a); 1261 m_context->clearColor(r, g, b, a);
1342 } 1262 }
1343 1263
1344 void WebGLRenderingContext::clearDepth(GLfloat depth) 1264 void WebGLRenderingContextBase::clearDepth(GLfloat depth)
1345 { 1265 {
1346 if (isContextLost()) 1266 if (isContextLost())
1347 return; 1267 return;
1348 m_clearDepth = depth; 1268 m_clearDepth = depth;
1349 m_context->clearDepth(depth); 1269 m_context->clearDepth(depth);
1350 } 1270 }
1351 1271
1352 void WebGLRenderingContext::clearStencil(GLint s) 1272 void WebGLRenderingContextBase::clearStencil(GLint s)
1353 { 1273 {
1354 if (isContextLost()) 1274 if (isContextLost())
1355 return; 1275 return;
1356 m_clearStencil = s; 1276 m_clearStencil = s;
1357 m_context->clearStencil(s); 1277 m_context->clearStencil(s);
1358 } 1278 }
1359 1279
1360 void WebGLRenderingContext::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) 1280 void WebGLRenderingContextBase::colorMask(GLboolean red, GLboolean green, GLbool ean blue, GLboolean alpha)
1361 { 1281 {
1362 if (isContextLost()) 1282 if (isContextLost())
1363 return; 1283 return;
1364 m_colorMask[0] = red; 1284 m_colorMask[0] = red;
1365 m_colorMask[1] = green; 1285 m_colorMask[1] = green;
1366 m_colorMask[2] = blue; 1286 m_colorMask[2] = blue;
1367 m_colorMask[3] = alpha; 1287 m_colorMask[3] = alpha;
1368 m_context->colorMask(red, green, blue, alpha); 1288 m_context->colorMask(red, green, blue, alpha);
1369 } 1289 }
1370 1290
1371 void WebGLRenderingContext::compileShader(WebGLShader* shader) 1291 void WebGLRenderingContextBase::compileShader(WebGLShader* shader)
1372 { 1292 {
1373 if (isContextLost() || !validateWebGLObject("compileShader", shader)) 1293 if (isContextLost() || !validateWebGLObject("compileShader", shader))
1374 return; 1294 return;
1375 m_context->compileShader(objectOrZero(shader)); 1295 m_context->compileShader(objectOrZero(shader));
1376 } 1296 }
1377 1297
1378 void WebGLRenderingContext::compressedTexImage2D(GLenum target, GLint level, GLe num internalformat, GLsizei width, GLsizei height, GLint border, ArrayBufferView * data) 1298 void WebGLRenderingContextBase::compressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, ArrayBuffer View* data)
1379 { 1299 {
1380 if (isContextLost()) 1300 if (isContextLost())
1381 return; 1301 return;
1382 if (!validateTexFuncLevel("compressedTexImage2D", target, level)) 1302 if (!validateTexFuncLevel("compressedTexImage2D", target, level))
1383 return; 1303 return;
1384 1304
1385 if (!validateCompressedTexFormat(internalformat)) { 1305 if (!validateCompressedTexFormat(internalformat)) {
1386 synthesizeGLError(GL_INVALID_ENUM, "compressedTexImage2D", "invalid inte rnalformat"); 1306 synthesizeGLError(GL_INVALID_ENUM, "compressedTexImage2D", "invalid inte rnalformat");
1387 return; 1307 return;
1388 } 1308 }
(...skipping 13 matching lines...) Expand all
1402 if (level && WebGLTexture::isNPOT(width, height)) { 1322 if (level && WebGLTexture::isNPOT(width, height)) {
1403 synthesizeGLError(GL_INVALID_VALUE, "compressedTexImage2D", "level > 0 not power of 2"); 1323 synthesizeGLError(GL_INVALID_VALUE, "compressedTexImage2D", "level > 0 not power of 2");
1404 return; 1324 return;
1405 } 1325 }
1406 } 1326 }
1407 m_context->compressedTexImage2D(target, level, internalformat, width, height , 1327 m_context->compressedTexImage2D(target, level, internalformat, width, height ,
1408 border, data->byteLength(), data-> baseAddress()); 1328 border, data->byteLength(), data-> baseAddress());
1409 tex->setLevelInfo(target, level, internalformat, width, height, GL_UNSIGNED_ BYTE); 1329 tex->setLevelInfo(target, level, internalformat, width, height, GL_UNSIGNED_ BYTE);
1410 } 1330 }
1411 1331
1412 void WebGLRenderingContext::compressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, Arra yBufferView* data) 1332 void WebGLRenderingContextBase::compressedTexSubImage2D(GLenum target, GLint lev el, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, ArrayBufferView* data)
1413 { 1333 {
1414 if (isContextLost()) 1334 if (isContextLost())
1415 return; 1335 return;
1416 if (!validateTexFuncLevel("compressedTexSubImage2D", target, level)) 1336 if (!validateTexFuncLevel("compressedTexSubImage2D", target, level))
1417 return; 1337 return;
1418 if (!validateCompressedTexFormat(format)) { 1338 if (!validateCompressedTexFormat(format)) {
1419 synthesizeGLError(GL_INVALID_ENUM, "compressedTexSubImage2D", "invalid f ormat"); 1339 synthesizeGLError(GL_INVALID_ENUM, "compressedTexSubImage2D", "invalid f ormat");
1420 return; 1340 return;
1421 } 1341 }
1422 if (!validateCompressedTexFuncData("compressedTexSubImage2D", width, height, format, data)) 1342 if (!validateCompressedTexFuncData("compressedTexSubImage2D", width, height, format, data))
1423 return; 1343 return;
1424 1344
1425 WebGLTexture* tex = validateTextureBinding("compressedTexSubImage2D", target , true); 1345 WebGLTexture* tex = validateTextureBinding("compressedTexSubImage2D", target , true);
1426 if (!tex) 1346 if (!tex)
1427 return; 1347 return;
1428 1348
1429 if (format != tex->getInternalFormat(target, level)) { 1349 if (format != tex->getInternalFormat(target, level)) {
1430 synthesizeGLError(GL_INVALID_OPERATION, "compressedTexSubImage2D", "form at does not match texture format"); 1350 synthesizeGLError(GL_INVALID_OPERATION, "compressedTexSubImage2D", "form at does not match texture format");
1431 return; 1351 return;
1432 } 1352 }
1433 1353
1434 if (!validateCompressedTexSubDimensions("compressedTexSubImage2D", target, l evel, xoffset, yoffset, width, height, format, tex)) 1354 if (!validateCompressedTexSubDimensions("compressedTexSubImage2D", target, l evel, xoffset, yoffset, width, height, format, tex))
1435 return; 1355 return;
1436 1356
1437 m_context->compressedTexSubImage2D(target, level, xoffset, yoffset, 1357 m_context->compressedTexSubImage2D(target, level, xoffset, yoffset,
1438 width, height, format, data->by teLength(), data->baseAddress()); 1358 width, height, format, data->by teLength(), data->baseAddress());
1439 } 1359 }
1440 1360
1441 bool WebGLRenderingContext::validateSettableTexFormat(const char* functionName, GLenum format) 1361 bool WebGLRenderingContextBase::validateSettableTexFormat(const char* functionNa me, GLenum format)
1442 { 1362 {
1443 if (WebGLImageConversion::getClearBitsByFormat(format) & (GL_DEPTH_BUFFER_BI T | GL_STENCIL_BUFFER_BIT)) { 1363 if (WebGLImageConversion::getClearBitsByFormat(format) & (GL_DEPTH_BUFFER_BI T | GL_STENCIL_BUFFER_BIT)) {
1444 synthesizeGLError(GL_INVALID_OPERATION, functionName, "format can not be set, only rendered to"); 1364 synthesizeGLError(GL_INVALID_OPERATION, functionName, "format can not be set, only rendered to");
1445 return false; 1365 return false;
1446 } 1366 }
1447 return true; 1367 return true;
1448 } 1368 }
1449 1369
1450 void WebGLRenderingContext::copyTexImage2D(GLenum target, GLint level, GLenum in ternalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) 1370 void WebGLRenderingContextBase::copyTexImage2D(GLenum target, GLint level, GLenu m internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
1451 { 1371 {
1452 if (isContextLost()) 1372 if (isContextLost())
1453 return; 1373 return;
1454 if (!validateTexFuncParameters("copyTexImage2D", NotTexSubImage2D, target, l evel, internalformat, width, height, border, internalformat, GL_UNSIGNED_BYTE)) 1374 if (!validateTexFuncParameters("copyTexImage2D", NotTexSubImage2D, target, l evel, internalformat, width, height, border, internalformat, GL_UNSIGNED_BYTE))
1455 return; 1375 return;
1456 if (!validateSettableTexFormat("copyTexImage2D", internalformat)) 1376 if (!validateSettableTexFormat("copyTexImage2D", internalformat))
1457 return; 1377 return;
1458 WebGLTexture* tex = validateTextureBinding("copyTexImage2D", target, true); 1378 WebGLTexture* tex = validateTextureBinding("copyTexImage2D", target, true);
1459 if (!tex) 1379 if (!tex)
1460 return; 1380 return;
(...skipping 10 matching lines...) Expand all
1471 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "copyTexImage2D", re ason); 1391 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "copyTexImage2D", re ason);
1472 return; 1392 return;
1473 } 1393 }
1474 clearIfComposited(); 1394 clearIfComposited();
1475 ScopedDrawingBufferBinder binder(m_drawingBuffer.get(), m_framebufferBinding .get()); 1395 ScopedDrawingBufferBinder binder(m_drawingBuffer.get(), m_framebufferBinding .get());
1476 m_context->copyTexImage2D(target, level, internalformat, x, y, width, height , border); 1396 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. 1397 // FIXME: if the framebuffer is not complete, none of the below should be ex ecuted.
1478 tex->setLevelInfo(target, level, internalformat, width, height, GL_UNSIGNED_ BYTE); 1398 tex->setLevelInfo(target, level, internalformat, width, height, GL_UNSIGNED_ BYTE);
1479 } 1399 }
1480 1400
1481 void WebGLRenderingContext::copyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) 1401 void WebGLRenderingContextBase::copyTexSubImage2D(GLenum target, GLint level, GL int xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
1482 { 1402 {
1483 if (isContextLost()) 1403 if (isContextLost())
1484 return; 1404 return;
1485 if (!validateTexFuncLevel("copyTexSubImage2D", target, level)) 1405 if (!validateTexFuncLevel("copyTexSubImage2D", target, level))
1486 return; 1406 return;
1487 WebGLTexture* tex = validateTextureBinding("copyTexSubImage2D", target, true ); 1407 WebGLTexture* tex = validateTextureBinding("copyTexSubImage2D", target, true );
1488 if (!tex) 1408 if (!tex)
1489 return; 1409 return;
1490 if (!validateSize("copyTexSubImage2D", xoffset, yoffset) || !validateSize("c opyTexSubImage2D", width, height)) 1410 if (!validateSize("copyTexSubImage2D", xoffset, yoffset) || !validateSize("c opyTexSubImage2D", width, height))
1491 return; 1411 return;
(...skipping 20 matching lines...) Expand all
1512 const char* reason = "framebuffer incomplete"; 1432 const char* reason = "framebuffer incomplete";
1513 if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context.get(), &reason)) { 1433 if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context.get(), &reason)) {
1514 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "copyTexSubImage2D", reason); 1434 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "copyTexSubImage2D", reason);
1515 return; 1435 return;
1516 } 1436 }
1517 clearIfComposited(); 1437 clearIfComposited();
1518 ScopedDrawingBufferBinder binder(m_drawingBuffer.get(), m_framebufferBinding .get()); 1438 ScopedDrawingBufferBinder binder(m_drawingBuffer.get(), m_framebufferBinding .get());
1519 m_context->copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, h eight); 1439 m_context->copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, h eight);
1520 } 1440 }
1521 1441
1522 PassRefPtr<WebGLBuffer> WebGLRenderingContext::createBuffer() 1442 PassRefPtr<WebGLBuffer> WebGLRenderingContextBase::createBuffer()
1523 { 1443 {
1524 if (isContextLost()) 1444 if (isContextLost())
1525 return 0; 1445 return 0;
1526 RefPtr<WebGLBuffer> o = WebGLBuffer::create(this); 1446 RefPtr<WebGLBuffer> o = WebGLBuffer::create(this);
1527 addSharedObject(o.get()); 1447 addSharedObject(o.get());
1528 return o; 1448 return o;
1529 } 1449 }
1530 1450
1531 PassRefPtr<WebGLFramebuffer> WebGLRenderingContext::createFramebuffer() 1451 PassRefPtr<WebGLFramebuffer> WebGLRenderingContextBase::createFramebuffer()
1532 { 1452 {
1533 if (isContextLost()) 1453 if (isContextLost())
1534 return 0; 1454 return 0;
1535 RefPtr<WebGLFramebuffer> o = WebGLFramebuffer::create(this); 1455 RefPtr<WebGLFramebuffer> o = WebGLFramebuffer::create(this);
1536 addContextObject(o.get()); 1456 addContextObject(o.get());
1537 return o; 1457 return o;
1538 } 1458 }
1539 1459
1540 PassRefPtr<WebGLTexture> WebGLRenderingContext::createTexture() 1460 PassRefPtr<WebGLTexture> WebGLRenderingContextBase::createTexture()
1541 { 1461 {
1542 if (isContextLost()) 1462 if (isContextLost())
1543 return 0; 1463 return 0;
1544 RefPtr<WebGLTexture> o = WebGLTexture::create(this); 1464 RefPtr<WebGLTexture> o = WebGLTexture::create(this);
1545 addSharedObject(o.get()); 1465 addSharedObject(o.get());
1546 return o; 1466 return o;
1547 } 1467 }
1548 1468
1549 PassRefPtr<WebGLProgram> WebGLRenderingContext::createProgram() 1469 PassRefPtr<WebGLProgram> WebGLRenderingContextBase::createProgram()
1550 { 1470 {
1551 if (isContextLost()) 1471 if (isContextLost())
1552 return 0; 1472 return 0;
1553 RefPtr<WebGLProgram> o = WebGLProgram::create(this); 1473 RefPtr<WebGLProgram> o = WebGLProgram::create(this);
1554 addSharedObject(o.get()); 1474 addSharedObject(o.get());
1555 return o; 1475 return o;
1556 } 1476 }
1557 1477
1558 PassRefPtr<WebGLRenderbuffer> WebGLRenderingContext::createRenderbuffer() 1478 PassRefPtr<WebGLRenderbuffer> WebGLRenderingContextBase::createRenderbuffer()
1559 { 1479 {
1560 if (isContextLost()) 1480 if (isContextLost())
1561 return 0; 1481 return 0;
1562 RefPtr<WebGLRenderbuffer> o = WebGLRenderbuffer::create(this); 1482 RefPtr<WebGLRenderbuffer> o = WebGLRenderbuffer::create(this);
1563 addSharedObject(o.get()); 1483 addSharedObject(o.get());
1564 return o; 1484 return o;
1565 } 1485 }
1566 1486
1567 WebGLRenderbuffer* WebGLRenderingContext::ensureEmulatedStencilBuffer(GLenum tar get, WebGLRenderbuffer* renderbuffer) 1487 WebGLRenderbuffer* WebGLRenderingContextBase::ensureEmulatedStencilBuffer(GLenum target, WebGLRenderbuffer* renderbuffer)
1568 { 1488 {
1569 if (isContextLost()) 1489 if (isContextLost())
1570 return 0; 1490 return 0;
1571 if (!renderbuffer->emulatedStencilBuffer()) { 1491 if (!renderbuffer->emulatedStencilBuffer()) {
1572 renderbuffer->setEmulatedStencilBuffer(createRenderbuffer()); 1492 renderbuffer->setEmulatedStencilBuffer(createRenderbuffer());
1573 m_context->bindRenderbuffer(target, objectOrZero(renderbuffer->emulatedS tencilBuffer())); 1493 m_context->bindRenderbuffer(target, objectOrZero(renderbuffer->emulatedS tencilBuffer()));
1574 m_context->bindRenderbuffer(target, objectOrZero(m_renderbufferBinding.g et())); 1494 m_context->bindRenderbuffer(target, objectOrZero(m_renderbufferBinding.g et()));
1575 } 1495 }
1576 return renderbuffer->emulatedStencilBuffer(); 1496 return renderbuffer->emulatedStencilBuffer();
1577 } 1497 }
1578 1498
1579 PassRefPtr<WebGLShader> WebGLRenderingContext::createShader(GLenum type) 1499 PassRefPtr<WebGLShader> WebGLRenderingContextBase::createShader(GLenum type)
1580 { 1500 {
1581 if (isContextLost()) 1501 if (isContextLost())
1582 return 0; 1502 return 0;
1583 if (type != GL_VERTEX_SHADER && type != GL_FRAGMENT_SHADER) { 1503 if (type != GL_VERTEX_SHADER && type != GL_FRAGMENT_SHADER) {
1584 synthesizeGLError(GL_INVALID_ENUM, "createShader", "invalid shader type" ); 1504 synthesizeGLError(GL_INVALID_ENUM, "createShader", "invalid shader type" );
1585 return 0; 1505 return 0;
1586 } 1506 }
1587 1507
1588 RefPtr<WebGLShader> o = WebGLShader::create(this, type); 1508 RefPtr<WebGLShader> o = WebGLShader::create(this, type);
1589 addSharedObject(o.get()); 1509 addSharedObject(o.get());
1590 return o; 1510 return o;
1591 } 1511 }
1592 1512
1593 void WebGLRenderingContext::cullFace(GLenum mode) 1513 void WebGLRenderingContextBase::cullFace(GLenum mode)
1594 { 1514 {
1595 if (isContextLost()) 1515 if (isContextLost())
1596 return; 1516 return;
1597 switch (mode) { 1517 switch (mode) {
1598 case GL_FRONT_AND_BACK: 1518 case GL_FRONT_AND_BACK:
1599 case GL_FRONT: 1519 case GL_FRONT:
1600 case GL_BACK: 1520 case GL_BACK:
1601 break; 1521 break;
1602 default: 1522 default:
1603 synthesizeGLError(GL_INVALID_ENUM, "cullFace", "invalid mode"); 1523 synthesizeGLError(GL_INVALID_ENUM, "cullFace", "invalid mode");
1604 return; 1524 return;
1605 } 1525 }
1606 m_context->cullFace(mode); 1526 m_context->cullFace(mode);
1607 } 1527 }
1608 1528
1609 bool WebGLRenderingContext::deleteObject(WebGLObject* object) 1529 bool WebGLRenderingContextBase::deleteObject(WebGLObject* object)
1610 { 1530 {
1611 if (isContextLost() || !object) 1531 if (isContextLost() || !object)
1612 return false; 1532 return false;
1613 if (!object->validate(contextGroup(), this)) { 1533 if (!object->validate(contextGroup(), this)) {
1614 synthesizeGLError(GL_INVALID_OPERATION, "delete", "object does not belon g to this context"); 1534 synthesizeGLError(GL_INVALID_OPERATION, "delete", "object does not belon g to this context");
1615 return false; 1535 return false;
1616 } 1536 }
1617 if (object->object()) { 1537 if (object->object()) {
1618 // We need to pass in context here because we want 1538 // We need to pass in context here because we want
1619 // things in this context unbound. 1539 // things in this context unbound.
1620 object->deleteObject(m_context.get()); 1540 object->deleteObject(m_context.get());
1621 } 1541 }
1622 return true; 1542 return true;
1623 } 1543 }
1624 1544
1625 void WebGLRenderingContext::deleteBuffer(WebGLBuffer* buffer) 1545 void WebGLRenderingContextBase::deleteBuffer(WebGLBuffer* buffer)
1626 { 1546 {
1627 if (!deleteObject(buffer)) 1547 if (!deleteObject(buffer))
1628 return; 1548 return;
1629 if (m_boundArrayBuffer == buffer) 1549 if (m_boundArrayBuffer == buffer)
1630 m_boundArrayBuffer = 0; 1550 m_boundArrayBuffer = 0;
1631 1551
1632 m_boundVertexArrayObject->unbindBuffer(buffer); 1552 m_boundVertexArrayObject->unbindBuffer(buffer);
1633 } 1553 }
1634 1554
1635 void WebGLRenderingContext::deleteFramebuffer(WebGLFramebuffer* framebuffer) 1555 void WebGLRenderingContextBase::deleteFramebuffer(WebGLFramebuffer* framebuffer)
1636 { 1556 {
1637 if (!deleteObject(framebuffer)) 1557 if (!deleteObject(framebuffer))
1638 return; 1558 return;
1639 if (framebuffer == m_framebufferBinding) { 1559 if (framebuffer == m_framebufferBinding) {
1640 m_framebufferBinding = 0; 1560 m_framebufferBinding = 0;
1641 m_drawingBuffer->setFramebufferBinding(0); 1561 m_drawingBuffer->setFramebufferBinding(0);
1642 // Have to call bindFramebuffer here to bind back to internal fbo. 1562 // Have to call bindFramebuffer here to bind back to internal fbo.
1643 m_drawingBuffer->bind(); 1563 m_drawingBuffer->bind();
1644 } 1564 }
1645 } 1565 }
1646 1566
1647 void WebGLRenderingContext::deleteProgram(WebGLProgram* program) 1567 void WebGLRenderingContextBase::deleteProgram(WebGLProgram* program)
1648 { 1568 {
1649 deleteObject(program); 1569 deleteObject(program);
1650 // We don't reset m_currentProgram to 0 here because the deletion of the 1570 // We don't reset m_currentProgram to 0 here because the deletion of the
1651 // current program is delayed. 1571 // current program is delayed.
1652 } 1572 }
1653 1573
1654 void WebGLRenderingContext::deleteRenderbuffer(WebGLRenderbuffer* renderbuffer) 1574 void WebGLRenderingContextBase::deleteRenderbuffer(WebGLRenderbuffer* renderbuff er)
1655 { 1575 {
1656 if (!deleteObject(renderbuffer)) 1576 if (!deleteObject(renderbuffer))
1657 return; 1577 return;
1658 if (renderbuffer == m_renderbufferBinding) 1578 if (renderbuffer == m_renderbufferBinding)
1659 m_renderbufferBinding = 0; 1579 m_renderbufferBinding = 0;
1660 if (m_framebufferBinding) 1580 if (m_framebufferBinding)
1661 m_framebufferBinding->removeAttachmentFromBoundFramebuffer(renderbuffer) ; 1581 m_framebufferBinding->removeAttachmentFromBoundFramebuffer(renderbuffer) ;
1662 } 1582 }
1663 1583
1664 void WebGLRenderingContext::deleteShader(WebGLShader* shader) 1584 void WebGLRenderingContextBase::deleteShader(WebGLShader* shader)
1665 { 1585 {
1666 deleteObject(shader); 1586 deleteObject(shader);
1667 } 1587 }
1668 1588
1669 void WebGLRenderingContext::deleteTexture(WebGLTexture* texture) 1589 void WebGLRenderingContextBase::deleteTexture(WebGLTexture* texture)
1670 { 1590 {
1671 if (!deleteObject(texture)) 1591 if (!deleteObject(texture))
1672 return; 1592 return;
1673 1593
1674 int maxBoundTextureIndex = -1; 1594 int maxBoundTextureIndex = -1;
1675 for (size_t i = 0; i < m_onePlusMaxNonDefaultTextureUnit; ++i) { 1595 for (size_t i = 0; i < m_onePlusMaxNonDefaultTextureUnit; ++i) {
1676 if (texture == m_textureUnits[i].m_texture2DBinding) { 1596 if (texture == m_textureUnits[i].m_texture2DBinding) {
1677 m_textureUnits[i].m_texture2DBinding = 0; 1597 m_textureUnits[i].m_texture2DBinding = 0;
1678 maxBoundTextureIndex = i; 1598 maxBoundTextureIndex = i;
1679 if (!i) 1599 if (!i)
1680 m_drawingBuffer->setTexture2DBinding(0); 1600 m_drawingBuffer->setTexture2DBinding(0);
1681 } 1601 }
1682 if (texture == m_textureUnits[i].m_textureCubeMapBinding) { 1602 if (texture == m_textureUnits[i].m_textureCubeMapBinding) {
1683 m_textureUnits[i].m_textureCubeMapBinding = 0; 1603 m_textureUnits[i].m_textureCubeMapBinding = 0;
1684 maxBoundTextureIndex = i; 1604 maxBoundTextureIndex = i;
1685 } 1605 }
1686 } 1606 }
1687 if (m_framebufferBinding) 1607 if (m_framebufferBinding)
1688 m_framebufferBinding->removeAttachmentFromBoundFramebuffer(texture); 1608 m_framebufferBinding->removeAttachmentFromBoundFramebuffer(texture);
1689 1609
1690 // If the deleted was bound to the the current maximum index, trace backward s to find the new max texture index 1610 // If the deleted was bound to the the current maximum index, trace backward s to find the new max texture index
1691 if (m_onePlusMaxNonDefaultTextureUnit == static_cast<unsigned long>(maxBound TextureIndex + 1)) { 1611 if (m_onePlusMaxNonDefaultTextureUnit == static_cast<unsigned long>(maxBound TextureIndex + 1)) {
1692 findNewMaxNonDefaultTextureUnit(); 1612 findNewMaxNonDefaultTextureUnit();
1693 } 1613 }
1694 } 1614 }
1695 1615
1696 void WebGLRenderingContext::depthFunc(GLenum func) 1616 void WebGLRenderingContextBase::depthFunc(GLenum func)
1697 { 1617 {
1698 if (isContextLost()) 1618 if (isContextLost())
1699 return; 1619 return;
1700 if (!validateStencilOrDepthFunc("depthFunc", func)) 1620 if (!validateStencilOrDepthFunc("depthFunc", func))
1701 return; 1621 return;
1702 m_context->depthFunc(func); 1622 m_context->depthFunc(func);
1703 } 1623 }
1704 1624
1705 void WebGLRenderingContext::depthMask(GLboolean flag) 1625 void WebGLRenderingContextBase::depthMask(GLboolean flag)
1706 { 1626 {
1707 if (isContextLost()) 1627 if (isContextLost())
1708 return; 1628 return;
1709 m_depthMask = flag; 1629 m_depthMask = flag;
1710 m_context->depthMask(flag); 1630 m_context->depthMask(flag);
1711 } 1631 }
1712 1632
1713 void WebGLRenderingContext::depthRange(GLfloat zNear, GLfloat zFar) 1633 void WebGLRenderingContextBase::depthRange(GLfloat zNear, GLfloat zFar)
1714 { 1634 {
1715 if (isContextLost()) 1635 if (isContextLost())
1716 return; 1636 return;
1717 if (zNear > zFar) { 1637 if (zNear > zFar) {
1718 synthesizeGLError(GL_INVALID_OPERATION, "depthRange", "zNear > zFar"); 1638 synthesizeGLError(GL_INVALID_OPERATION, "depthRange", "zNear > zFar");
1719 return; 1639 return;
1720 } 1640 }
1721 m_context->depthRange(zNear, zFar); 1641 m_context->depthRange(zNear, zFar);
1722 } 1642 }
1723 1643
1724 void WebGLRenderingContext::detachShader(WebGLProgram* program, WebGLShader* sha der) 1644 void WebGLRenderingContextBase::detachShader(WebGLProgram* program, WebGLShader* shader)
1725 { 1645 {
1726 if (isContextLost() || !validateWebGLObject("detachShader", program) || !val idateWebGLObject("detachShader", shader)) 1646 if (isContextLost() || !validateWebGLObject("detachShader", program) || !val idateWebGLObject("detachShader", shader))
1727 return; 1647 return;
1728 if (!program->detachShader(shader)) { 1648 if (!program->detachShader(shader)) {
1729 synthesizeGLError(GL_INVALID_OPERATION, "detachShader", "shader not atta ched"); 1649 synthesizeGLError(GL_INVALID_OPERATION, "detachShader", "shader not atta ched");
1730 return; 1650 return;
1731 } 1651 }
1732 m_context->detachShader(objectOrZero(program), objectOrZero(shader)); 1652 m_context->detachShader(objectOrZero(program), objectOrZero(shader));
1733 shader->onDetached(m_context.get()); 1653 shader->onDetached(m_context.get());
1734 } 1654 }
1735 1655
1736 void WebGLRenderingContext::disable(GLenum cap) 1656 void WebGLRenderingContextBase::disable(GLenum cap)
1737 { 1657 {
1738 if (isContextLost() || !validateCapability("disable", cap)) 1658 if (isContextLost() || !validateCapability("disable", cap))
1739 return; 1659 return;
1740 if (cap == GL_STENCIL_TEST) { 1660 if (cap == GL_STENCIL_TEST) {
1741 m_stencilEnabled = false; 1661 m_stencilEnabled = false;
1742 applyStencilTest(); 1662 applyStencilTest();
1743 return; 1663 return;
1744 } 1664 }
1745 if (cap == GL_SCISSOR_TEST) { 1665 if (cap == GL_SCISSOR_TEST) {
1746 m_scissorEnabled = false; 1666 m_scissorEnabled = false;
1747 m_drawingBuffer->setScissorEnabled(m_scissorEnabled); 1667 m_drawingBuffer->setScissorEnabled(m_scissorEnabled);
1748 } 1668 }
1749 m_context->disable(cap); 1669 m_context->disable(cap);
1750 } 1670 }
1751 1671
1752 void WebGLRenderingContext::disableVertexAttribArray(GLuint index) 1672 void WebGLRenderingContextBase::disableVertexAttribArray(GLuint index)
1753 { 1673 {
1754 if (isContextLost()) 1674 if (isContextLost())
1755 return; 1675 return;
1756 if (index >= m_maxVertexAttribs) { 1676 if (index >= m_maxVertexAttribs) {
1757 synthesizeGLError(GL_INVALID_VALUE, "disableVertexAttribArray", "index o ut of range"); 1677 synthesizeGLError(GL_INVALID_VALUE, "disableVertexAttribArray", "index o ut of range");
1758 return; 1678 return;
1759 } 1679 }
1760 1680
1761 WebGLVertexArrayObjectOES::VertexAttribState& state = m_boundVertexArrayObje ct->getVertexAttribState(index); 1681 WebGLVertexArrayObjectOES::VertexAttribState& state = m_boundVertexArrayObje ct->getVertexAttribState(index);
1762 state.enabled = false; 1682 state.enabled = false;
1763 1683
1764 // If the disabled index is the current maximum, trace backwards to find the new max enabled attrib index 1684 // If the disabled index is the current maximum, trace backwards to find the new max enabled attrib index
1765 if (m_onePlusMaxEnabledAttribIndex == index + 1) { 1685 if (m_onePlusMaxEnabledAttribIndex == index + 1) {
1766 findNewMaxEnabledAttribIndex(); 1686 findNewMaxEnabledAttribIndex();
1767 } 1687 }
1768 1688
1769 m_context->disableVertexAttribArray(index); 1689 m_context->disableVertexAttribArray(index);
1770 } 1690 }
1771 1691
1772 bool WebGLRenderingContext::validateRenderingState(const char* functionName) 1692 bool WebGLRenderingContextBase::validateRenderingState(const char* functionName)
1773 { 1693 {
1774 if (!m_currentProgram) { 1694 if (!m_currentProgram) {
1775 synthesizeGLError(GL_INVALID_OPERATION, functionName, "no valid shader p rogram in use"); 1695 synthesizeGLError(GL_INVALID_OPERATION, functionName, "no valid shader p rogram in use");
1776 return false; 1696 return false;
1777 } 1697 }
1778 1698
1779 // Look in each enabled vertex attrib and check if they've been bound to a b uffer. 1699 // Look in each enabled vertex attrib and check if they've been bound to a b uffer.
1780 for (unsigned i = 0; i < m_onePlusMaxEnabledAttribIndex; ++i) { 1700 for (unsigned i = 0; i < m_onePlusMaxEnabledAttribIndex; ++i) {
1781 const WebGLVertexArrayObjectOES::VertexAttribState& state = m_boundVerte xArrayObject->getVertexAttribState(i); 1701 const WebGLVertexArrayObjectOES::VertexAttribState& state = m_boundVerte xArrayObject->getVertexAttribState(i);
1782 if (state.enabled 1702 if (state.enabled
1783 && (!state.bufferBinding || !state.bufferBinding->object())) { 1703 && (!state.bufferBinding || !state.bufferBinding->object())) {
1784 synthesizeGLError(GL_INVALID_OPERATION, functionName, String::format ("attribute %d is enabled but has no buffer bound", i).utf8().data()); 1704 synthesizeGLError(GL_INVALID_OPERATION, functionName, String::format ("attribute %d is enabled but has no buffer bound", i).utf8().data());
1785 return false; 1705 return false;
1786 } 1706 }
1787 } 1707 }
1788 1708
1789 return true; 1709 return true;
1790 } 1710 }
1791 1711
1792 bool WebGLRenderingContext::validateWebGLObject(const char* functionName, WebGLO bject* object) 1712 bool WebGLRenderingContextBase::validateWebGLObject(const char* functionName, We bGLObject* object)
1793 { 1713 {
1794 if (!object || !object->object()) { 1714 if (!object || !object->object()) {
1795 synthesizeGLError(GL_INVALID_VALUE, functionName, "no object or object d eleted"); 1715 synthesizeGLError(GL_INVALID_VALUE, functionName, "no object or object d eleted");
1796 return false; 1716 return false;
1797 } 1717 }
1798 if (!object->validate(contextGroup(), this)) { 1718 if (!object->validate(contextGroup(), this)) {
1799 synthesizeGLError(GL_INVALID_OPERATION, functionName, "object does not b elong to this context"); 1719 synthesizeGLError(GL_INVALID_OPERATION, functionName, "object does not b elong to this context");
1800 return false; 1720 return false;
1801 } 1721 }
1802 return true; 1722 return true;
1803 } 1723 }
1804 1724
1805 void WebGLRenderingContext::drawArrays(GLenum mode, GLint first, GLsizei count) 1725 void WebGLRenderingContextBase::drawArrays(GLenum mode, GLint first, GLsizei cou nt)
1806 { 1726 {
1807 if (!validateDrawArrays("drawArrays", mode, first, count)) 1727 if (!validateDrawArrays("drawArrays", mode, first, count))
1808 return; 1728 return;
1809 1729
1810 clearIfComposited(); 1730 clearIfComposited();
1811 1731
1812 handleTextureCompleteness("drawArrays", true); 1732 handleTextureCompleteness("drawArrays", true);
1813 m_context->drawArrays(mode, first, count); 1733 m_context->drawArrays(mode, first, count);
1814 handleTextureCompleteness("drawArrays", false); 1734 handleTextureCompleteness("drawArrays", false);
1815 markContextChanged(); 1735 markContextChanged();
1816 } 1736 }
1817 1737
1818 void WebGLRenderingContext::drawElements(GLenum mode, GLsizei count, GLenum type , long long offset) 1738 void WebGLRenderingContextBase::drawElements(GLenum mode, GLsizei count, GLenum type, long long offset)
1819 { 1739 {
1820 if (!validateDrawElements("drawElements", mode, count, type, offset)) 1740 if (!validateDrawElements("drawElements", mode, count, type, offset))
1821 return; 1741 return;
1822 1742
1823 clearIfComposited(); 1743 clearIfComposited();
1824 1744
1825 handleTextureCompleteness("drawElements", true); 1745 handleTextureCompleteness("drawElements", true);
1826 m_context->drawElements(mode, count, type, static_cast<GLintptr>(offset)); 1746 m_context->drawElements(mode, count, type, static_cast<GLintptr>(offset));
1827 handleTextureCompleteness("drawElements", false); 1747 handleTextureCompleteness("drawElements", false);
1828 markContextChanged(); 1748 markContextChanged();
1829 } 1749 }
1830 1750
1831 void WebGLRenderingContext::drawArraysInstancedANGLE(GLenum mode, GLint first, G Lsizei count, GLsizei primcount) 1751 void WebGLRenderingContextBase::drawArraysInstancedANGLE(GLenum mode, GLint firs t, GLsizei count, GLsizei primcount)
1832 { 1752 {
1833 if (!validateDrawArrays("drawArraysInstancedANGLE", mode, first, count)) 1753 if (!validateDrawArrays("drawArraysInstancedANGLE", mode, first, count))
1834 return; 1754 return;
1835 1755
1836 if (!validateDrawInstanced("drawArraysInstancedANGLE", primcount)) 1756 if (!validateDrawInstanced("drawArraysInstancedANGLE", primcount))
1837 return; 1757 return;
1838 1758
1839 clearIfComposited(); 1759 clearIfComposited();
1840 1760
1841 handleTextureCompleteness("drawArraysInstancedANGLE", true); 1761 handleTextureCompleteness("drawArraysInstancedANGLE", true);
1842 m_context->drawArraysInstancedANGLE(mode, first, count, primcount); 1762 m_context->drawArraysInstancedANGLE(mode, first, count, primcount);
1843 handleTextureCompleteness("drawArraysInstancedANGLE", false); 1763 handleTextureCompleteness("drawArraysInstancedANGLE", false);
1844 markContextChanged(); 1764 markContextChanged();
1845 } 1765 }
1846 1766
1847 void WebGLRenderingContext::drawElementsInstancedANGLE(GLenum mode, GLsizei coun t, GLenum type, GLintptr offset, GLsizei primcount) 1767 void WebGLRenderingContextBase::drawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, GLintptr offset, GLsizei primcount)
1848 { 1768 {
1849 if (!validateDrawElements("drawElementsInstancedANGLE", mode, count, type, o ffset)) 1769 if (!validateDrawElements("drawElementsInstancedANGLE", mode, count, type, o ffset))
1850 return; 1770 return;
1851 1771
1852 if (!validateDrawInstanced("drawElementsInstancedANGLE", primcount)) 1772 if (!validateDrawInstanced("drawElementsInstancedANGLE", primcount))
1853 return; 1773 return;
1854 1774
1855 clearIfComposited(); 1775 clearIfComposited();
1856 1776
1857 handleTextureCompleteness("drawElementsInstancedANGLE", true); 1777 handleTextureCompleteness("drawElementsInstancedANGLE", true);
1858 m_context->drawElementsInstancedANGLE(mode, count, type, static_cast<GLintpt r>(offset), primcount); 1778 m_context->drawElementsInstancedANGLE(mode, count, type, static_cast<GLintpt r>(offset), primcount);
1859 handleTextureCompleteness("drawElementsInstancedANGLE", false); 1779 handleTextureCompleteness("drawElementsInstancedANGLE", false);
1860 markContextChanged(); 1780 markContextChanged();
1861 } 1781 }
1862 1782
1863 void WebGLRenderingContext::enable(GLenum cap) 1783 void WebGLRenderingContextBase::enable(GLenum cap)
1864 { 1784 {
1865 if (isContextLost() || !validateCapability("enable", cap)) 1785 if (isContextLost() || !validateCapability("enable", cap))
1866 return; 1786 return;
1867 if (cap == GL_STENCIL_TEST) { 1787 if (cap == GL_STENCIL_TEST) {
1868 m_stencilEnabled = true; 1788 m_stencilEnabled = true;
1869 applyStencilTest(); 1789 applyStencilTest();
1870 return; 1790 return;
1871 } 1791 }
1872 if (cap == GL_SCISSOR_TEST) { 1792 if (cap == GL_SCISSOR_TEST) {
1873 m_scissorEnabled = true; 1793 m_scissorEnabled = true;
1874 m_drawingBuffer->setScissorEnabled(m_scissorEnabled); 1794 m_drawingBuffer->setScissorEnabled(m_scissorEnabled);
1875 } 1795 }
1876 m_context->enable(cap); 1796 m_context->enable(cap);
1877 } 1797 }
1878 1798
1879 void WebGLRenderingContext::enableVertexAttribArray(GLuint index) 1799 void WebGLRenderingContextBase::enableVertexAttribArray(GLuint index)
1880 { 1800 {
1881 if (isContextLost()) 1801 if (isContextLost())
1882 return; 1802 return;
1883 if (index >= m_maxVertexAttribs) { 1803 if (index >= m_maxVertexAttribs) {
1884 synthesizeGLError(GL_INVALID_VALUE, "enableVertexAttribArray", "index ou t of range"); 1804 synthesizeGLError(GL_INVALID_VALUE, "enableVertexAttribArray", "index ou t of range");
1885 return; 1805 return;
1886 } 1806 }
1887 1807
1888 WebGLVertexArrayObjectOES::VertexAttribState& state = m_boundVertexArrayObje ct->getVertexAttribState(index); 1808 WebGLVertexArrayObjectOES::VertexAttribState& state = m_boundVertexArrayObje ct->getVertexAttribState(index);
1889 state.enabled = true; 1809 state.enabled = true;
1890 1810
1891 m_onePlusMaxEnabledAttribIndex = max(index + 1, m_onePlusMaxEnabledAttribInd ex); 1811 m_onePlusMaxEnabledAttribIndex = max(index + 1, m_onePlusMaxEnabledAttribInd ex);
1892 1812
1893 m_context->enableVertexAttribArray(index); 1813 m_context->enableVertexAttribArray(index);
1894 } 1814 }
1895 1815
1896 void WebGLRenderingContext::finish() 1816 void WebGLRenderingContextBase::finish()
1897 { 1817 {
1898 if (isContextLost()) 1818 if (isContextLost())
1899 return; 1819 return;
1900 m_context->flush(); // Intentionally a flush, not a finish. 1820 m_context->flush(); // Intentionally a flush, not a finish.
1901 } 1821 }
1902 1822
1903 void WebGLRenderingContext::flush() 1823 void WebGLRenderingContextBase::flush()
1904 { 1824 {
1905 if (isContextLost()) 1825 if (isContextLost())
1906 return; 1826 return;
1907 m_context->flush(); 1827 m_context->flush();
1908 } 1828 }
1909 1829
1910 void WebGLRenderingContext::framebufferRenderbuffer(GLenum target, GLenum attach ment, GLenum renderbuffertarget, WebGLRenderbuffer* buffer) 1830 void WebGLRenderingContextBase::framebufferRenderbuffer(GLenum target, GLenum at tachment, GLenum renderbuffertarget, WebGLRenderbuffer* buffer)
1911 { 1831 {
1912 if (isContextLost() || !validateFramebufferFuncParameters("framebufferRender buffer", target, attachment)) 1832 if (isContextLost() || !validateFramebufferFuncParameters("framebufferRender buffer", target, attachment))
1913 return; 1833 return;
1914 if (renderbuffertarget != GL_RENDERBUFFER) { 1834 if (renderbuffertarget != GL_RENDERBUFFER) {
1915 synthesizeGLError(GL_INVALID_ENUM, "framebufferRenderbuffer", "invalid t arget"); 1835 synthesizeGLError(GL_INVALID_ENUM, "framebufferRenderbuffer", "invalid t arget");
1916 return; 1836 return;
1917 } 1837 }
1918 if (buffer && !buffer->validate(contextGroup(), this)) { 1838 if (buffer && !buffer->validate(contextGroup(), this)) {
1919 synthesizeGLError(GL_INVALID_OPERATION, "framebufferRenderbuffer", "no b uffer or buffer not from this context"); 1839 synthesizeGLError(GL_INVALID_OPERATION, "framebufferRenderbuffer", "no b uffer or buffer not from this context");
1920 return; 1840 return;
(...skipping 21 matching lines...) Expand all
1942 m_context->framebufferRenderbuffer(target, GL_STENCIL_ATTACHMENT, re nderbuffertarget, objectOrZero(emulatedStencilBuffer)); 1862 m_context->framebufferRenderbuffer(target, GL_STENCIL_ATTACHMENT, re nderbuffertarget, objectOrZero(emulatedStencilBuffer));
1943 } 1863 }
1944 break; 1864 break;
1945 default: 1865 default:
1946 m_context->framebufferRenderbuffer(target, attachment, renderbuffertarge t, bufferObject); 1866 m_context->framebufferRenderbuffer(target, attachment, renderbuffertarge t, bufferObject);
1947 } 1867 }
1948 m_framebufferBinding->setAttachmentForBoundFramebuffer(attachment, buffer); 1868 m_framebufferBinding->setAttachmentForBoundFramebuffer(attachment, buffer);
1949 applyStencilTest(); 1869 applyStencilTest();
1950 } 1870 }
1951 1871
1952 void WebGLRenderingContext::framebufferTexture2D(GLenum target, GLenum attachmen t, GLenum textarget, WebGLTexture* texture, GLint level) 1872 void WebGLRenderingContextBase::framebufferTexture2D(GLenum target, GLenum attac hment, GLenum textarget, WebGLTexture* texture, GLint level)
1953 { 1873 {
1954 if (isContextLost() || !validateFramebufferFuncParameters("framebufferTextur e2D", target, attachment)) 1874 if (isContextLost() || !validateFramebufferFuncParameters("framebufferTextur e2D", target, attachment))
1955 return; 1875 return;
1956 if (level) { 1876 if (level) {
1957 synthesizeGLError(GL_INVALID_VALUE, "framebufferTexture2D", "level not 0 "); 1877 synthesizeGLError(GL_INVALID_VALUE, "framebufferTexture2D", "level not 0 ");
1958 return; 1878 return;
1959 } 1879 }
1960 if (texture && !texture->validate(contextGroup(), this)) { 1880 if (texture && !texture->validate(contextGroup(), this)) {
1961 synthesizeGLError(GL_INVALID_OPERATION, "framebufferTexture2D", "no text ure or texture not from this context"); 1881 synthesizeGLError(GL_INVALID_OPERATION, "framebufferTexture2D", "no text ure or texture not from this context");
1962 return; 1882 return;
(...skipping 17 matching lines...) Expand all
1980 case GL_STENCIL_ATTACHMENT: 1900 case GL_STENCIL_ATTACHMENT:
1981 m_context->framebufferTexture2D(target, attachment, textarget, textureOb ject, level); 1901 m_context->framebufferTexture2D(target, attachment, textarget, textureOb ject, level);
1982 break; 1902 break;
1983 default: 1903 default:
1984 m_context->framebufferTexture2D(target, attachment, textarget, textureOb ject, level); 1904 m_context->framebufferTexture2D(target, attachment, textarget, textureOb ject, level);
1985 } 1905 }
1986 m_framebufferBinding->setAttachmentForBoundFramebuffer(attachment, textarget , texture, level); 1906 m_framebufferBinding->setAttachmentForBoundFramebuffer(attachment, textarget , texture, level);
1987 applyStencilTest(); 1907 applyStencilTest();
1988 } 1908 }
1989 1909
1990 void WebGLRenderingContext::frontFace(GLenum mode) 1910 void WebGLRenderingContextBase::frontFace(GLenum mode)
1991 { 1911 {
1992 if (isContextLost()) 1912 if (isContextLost())
1993 return; 1913 return;
1994 switch (mode) { 1914 switch (mode) {
1995 case GL_CW: 1915 case GL_CW:
1996 case GL_CCW: 1916 case GL_CCW:
1997 break; 1917 break;
1998 default: 1918 default:
1999 synthesizeGLError(GL_INVALID_ENUM, "frontFace", "invalid mode"); 1919 synthesizeGLError(GL_INVALID_ENUM, "frontFace", "invalid mode");
2000 return; 1920 return;
2001 } 1921 }
2002 m_context->frontFace(mode); 1922 m_context->frontFace(mode);
2003 } 1923 }
2004 1924
2005 void WebGLRenderingContext::generateMipmap(GLenum target) 1925 void WebGLRenderingContextBase::generateMipmap(GLenum target)
2006 { 1926 {
2007 if (isContextLost()) 1927 if (isContextLost())
2008 return; 1928 return;
2009 WebGLTexture* tex = validateTextureBinding("generateMipmap", target, false); 1929 WebGLTexture* tex = validateTextureBinding("generateMipmap", target, false);
2010 if (!tex) 1930 if (!tex)
2011 return; 1931 return;
2012 if (!tex->canGenerateMipmaps()) { 1932 if (!tex->canGenerateMipmaps()) {
2013 synthesizeGLError(GL_INVALID_OPERATION, "generateMipmap", "level 0 not p ower of 2 or not all the same size"); 1933 synthesizeGLError(GL_INVALID_OPERATION, "generateMipmap", "level 0 not p ower of 2 or not all the same size");
2014 return; 1934 return;
2015 } 1935 }
(...skipping 10 matching lines...) Expand all
2026 } 1946 }
2027 #endif 1947 #endif
2028 m_context->generateMipmap(target); 1948 m_context->generateMipmap(target);
2029 #if OS(MACOSX) 1949 #if OS(MACOSX)
2030 if (needToResetMinFilter) 1950 if (needToResetMinFilter)
2031 m_context->texParameteri(target, GL_TEXTURE_MIN_FILTER, tex->getMinFilte r()); 1951 m_context->texParameteri(target, GL_TEXTURE_MIN_FILTER, tex->getMinFilte r());
2032 #endif 1952 #endif
2033 tex->generateMipmapLevelInfo(); 1953 tex->generateMipmapLevelInfo();
2034 } 1954 }
2035 1955
2036 PassRefPtr<WebGLActiveInfo> WebGLRenderingContext::getActiveAttrib(WebGLProgram* program, GLuint index) 1956 PassRefPtr<WebGLActiveInfo> WebGLRenderingContextBase::getActiveAttrib(WebGLProg ram* program, GLuint index)
2037 { 1957 {
2038 if (isContextLost() || !validateWebGLObject("getActiveAttrib", program)) 1958 if (isContextLost() || !validateWebGLObject("getActiveAttrib", program))
2039 return 0; 1959 return 0;
2040 blink::WebGraphicsContext3D::ActiveInfo info; 1960 blink::WebGraphicsContext3D::ActiveInfo info;
2041 if (!m_context->getActiveAttrib(objectOrZero(program), index, info)) 1961 if (!m_context->getActiveAttrib(objectOrZero(program), index, info))
2042 return 0; 1962 return 0;
2043 return WebGLActiveInfo::create(info.name, info.type, info.size); 1963 return WebGLActiveInfo::create(info.name, info.type, info.size);
2044 } 1964 }
2045 1965
2046 PassRefPtr<WebGLActiveInfo> WebGLRenderingContext::getActiveUniform(WebGLProgram * program, GLuint index) 1966 PassRefPtr<WebGLActiveInfo> WebGLRenderingContextBase::getActiveUniform(WebGLPro gram* program, GLuint index)
2047 { 1967 {
2048 if (isContextLost() || !validateWebGLObject("getActiveUniform", program)) 1968 if (isContextLost() || !validateWebGLObject("getActiveUniform", program))
2049 return 0; 1969 return 0;
2050 blink::WebGraphicsContext3D::ActiveInfo info; 1970 blink::WebGraphicsContext3D::ActiveInfo info;
2051 if (!m_context->getActiveUniform(objectOrZero(program), index, info)) 1971 if (!m_context->getActiveUniform(objectOrZero(program), index, info))
2052 return 0; 1972 return 0;
2053 return WebGLActiveInfo::create(info.name, info.type, info.size); 1973 return WebGLActiveInfo::create(info.name, info.type, info.size);
2054 } 1974 }
2055 1975
2056 bool WebGLRenderingContext::getAttachedShaders(WebGLProgram* program, Vector<Ref Ptr<WebGLShader> >& shaderObjects) 1976 bool WebGLRenderingContextBase::getAttachedShaders(WebGLProgram* program, Vector <RefPtr<WebGLShader> >& shaderObjects)
2057 { 1977 {
2058 shaderObjects.clear(); 1978 shaderObjects.clear();
2059 if (isContextLost() || !validateWebGLObject("getAttachedShaders", program)) 1979 if (isContextLost() || !validateWebGLObject("getAttachedShaders", program))
2060 return false; 1980 return false;
2061 1981
2062 const GLenum shaderType[] = { 1982 const GLenum shaderType[] = {
2063 GL_VERTEX_SHADER, 1983 GL_VERTEX_SHADER,
2064 GL_FRAGMENT_SHADER 1984 GL_FRAGMENT_SHADER
2065 }; 1985 };
2066 for (unsigned i = 0; i < sizeof(shaderType) / sizeof(GLenum); ++i) { 1986 for (unsigned i = 0; i < sizeof(shaderType) / sizeof(GLenum); ++i) {
2067 WebGLShader* shader = program->getAttachedShader(shaderType[i]); 1987 WebGLShader* shader = program->getAttachedShader(shaderType[i]);
2068 if (shader) 1988 if (shader)
2069 shaderObjects.append(shader); 1989 shaderObjects.append(shader);
2070 } 1990 }
2071 return true; 1991 return true;
2072 } 1992 }
2073 1993
2074 GLint WebGLRenderingContext::getAttribLocation(WebGLProgram* program, const Stri ng& name) 1994 GLint WebGLRenderingContextBase::getAttribLocation(WebGLProgram* program, const String& name)
2075 { 1995 {
2076 if (isContextLost() || !validateWebGLObject("getAttribLocation", program)) 1996 if (isContextLost() || !validateWebGLObject("getAttribLocation", program))
2077 return -1; 1997 return -1;
2078 if (!validateLocationLength("getAttribLocation", name)) 1998 if (!validateLocationLength("getAttribLocation", name))
2079 return -1; 1999 return -1;
2080 if (!validateString("getAttribLocation", name)) 2000 if (!validateString("getAttribLocation", name))
2081 return -1; 2001 return -1;
2082 if (isPrefixReserved(name)) 2002 if (isPrefixReserved(name))
2083 return -1; 2003 return -1;
2084 if (!program->linkStatus()) { 2004 if (!program->linkStatus()) {
2085 synthesizeGLError(GL_INVALID_OPERATION, "getAttribLocation", "program no t linked"); 2005 synthesizeGLError(GL_INVALID_OPERATION, "getAttribLocation", "program no t linked");
2086 return 0; 2006 return 0;
2087 } 2007 }
2088 return m_context->getAttribLocation(objectOrZero(program), name.utf8().data( )); 2008 return m_context->getAttribLocation(objectOrZero(program), name.utf8().data( ));
2089 } 2009 }
2090 2010
2091 WebGLGetInfo WebGLRenderingContext::getBufferParameter(GLenum target, GLenum pna me) 2011 WebGLGetInfo WebGLRenderingContextBase::getBufferParameter(GLenum target, GLenum pname)
2092 { 2012 {
2093 if (isContextLost()) 2013 if (isContextLost())
2094 return WebGLGetInfo(); 2014 return WebGLGetInfo();
2095 if (target != GL_ARRAY_BUFFER && target != GL_ELEMENT_ARRAY_BUFFER) { 2015 if (target != GL_ARRAY_BUFFER && target != GL_ELEMENT_ARRAY_BUFFER) {
2096 synthesizeGLError(GL_INVALID_ENUM, "getBufferParameter", "invalid target "); 2016 synthesizeGLError(GL_INVALID_ENUM, "getBufferParameter", "invalid target ");
2097 return WebGLGetInfo(); 2017 return WebGLGetInfo();
2098 } 2018 }
2099 2019
2100 if (pname != GL_BUFFER_SIZE && pname != GL_BUFFER_USAGE) { 2020 if (pname != GL_BUFFER_SIZE && pname != GL_BUFFER_USAGE) {
2101 synthesizeGLError(GL_INVALID_ENUM, "getBufferParameter", "invalid parame ter name"); 2021 synthesizeGLError(GL_INVALID_ENUM, "getBufferParameter", "invalid parame ter name");
2102 return WebGLGetInfo(); 2022 return WebGLGetInfo();
2103 } 2023 }
2104 2024
2105 GLint value = 0; 2025 GLint value = 0;
2106 m_context->getBufferParameteriv(target, pname, &value); 2026 m_context->getBufferParameteriv(target, pname, &value);
2107 if (pname == GL_BUFFER_SIZE) 2027 if (pname == GL_BUFFER_SIZE)
2108 return WebGLGetInfo(value); 2028 return WebGLGetInfo(value);
2109 return WebGLGetInfo(static_cast<unsigned>(value)); 2029 return WebGLGetInfo(static_cast<unsigned>(value));
2110 } 2030 }
2111 2031
2112 PassRefPtr<WebGLContextAttributes> WebGLRenderingContext::getContextAttributes() 2032 PassRefPtr<WebGLContextAttributes> WebGLRenderingContextBase::getContextAttribut es()
2113 { 2033 {
2114 if (isContextLost()) 2034 if (isContextLost())
2115 return 0; 2035 return 0;
2116 // We always need to return a new WebGLContextAttributes object to 2036 // We always need to return a new WebGLContextAttributes object to
2117 // prevent the user from mutating any cached version. 2037 // prevent the user from mutating any cached version.
2118 blink::WebGraphicsContext3D::Attributes attrs = m_context->getContextAttribu tes(); 2038 blink::WebGraphicsContext3D::Attributes attrs = m_context->getContextAttribu tes();
2119 RefPtr<WebGLContextAttributes> attributes = m_requestedAttributes->clone(); 2039 RefPtr<WebGLContextAttributes> attributes = m_requestedAttributes->clone();
2120 // Some requested attributes may not be honored, so we need to query the und erlying 2040 // Some requested attributes may not be honored, so we need to query the und erlying
2121 // context/drawing buffer and adjust accordingly. 2041 // context/drawing buffer and adjust accordingly.
2122 if (m_requestedAttributes->depth() && !attrs.depth) 2042 if (m_requestedAttributes->depth() && !attrs.depth)
2123 attributes->setDepth(false); 2043 attributes->setDepth(false);
2124 if (m_requestedAttributes->stencil() && !attrs.stencil) 2044 if (m_requestedAttributes->stencil() && !attrs.stencil)
2125 attributes->setStencil(false); 2045 attributes->setStencil(false);
2126 attributes->setAntialias(m_drawingBuffer->multisample()); 2046 attributes->setAntialias(m_drawingBuffer->multisample());
2127 return attributes.release(); 2047 return attributes.release();
2128 } 2048 }
2129 2049
2130 GLenum WebGLRenderingContext::getError() 2050 GLenum WebGLRenderingContextBase::getError()
2131 { 2051 {
2132 if (m_lostContextErrors.size()) { 2052 if (m_lostContextErrors.size()) {
2133 GLenum err = m_lostContextErrors.first(); 2053 GLenum err = m_lostContextErrors.first();
2134 m_lostContextErrors.remove(0); 2054 m_lostContextErrors.remove(0);
2135 return err; 2055 return err;
2136 } 2056 }
2137 2057
2138 if (isContextLost()) 2058 if (isContextLost())
2139 return GL_NO_ERROR; 2059 return GL_NO_ERROR;
2140 2060
2141 return m_context->getError(); 2061 return m_context->getError();
2142 } 2062 }
2143 2063
2144 bool WebGLRenderingContext::ExtensionTracker::matchesNameWithPrefixes(const Stri ng& name) const 2064 bool WebGLRenderingContextBase::ExtensionTracker::matchesNameWithPrefixes(const String& name) const
2145 { 2065 {
2146 static const char* const unprefixed[] = { "", 0, }; 2066 static const char* const unprefixed[] = { "", 0, };
2147 2067
2148 const char* const* prefixes = m_prefixes ? m_prefixes : unprefixed; 2068 const char* const* prefixes = m_prefixes ? m_prefixes : unprefixed;
2149 for (; *prefixes; ++prefixes) { 2069 for (; *prefixes; ++prefixes) {
2150 String prefixedName = String(*prefixes) + extensionName(); 2070 String prefixedName = String(*prefixes) + extensionName();
2151 if (equalIgnoringCase(prefixedName, name)) { 2071 if (equalIgnoringCase(prefixedName, name)) {
2152 return true; 2072 return true;
2153 } 2073 }
2154 } 2074 }
2155 return false; 2075 return false;
2156 } 2076 }
2157 2077
2158 PassRefPtr<WebGLExtension> WebGLRenderingContext::getExtension(const String& nam e) 2078 PassRefPtr<WebGLExtension> WebGLRenderingContextBase::getExtension(const String& name)
2159 { 2079 {
2160 if (isContextLost()) 2080 if (isContextLost())
2161 return 0; 2081 return 0;
2162 2082
2163 for (size_t i = 0; i < m_extensions.size(); ++i) { 2083 for (size_t i = 0; i < m_extensions.size(); ++i) {
2164 ExtensionTracker* tracker = m_extensions[i]; 2084 ExtensionTracker* tracker = m_extensions[i];
2165 if (tracker->matchesNameWithPrefixes(name)) { 2085 if (tracker->matchesNameWithPrefixes(name)) {
2166 if (tracker->webglDebugRendererInfo() && !allowWebGLDebugRendererInf o()) 2086 if (tracker->webglDebugRendererInfo() && !allowWebGLDebugRendererInf o())
2167 return 0; 2087 return 0;
2168 if (tracker->privileged() && !allowPrivilegedExtensions()) 2088 if (tracker->privileged() && !allowPrivilegedExtensions())
2169 return 0; 2089 return 0;
2170 if (tracker->draft() && !RuntimeEnabledFeatures::webGLDraftExtension sEnabled()) 2090 if (tracker->draft() && !RuntimeEnabledFeatures::webGLDraftExtension sEnabled())
2171 return 0; 2091 return 0;
2172 if (!tracker->supported(this)) 2092 if (!tracker->supported(this))
2173 return 0; 2093 return 0;
2174 return tracker->getExtension(this); 2094
2095 RefPtr<WebGLExtension> extension = tracker->getExtension(this);
2096 if (extension)
2097 m_extensionEnabled[extension->name()] = true;
2098 return extension.release();
2175 } 2099 }
2176 } 2100 }
2177 2101
2178 return 0; 2102 return 0;
2179 } 2103 }
2180 2104
2181 WebGLGetInfo WebGLRenderingContext::getFramebufferAttachmentParameter(GLenum tar get, GLenum attachment, GLenum pname) 2105 WebGLGetInfo WebGLRenderingContextBase::getFramebufferAttachmentParameter(GLenum target, GLenum attachment, GLenum pname)
2182 { 2106 {
2183 if (isContextLost() || !validateFramebufferFuncParameters("getFramebufferAtt achmentParameter", target, attachment)) 2107 if (isContextLost() || !validateFramebufferFuncParameters("getFramebufferAtt achmentParameter", target, attachment))
2184 return WebGLGetInfo(); 2108 return WebGLGetInfo();
2185 2109
2186 if (!m_framebufferBinding || !m_framebufferBinding->object()) { 2110 if (!m_framebufferBinding || !m_framebufferBinding->object()) {
2187 synthesizeGLError(GL_INVALID_OPERATION, "getFramebufferAttachmentParamet er", "no framebuffer bound"); 2111 synthesizeGLError(GL_INVALID_OPERATION, "getFramebufferAttachmentParamet er", "no framebuffer bound");
2188 return WebGLGetInfo(); 2112 return WebGLGetInfo();
2189 } 2113 }
2190 2114
2191 WebGLSharedObject* object = m_framebufferBinding->getAttachmentObject(attach ment); 2115 WebGLSharedObject* object = m_framebufferBinding->getAttachmentObject(attach ment);
(...skipping 30 matching lines...) Expand all
2222 return WebGLGetInfo(GL_RENDERBUFFER); 2146 return WebGLGetInfo(GL_RENDERBUFFER);
2223 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: 2147 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
2224 return WebGLGetInfo(PassRefPtr<WebGLRenderbuffer>(static_cast<WebGLR enderbuffer*>(object))); 2148 return WebGLGetInfo(PassRefPtr<WebGLRenderbuffer>(static_cast<WebGLR enderbuffer*>(object)));
2225 default: 2149 default:
2226 synthesizeGLError(GL_INVALID_ENUM, "getFramebufferAttachmentParamete r", "invalid parameter name for renderbuffer attachment"); 2150 synthesizeGLError(GL_INVALID_ENUM, "getFramebufferAttachmentParamete r", "invalid parameter name for renderbuffer attachment");
2227 return WebGLGetInfo(); 2151 return WebGLGetInfo();
2228 } 2152 }
2229 } 2153 }
2230 } 2154 }
2231 2155
2232 WebGLGetInfo WebGLRenderingContext::getParameter(GLenum pname) 2156 WebGLGetInfo WebGLRenderingContextBase::getParameter(GLenum pname)
2233 { 2157 {
2234 if (isContextLost()) 2158 if (isContextLost())
2235 return WebGLGetInfo(); 2159 return WebGLGetInfo();
2236 const int intZero = 0; 2160 const int intZero = 0;
2237 switch (pname) { 2161 switch (pname) {
2238 case GL_ACTIVE_TEXTURE: 2162 case GL_ACTIVE_TEXTURE:
2239 return getUnsignedIntParameter(pname); 2163 return getUnsignedIntParameter(pname);
2240 case GL_ALIASED_LINE_WIDTH_RANGE: 2164 case GL_ALIASED_LINE_WIDTH_RANGE:
2241 return getWebGLFloatArrayParameter(pname); 2165 return getWebGLFloatArrayParameter(pname);
2242 case GL_ALIASED_POINT_SIZE_RANGE: 2166 case GL_ALIASED_POINT_SIZE_RANGE:
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
2406 return WebGLGetInfo(m_unpackPremultiplyAlpha); 2330 return WebGLGetInfo(m_unpackPremultiplyAlpha);
2407 case GC3D_UNPACK_COLORSPACE_CONVERSION_WEBGL: 2331 case GC3D_UNPACK_COLORSPACE_CONVERSION_WEBGL:
2408 return WebGLGetInfo(m_unpackColorspaceConversion); 2332 return WebGLGetInfo(m_unpackColorspaceConversion);
2409 case GL_VENDOR: 2333 case GL_VENDOR:
2410 return WebGLGetInfo(String("WebKit")); 2334 return WebGLGetInfo(String("WebKit"));
2411 case GL_VERSION: 2335 case GL_VERSION:
2412 return WebGLGetInfo("WebGL 1.0 (" + String(m_context->getString(GL_VERSI ON)) + ")"); 2336 return WebGLGetInfo("WebGL 1.0 (" + String(m_context->getString(GL_VERSI ON)) + ")");
2413 case GL_VIEWPORT: 2337 case GL_VIEWPORT:
2414 return getWebGLIntArrayParameter(pname); 2338 return getWebGLIntArrayParameter(pname);
2415 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES: // OES_standard_derivatives 2339 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES: // OES_standard_derivatives
2416 if (m_oesStandardDerivatives) 2340 if (extensionEnabled(OESStandardDerivativesName))
2417 return getUnsignedIntParameter(GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OE S); 2341 return getUnsignedIntParameter(GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OE S);
2418 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me, OES_standard_derivatives not enabled"); 2342 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me, OES_standard_derivatives not enabled");
2419 return WebGLGetInfo(); 2343 return WebGLGetInfo();
2420 case WebGLDebugRendererInfo::UNMASKED_RENDERER_WEBGL: 2344 case WebGLDebugRendererInfo::UNMASKED_RENDERER_WEBGL:
2421 if (m_webglDebugRendererInfo) 2345 if (extensionEnabled(WebGLDebugRendererInfoName))
2422 return WebGLGetInfo(m_context->getString(GL_RENDERER)); 2346 return WebGLGetInfo(m_context->getString(GL_RENDERER));
2423 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me, WEBGL_debug_renderer_info not enabled"); 2347 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me, WEBGL_debug_renderer_info not enabled");
2424 return WebGLGetInfo(); 2348 return WebGLGetInfo();
2425 case WebGLDebugRendererInfo::UNMASKED_VENDOR_WEBGL: 2349 case WebGLDebugRendererInfo::UNMASKED_VENDOR_WEBGL:
2426 if (m_webglDebugRendererInfo) 2350 if (extensionEnabled(WebGLDebugRendererInfoName))
2427 return WebGLGetInfo(m_context->getString(GL_VENDOR)); 2351 return WebGLGetInfo(m_context->getString(GL_VENDOR));
2428 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me, WEBGL_debug_renderer_info not enabled"); 2352 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me, WEBGL_debug_renderer_info not enabled");
2429 return WebGLGetInfo(); 2353 return WebGLGetInfo();
2430 case GL_VERTEX_ARRAY_BINDING_OES: // OES_vertex_array_object 2354 case GL_VERTEX_ARRAY_BINDING_OES: // OES_vertex_array_object
2431 if (m_oesVertexArrayObject) { 2355 if (extensionEnabled(OESVertexArrayObjectName)) {
2432 if (!m_boundVertexArrayObject->isDefaultObject()) 2356 if (!m_boundVertexArrayObject->isDefaultObject())
2433 return WebGLGetInfo(PassRefPtr<WebGLVertexArrayObjectOES>(m_boun dVertexArrayObject)); 2357 return WebGLGetInfo(PassRefPtr<WebGLVertexArrayObjectOES>(m_boun dVertexArrayObject));
2434 return WebGLGetInfo(); 2358 return WebGLGetInfo();
2435 } 2359 }
2436 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me, OES_vertex_array_object not enabled"); 2360 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me, OES_vertex_array_object not enabled");
2437 return WebGLGetInfo(); 2361 return WebGLGetInfo();
2438 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT: // EXT_texture_filter_anisotropic 2362 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT: // EXT_texture_filter_anisotropic
2439 if (m_extTextureFilterAnisotropic) 2363 if (extensionEnabled(EXTTextureFilterAnisotropicName))
2440 return getUnsignedIntParameter(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT); 2364 return getUnsignedIntParameter(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT);
2441 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me, EXT_texture_filter_anisotropic not enabled"); 2365 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me, EXT_texture_filter_anisotropic not enabled");
2442 return WebGLGetInfo(); 2366 return WebGLGetInfo();
2443 case GL_MAX_COLOR_ATTACHMENTS_EXT: // EXT_draw_buffers BEGIN 2367 case GL_MAX_COLOR_ATTACHMENTS_EXT: // EXT_draw_buffers BEGIN
2444 if (m_webglDrawBuffers) 2368 if (extensionEnabled(WebGLDrawBuffersName))
2445 return WebGLGetInfo(maxColorAttachments()); 2369 return WebGLGetInfo(maxColorAttachments());
2446 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me, WEBGL_draw_buffers not enabled"); 2370 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me, WEBGL_draw_buffers not enabled");
2447 return WebGLGetInfo(); 2371 return WebGLGetInfo();
2448 case GL_MAX_DRAW_BUFFERS_EXT: 2372 case GL_MAX_DRAW_BUFFERS_EXT:
2449 if (m_webglDrawBuffers) 2373 if (extensionEnabled(WebGLDrawBuffersName))
2450 return WebGLGetInfo(maxDrawBuffers()); 2374 return WebGLGetInfo(maxDrawBuffers());
2451 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me, WEBGL_draw_buffers not enabled"); 2375 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me, WEBGL_draw_buffers not enabled");
2452 return WebGLGetInfo(); 2376 return WebGLGetInfo();
2453 default: 2377 default:
2454 if (m_webglDrawBuffers 2378 if (extensionEnabled(WebGLDrawBuffersName)
2455 && pname >= GL_DRAW_BUFFER0_EXT 2379 && pname >= GL_DRAW_BUFFER0_EXT
2456 && pname < static_cast<GLenum>(GL_DRAW_BUFFER0_EXT + maxDrawBuffers( ))) { 2380 && pname < static_cast<GLenum>(GL_DRAW_BUFFER0_EXT + maxDrawBuffers( ))) {
2457 GLint value = GL_NONE; 2381 GLint value = GL_NONE;
2458 if (m_framebufferBinding) 2382 if (m_framebufferBinding)
2459 value = m_framebufferBinding->getDrawBuffer(pname); 2383 value = m_framebufferBinding->getDrawBuffer(pname);
2460 else // emulated backbuffer 2384 else // emulated backbuffer
2461 value = m_backDrawBuffer; 2385 value = m_backDrawBuffer;
2462 return WebGLGetInfo(value); 2386 return WebGLGetInfo(value);
2463 } 2387 }
2464 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me"); 2388 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me");
2465 return WebGLGetInfo(); 2389 return WebGLGetInfo();
2466 } 2390 }
2467 } 2391 }
2468 2392
2469 WebGLGetInfo WebGLRenderingContext::getProgramParameter(WebGLProgram* program, G Lenum pname) 2393 WebGLGetInfo WebGLRenderingContextBase::getProgramParameter(WebGLProgram* progra m, GLenum pname)
2470 { 2394 {
2471 if (isContextLost() || !validateWebGLObject("getProgramParameter", program)) 2395 if (isContextLost() || !validateWebGLObject("getProgramParameter", program))
2472 return WebGLGetInfo(); 2396 return WebGLGetInfo();
2473 2397
2474 GLint value = 0; 2398 GLint value = 0;
2475 switch (pname) { 2399 switch (pname) {
2476 case GL_DELETE_STATUS: 2400 case GL_DELETE_STATUS:
2477 return WebGLGetInfo(program->isDeleted()); 2401 return WebGLGetInfo(program->isDeleted());
2478 case GL_VALIDATE_STATUS: 2402 case GL_VALIDATE_STATUS:
2479 m_context->getProgramiv(objectOrZero(program), pname, &value); 2403 m_context->getProgramiv(objectOrZero(program), pname, &value);
2480 return WebGLGetInfo(static_cast<bool>(value)); 2404 return WebGLGetInfo(static_cast<bool>(value));
2481 case GL_LINK_STATUS: 2405 case GL_LINK_STATUS:
2482 return WebGLGetInfo(program->linkStatus()); 2406 return WebGLGetInfo(program->linkStatus());
2483 case GL_ATTACHED_SHADERS: 2407 case GL_ATTACHED_SHADERS:
2484 case GL_ACTIVE_ATTRIBUTES: 2408 case GL_ACTIVE_ATTRIBUTES:
2485 case GL_ACTIVE_UNIFORMS: 2409 case GL_ACTIVE_UNIFORMS:
2486 m_context->getProgramiv(objectOrZero(program), pname, &value); 2410 m_context->getProgramiv(objectOrZero(program), pname, &value);
2487 return WebGLGetInfo(value); 2411 return WebGLGetInfo(value);
2488 default: 2412 default:
2489 synthesizeGLError(GL_INVALID_ENUM, "getProgramParameter", "invalid param eter name"); 2413 synthesizeGLError(GL_INVALID_ENUM, "getProgramParameter", "invalid param eter name");
2490 return WebGLGetInfo(); 2414 return WebGLGetInfo();
2491 } 2415 }
2492 } 2416 }
2493 2417
2494 String WebGLRenderingContext::getProgramInfoLog(WebGLProgram* program) 2418 String WebGLRenderingContextBase::getProgramInfoLog(WebGLProgram* program)
2495 { 2419 {
2496 if (isContextLost()) 2420 if (isContextLost())
2497 return String(); 2421 return String();
2498 if (!validateWebGLObject("getProgramInfoLog", program)) 2422 if (!validateWebGLObject("getProgramInfoLog", program))
2499 return ""; 2423 return "";
2500 return ensureNotNull(m_context->getProgramInfoLog(objectOrZero(program))); 2424 return ensureNotNull(m_context->getProgramInfoLog(objectOrZero(program)));
2501 } 2425 }
2502 2426
2503 WebGLGetInfo WebGLRenderingContext::getRenderbufferParameter(GLenum target, GLen um pname) 2427 WebGLGetInfo WebGLRenderingContextBase::getRenderbufferParameter(GLenum target, GLenum pname)
2504 { 2428 {
2505 if (isContextLost()) 2429 if (isContextLost())
2506 return WebGLGetInfo(); 2430 return WebGLGetInfo();
2507 if (target != GL_RENDERBUFFER) { 2431 if (target != GL_RENDERBUFFER) {
2508 synthesizeGLError(GL_INVALID_ENUM, "getRenderbufferParameter", "invalid target"); 2432 synthesizeGLError(GL_INVALID_ENUM, "getRenderbufferParameter", "invalid target");
2509 return WebGLGetInfo(); 2433 return WebGLGetInfo();
2510 } 2434 }
2511 if (!m_renderbufferBinding || !m_renderbufferBinding->object()) { 2435 if (!m_renderbufferBinding || !m_renderbufferBinding->object()) {
2512 synthesizeGLError(GL_INVALID_OPERATION, "getRenderbufferParameter", "no renderbuffer bound"); 2436 synthesizeGLError(GL_INVALID_OPERATION, "getRenderbufferParameter", "no renderbuffer bound");
2513 return WebGLGetInfo(); 2437 return WebGLGetInfo();
(...skipping 20 matching lines...) Expand all
2534 } 2458 }
2535 return WebGLGetInfo(value); 2459 return WebGLGetInfo(value);
2536 case GL_RENDERBUFFER_INTERNAL_FORMAT: 2460 case GL_RENDERBUFFER_INTERNAL_FORMAT:
2537 return WebGLGetInfo(m_renderbufferBinding->internalFormat()); 2461 return WebGLGetInfo(m_renderbufferBinding->internalFormat());
2538 default: 2462 default:
2539 synthesizeGLError(GL_INVALID_ENUM, "getRenderbufferParameter", "invalid parameter name"); 2463 synthesizeGLError(GL_INVALID_ENUM, "getRenderbufferParameter", "invalid parameter name");
2540 return WebGLGetInfo(); 2464 return WebGLGetInfo();
2541 } 2465 }
2542 } 2466 }
2543 2467
2544 WebGLGetInfo WebGLRenderingContext::getShaderParameter(WebGLShader* shader, GLen um pname) 2468 WebGLGetInfo WebGLRenderingContextBase::getShaderParameter(WebGLShader* shader, GLenum pname)
2545 { 2469 {
2546 if (isContextLost() || !validateWebGLObject("getShaderParameter", shader)) 2470 if (isContextLost() || !validateWebGLObject("getShaderParameter", shader))
2547 return WebGLGetInfo(); 2471 return WebGLGetInfo();
2548 GLint value = 0; 2472 GLint value = 0;
2549 switch (pname) { 2473 switch (pname) {
2550 case GL_DELETE_STATUS: 2474 case GL_DELETE_STATUS:
2551 return WebGLGetInfo(shader->isDeleted()); 2475 return WebGLGetInfo(shader->isDeleted());
2552 case GL_COMPILE_STATUS: 2476 case GL_COMPILE_STATUS:
2553 m_context->getShaderiv(objectOrZero(shader), pname, &value); 2477 m_context->getShaderiv(objectOrZero(shader), pname, &value);
2554 return WebGLGetInfo(static_cast<bool>(value)); 2478 return WebGLGetInfo(static_cast<bool>(value));
2555 case GL_SHADER_TYPE: 2479 case GL_SHADER_TYPE:
2556 m_context->getShaderiv(objectOrZero(shader), pname, &value); 2480 m_context->getShaderiv(objectOrZero(shader), pname, &value);
2557 return WebGLGetInfo(static_cast<unsigned>(value)); 2481 return WebGLGetInfo(static_cast<unsigned>(value));
2558 default: 2482 default:
2559 synthesizeGLError(GL_INVALID_ENUM, "getShaderParameter", "invalid parame ter name"); 2483 synthesizeGLError(GL_INVALID_ENUM, "getShaderParameter", "invalid parame ter name");
2560 return WebGLGetInfo(); 2484 return WebGLGetInfo();
2561 } 2485 }
2562 } 2486 }
2563 2487
2564 String WebGLRenderingContext::getShaderInfoLog(WebGLShader* shader) 2488 String WebGLRenderingContextBase::getShaderInfoLog(WebGLShader* shader)
2565 { 2489 {
2566 if (isContextLost()) 2490 if (isContextLost())
2567 return String(); 2491 return String();
2568 if (!validateWebGLObject("getShaderInfoLog", shader)) 2492 if (!validateWebGLObject("getShaderInfoLog", shader))
2569 return ""; 2493 return "";
2570 return ensureNotNull(m_context->getShaderInfoLog(objectOrZero(shader))); 2494 return ensureNotNull(m_context->getShaderInfoLog(objectOrZero(shader)));
2571 } 2495 }
2572 2496
2573 PassRefPtr<WebGLShaderPrecisionFormat> WebGLRenderingContext::getShaderPrecision Format(GLenum shaderType, GLenum precisionType) 2497 PassRefPtr<WebGLShaderPrecisionFormat> WebGLRenderingContextBase::getShaderPreci sionFormat(GLenum shaderType, GLenum precisionType)
2574 { 2498 {
2575 if (isContextLost()) 2499 if (isContextLost())
2576 return 0; 2500 return 0;
2577 switch (shaderType) { 2501 switch (shaderType) {
2578 case GL_VERTEX_SHADER: 2502 case GL_VERTEX_SHADER:
2579 case GL_FRAGMENT_SHADER: 2503 case GL_FRAGMENT_SHADER:
2580 break; 2504 break;
2581 default: 2505 default:
2582 synthesizeGLError(GL_INVALID_ENUM, "getShaderPrecisionFormat", "invalid shader type"); 2506 synthesizeGLError(GL_INVALID_ENUM, "getShaderPrecisionFormat", "invalid shader type");
2583 return 0; 2507 return 0;
(...skipping 10 matching lines...) Expand all
2594 synthesizeGLError(GL_INVALID_ENUM, "getShaderPrecisionFormat", "invalid precision type"); 2518 synthesizeGLError(GL_INVALID_ENUM, "getShaderPrecisionFormat", "invalid precision type");
2595 return 0; 2519 return 0;
2596 } 2520 }
2597 2521
2598 GLint range[2] = {0, 0}; 2522 GLint range[2] = {0, 0};
2599 GLint precision = 0; 2523 GLint precision = 0;
2600 m_context->getShaderPrecisionFormat(shaderType, precisionType, range, &preci sion); 2524 m_context->getShaderPrecisionFormat(shaderType, precisionType, range, &preci sion);
2601 return WebGLShaderPrecisionFormat::create(range[0], range[1], precision); 2525 return WebGLShaderPrecisionFormat::create(range[0], range[1], precision);
2602 } 2526 }
2603 2527
2604 String WebGLRenderingContext::getShaderSource(WebGLShader* shader) 2528 String WebGLRenderingContextBase::getShaderSource(WebGLShader* shader)
2605 { 2529 {
2606 if (isContextLost()) 2530 if (isContextLost())
2607 return String(); 2531 return String();
2608 if (!validateWebGLObject("getShaderSource", shader)) 2532 if (!validateWebGLObject("getShaderSource", shader))
2609 return ""; 2533 return "";
2610 return ensureNotNull(shader->source()); 2534 return ensureNotNull(shader->source());
2611 } 2535 }
2612 2536
2613 Vector<String> WebGLRenderingContext::getSupportedExtensions() 2537 Vector<String> WebGLRenderingContextBase::getSupportedExtensions()
2614 { 2538 {
2615 Vector<String> result; 2539 Vector<String> result;
2616 if (isContextLost()) 2540 if (isContextLost())
2617 return result; 2541 return result;
2618 2542
2619 for (size_t i = 0; i < m_extensions.size(); ++i) { 2543 for (size_t i = 0; i < m_extensions.size(); ++i) {
2620 ExtensionTracker* tracker = m_extensions[i]; 2544 ExtensionTracker* tracker = m_extensions[i];
2621 if (tracker->webglDebugRendererInfo() && !allowWebGLDebugRendererInfo()) 2545 if (tracker->webglDebugRendererInfo() && !allowWebGLDebugRendererInfo())
2622 continue; 2546 continue;
2623 if (tracker->privileged() && !allowPrivilegedExtensions()) 2547 if (tracker->privileged() && !allowPrivilegedExtensions())
2624 continue; 2548 continue;
2625 if (tracker->draft() && !RuntimeEnabledFeatures::webGLDraftExtensionsEna bled()) 2549 if (tracker->draft() && !RuntimeEnabledFeatures::webGLDraftExtensionsEna bled())
2626 continue; 2550 continue;
2627 if (tracker->supported(this)) 2551 if (tracker->supported(this))
2628 result.append(String(tracker->prefixed() ? "WEBKIT_" : "") + tracke r->extensionName()); 2552 result.append(String(tracker->prefixed() ? "WEBKIT_" : "") + tracke r->extensionName());
2629 } 2553 }
2630 2554
2631 return result; 2555 return result;
2632 } 2556 }
2633 2557
2634 WebGLGetInfo WebGLRenderingContext::getTexParameter(GLenum target, GLenum pname) 2558 WebGLGetInfo WebGLRenderingContextBase::getTexParameter(GLenum target, GLenum pn ame)
2635 { 2559 {
2636 if (isContextLost()) 2560 if (isContextLost())
2637 return WebGLGetInfo(); 2561 return WebGLGetInfo();
2638 WebGLTexture* tex = validateTextureBinding("getTexParameter", target, false) ; 2562 WebGLTexture* tex = validateTextureBinding("getTexParameter", target, false) ;
2639 if (!tex) 2563 if (!tex)
2640 return WebGLGetInfo(); 2564 return WebGLGetInfo();
2641 GLint value = 0; 2565 GLint value = 0;
2642 switch (pname) { 2566 switch (pname) {
2643 case GL_TEXTURE_MAG_FILTER: 2567 case GL_TEXTURE_MAG_FILTER:
2644 case GL_TEXTURE_MIN_FILTER: 2568 case GL_TEXTURE_MIN_FILTER:
2645 case GL_TEXTURE_WRAP_S: 2569 case GL_TEXTURE_WRAP_S:
2646 case GL_TEXTURE_WRAP_T: 2570 case GL_TEXTURE_WRAP_T:
2647 m_context->getTexParameteriv(target, pname, &value); 2571 m_context->getTexParameteriv(target, pname, &value);
2648 return WebGLGetInfo(static_cast<unsigned>(value)); 2572 return WebGLGetInfo(static_cast<unsigned>(value));
2649 case GL_TEXTURE_MAX_ANISOTROPY_EXT: // EXT_texture_filter_anisotropic 2573 case GL_TEXTURE_MAX_ANISOTROPY_EXT: // EXT_texture_filter_anisotropic
2650 if (m_extTextureFilterAnisotropic) { 2574 if (extensionEnabled(EXTTextureFilterAnisotropicName)) {
2651 m_context->getTexParameteriv(target, pname, &value); 2575 m_context->getTexParameteriv(target, pname, &value);
2652 return WebGLGetInfo(static_cast<unsigned>(value)); 2576 return WebGLGetInfo(static_cast<unsigned>(value));
2653 } 2577 }
2654 synthesizeGLError(GL_INVALID_ENUM, "getTexParameter", "invalid parameter name, EXT_texture_filter_anisotropic not enabled"); 2578 synthesizeGLError(GL_INVALID_ENUM, "getTexParameter", "invalid parameter name, EXT_texture_filter_anisotropic not enabled");
2655 return WebGLGetInfo(); 2579 return WebGLGetInfo();
2656 default: 2580 default:
2657 synthesizeGLError(GL_INVALID_ENUM, "getTexParameter", "invalid parameter name"); 2581 synthesizeGLError(GL_INVALID_ENUM, "getTexParameter", "invalid parameter name");
2658 return WebGLGetInfo(); 2582 return WebGLGetInfo();
2659 } 2583 }
2660 } 2584 }
2661 2585
2662 WebGLGetInfo WebGLRenderingContext::getUniform(WebGLProgram* program, const WebG LUniformLocation* uniformLocation) 2586 WebGLGetInfo WebGLRenderingContextBase::getUniform(WebGLProgram* program, const WebGLUniformLocation* uniformLocation)
2663 { 2587 {
2664 if (isContextLost() || !validateWebGLObject("getUniform", program)) 2588 if (isContextLost() || !validateWebGLObject("getUniform", program))
2665 return WebGLGetInfo(); 2589 return WebGLGetInfo();
2666 if (!uniformLocation || uniformLocation->program() != program) { 2590 if (!uniformLocation || uniformLocation->program() != program) {
2667 synthesizeGLError(GL_INVALID_OPERATION, "getUniform", "no uniformlocatio n or not valid for this program"); 2591 synthesizeGLError(GL_INVALID_OPERATION, "getUniform", "no uniformlocatio n or not valid for this program");
2668 return WebGLGetInfo(); 2592 return WebGLGetInfo();
2669 } 2593 }
2670 GLint location = uniformLocation->location(); 2594 GLint location = uniformLocation->location();
2671 2595
2672 // FIXME: make this more efficient using WebGLUniformLocation and caching ty pes in it 2596 // FIXME: make this more efficient using WebGLUniformLocation and caching ty pes in it
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
2797 notImplemented(); 2721 notImplemented();
2798 } 2722 }
2799 } 2723 }
2800 } 2724 }
2801 } 2725 }
2802 // If we get here, something went wrong in our unfortunately complex logic a bove 2726 // If we get here, something went wrong in our unfortunately complex logic a bove
2803 synthesizeGLError(GL_INVALID_VALUE, "getUniform", "unknown error"); 2727 synthesizeGLError(GL_INVALID_VALUE, "getUniform", "unknown error");
2804 return WebGLGetInfo(); 2728 return WebGLGetInfo();
2805 } 2729 }
2806 2730
2807 PassRefPtr<WebGLUniformLocation> WebGLRenderingContext::getUniformLocation(WebGL Program* program, const String& name) 2731 PassRefPtr<WebGLUniformLocation> WebGLRenderingContextBase::getUniformLocation(W ebGLProgram* program, const String& name)
2808 { 2732 {
2809 if (isContextLost() || !validateWebGLObject("getUniformLocation", program)) 2733 if (isContextLost() || !validateWebGLObject("getUniformLocation", program))
2810 return 0; 2734 return 0;
2811 if (!validateLocationLength("getUniformLocation", name)) 2735 if (!validateLocationLength("getUniformLocation", name))
2812 return 0; 2736 return 0;
2813 if (!validateString("getUniformLocation", name)) 2737 if (!validateString("getUniformLocation", name))
2814 return 0; 2738 return 0;
2815 if (isPrefixReserved(name)) 2739 if (isPrefixReserved(name))
2816 return 0; 2740 return 0;
2817 if (!program->linkStatus()) { 2741 if (!program->linkStatus()) {
2818 synthesizeGLError(GL_INVALID_OPERATION, "getUniformLocation", "program n ot linked"); 2742 synthesizeGLError(GL_INVALID_OPERATION, "getUniformLocation", "program n ot linked");
2819 return 0; 2743 return 0;
2820 } 2744 }
2821 GLint uniformLocation = m_context->getUniformLocation(objectOrZero(program), name.utf8().data()); 2745 GLint uniformLocation = m_context->getUniformLocation(objectOrZero(program), name.utf8().data());
2822 if (uniformLocation == -1) 2746 if (uniformLocation == -1)
2823 return 0; 2747 return 0;
2824 return WebGLUniformLocation::create(program, uniformLocation); 2748 return WebGLUniformLocation::create(program, uniformLocation);
2825 } 2749 }
2826 2750
2827 WebGLGetInfo WebGLRenderingContext::getVertexAttrib(GLuint index, GLenum pname) 2751 WebGLGetInfo WebGLRenderingContextBase::getVertexAttrib(GLuint index, GLenum pna me)
2828 { 2752 {
2829 if (isContextLost()) 2753 if (isContextLost())
2830 return WebGLGetInfo(); 2754 return WebGLGetInfo();
2831 if (index >= m_maxVertexAttribs) { 2755 if (index >= m_maxVertexAttribs) {
2832 synthesizeGLError(GL_INVALID_VALUE, "getVertexAttrib", "index out of ran ge"); 2756 synthesizeGLError(GL_INVALID_VALUE, "getVertexAttrib", "index out of ran ge");
2833 return WebGLGetInfo(); 2757 return WebGLGetInfo();
2834 } 2758 }
2835 const WebGLVertexArrayObjectOES::VertexAttribState& state = m_boundVertexArr ayObject->getVertexAttribState(index); 2759 const WebGLVertexArrayObjectOES::VertexAttribState& state = m_boundVertexArr ayObject->getVertexAttribState(index);
2836 2760
2837 if (m_angleInstancedArrays && pname == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE) 2761 if (extensionEnabled(ANGLEInstancedArraysName) && pname == GL_VERTEX_ATTRIB_ ARRAY_DIVISOR_ANGLE)
2838 return WebGLGetInfo(state.divisor); 2762 return WebGLGetInfo(state.divisor);
2839 2763
2840 switch (pname) { 2764 switch (pname) {
2841 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: 2765 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
2842 if (!state.bufferBinding || !state.bufferBinding->object()) 2766 if (!state.bufferBinding || !state.bufferBinding->object())
2843 return WebGLGetInfo(); 2767 return WebGLGetInfo();
2844 return WebGLGetInfo(PassRefPtr<WebGLBuffer>(state.bufferBinding)); 2768 return WebGLGetInfo(PassRefPtr<WebGLBuffer>(state.bufferBinding));
2845 case GL_VERTEX_ATTRIB_ARRAY_ENABLED: 2769 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
2846 return WebGLGetInfo(state.enabled); 2770 return WebGLGetInfo(state.enabled);
2847 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: 2771 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
2848 return WebGLGetInfo(state.normalized); 2772 return WebGLGetInfo(state.normalized);
2849 case GL_VERTEX_ATTRIB_ARRAY_SIZE: 2773 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
2850 return WebGLGetInfo(state.size); 2774 return WebGLGetInfo(state.size);
2851 case GL_VERTEX_ATTRIB_ARRAY_STRIDE: 2775 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
2852 return WebGLGetInfo(state.originalStride); 2776 return WebGLGetInfo(state.originalStride);
2853 case GL_VERTEX_ATTRIB_ARRAY_TYPE: 2777 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
2854 return WebGLGetInfo(state.type); 2778 return WebGLGetInfo(state.type);
2855 case GL_CURRENT_VERTEX_ATTRIB: 2779 case GL_CURRENT_VERTEX_ATTRIB:
2856 return WebGLGetInfo(Float32Array::create(m_vertexAttribValue[index].valu e, 4)); 2780 return WebGLGetInfo(Float32Array::create(m_vertexAttribValue[index].valu e, 4));
2857 default: 2781 default:
2858 synthesizeGLError(GL_INVALID_ENUM, "getVertexAttrib", "invalid parameter name"); 2782 synthesizeGLError(GL_INVALID_ENUM, "getVertexAttrib", "invalid parameter name");
2859 return WebGLGetInfo(); 2783 return WebGLGetInfo();
2860 } 2784 }
2861 } 2785 }
2862 2786
2863 long long WebGLRenderingContext::getVertexAttribOffset(GLuint index, GLenum pnam e) 2787 long long WebGLRenderingContextBase::getVertexAttribOffset(GLuint index, GLenum pname)
2864 { 2788 {
2865 if (isContextLost()) 2789 if (isContextLost())
2866 return 0; 2790 return 0;
2867 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER) { 2791 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER) {
2868 synthesizeGLError(GL_INVALID_ENUM, "getVertexAttribOffset", "invalid par ameter name"); 2792 synthesizeGLError(GL_INVALID_ENUM, "getVertexAttribOffset", "invalid par ameter name");
2869 return 0; 2793 return 0;
2870 } 2794 }
2871 GLsizeiptr result = m_context->getVertexAttribOffset(index, pname); 2795 GLsizeiptr result = m_context->getVertexAttribOffset(index, pname);
2872 return static_cast<long long>(result); 2796 return static_cast<long long>(result);
2873 } 2797 }
2874 2798
2875 void WebGLRenderingContext::hint(GLenum target, GLenum mode) 2799 void WebGLRenderingContextBase::hint(GLenum target, GLenum mode)
2876 { 2800 {
2877 if (isContextLost()) 2801 if (isContextLost())
2878 return; 2802 return;
2879 bool isValid = false; 2803 bool isValid = false;
2880 switch (target) { 2804 switch (target) {
2881 case GL_GENERATE_MIPMAP_HINT: 2805 case GL_GENERATE_MIPMAP_HINT:
2882 isValid = true; 2806 isValid = true;
2883 break; 2807 break;
2884 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES: // OES_standard_derivatives 2808 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES: // OES_standard_derivatives
2885 if (m_oesStandardDerivatives) 2809 if (extensionEnabled(OESStandardDerivativesName))
2886 isValid = true; 2810 isValid = true;
2887 break; 2811 break;
2888 } 2812 }
2889 if (!isValid) { 2813 if (!isValid) {
2890 synthesizeGLError(GL_INVALID_ENUM, "hint", "invalid target"); 2814 synthesizeGLError(GL_INVALID_ENUM, "hint", "invalid target");
2891 return; 2815 return;
2892 } 2816 }
2893 m_context->hint(target, mode); 2817 m_context->hint(target, mode);
2894 } 2818 }
2895 2819
2896 GLboolean WebGLRenderingContext::isBuffer(WebGLBuffer* buffer) 2820 GLboolean WebGLRenderingContextBase::isBuffer(WebGLBuffer* buffer)
2897 { 2821 {
2898 if (!buffer || isContextLost()) 2822 if (!buffer || isContextLost())
2899 return 0; 2823 return 0;
2900 2824
2901 if (!buffer->hasEverBeenBound()) 2825 if (!buffer->hasEverBeenBound())
2902 return 0; 2826 return 0;
2903 2827
2904 return m_context->isBuffer(buffer->object()); 2828 return m_context->isBuffer(buffer->object());
2905 } 2829 }
2906 2830
2907 bool WebGLRenderingContext::isContextLost() 2831 bool WebGLRenderingContextBase::isContextLost()
2908 { 2832 {
2909 return m_contextLost; 2833 return m_contextLost;
2910 } 2834 }
2911 2835
2912 GLboolean WebGLRenderingContext::isEnabled(GLenum cap) 2836 GLboolean WebGLRenderingContextBase::isEnabled(GLenum cap)
2913 { 2837 {
2914 if (isContextLost() || !validateCapability("isEnabled", cap)) 2838 if (isContextLost() || !validateCapability("isEnabled", cap))
2915 return 0; 2839 return 0;
2916 if (cap == GL_STENCIL_TEST) 2840 if (cap == GL_STENCIL_TEST)
2917 return m_stencilEnabled; 2841 return m_stencilEnabled;
2918 return m_context->isEnabled(cap); 2842 return m_context->isEnabled(cap);
2919 } 2843 }
2920 2844
2921 GLboolean WebGLRenderingContext::isFramebuffer(WebGLFramebuffer* framebuffer) 2845 GLboolean WebGLRenderingContextBase::isFramebuffer(WebGLFramebuffer* framebuffer )
2922 { 2846 {
2923 if (!framebuffer || isContextLost()) 2847 if (!framebuffer || isContextLost())
2924 return 0; 2848 return 0;
2925 2849
2926 if (!framebuffer->hasEverBeenBound()) 2850 if (!framebuffer->hasEverBeenBound())
2927 return 0; 2851 return 0;
2928 2852
2929 return m_context->isFramebuffer(framebuffer->object()); 2853 return m_context->isFramebuffer(framebuffer->object());
2930 } 2854 }
2931 2855
2932 GLboolean WebGLRenderingContext::isProgram(WebGLProgram* program) 2856 GLboolean WebGLRenderingContextBase::isProgram(WebGLProgram* program)
2933 { 2857 {
2934 if (!program || isContextLost()) 2858 if (!program || isContextLost())
2935 return 0; 2859 return 0;
2936 2860
2937 return m_context->isProgram(program->object()); 2861 return m_context->isProgram(program->object());
2938 } 2862 }
2939 2863
2940 GLboolean WebGLRenderingContext::isRenderbuffer(WebGLRenderbuffer* renderbuffer) 2864 GLboolean WebGLRenderingContextBase::isRenderbuffer(WebGLRenderbuffer* renderbuf fer)
2941 { 2865 {
2942 if (!renderbuffer || isContextLost()) 2866 if (!renderbuffer || isContextLost())
2943 return 0; 2867 return 0;
2944 2868
2945 if (!renderbuffer->hasEverBeenBound()) 2869 if (!renderbuffer->hasEverBeenBound())
2946 return 0; 2870 return 0;
2947 2871
2948 return m_context->isRenderbuffer(renderbuffer->object()); 2872 return m_context->isRenderbuffer(renderbuffer->object());
2949 } 2873 }
2950 2874
2951 GLboolean WebGLRenderingContext::isShader(WebGLShader* shader) 2875 GLboolean WebGLRenderingContextBase::isShader(WebGLShader* shader)
2952 { 2876 {
2953 if (!shader || isContextLost()) 2877 if (!shader || isContextLost())
2954 return 0; 2878 return 0;
2955 2879
2956 return m_context->isShader(shader->object()); 2880 return m_context->isShader(shader->object());
2957 } 2881 }
2958 2882
2959 GLboolean WebGLRenderingContext::isTexture(WebGLTexture* texture) 2883 GLboolean WebGLRenderingContextBase::isTexture(WebGLTexture* texture)
2960 { 2884 {
2961 if (!texture || isContextLost()) 2885 if (!texture || isContextLost())
2962 return 0; 2886 return 0;
2963 2887
2964 if (!texture->hasEverBeenBound()) 2888 if (!texture->hasEverBeenBound())
2965 return 0; 2889 return 0;
2966 2890
2967 return m_context->isTexture(texture->object()); 2891 return m_context->isTexture(texture->object());
2968 } 2892 }
2969 2893
2970 void WebGLRenderingContext::lineWidth(GLfloat width) 2894 void WebGLRenderingContextBase::lineWidth(GLfloat width)
2971 { 2895 {
2972 if (isContextLost()) 2896 if (isContextLost())
2973 return; 2897 return;
2974 m_context->lineWidth(width); 2898 m_context->lineWidth(width);
2975 } 2899 }
2976 2900
2977 void WebGLRenderingContext::linkProgram(WebGLProgram* program) 2901 void WebGLRenderingContextBase::linkProgram(WebGLProgram* program)
2978 { 2902 {
2979 if (isContextLost() || !validateWebGLObject("linkProgram", program)) 2903 if (isContextLost() || !validateWebGLObject("linkProgram", program))
2980 return; 2904 return;
2981 2905
2982 m_context->linkProgram(objectOrZero(program)); 2906 m_context->linkProgram(objectOrZero(program));
2983 program->increaseLinkCount(); 2907 program->increaseLinkCount();
2984 } 2908 }
2985 2909
2986 void WebGLRenderingContext::pixelStorei(GLenum pname, GLint param) 2910 void WebGLRenderingContextBase::pixelStorei(GLenum pname, GLint param)
2987 { 2911 {
2988 if (isContextLost()) 2912 if (isContextLost())
2989 return; 2913 return;
2990 switch (pname) { 2914 switch (pname) {
2991 case GC3D_UNPACK_FLIP_Y_WEBGL: 2915 case GC3D_UNPACK_FLIP_Y_WEBGL:
2992 m_unpackFlipY = param; 2916 m_unpackFlipY = param;
2993 break; 2917 break;
2994 case GC3D_UNPACK_PREMULTIPLY_ALPHA_WEBGL: 2918 case GC3D_UNPACK_PREMULTIPLY_ALPHA_WEBGL:
2995 m_unpackPremultiplyAlpha = param; 2919 m_unpackPremultiplyAlpha = param;
2996 break; 2920 break;
(...skipping 19 matching lines...) Expand all
3016 synthesizeGLError(GL_INVALID_VALUE, "pixelStorei", "invalid paramete r for alignment"); 2940 synthesizeGLError(GL_INVALID_VALUE, "pixelStorei", "invalid paramete r for alignment");
3017 return; 2941 return;
3018 } 2942 }
3019 break; 2943 break;
3020 default: 2944 default:
3021 synthesizeGLError(GL_INVALID_ENUM, "pixelStorei", "invalid parameter nam e"); 2945 synthesizeGLError(GL_INVALID_ENUM, "pixelStorei", "invalid parameter nam e");
3022 return; 2946 return;
3023 } 2947 }
3024 } 2948 }
3025 2949
3026 void WebGLRenderingContext::polygonOffset(GLfloat factor, GLfloat units) 2950 void WebGLRenderingContextBase::polygonOffset(GLfloat factor, GLfloat units)
3027 { 2951 {
3028 if (isContextLost()) 2952 if (isContextLost())
3029 return; 2953 return;
3030 m_context->polygonOffset(factor, units); 2954 m_context->polygonOffset(factor, units);
3031 } 2955 }
3032 2956
3033 void WebGLRenderingContext::readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, ArrayBufferView* pixels) 2957 void WebGLRenderingContextBase::readPixels(GLint x, GLint y, GLsizei width, GLsi zei height, GLenum format, GLenum type, ArrayBufferView* pixels)
3034 { 2958 {
3035 if (isContextLost()) 2959 if (isContextLost())
3036 return; 2960 return;
3037 // Due to WebGL's same-origin restrictions, it is not possible to 2961 // Due to WebGL's same-origin restrictions, it is not possible to
3038 // taint the origin using the WebGL API. 2962 // taint the origin using the WebGL API.
3039 ASSERT(canvas()->originClean()); 2963 ASSERT(canvas()->originClean());
3040 // Validate input parameters. 2964 // Validate input parameters.
3041 if (!pixels) { 2965 if (!pixels) {
3042 synthesizeGLError(GL_INVALID_VALUE, "readPixels", "no destination ArrayB ufferView"); 2966 synthesizeGLError(GL_INVALID_VALUE, "readPixels", "no destination ArrayB ufferView");
3043 return; 2967 return;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
3105 for (GLsizei ix = 0; ix < width; ++ix) { 3029 for (GLsizei ix = 0; ix < width; ++ix) {
3106 pixels[3] = 255; 3030 pixels[3] = 255;
3107 pixels += 4; 3031 pixels += 4;
3108 } 3032 }
3109 pixels += padding; 3033 pixels += padding;
3110 } 3034 }
3111 } 3035 }
3112 #endif 3036 #endif
3113 } 3037 }
3114 3038
3115 void WebGLRenderingContext::renderbufferStorage(GLenum target, GLenum internalfo rmat, GLsizei width, GLsizei height) 3039 void WebGLRenderingContextBase::renderbufferStorage(GLenum target, GLenum intern alformat, GLsizei width, GLsizei height)
3116 { 3040 {
3117 if (isContextLost()) 3041 if (isContextLost())
3118 return; 3042 return;
3119 if (target != GL_RENDERBUFFER) { 3043 if (target != GL_RENDERBUFFER) {
3120 synthesizeGLError(GL_INVALID_ENUM, "renderbufferStorage", "invalid targe t"); 3044 synthesizeGLError(GL_INVALID_ENUM, "renderbufferStorage", "invalid targe t");
3121 return; 3045 return;
3122 } 3046 }
3123 if (!m_renderbufferBinding || !m_renderbufferBinding->object()) { 3047 if (!m_renderbufferBinding || !m_renderbufferBinding->object()) {
3124 synthesizeGLError(GL_INVALID_OPERATION, "renderbufferStorage", "no bound renderbuffer"); 3048 synthesizeGLError(GL_INVALID_OPERATION, "renderbufferStorage", "no bound renderbuffer");
3125 return; 3049 return;
(...skipping 30 matching lines...) Expand all
3156 m_renderbufferBinding->setSize(width, height); 3080 m_renderbufferBinding->setSize(width, height);
3157 m_renderbufferBinding->setInternalFormat(internalformat); 3081 m_renderbufferBinding->setInternalFormat(internalformat);
3158 break; 3082 break;
3159 default: 3083 default:
3160 synthesizeGLError(GL_INVALID_ENUM, "renderbufferStorage", "invalid inter nalformat"); 3084 synthesizeGLError(GL_INVALID_ENUM, "renderbufferStorage", "invalid inter nalformat");
3161 return; 3085 return;
3162 } 3086 }
3163 applyStencilTest(); 3087 applyStencilTest();
3164 } 3088 }
3165 3089
3166 void WebGLRenderingContext::sampleCoverage(GLfloat value, GLboolean invert) 3090 void WebGLRenderingContextBase::sampleCoverage(GLfloat value, GLboolean invert)
3167 { 3091 {
3168 if (isContextLost()) 3092 if (isContextLost())
3169 return; 3093 return;
3170 m_context->sampleCoverage(value, invert); 3094 m_context->sampleCoverage(value, invert);
3171 } 3095 }
3172 3096
3173 void WebGLRenderingContext::scissor(GLint x, GLint y, GLsizei width, GLsizei hei ght) 3097 void WebGLRenderingContextBase::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
3174 { 3098 {
3175 if (isContextLost()) 3099 if (isContextLost())
3176 return; 3100 return;
3177 if (!validateSize("scissor", width, height)) 3101 if (!validateSize("scissor", width, height))
3178 return; 3102 return;
3179 m_context->scissor(x, y, width, height); 3103 m_context->scissor(x, y, width, height);
3180 } 3104 }
3181 3105
3182 void WebGLRenderingContext::shaderSource(WebGLShader* shader, const String& stri ng) 3106 void WebGLRenderingContextBase::shaderSource(WebGLShader* shader, const String& string)
3183 { 3107 {
3184 if (isContextLost() || !validateWebGLObject("shaderSource", shader)) 3108 if (isContextLost() || !validateWebGLObject("shaderSource", shader))
3185 return; 3109 return;
3186 String stringWithoutComments = StripComments(string).result(); 3110 String stringWithoutComments = StripComments(string).result();
3187 if (!validateString("shaderSource", stringWithoutComments)) 3111 if (!validateString("shaderSource", stringWithoutComments))
3188 return; 3112 return;
3189 shader->setSource(string); 3113 shader->setSource(string);
3190 m_context->shaderSource(objectOrZero(shader), stringWithoutComments.utf8().d ata()); 3114 m_context->shaderSource(objectOrZero(shader), stringWithoutComments.utf8().d ata());
3191 } 3115 }
3192 3116
3193 void WebGLRenderingContext::stencilFunc(GLenum func, GLint ref, GLuint mask) 3117 void WebGLRenderingContextBase::stencilFunc(GLenum func, GLint ref, GLuint mask)
3194 { 3118 {
3195 if (isContextLost()) 3119 if (isContextLost())
3196 return; 3120 return;
3197 if (!validateStencilOrDepthFunc("stencilFunc", func)) 3121 if (!validateStencilOrDepthFunc("stencilFunc", func))
3198 return; 3122 return;
3199 m_stencilFuncRef = ref; 3123 m_stencilFuncRef = ref;
3200 m_stencilFuncRefBack = ref; 3124 m_stencilFuncRefBack = ref;
3201 m_stencilFuncMask = mask; 3125 m_stencilFuncMask = mask;
3202 m_stencilFuncMaskBack = mask; 3126 m_stencilFuncMaskBack = mask;
3203 m_context->stencilFunc(func, ref, mask); 3127 m_context->stencilFunc(func, ref, mask);
3204 } 3128 }
3205 3129
3206 void WebGLRenderingContext::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask) 3130 void WebGLRenderingContextBase::stencilFuncSeparate(GLenum face, GLenum func, GL int ref, GLuint mask)
3207 { 3131 {
3208 if (isContextLost()) 3132 if (isContextLost())
3209 return; 3133 return;
3210 if (!validateStencilOrDepthFunc("stencilFuncSeparate", func)) 3134 if (!validateStencilOrDepthFunc("stencilFuncSeparate", func))
3211 return; 3135 return;
3212 switch (face) { 3136 switch (face) {
3213 case GL_FRONT_AND_BACK: 3137 case GL_FRONT_AND_BACK:
3214 m_stencilFuncRef = ref; 3138 m_stencilFuncRef = ref;
3215 m_stencilFuncRefBack = ref; 3139 m_stencilFuncRefBack = ref;
3216 m_stencilFuncMask = mask; 3140 m_stencilFuncMask = mask;
3217 m_stencilFuncMaskBack = mask; 3141 m_stencilFuncMaskBack = mask;
3218 break; 3142 break;
3219 case GL_FRONT: 3143 case GL_FRONT:
3220 m_stencilFuncRef = ref; 3144 m_stencilFuncRef = ref;
3221 m_stencilFuncMask = mask; 3145 m_stencilFuncMask = mask;
3222 break; 3146 break;
3223 case GL_BACK: 3147 case GL_BACK:
3224 m_stencilFuncRefBack = ref; 3148 m_stencilFuncRefBack = ref;
3225 m_stencilFuncMaskBack = mask; 3149 m_stencilFuncMaskBack = mask;
3226 break; 3150 break;
3227 default: 3151 default:
3228 synthesizeGLError(GL_INVALID_ENUM, "stencilFuncSeparate", "invalid face" ); 3152 synthesizeGLError(GL_INVALID_ENUM, "stencilFuncSeparate", "invalid face" );
3229 return; 3153 return;
3230 } 3154 }
3231 m_context->stencilFuncSeparate(face, func, ref, mask); 3155 m_context->stencilFuncSeparate(face, func, ref, mask);
3232 } 3156 }
3233 3157
3234 void WebGLRenderingContext::stencilMask(GLuint mask) 3158 void WebGLRenderingContextBase::stencilMask(GLuint mask)
3235 { 3159 {
3236 if (isContextLost()) 3160 if (isContextLost())
3237 return; 3161 return;
3238 m_stencilMask = mask; 3162 m_stencilMask = mask;
3239 m_stencilMaskBack = mask; 3163 m_stencilMaskBack = mask;
3240 m_context->stencilMask(mask); 3164 m_context->stencilMask(mask);
3241 } 3165 }
3242 3166
3243 void WebGLRenderingContext::stencilMaskSeparate(GLenum face, GLuint mask) 3167 void WebGLRenderingContextBase::stencilMaskSeparate(GLenum face, GLuint mask)
3244 { 3168 {
3245 if (isContextLost()) 3169 if (isContextLost())
3246 return; 3170 return;
3247 switch (face) { 3171 switch (face) {
3248 case GL_FRONT_AND_BACK: 3172 case GL_FRONT_AND_BACK:
3249 m_stencilMask = mask; 3173 m_stencilMask = mask;
3250 m_stencilMaskBack = mask; 3174 m_stencilMaskBack = mask;
3251 break; 3175 break;
3252 case GL_FRONT: 3176 case GL_FRONT:
3253 m_stencilMask = mask; 3177 m_stencilMask = mask;
3254 break; 3178 break;
3255 case GL_BACK: 3179 case GL_BACK:
3256 m_stencilMaskBack = mask; 3180 m_stencilMaskBack = mask;
3257 break; 3181 break;
3258 default: 3182 default:
3259 synthesizeGLError(GL_INVALID_ENUM, "stencilMaskSeparate", "invalid face" ); 3183 synthesizeGLError(GL_INVALID_ENUM, "stencilMaskSeparate", "invalid face" );
3260 return; 3184 return;
3261 } 3185 }
3262 m_context->stencilMaskSeparate(face, mask); 3186 m_context->stencilMaskSeparate(face, mask);
3263 } 3187 }
3264 3188
3265 void WebGLRenderingContext::stencilOp(GLenum fail, GLenum zfail, GLenum zpass) 3189 void WebGLRenderingContextBase::stencilOp(GLenum fail, GLenum zfail, GLenum zpas s)
3266 { 3190 {
3267 if (isContextLost()) 3191 if (isContextLost())
3268 return; 3192 return;
3269 m_context->stencilOp(fail, zfail, zpass); 3193 m_context->stencilOp(fail, zfail, zpass);
3270 } 3194 }
3271 3195
3272 void WebGLRenderingContext::stencilOpSeparate(GLenum face, GLenum fail, GLenum z fail, GLenum zpass) 3196 void WebGLRenderingContextBase::stencilOpSeparate(GLenum face, GLenum fail, GLen um zfail, GLenum zpass)
3273 { 3197 {
3274 if (isContextLost()) 3198 if (isContextLost())
3275 return; 3199 return;
3276 m_context->stencilOpSeparate(face, fail, zfail, zpass); 3200 m_context->stencilOpSeparate(face, fail, zfail, zpass);
3277 } 3201 }
3278 3202
3279 GLenum WebGLRenderingContext::convertTexInternalFormat(GLenum internalformat, GL enum type) 3203 GLenum WebGLRenderingContextBase::convertTexInternalFormat(GLenum internalformat , GLenum type)
3280 { 3204 {
3281 // Convert to sized internal formats that are renderable with GL_CHROMIUM_co lor_buffer_float_rgb(a). 3205 // Convert to sized internal formats that are renderable with GL_CHROMIUM_co lor_buffer_float_rgb(a).
3282 if (type == GL_FLOAT && internalformat == GL_RGBA 3206 if (type == GL_FLOAT && internalformat == GL_RGBA
3283 && extensionsUtil()->isExtensionEnabled("GL_CHROMIUM_color_buffer_float_ rgba")) 3207 && extensionsUtil()->isExtensionEnabled("GL_CHROMIUM_color_buffer_float_ rgba"))
3284 return GL_RGBA32F_EXT; 3208 return GL_RGBA32F_EXT;
3285 if (type == GL_FLOAT && internalformat == GL_RGB 3209 if (type == GL_FLOAT && internalformat == GL_RGB
3286 && extensionsUtil()->isExtensionEnabled("GL_CHROMIUM_color_buffer_float_ rgb")) 3210 && extensionsUtil()->isExtensionEnabled("GL_CHROMIUM_color_buffer_float_ rgb"))
3287 return GL_RGB32F_EXT; 3211 return GL_RGB32F_EXT;
3288 return internalformat; 3212 return internalformat;
3289 } 3213 }
3290 3214
3291 void WebGLRenderingContext::texImage2DBase(GLenum target, GLint level, GLenum in ternalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void* pixels, ExceptionState& exceptionState) 3215 void WebGLRenderingContextBase::texImage2DBase(GLenum target, GLint level, GLenu m internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GL enum type, const void* pixels, ExceptionState& exceptionState)
3292 { 3216 {
3293 // All calling functions check isContextLost, so a duplicate check is not ne eded here. 3217 // All calling functions check isContextLost, so a duplicate check is not ne eded here.
3294 // FIXME: Handle errors. 3218 // FIXME: Handle errors.
3295 WebGLTexture* tex = validateTextureBinding("texImage2D", target, true); 3219 WebGLTexture* tex = validateTextureBinding("texImage2D", target, true);
3296 ASSERT(validateTexFuncParameters("texImage2D", NotTexSubImage2D, target, lev el, internalformat, width, height, border, format, type)); 3220 ASSERT(validateTexFuncParameters("texImage2D", NotTexSubImage2D, target, lev el, internalformat, width, height, border, format, type));
3297 ASSERT(tex); 3221 ASSERT(tex);
3298 ASSERT(!level || !WebGLTexture::isNPOT(width, height)); 3222 ASSERT(!level || !WebGLTexture::isNPOT(width, height));
3299 ASSERT(!pixels || validateSettableTexFormat("texImage2D", internalformat)); 3223 ASSERT(!pixels || validateSettableTexFormat("texImage2D", internalformat));
3300 m_context->texImage2D(target, level, convertTexInternalFormat(internalformat , type), width, height, border, format, type, pixels); 3224 m_context->texImage2D(target, level, convertTexInternalFormat(internalformat , type), width, height, border, format, type, pixels);
3301 tex->setLevelInfo(target, level, internalformat, width, height, type); 3225 tex->setLevelInfo(target, level, internalformat, width, height, type);
3302 } 3226 }
3303 3227
3304 void WebGLRenderingContext::texImage2DImpl(GLenum target, GLint level, GLenum in ternalformat, GLenum format, GLenum type, Image* image, WebGLImageConversion::Im ageHtmlDomSource domSource, bool flipY, bool premultiplyAlpha, ExceptionState& e xceptionState) 3228 void WebGLRenderingContextBase::texImage2DImpl(GLenum target, GLint level, GLenu m internalformat, GLenum format, GLenum type, Image* image, WebGLImageConversion ::ImageHtmlDomSource domSource, bool flipY, bool premultiplyAlpha, ExceptionStat e& exceptionState)
3305 { 3229 {
3306 // All calling functions check isContextLost, so a duplicate check is not ne eded here. 3230 // All calling functions check isContextLost, so a duplicate check is not ne eded here.
3307 Vector<uint8_t> data; 3231 Vector<uint8_t> data;
3308 WebGLImageConversion::ImageExtractor imageExtractor(image, domSource, premul tiplyAlpha, m_unpackColorspaceConversion == GL_NONE); 3232 WebGLImageConversion::ImageExtractor imageExtractor(image, domSource, premul tiplyAlpha, m_unpackColorspaceConversion == GL_NONE);
3309 if (!imageExtractor.extractSucceeded()) { 3233 if (!imageExtractor.extractSucceeded()) {
3310 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "bad image data"); 3234 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "bad image data");
3311 return; 3235 return;
3312 } 3236 }
3313 WebGLImageConversion::DataFormat sourceDataFormat = imageExtractor.imageSour ceFormat(); 3237 WebGLImageConversion::DataFormat sourceDataFormat = imageExtractor.imageSour ceFormat();
3314 WebGLImageConversion::AlphaOp alphaOp = imageExtractor.imageAlphaOp(); 3238 WebGLImageConversion::AlphaOp alphaOp = imageExtractor.imageAlphaOp();
3315 const void* imagePixelData = imageExtractor.imagePixelData(); 3239 const void* imagePixelData = imageExtractor.imagePixelData();
3316 3240
3317 bool needConversion = true; 3241 bool needConversion = true;
3318 if (type == GL_UNSIGNED_BYTE && sourceDataFormat == WebGLImageConversion::Da taFormatRGBA8 && format == GL_RGBA && alphaOp == WebGLImageConversion::AlphaDoNo thing && !flipY) 3242 if (type == GL_UNSIGNED_BYTE && sourceDataFormat == WebGLImageConversion::Da taFormatRGBA8 && format == GL_RGBA && alphaOp == WebGLImageConversion::AlphaDoNo thing && !flipY)
3319 needConversion = false; 3243 needConversion = false;
3320 else { 3244 else {
3321 if (!WebGLImageConversion::packImageData(image, imagePixelData, format, type, flipY, alphaOp, sourceDataFormat, imageExtractor.imageWidth(), imageExtrac tor.imageHeight(), imageExtractor.imageSourceUnpackAlignment(), data)) { 3245 if (!WebGLImageConversion::packImageData(image, imagePixelData, format, type, flipY, alphaOp, sourceDataFormat, imageExtractor.imageWidth(), imageExtrac tor.imageHeight(), imageExtractor.imageSourceUnpackAlignment(), data)) {
3322 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "packImage error") ; 3246 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "packImage error") ;
3323 return; 3247 return;
3324 } 3248 }
3325 } 3249 }
3326 3250
3327 if (m_unpackAlignment != 1) 3251 if (m_unpackAlignment != 1)
3328 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, 1); 3252 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, 1);
3329 texImage2DBase(target, level, internalformat, image->width(), image->height( ), 0, format, type, needConversion ? data.data() : imagePixelData, exceptionStat e); 3253 texImage2DBase(target, level, internalformat, image->width(), image->height( ), 0, format, type, needConversion ? data.data() : imagePixelData, exceptionStat e);
3330 if (m_unpackAlignment != 1) 3254 if (m_unpackAlignment != 1)
3331 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); 3255 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
3332 } 3256 }
3333 3257
3334 bool WebGLRenderingContext::validateTexFunc(const char* functionName, TexFuncVal idationFunctionType functionType, TexFuncValidationSourceType sourceType, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLin t border, GLenum format, GLenum type, GLint xoffset, GLint yoffset) 3258 bool WebGLRenderingContextBase::validateTexFunc(const char* functionName, TexFun cValidationFunctionType functionType, TexFuncValidationSourceType sourceType, GL enum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, GLint xoffset, GLint yoffset)
3335 { 3259 {
3336 if (!validateTexFuncParameters(functionName, functionType, target, level, in ternalformat, width, height, border, format, type)) 3260 if (!validateTexFuncParameters(functionName, functionType, target, level, in ternalformat, width, height, border, format, type))
3337 return false; 3261 return false;
3338 3262
3339 WebGLTexture* texture = validateTextureBinding(functionName, target, true); 3263 WebGLTexture* texture = validateTextureBinding(functionName, target, true);
3340 if (!texture) 3264 if (!texture)
3341 return false; 3265 return false;
3342 3266
3343 if (functionType == NotTexSubImage2D) { 3267 if (functionType == NotTexSubImage2D) {
3344 if (level && WebGLTexture::isNPOT(width, height)) { 3268 if (level && WebGLTexture::isNPOT(width, height)) {
(...skipping 22 matching lines...) Expand all
3367 } 3291 }
3368 if (texture->getInternalFormat(target, level) != format || texture->getT ype(target, level) != type) { 3292 if (texture->getInternalFormat(target, level) != format || texture->getT ype(target, level) != type) {
3369 synthesizeGLError(GL_INVALID_OPERATION, functionName, "type and form at do not match texture"); 3293 synthesizeGLError(GL_INVALID_OPERATION, functionName, "type and form at do not match texture");
3370 return false; 3294 return false;
3371 } 3295 }
3372 } 3296 }
3373 3297
3374 return true; 3298 return true;
3375 } 3299 }
3376 3300
3377 PassRefPtr<Image> WebGLRenderingContext::drawImageIntoBuffer(Image* image, int w idth, int height) 3301 PassRefPtr<Image> WebGLRenderingContextBase::drawImageIntoBuffer(Image* image, i nt width, int height)
3378 { 3302 {
3379 IntSize size(width, height); 3303 IntSize size(width, height);
3380 ImageBuffer* buf = m_generatedImageCache.imageBuffer(size); 3304 ImageBuffer* buf = m_generatedImageCache.imageBuffer(size);
3381 if (!buf) { 3305 if (!buf) {
3382 synthesizeGLError(GL_OUT_OF_MEMORY, "texImage2D", "out of memory"); 3306 synthesizeGLError(GL_OUT_OF_MEMORY, "texImage2D", "out of memory");
3383 return 0; 3307 return 0;
3384 } 3308 }
3385 3309
3386 IntRect srcRect(IntPoint(), image->size()); 3310 IntRect srcRect(IntPoint(), image->size());
3387 IntRect destRect(0, 0, size.width(), size.height()); 3311 IntRect destRect(0, 0, size.width(), size.height());
3388 buf->context()->drawImage(image, destRect, srcRect); 3312 buf->context()->drawImage(image, destRect, srcRect);
3389 return buf->copyImage(ImageBuffer::fastCopyImageMode()); 3313 return buf->copyImage(ImageBuffer::fastCopyImageMode());
3390 } 3314 }
3391 3315
3392 void WebGLRenderingContext::texImage2D(GLenum target, GLint level, GLenum intern alformat, 3316 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat,
3393 GLsizei width, GLsizei height, GLint border, 3317 GLsizei width, GLsizei height, GLint border,
3394 GLenum format, GLenum type, ArrayBufferView* pixels, ExceptionState& excepti onState) 3318 GLenum format, GLenum type, ArrayBufferView* pixels, ExceptionState& excepti onState)
3395 { 3319 {
3396 if (isContextLost() || !validateTexFuncData("texImage2D", level, width, heig ht, format, type, pixels, NullAllowed) 3320 if (isContextLost() || !validateTexFuncData("texImage2D", level, width, heig ht, format, type, pixels, NullAllowed)
3397 || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceArrayBufferVie w, target, level, internalformat, width, height, border, format, type, 0, 0)) 3321 || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceArrayBufferVie w, target, level, internalformat, width, height, border, format, type, 0, 0))
3398 return; 3322 return;
3399 void* data = pixels ? pixels->baseAddress() : 0; 3323 void* data = pixels ? pixels->baseAddress() : 0;
3400 Vector<uint8_t> tempData; 3324 Vector<uint8_t> tempData;
3401 bool changeUnpackAlignment = false; 3325 bool changeUnpackAlignment = false;
3402 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) { 3326 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) {
3403 if (!WebGLImageConversion::extractTextureData(width, height, format, typ e, m_unpackAlignment, m_unpackFlipY, m_unpackPremultiplyAlpha, data, tempData)) 3327 if (!WebGLImageConversion::extractTextureData(width, height, format, typ e, m_unpackAlignment, m_unpackFlipY, m_unpackPremultiplyAlpha, data, tempData))
3404 return; 3328 return;
3405 data = tempData.data(); 3329 data = tempData.data();
3406 changeUnpackAlignment = true; 3330 changeUnpackAlignment = true;
3407 } 3331 }
3408 if (changeUnpackAlignment) 3332 if (changeUnpackAlignment)
3409 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, 1); 3333 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, 1);
3410 texImage2DBase(target, level, internalformat, width, height, border, format, type, data, exceptionState); 3334 texImage2DBase(target, level, internalformat, width, height, border, format, type, data, exceptionState);
3411 if (changeUnpackAlignment) 3335 if (changeUnpackAlignment)
3412 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); 3336 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
3413 } 3337 }
3414 3338
3415 void WebGLRenderingContext::texImage2D(GLenum target, GLint level, GLenum intern alformat, 3339 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat,
3416 GLenum format, GLenum type, ImageData* pixels, ExceptionState& exceptionStat e) 3340 GLenum format, GLenum type, ImageData* pixels, ExceptionState& exceptionStat e)
3417 { 3341 {
3418 if (isContextLost() || !pixels || !validateTexFunc("texImage2D", NotTexSubIm age2D, SourceImageData, target, level, internalformat, pixels->width(), pixels-> height(), 0, format, type, 0, 0)) 3342 if (isContextLost() || !pixels || !validateTexFunc("texImage2D", NotTexSubIm age2D, SourceImageData, target, level, internalformat, pixels->width(), pixels-> height(), 0, format, type, 0, 0))
3419 return; 3343 return;
3420 Vector<uint8_t> data; 3344 Vector<uint8_t> data;
3421 bool needConversion = true; 3345 bool needConversion = true;
3422 // The data from ImageData is always of format RGBA8. 3346 // The data from ImageData is always of format RGBA8.
3423 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required. 3347 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required.
3424 if (!m_unpackFlipY && !m_unpackPremultiplyAlpha && format == GL_RGBA && type == GL_UNSIGNED_BYTE) 3348 if (!m_unpackFlipY && !m_unpackPremultiplyAlpha && format == GL_RGBA && type == GL_UNSIGNED_BYTE)
3425 needConversion = false; 3349 needConversion = false;
3426 else { 3350 else {
3427 if (!WebGLImageConversion::extractImageData(pixels->data()->data(), pixe ls->size(), format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) { 3351 if (!WebGLImageConversion::extractImageData(pixels->data()->data(), pixe ls->size(), format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) {
3428 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "bad image data"); 3352 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "bad image data");
3429 return; 3353 return;
3430 } 3354 }
3431 } 3355 }
3432 if (m_unpackAlignment != 1) 3356 if (m_unpackAlignment != 1)
3433 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, 1); 3357 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, 1);
3434 texImage2DBase(target, level, internalformat, pixels->width(), pixels->heigh t(), 0, format, type, needConversion ? data.data() : pixels->data()->data(), exc eptionState); 3358 texImage2DBase(target, level, internalformat, pixels->width(), pixels->heigh t(), 0, format, type, needConversion ? data.data() : pixels->data()->data(), exc eptionState);
3435 if (m_unpackAlignment != 1) 3359 if (m_unpackAlignment != 1)
3436 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); 3360 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
3437 } 3361 }
3438 3362
3439 void WebGLRenderingContext::texImage2D(GLenum target, GLint level, GLenum intern alformat, 3363 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat,
3440 GLenum format, GLenum type, HTMLImageElement* image, ExceptionState& excepti onState) 3364 GLenum format, GLenum type, HTMLImageElement* image, ExceptionState& excepti onState)
3441 { 3365 {
3442 if (isContextLost() || !validateHTMLImageElement("texImage2D", image, except ionState)) 3366 if (isContextLost() || !validateHTMLImageElement("texImage2D", image, except ionState))
3443 return; 3367 return;
3444 3368
3445 RefPtr<Image> imageForRender = image->cachedImage()->imageForRenderer(image- >renderer()); 3369 RefPtr<Image> imageForRender = image->cachedImage()->imageForRenderer(image- >renderer());
3446 if (imageForRender->isSVGImage()) 3370 if (imageForRender->isSVGImage())
3447 imageForRender = drawImageIntoBuffer(imageForRender.get(), image->width( ), image->height()); 3371 imageForRender = drawImageIntoBuffer(imageForRender.get(), image->width( ), image->height());
3448 3372
3449 if (!imageForRender || !validateTexFunc("texImage2D", NotTexSubImage2D, Sour ceHTMLImageElement, target, level, internalformat, imageForRender->width(), imag eForRender->height(), 0, format, type, 0, 0)) 3373 if (!imageForRender || !validateTexFunc("texImage2D", NotTexSubImage2D, Sour ceHTMLImageElement, target, level, internalformat, imageForRender->width(), imag eForRender->height(), 0, format, type, 0, 0))
3450 return; 3374 return;
3451 3375
3452 texImage2DImpl(target, level, internalformat, format, type, imageForRender.g et(), WebGLImageConversion::HtmlDomImage, m_unpackFlipY, m_unpackPremultiplyAlph a, exceptionState); 3376 texImage2DImpl(target, level, internalformat, format, type, imageForRender.g et(), WebGLImageConversion::HtmlDomImage, m_unpackFlipY, m_unpackPremultiplyAlph a, exceptionState);
3453 } 3377 }
3454 3378
3455 void WebGLRenderingContext::texImage2D(GLenum target, GLint level, GLenum intern alformat, 3379 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat,
3456 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep tionState) 3380 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep tionState)
3457 { 3381 {
3458 if (isContextLost() || !validateHTMLCanvasElement("texImage2D", canvas, exce ptionState) || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLCanvas Element, target, level, internalformat, canvas->width(), canvas->height(), 0, fo rmat, type, 0, 0)) 3382 if (isContextLost() || !validateHTMLCanvasElement("texImage2D", canvas, exce ptionState) || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLCanvas Element, target, level, internalformat, canvas->width(), canvas->height(), 0, fo rmat, type, 0, 0))
3459 return; 3383 return;
3460 3384
3461 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true); 3385 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true);
3462 // If possible, copy from the canvas element directly to the texture 3386 // If possible, copy from the canvas element directly to the texture
3463 // via the GPU, without a read-back to system memory. 3387 // via the GPU, without a read-back to system memory.
3464 if (GL_TEXTURE_2D == target && texture) { 3388 if (GL_TEXTURE_2D == target && texture) {
3465 if (!canvas->is3D()) { 3389 if (!canvas->is3D()) {
3466 ImageBuffer* buffer = canvas->buffer(); 3390 ImageBuffer* buffer = canvas->buffer();
3467 if (buffer && buffer->copyToPlatformTexture(m_context.get(), texture ->object(), internalformat, type, 3391 if (buffer && buffer->copyToPlatformTexture(m_context.get(), texture ->object(), internalformat, type,
3468 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) { 3392 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) {
3469 texture->setLevelInfo(target, level, internalformat, canvas->wid th(), canvas->height(), type); 3393 texture->setLevelInfo(target, level, internalformat, canvas->wid th(), canvas->height(), type);
3470 return; 3394 return;
3471 } 3395 }
3472 } else { 3396 } else {
3473 WebGLRenderingContext* gl = toWebGLRenderingContext(canvas->renderin gContext()); 3397 WebGLRenderingContextBase* gl = toWebGLRenderingContextBase(canvas-> renderingContext());
3474 if (gl && gl->m_drawingBuffer->copyToPlatformTexture(m_context.get() , texture->object(), internalformat, type, 3398 if (gl && gl->m_drawingBuffer->copyToPlatformTexture(m_context.get() , texture->object(), internalformat, type,
3475 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) { 3399 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) {
3476 texture->setLevelInfo(target, level, internalformat, canvas->wid th(), canvas->height(), type); 3400 texture->setLevelInfo(target, level, internalformat, canvas->wid th(), canvas->height(), type);
3477 return; 3401 return;
3478 } 3402 }
3479 } 3403 }
3480 } 3404 }
3481 3405
3482 RefPtr<ImageData> imageData = canvas->getImageData(); 3406 RefPtr<ImageData> imageData = canvas->getImageData();
3483 if (imageData) 3407 if (imageData)
3484 texImage2D(target, level, internalformat, format, type, imageData.get(), exceptionState); 3408 texImage2D(target, level, internalformat, format, type, imageData.get(), exceptionState);
3485 else 3409 else
3486 texImage2DImpl(target, level, internalformat, format, type, canvas->copi edImage(), WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpackPremultip lyAlpha, exceptionState); 3410 texImage2DImpl(target, level, internalformat, format, type, canvas->copi edImage(), WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpackPremultip lyAlpha, exceptionState);
3487 } 3411 }
3488 3412
3489 PassRefPtr<Image> WebGLRenderingContext::videoFrameToImage(HTMLVideoElement* vid eo, BackingStoreCopy backingStoreCopy) 3413 PassRefPtr<Image> WebGLRenderingContextBase::videoFrameToImage(HTMLVideoElement* video, BackingStoreCopy backingStoreCopy)
3490 { 3414 {
3491 IntSize size(video->videoWidth(), video->videoHeight()); 3415 IntSize size(video->videoWidth(), video->videoHeight());
3492 ImageBuffer* buf = m_generatedImageCache.imageBuffer(size); 3416 ImageBuffer* buf = m_generatedImageCache.imageBuffer(size);
3493 if (!buf) { 3417 if (!buf) {
3494 synthesizeGLError(GL_OUT_OF_MEMORY, "texImage2D", "out of memory"); 3418 synthesizeGLError(GL_OUT_OF_MEMORY, "texImage2D", "out of memory");
3495 return 0; 3419 return 0;
3496 } 3420 }
3497 IntRect destRect(0, 0, size.width(), size.height()); 3421 IntRect destRect(0, 0, size.width(), size.height());
3498 // FIXME: Turn this into a GPU-GPU texture copy instead of CPU readback. 3422 // FIXME: Turn this into a GPU-GPU texture copy instead of CPU readback.
3499 video->paintCurrentFrameInContext(buf->context(), destRect); 3423 video->paintCurrentFrameInContext(buf->context(), destRect);
3500 return buf->copyImage(backingStoreCopy); 3424 return buf->copyImage(backingStoreCopy);
3501 } 3425 }
3502 3426
3503 void WebGLRenderingContext::texImage2D(GLenum target, GLint level, GLenum intern alformat, 3427 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat,
3504 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState) 3428 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState)
3505 { 3429 {
3506 if (isContextLost() || !validateHTMLVideoElement("texImage2D", video, except ionState) 3430 if (isContextLost() || !validateHTMLVideoElement("texImage2D", video, except ionState)
3507 || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLVideoEleme nt, target, level, internalformat, video->videoWidth(), video->videoHeight(), 0, format, type, 0, 0)) 3431 || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLVideoEleme nt, target, level, internalformat, video->videoWidth(), video->videoHeight(), 0, format, type, 0, 0))
3508 return; 3432 return;
3509 3433
3510 // Go through the fast path doing a GPU-GPU textures copy without a readback to system memory if possible. 3434 // Go through the fast path doing a GPU-GPU textures copy without a readback to system memory if possible.
3511 // Otherwise, it will fall back to the normal SW path. 3435 // Otherwise, it will fall back to the normal SW path.
3512 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true); 3436 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true);
3513 if (GL_TEXTURE_2D == target && texture) { 3437 if (GL_TEXTURE_2D == target && texture) {
3514 if (video->copyVideoTextureToPlatformTexture(m_context.get(), texture->o bject(), level, type, internalformat, m_unpackPremultiplyAlpha, m_unpackFlipY)) { 3438 if (video->copyVideoTextureToPlatformTexture(m_context.get(), texture->o bject(), level, type, internalformat, m_unpackPremultiplyAlpha, m_unpackFlipY)) {
3515 texture->setLevelInfo(target, level, internalformat, video->videoWid th(), video->videoHeight(), type); 3439 texture->setLevelInfo(target, level, internalformat, video->videoWid th(), video->videoHeight(), type);
3516 return; 3440 return;
3517 } 3441 }
3518 } 3442 }
3519 3443
3520 // Normal pure SW path. 3444 // Normal pure SW path.
3521 RefPtr<Image> image = videoFrameToImage(video, ImageBuffer::fastCopyImageMod e()); 3445 RefPtr<Image> image = videoFrameToImage(video, ImageBuffer::fastCopyImageMod e());
3522 if (!image) 3446 if (!image)
3523 return; 3447 return;
3524 texImage2DImpl(target, level, internalformat, format, type, image.get(), Web GLImageConversion::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha, except ionState); 3448 texImage2DImpl(target, level, internalformat, format, type, image.get(), Web GLImageConversion::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha, except ionState);
3525 } 3449 }
3526 3450
3527 void WebGLRenderingContext::texParameter(GLenum target, GLenum pname, GLfloat pa ramf, GLint parami, bool isFloat) 3451 void WebGLRenderingContextBase::texParameter(GLenum target, GLenum pname, GLfloa t paramf, GLint parami, bool isFloat)
3528 { 3452 {
3529 if (isContextLost()) 3453 if (isContextLost())
3530 return; 3454 return;
3531 WebGLTexture* tex = validateTextureBinding("texParameter", target, false); 3455 WebGLTexture* tex = validateTextureBinding("texParameter", target, false);
3532 if (!tex) 3456 if (!tex)
3533 return; 3457 return;
3534 switch (pname) { 3458 switch (pname) {
3535 case GL_TEXTURE_MIN_FILTER: 3459 case GL_TEXTURE_MIN_FILTER:
3536 case GL_TEXTURE_MAG_FILTER: 3460 case GL_TEXTURE_MAG_FILTER:
3537 break; 3461 break;
3538 case GL_TEXTURE_WRAP_S: 3462 case GL_TEXTURE_WRAP_S:
3539 case GL_TEXTURE_WRAP_T: 3463 case GL_TEXTURE_WRAP_T:
3540 if ((isFloat && paramf != GL_CLAMP_TO_EDGE && paramf != GL_MIRRORED_REPE AT && paramf != GL_REPEAT) 3464 if ((isFloat && paramf != GL_CLAMP_TO_EDGE && paramf != GL_MIRRORED_REPE AT && paramf != GL_REPEAT)
3541 || (!isFloat && parami != GL_CLAMP_TO_EDGE && parami != GL_MIRRORED_ REPEAT && parami != GL_REPEAT)) { 3465 || (!isFloat && parami != GL_CLAMP_TO_EDGE && parami != GL_MIRRORED_ REPEAT && parami != GL_REPEAT)) {
3542 synthesizeGLError(GL_INVALID_ENUM, "texParameter", "invalid paramete r"); 3466 synthesizeGLError(GL_INVALID_ENUM, "texParameter", "invalid paramete r");
3543 return; 3467 return;
3544 } 3468 }
3545 break; 3469 break;
3546 case GL_TEXTURE_MAX_ANISOTROPY_EXT: // EXT_texture_filter_anisotropic 3470 case GL_TEXTURE_MAX_ANISOTROPY_EXT: // EXT_texture_filter_anisotropic
3547 if (!m_extTextureFilterAnisotropic) { 3471 if (!extensionEnabled(EXTTextureFilterAnisotropicName)) {
3548 synthesizeGLError(GL_INVALID_ENUM, "texParameter", "invalid paramete r, EXT_texture_filter_anisotropic not enabled"); 3472 synthesizeGLError(GL_INVALID_ENUM, "texParameter", "invalid paramete r, EXT_texture_filter_anisotropic not enabled");
3549 return; 3473 return;
3550 } 3474 }
3551 break; 3475 break;
3552 default: 3476 default:
3553 synthesizeGLError(GL_INVALID_ENUM, "texParameter", "invalid parameter na me"); 3477 synthesizeGLError(GL_INVALID_ENUM, "texParameter", "invalid parameter na me");
3554 return; 3478 return;
3555 } 3479 }
3556 if (isFloat) { 3480 if (isFloat) {
3557 tex->setParameterf(pname, paramf); 3481 tex->setParameterf(pname, paramf);
3558 m_context->texParameterf(target, pname, paramf); 3482 m_context->texParameterf(target, pname, paramf);
3559 } else { 3483 } else {
3560 tex->setParameteri(pname, parami); 3484 tex->setParameteri(pname, parami);
3561 m_context->texParameteri(target, pname, parami); 3485 m_context->texParameteri(target, pname, parami);
3562 } 3486 }
3563 } 3487 }
3564 3488
3565 void WebGLRenderingContext::texParameterf(GLenum target, GLenum pname, GLfloat p aram) 3489 void WebGLRenderingContextBase::texParameterf(GLenum target, GLenum pname, GLflo at param)
3566 { 3490 {
3567 texParameter(target, pname, param, 0, true); 3491 texParameter(target, pname, param, 0, true);
3568 } 3492 }
3569 3493
3570 void WebGLRenderingContext::texParameteri(GLenum target, GLenum pname, GLint par am) 3494 void WebGLRenderingContextBase::texParameteri(GLenum target, GLenum pname, GLint param)
3571 { 3495 {
3572 texParameter(target, pname, 0, param, false); 3496 texParameter(target, pname, 0, param, false);
3573 } 3497 }
3574 3498
3575 void WebGLRenderingContext::texSubImage2DBase(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum typ e, const void* pixels, ExceptionState& exceptionState) 3499 void WebGLRenderingContextBase::texSubImage2DBase(GLenum target, GLint level, GL int xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void* pixels, ExceptionState& exceptionState)
3576 { 3500 {
3577 // FIXME: Handle errors. 3501 // FIXME: Handle errors.
3578 ASSERT(!isContextLost()); 3502 ASSERT(!isContextLost());
3579 ASSERT(validateTexFuncParameters("texSubImage2D", TexSubImage2D, target, lev el, format, width, height, 0, format, type)); 3503 ASSERT(validateTexFuncParameters("texSubImage2D", TexSubImage2D, target, lev el, format, width, height, 0, format, type));
3580 ASSERT(validateSize("texSubImage2D", xoffset, yoffset)); 3504 ASSERT(validateSize("texSubImage2D", xoffset, yoffset));
3581 ASSERT(validateSettableTexFormat("texSubImage2D", format)); 3505 ASSERT(validateSettableTexFormat("texSubImage2D", format));
3582 WebGLTexture* tex = validateTextureBinding("texSubImage2D", target, true); 3506 WebGLTexture* tex = validateTextureBinding("texSubImage2D", target, true);
3583 if (!tex) { 3507 if (!tex) {
3584 ASSERT_NOT_REACHED(); 3508 ASSERT_NOT_REACHED();
3585 return; 3509 return;
3586 } 3510 }
3587 ASSERT((xoffset + width) >= 0); 3511 ASSERT((xoffset + width) >= 0);
3588 ASSERT((yoffset + height) >= 0); 3512 ASSERT((yoffset + height) >= 0);
3589 ASSERT(tex->getWidth(target, level) >= (xoffset + width)); 3513 ASSERT(tex->getWidth(target, level) >= (xoffset + width));
3590 ASSERT(tex->getHeight(target, level) >= (yoffset + height)); 3514 ASSERT(tex->getHeight(target, level) >= (yoffset + height));
3591 ASSERT(tex->getInternalFormat(target, level) == format); 3515 ASSERT(tex->getInternalFormat(target, level) == format);
3592 ASSERT(tex->getType(target, level) == type); 3516 ASSERT(tex->getType(target, level) == type);
3593 m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, for mat, type, pixels); 3517 m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, for mat, type, pixels);
3594 } 3518 }
3595 3519
3596 void WebGLRenderingContext::texSubImage2DImpl(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLenum format, GLenum type, Image* image, WebGLImageConv ersion::ImageHtmlDomSource domSource, bool flipY, bool premultiplyAlpha, Excepti onState& exceptionState) 3520 void WebGLRenderingContextBase::texSubImage2DImpl(GLenum target, GLint level, GL int xoffset, GLint yoffset, GLenum format, GLenum type, Image* image, WebGLImage Conversion::ImageHtmlDomSource domSource, bool flipY, bool premultiplyAlpha, Exc eptionState& exceptionState)
3597 { 3521 {
3598 // All calling functions check isContextLost, so a duplicate check is not ne eded here. 3522 // All calling functions check isContextLost, so a duplicate check is not ne eded here.
3599 Vector<uint8_t> data; 3523 Vector<uint8_t> data;
3600 WebGLImageConversion::ImageExtractor imageExtractor(image, domSource, premul tiplyAlpha, m_unpackColorspaceConversion == GL_NONE); 3524 WebGLImageConversion::ImageExtractor imageExtractor(image, domSource, premul tiplyAlpha, m_unpackColorspaceConversion == GL_NONE);
3601 if (!imageExtractor.extractSucceeded()) { 3525 if (!imageExtractor.extractSucceeded()) {
3602 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "bad image"); 3526 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "bad image");
3603 return; 3527 return;
3604 } 3528 }
3605 WebGLImageConversion::DataFormat sourceDataFormat = imageExtractor.imageSour ceFormat(); 3529 WebGLImageConversion::DataFormat sourceDataFormat = imageExtractor.imageSour ceFormat();
3606 WebGLImageConversion::AlphaOp alphaOp = imageExtractor.imageAlphaOp(); 3530 WebGLImageConversion::AlphaOp alphaOp = imageExtractor.imageAlphaOp();
3607 const void* imagePixelData = imageExtractor.imagePixelData(); 3531 const void* imagePixelData = imageExtractor.imagePixelData();
3608 3532
3609 bool needConversion = true; 3533 bool needConversion = true;
3610 if (type == GL_UNSIGNED_BYTE && sourceDataFormat == WebGLImageConversion::Da taFormatRGBA8 && format == GL_RGBA && alphaOp == WebGLImageConversion::AlphaDoNo thing && !flipY) 3534 if (type == GL_UNSIGNED_BYTE && sourceDataFormat == WebGLImageConversion::Da taFormatRGBA8 && format == GL_RGBA && alphaOp == WebGLImageConversion::AlphaDoNo thing && !flipY)
3611 needConversion = false; 3535 needConversion = false;
3612 else { 3536 else {
3613 if (!WebGLImageConversion::packImageData(image, imagePixelData, format, type, flipY, alphaOp, sourceDataFormat, imageExtractor.imageWidth(), imageExtrac tor.imageHeight(), imageExtractor.imageSourceUnpackAlignment(), data)) { 3537 if (!WebGLImageConversion::packImageData(image, imagePixelData, format, type, flipY, alphaOp, sourceDataFormat, imageExtractor.imageWidth(), imageExtrac tor.imageHeight(), imageExtractor.imageSourceUnpackAlignment(), data)) {
3614 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "bad image data"); 3538 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "bad image data");
3615 return; 3539 return;
3616 } 3540 }
3617 } 3541 }
3618 3542
3619 if (m_unpackAlignment != 1) 3543 if (m_unpackAlignment != 1)
3620 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, 1); 3544 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, 1);
3621 texSubImage2DBase(target, level, xoffset, yoffset, image->width(), image->he ight(), format, type, needConversion ? data.data() : imagePixelData, exceptionS tate); 3545 texSubImage2DBase(target, level, xoffset, yoffset, image->width(), image->he ight(), format, type, needConversion ? data.data() : imagePixelData, exceptionS tate);
3622 if (m_unpackAlignment != 1) 3546 if (m_unpackAlignment != 1)
3623 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); 3547 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
3624 } 3548 }
3625 3549
3626 void WebGLRenderingContext::texSubImage2D(GLenum target, GLint level, GLint xoff set, GLint yoffset, 3550 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
3627 GLsizei width, GLsizei height, 3551 GLsizei width, GLsizei height,
3628 GLenum format, GLenum type, ArrayBufferView* pixels, ExceptionState& excepti onState) 3552 GLenum format, GLenum type, ArrayBufferView* pixels, ExceptionState& excepti onState)
3629 { 3553 {
3630 if (isContextLost() || !validateTexFuncData("texSubImage2D", level, width, h eight, format, type, pixels, NullNotAllowed) 3554 if (isContextLost() || !validateTexFuncData("texSubImage2D", level, width, h eight, format, type, pixels, NullNotAllowed)
3631 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceArrayBufferVie w, target, level, format, width, height, 0, format, type, xoffset, yoffset)) 3555 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceArrayBufferVie w, target, level, format, width, height, 0, format, type, xoffset, yoffset))
3632 return; 3556 return;
3633 void* data = pixels->baseAddress(); 3557 void* data = pixels->baseAddress();
3634 Vector<uint8_t> tempData; 3558 Vector<uint8_t> tempData;
3635 bool changeUnpackAlignment = false; 3559 bool changeUnpackAlignment = false;
3636 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) { 3560 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) {
3637 if (!WebGLImageConversion::extractTextureData(width, height, format, typ e, 3561 if (!WebGLImageConversion::extractTextureData(width, height, format, typ e,
3638 m_unpackAlignment, 3562 m_unpackAlignment,
3639 m_unpackFlipY, m_unpackPremultiplyAlp ha, 3563 m_unpackFlipY, m_unpackPremultiplyAlp ha,
3640 data, 3564 data,
3641 tempData)) 3565 tempData))
3642 return; 3566 return;
3643 data = tempData.data(); 3567 data = tempData.data();
3644 changeUnpackAlignment = true; 3568 changeUnpackAlignment = true;
3645 } 3569 }
3646 if (changeUnpackAlignment) 3570 if (changeUnpackAlignment)
3647 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, 1); 3571 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, 1);
3648 texSubImage2DBase(target, level, xoffset, yoffset, width, height, format, ty pe, data, exceptionState); 3572 texSubImage2DBase(target, level, xoffset, yoffset, width, height, format, ty pe, data, exceptionState);
3649 if (changeUnpackAlignment) 3573 if (changeUnpackAlignment)
3650 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); 3574 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
3651 } 3575 }
3652 3576
3653 void WebGLRenderingContext::texSubImage2D(GLenum target, GLint level, GLint xoff set, GLint yoffset, 3577 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
3654 GLenum format, GLenum type, ImageData* pixels, ExceptionState& exceptionStat e) 3578 GLenum format, GLenum type, ImageData* pixels, ExceptionState& exceptionStat e)
3655 { 3579 {
3656 if (isContextLost() || !pixels || !validateTexFunc("texSubImage2D", TexSubIm age2D, SourceImageData, target, level, format, pixels->width(), pixels->height( ), 0, format, type, xoffset, yoffset)) 3580 if (isContextLost() || !pixels || !validateTexFunc("texSubImage2D", TexSubIm age2D, SourceImageData, target, level, format, pixels->width(), pixels->height( ), 0, format, type, xoffset, yoffset))
3657 return; 3581 return;
3658 3582
3659 Vector<uint8_t> data; 3583 Vector<uint8_t> data;
3660 bool needConversion = true; 3584 bool needConversion = true;
3661 // The data from ImageData is always of format RGBA8. 3585 // The data from ImageData is always of format RGBA8.
3662 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required. 3586 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required.
3663 if (format == GL_RGBA && type == GL_UNSIGNED_BYTE && !m_unpackFlipY && !m_un packPremultiplyAlpha) 3587 if (format == GL_RGBA && type == GL_UNSIGNED_BYTE && !m_unpackFlipY && !m_un packPremultiplyAlpha)
3664 needConversion = false; 3588 needConversion = false;
3665 else { 3589 else {
3666 if (!WebGLImageConversion::extractImageData(pixels->data()->data(), pixe ls->size(), format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) { 3590 if (!WebGLImageConversion::extractImageData(pixels->data()->data(), pixe ls->size(), format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) {
3667 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "bad image data "); 3591 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "bad image data ");
3668 return; 3592 return;
3669 } 3593 }
3670 } 3594 }
3671 if (m_unpackAlignment != 1) 3595 if (m_unpackAlignment != 1)
3672 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, 1); 3596 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, 1);
3673 texSubImage2DBase(target, level, xoffset, yoffset, pixels->width(), pixels-> height(), format, type, needConversion ? data.data() : pixels->data()->data(), e xceptionState); 3597 texSubImage2DBase(target, level, xoffset, yoffset, pixels->width(), pixels-> height(), format, type, needConversion ? data.data() : pixels->data()->data(), e xceptionState);
3674 if (m_unpackAlignment != 1) 3598 if (m_unpackAlignment != 1)
3675 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); 3599 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
3676 } 3600 }
3677 3601
3678 void WebGLRenderingContext::texSubImage2D(GLenum target, GLint level, GLint xoff set, GLint yoffset, 3602 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
3679 GLenum format, GLenum type, HTMLImageElement* image, ExceptionState& excepti onState) 3603 GLenum format, GLenum type, HTMLImageElement* image, ExceptionState& excepti onState)
3680 { 3604 {
3681 if (isContextLost() || !validateHTMLImageElement("texSubImage2D", image, exc eptionState)) 3605 if (isContextLost() || !validateHTMLImageElement("texSubImage2D", image, exc eptionState))
3682 return; 3606 return;
3683 3607
3684 RefPtr<Image> imageForRender = image->cachedImage()->imageForRenderer(image- >renderer()); 3608 RefPtr<Image> imageForRender = image->cachedImage()->imageForRenderer(image- >renderer());
3685 if (imageForRender->isSVGImage()) 3609 if (imageForRender->isSVGImage())
3686 imageForRender = drawImageIntoBuffer(imageForRender.get(), image->width( ), image->height()); 3610 imageForRender = drawImageIntoBuffer(imageForRender.get(), image->width( ), image->height());
3687 3611
3688 if (!imageForRender || !validateTexFunc("texSubImage2D", TexSubImage2D, Sour ceHTMLImageElement, target, level, format, imageForRender->width(), imageForRend er->height(), 0, format, type, xoffset, yoffset)) 3612 if (!imageForRender || !validateTexFunc("texSubImage2D", TexSubImage2D, Sour ceHTMLImageElement, target, level, format, imageForRender->width(), imageForRend er->height(), 0, format, type, xoffset, yoffset))
3689 return; 3613 return;
3690 3614
3691 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, imageForRen der.get(), WebGLImageConversion::HtmlDomImage, m_unpackFlipY, m_unpackPremultipl yAlpha, exceptionState); 3615 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, imageForRen der.get(), WebGLImageConversion::HtmlDomImage, m_unpackFlipY, m_unpackPremultipl yAlpha, exceptionState);
3692 } 3616 }
3693 3617
3694 void WebGLRenderingContext::texSubImage2D(GLenum target, GLint level, GLint xoff set, GLint yoffset, 3618 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
3695 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep tionState) 3619 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep tionState)
3696 { 3620 {
3697 if (isContextLost() || !validateHTMLCanvasElement("texSubImage2D", canvas, e xceptionState) 3621 if (isContextLost() || !validateHTMLCanvasElement("texSubImage2D", canvas, e xceptionState)
3698 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLCanvasElem ent, target, level, format, canvas->width(), canvas->height(), 0, format, type, xoffset, yoffset)) 3622 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLCanvasElem ent, target, level, format, canvas->width(), canvas->height(), 0, format, type, xoffset, yoffset))
3699 return; 3623 return;
3700 3624
3701 RefPtr<ImageData> imageData = canvas->getImageData(); 3625 RefPtr<ImageData> imageData = canvas->getImageData();
3702 if (imageData) 3626 if (imageData)
3703 texSubImage2D(target, level, xoffset, yoffset, format, type, imageData.g et(), exceptionState); 3627 texSubImage2D(target, level, xoffset, yoffset, format, type, imageData.g et(), exceptionState);
3704 else 3628 else
3705 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, canvas- >copiedImage(), WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpackPrem ultiplyAlpha, exceptionState); 3629 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, canvas- >copiedImage(), WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpackPrem ultiplyAlpha, exceptionState);
3706 } 3630 }
3707 3631
3708 void WebGLRenderingContext::texSubImage2D(GLenum target, GLint level, GLint xoff set, GLint yoffset, 3632 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
3709 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState) 3633 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState)
3710 { 3634 {
3711 if (isContextLost() || !validateHTMLVideoElement("texSubImage2D", video, exc eptionState) 3635 if (isContextLost() || !validateHTMLVideoElement("texSubImage2D", video, exc eptionState)
3712 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLVideoEleme nt, target, level, format, video->videoWidth(), video->videoHeight(), 0, format, type, xoffset, yoffset)) 3636 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLVideoEleme nt, target, level, format, video->videoWidth(), video->videoHeight(), 0, format, type, xoffset, yoffset))
3713 return; 3637 return;
3714 3638
3715 RefPtr<Image> image = videoFrameToImage(video, ImageBuffer::fastCopyImageMod e()); 3639 RefPtr<Image> image = videoFrameToImage(video, ImageBuffer::fastCopyImageMod e());
3716 if (!image) 3640 if (!image)
3717 return; 3641 return;
3718 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, image.get() , WebGLImageConversion::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha, e xceptionState); 3642 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, image.get() , WebGLImageConversion::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha, e xceptionState);
3719 } 3643 }
3720 3644
3721 void WebGLRenderingContext::uniform1f(const WebGLUniformLocation* location, GLfl oat x) 3645 void WebGLRenderingContextBase::uniform1f(const WebGLUniformLocation* location, GLfloat x)
3722 { 3646 {
3723 if (isContextLost() || !location) 3647 if (isContextLost() || !location)
3724 return; 3648 return;
3725 3649
3726 if (location->program() != m_currentProgram) { 3650 if (location->program() != m_currentProgram) {
3727 synthesizeGLError(GL_INVALID_OPERATION, "uniform1f", "location not for c urrent program"); 3651 synthesizeGLError(GL_INVALID_OPERATION, "uniform1f", "location not for c urrent program");
3728 return; 3652 return;
3729 } 3653 }
3730 3654
3731 m_context->uniform1f(location->location(), x); 3655 m_context->uniform1f(location->location(), x);
3732 } 3656 }
3733 3657
3734 void WebGLRenderingContext::uniform1fv(const WebGLUniformLocation* location, Flo at32Array* v) 3658 void WebGLRenderingContextBase::uniform1fv(const WebGLUniformLocation* location, Float32Array* v)
3735 { 3659 {
3736 if (isContextLost() || !validateUniformParameters("uniform1fv", location, v, 1)) 3660 if (isContextLost() || !validateUniformParameters("uniform1fv", location, v, 1))
3737 return; 3661 return;
3738 3662
3739 m_context->uniform1fv(location->location(), v->length(), v->data()); 3663 m_context->uniform1fv(location->location(), v->length(), v->data());
3740 } 3664 }
3741 3665
3742 void WebGLRenderingContext::uniform1fv(const WebGLUniformLocation* location, GLf loat* v, GLsizei size) 3666 void WebGLRenderingContextBase::uniform1fv(const WebGLUniformLocation* location, GLfloat* v, GLsizei size)
3743 { 3667 {
3744 if (isContextLost() || !validateUniformParameters("uniform1fv", location, v, size, 1)) 3668 if (isContextLost() || !validateUniformParameters("uniform1fv", location, v, size, 1))
3745 return; 3669 return;
3746 3670
3747 m_context->uniform1fv(location->location(), size, v); 3671 m_context->uniform1fv(location->location(), size, v);
3748 } 3672 }
3749 3673
3750 void WebGLRenderingContext::uniform1i(const WebGLUniformLocation* location, GLin t x) 3674 void WebGLRenderingContextBase::uniform1i(const WebGLUniformLocation* location, GLint x)
3751 { 3675 {
3752 if (isContextLost() || !location) 3676 if (isContextLost() || !location)
3753 return; 3677 return;
3754 3678
3755 if (location->program() != m_currentProgram) { 3679 if (location->program() != m_currentProgram) {
3756 synthesizeGLError(GL_INVALID_OPERATION, "uniform1i", "location not for c urrent program"); 3680 synthesizeGLError(GL_INVALID_OPERATION, "uniform1i", "location not for c urrent program");
3757 return; 3681 return;
3758 } 3682 }
3759 3683
3760 m_context->uniform1i(location->location(), x); 3684 m_context->uniform1i(location->location(), x);
3761 } 3685 }
3762 3686
3763 void WebGLRenderingContext::uniform1iv(const WebGLUniformLocation* location, Int 32Array* v) 3687 void WebGLRenderingContextBase::uniform1iv(const WebGLUniformLocation* location, Int32Array* v)
3764 { 3688 {
3765 if (isContextLost() || !validateUniformParameters("uniform1iv", location, v, 1)) 3689 if (isContextLost() || !validateUniformParameters("uniform1iv", location, v, 1))
3766 return; 3690 return;
3767 3691
3768 m_context->uniform1iv(location->location(), v->length(), v->data()); 3692 m_context->uniform1iv(location->location(), v->length(), v->data());
3769 } 3693 }
3770 3694
3771 void WebGLRenderingContext::uniform1iv(const WebGLUniformLocation* location, GLi nt* v, GLsizei size) 3695 void WebGLRenderingContextBase::uniform1iv(const WebGLUniformLocation* location, GLint* v, GLsizei size)
3772 { 3696 {
3773 if (isContextLost() || !validateUniformParameters("uniform1iv", location, v, size, 1)) 3697 if (isContextLost() || !validateUniformParameters("uniform1iv", location, v, size, 1))
3774 return; 3698 return;
3775 3699
3776 m_context->uniform1iv(location->location(), size, v); 3700 m_context->uniform1iv(location->location(), size, v);
3777 } 3701 }
3778 3702
3779 void WebGLRenderingContext::uniform2f(const WebGLUniformLocation* location, GLfl oat x, GLfloat y) 3703 void WebGLRenderingContextBase::uniform2f(const WebGLUniformLocation* location, GLfloat x, GLfloat y)
3780 { 3704 {
3781 if (isContextLost() || !location) 3705 if (isContextLost() || !location)
3782 return; 3706 return;
3783 3707
3784 if (location->program() != m_currentProgram) { 3708 if (location->program() != m_currentProgram) {
3785 synthesizeGLError(GL_INVALID_OPERATION, "uniform2f", "location not for c urrent program"); 3709 synthesizeGLError(GL_INVALID_OPERATION, "uniform2f", "location not for c urrent program");
3786 return; 3710 return;
3787 } 3711 }
3788 3712
3789 m_context->uniform2f(location->location(), x, y); 3713 m_context->uniform2f(location->location(), x, y);
3790 } 3714 }
3791 3715
3792 void WebGLRenderingContext::uniform2fv(const WebGLUniformLocation* location, Flo at32Array* v) 3716 void WebGLRenderingContextBase::uniform2fv(const WebGLUniformLocation* location, Float32Array* v)
3793 { 3717 {
3794 if (isContextLost() || !validateUniformParameters("uniform2fv", location, v, 2)) 3718 if (isContextLost() || !validateUniformParameters("uniform2fv", location, v, 2))
3795 return; 3719 return;
3796 3720
3797 m_context->uniform2fv(location->location(), v->length() / 2, v->data()); 3721 m_context->uniform2fv(location->location(), v->length() / 2, v->data());
3798 } 3722 }
3799 3723
3800 void WebGLRenderingContext::uniform2fv(const WebGLUniformLocation* location, GLf loat* v, GLsizei size) 3724 void WebGLRenderingContextBase::uniform2fv(const WebGLUniformLocation* location, GLfloat* v, GLsizei size)
3801 { 3725 {
3802 if (isContextLost() || !validateUniformParameters("uniform2fv", location, v, size, 2)) 3726 if (isContextLost() || !validateUniformParameters("uniform2fv", location, v, size, 2))
3803 return; 3727 return;
3804 3728
3805 m_context->uniform2fv(location->location(), size / 2, v); 3729 m_context->uniform2fv(location->location(), size / 2, v);
3806 } 3730 }
3807 3731
3808 void WebGLRenderingContext::uniform2i(const WebGLUniformLocation* location, GLin t x, GLint y) 3732 void WebGLRenderingContextBase::uniform2i(const WebGLUniformLocation* location, GLint x, GLint y)
3809 { 3733 {
3810 if (isContextLost() || !location) 3734 if (isContextLost() || !location)
3811 return; 3735 return;
3812 3736
3813 if (location->program() != m_currentProgram) { 3737 if (location->program() != m_currentProgram) {
3814 synthesizeGLError(GL_INVALID_OPERATION, "uniform2i", "location not for c urrent program"); 3738 synthesizeGLError(GL_INVALID_OPERATION, "uniform2i", "location not for c urrent program");
3815 return; 3739 return;
3816 } 3740 }
3817 3741
3818 m_context->uniform2i(location->location(), x, y); 3742 m_context->uniform2i(location->location(), x, y);
3819 } 3743 }
3820 3744
3821 void WebGLRenderingContext::uniform2iv(const WebGLUniformLocation* location, Int 32Array* v) 3745 void WebGLRenderingContextBase::uniform2iv(const WebGLUniformLocation* location, Int32Array* v)
3822 { 3746 {
3823 if (isContextLost() || !validateUniformParameters("uniform2iv", location, v, 2)) 3747 if (isContextLost() || !validateUniformParameters("uniform2iv", location, v, 2))
3824 return; 3748 return;
3825 3749
3826 m_context->uniform2iv(location->location(), v->length() / 2, v->data()); 3750 m_context->uniform2iv(location->location(), v->length() / 2, v->data());
3827 } 3751 }
3828 3752
3829 void WebGLRenderingContext::uniform2iv(const WebGLUniformLocation* location, GLi nt* v, GLsizei size) 3753 void WebGLRenderingContextBase::uniform2iv(const WebGLUniformLocation* location, GLint* v, GLsizei size)
3830 { 3754 {
3831 if (isContextLost() || !validateUniformParameters("uniform2iv", location, v, size, 2)) 3755 if (isContextLost() || !validateUniformParameters("uniform2iv", location, v, size, 2))
3832 return; 3756 return;
3833 3757
3834 m_context->uniform2iv(location->location(), size / 2, v); 3758 m_context->uniform2iv(location->location(), size / 2, v);
3835 } 3759 }
3836 3760
3837 void WebGLRenderingContext::uniform3f(const WebGLUniformLocation* location, GLfl oat x, GLfloat y, GLfloat z) 3761 void WebGLRenderingContextBase::uniform3f(const WebGLUniformLocation* location, GLfloat x, GLfloat y, GLfloat z)
3838 { 3762 {
3839 if (isContextLost() || !location) 3763 if (isContextLost() || !location)
3840 return; 3764 return;
3841 3765
3842 if (location->program() != m_currentProgram) { 3766 if (location->program() != m_currentProgram) {
3843 synthesizeGLError(GL_INVALID_OPERATION, "uniform3f", "location not for c urrent program"); 3767 synthesizeGLError(GL_INVALID_OPERATION, "uniform3f", "location not for c urrent program");
3844 return; 3768 return;
3845 } 3769 }
3846 3770
3847 m_context->uniform3f(location->location(), x, y, z); 3771 m_context->uniform3f(location->location(), x, y, z);
3848 } 3772 }
3849 3773
3850 void WebGLRenderingContext::uniform3fv(const WebGLUniformLocation* location, Flo at32Array* v) 3774 void WebGLRenderingContextBase::uniform3fv(const WebGLUniformLocation* location, Float32Array* v)
3851 { 3775 {
3852 if (isContextLost() || !validateUniformParameters("uniform3fv", location, v, 3)) 3776 if (isContextLost() || !validateUniformParameters("uniform3fv", location, v, 3))
3853 return; 3777 return;
3854 3778
3855 m_context->uniform3fv(location->location(), v->length() / 3, v->data()); 3779 m_context->uniform3fv(location->location(), v->length() / 3, v->data());
3856 } 3780 }
3857 3781
3858 void WebGLRenderingContext::uniform3fv(const WebGLUniformLocation* location, GLf loat* v, GLsizei size) 3782 void WebGLRenderingContextBase::uniform3fv(const WebGLUniformLocation* location, GLfloat* v, GLsizei size)
3859 { 3783 {
3860 if (isContextLost() || !validateUniformParameters("uniform3fv", location, v, size, 3)) 3784 if (isContextLost() || !validateUniformParameters("uniform3fv", location, v, size, 3))
3861 return; 3785 return;
3862 3786
3863 m_context->uniform3fv(location->location(), size / 3, v); 3787 m_context->uniform3fv(location->location(), size / 3, v);
3864 } 3788 }
3865 3789
3866 void WebGLRenderingContext::uniform3i(const WebGLUniformLocation* location, GLin t x, GLint y, GLint z) 3790 void WebGLRenderingContextBase::uniform3i(const WebGLUniformLocation* location, GLint x, GLint y, GLint z)
3867 { 3791 {
3868 if (isContextLost() || !location) 3792 if (isContextLost() || !location)
3869 return; 3793 return;
3870 3794
3871 if (location->program() != m_currentProgram) { 3795 if (location->program() != m_currentProgram) {
3872 synthesizeGLError(GL_INVALID_OPERATION, "uniform3i", "location not for c urrent program"); 3796 synthesizeGLError(GL_INVALID_OPERATION, "uniform3i", "location not for c urrent program");
3873 return; 3797 return;
3874 } 3798 }
3875 3799
3876 m_context->uniform3i(location->location(), x, y, z); 3800 m_context->uniform3i(location->location(), x, y, z);
3877 } 3801 }
3878 3802
3879 void WebGLRenderingContext::uniform3iv(const WebGLUniformLocation* location, Int 32Array* v) 3803 void WebGLRenderingContextBase::uniform3iv(const WebGLUniformLocation* location, Int32Array* v)
3880 { 3804 {
3881 if (isContextLost() || !validateUniformParameters("uniform3iv", location, v, 3)) 3805 if (isContextLost() || !validateUniformParameters("uniform3iv", location, v, 3))
3882 return; 3806 return;
3883 3807
3884 m_context->uniform3iv(location->location(), v->length() / 3, v->data()); 3808 m_context->uniform3iv(location->location(), v->length() / 3, v->data());
3885 } 3809 }
3886 3810
3887 void WebGLRenderingContext::uniform3iv(const WebGLUniformLocation* location, GLi nt* v, GLsizei size) 3811 void WebGLRenderingContextBase::uniform3iv(const WebGLUniformLocation* location, GLint* v, GLsizei size)
3888 { 3812 {
3889 if (isContextLost() || !validateUniformParameters("uniform3iv", location, v, size, 3)) 3813 if (isContextLost() || !validateUniformParameters("uniform3iv", location, v, size, 3))
3890 return; 3814 return;
3891 3815
3892 m_context->uniform3iv(location->location(), size / 3, v); 3816 m_context->uniform3iv(location->location(), size / 3, v);
3893 } 3817 }
3894 3818
3895 void WebGLRenderingContext::uniform4f(const WebGLUniformLocation* location, GLfl oat x, GLfloat y, GLfloat z, GLfloat w) 3819 void WebGLRenderingContextBase::uniform4f(const WebGLUniformLocation* location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
3896 { 3820 {
3897 if (isContextLost() || !location) 3821 if (isContextLost() || !location)
3898 return; 3822 return;
3899 3823
3900 if (location->program() != m_currentProgram) { 3824 if (location->program() != m_currentProgram) {
3901 synthesizeGLError(GL_INVALID_OPERATION, "uniform4f", "location not for c urrent program"); 3825 synthesizeGLError(GL_INVALID_OPERATION, "uniform4f", "location not for c urrent program");
3902 return; 3826 return;
3903 } 3827 }
3904 3828
3905 m_context->uniform4f(location->location(), x, y, z, w); 3829 m_context->uniform4f(location->location(), x, y, z, w);
3906 } 3830 }
3907 3831
3908 void WebGLRenderingContext::uniform4fv(const WebGLUniformLocation* location, Flo at32Array* v) 3832 void WebGLRenderingContextBase::uniform4fv(const WebGLUniformLocation* location, Float32Array* v)
3909 { 3833 {
3910 if (isContextLost() || !validateUniformParameters("uniform4fv", location, v, 4)) 3834 if (isContextLost() || !validateUniformParameters("uniform4fv", location, v, 4))
3911 return; 3835 return;
3912 3836
3913 m_context->uniform4fv(location->location(), v->length() / 4, v->data()); 3837 m_context->uniform4fv(location->location(), v->length() / 4, v->data());
3914 } 3838 }
3915 3839
3916 void WebGLRenderingContext::uniform4fv(const WebGLUniformLocation* location, GLf loat* v, GLsizei size) 3840 void WebGLRenderingContextBase::uniform4fv(const WebGLUniformLocation* location, GLfloat* v, GLsizei size)
3917 { 3841 {
3918 if (isContextLost() || !validateUniformParameters("uniform4fv", location, v, size, 4)) 3842 if (isContextLost() || !validateUniformParameters("uniform4fv", location, v, size, 4))
3919 return; 3843 return;
3920 3844
3921 m_context->uniform4fv(location->location(), size / 4, v); 3845 m_context->uniform4fv(location->location(), size / 4, v);
3922 } 3846 }
3923 3847
3924 void WebGLRenderingContext::uniform4i(const WebGLUniformLocation* location, GLin t x, GLint y, GLint z, GLint w) 3848 void WebGLRenderingContextBase::uniform4i(const WebGLUniformLocation* location, GLint x, GLint y, GLint z, GLint w)
3925 { 3849 {
3926 if (isContextLost() || !location) 3850 if (isContextLost() || !location)
3927 return; 3851 return;
3928 3852
3929 if (location->program() != m_currentProgram) { 3853 if (location->program() != m_currentProgram) {
3930 synthesizeGLError(GL_INVALID_OPERATION, "uniform4i", "location not for c urrent program"); 3854 synthesizeGLError(GL_INVALID_OPERATION, "uniform4i", "location not for c urrent program");
3931 return; 3855 return;
3932 } 3856 }
3933 3857
3934 m_context->uniform4i(location->location(), x, y, z, w); 3858 m_context->uniform4i(location->location(), x, y, z, w);
3935 } 3859 }
3936 3860
3937 void WebGLRenderingContext::uniform4iv(const WebGLUniformLocation* location, Int 32Array* v) 3861 void WebGLRenderingContextBase::uniform4iv(const WebGLUniformLocation* location, Int32Array* v)
3938 { 3862 {
3939 if (isContextLost() || !validateUniformParameters("uniform4iv", location, v, 4)) 3863 if (isContextLost() || !validateUniformParameters("uniform4iv", location, v, 4))
3940 return; 3864 return;
3941 3865
3942 m_context->uniform4iv(location->location(), v->length() / 4, v->data()); 3866 m_context->uniform4iv(location->location(), v->length() / 4, v->data());
3943 } 3867 }
3944 3868
3945 void WebGLRenderingContext::uniform4iv(const WebGLUniformLocation* location, GLi nt* v, GLsizei size) 3869 void WebGLRenderingContextBase::uniform4iv(const WebGLUniformLocation* location, GLint* v, GLsizei size)
3946 { 3870 {
3947 if (isContextLost() || !validateUniformParameters("uniform4iv", location, v, size, 4)) 3871 if (isContextLost() || !validateUniformParameters("uniform4iv", location, v, size, 4))
3948 return; 3872 return;
3949 3873
3950 m_context->uniform4iv(location->location(), size / 4, v); 3874 m_context->uniform4iv(location->location(), size / 4, v);
3951 } 3875 }
3952 3876
3953 void WebGLRenderingContext::uniformMatrix2fv(const WebGLUniformLocation* locatio n, GLboolean transpose, Float32Array* v) 3877 void WebGLRenderingContextBase::uniformMatrix2fv(const WebGLUniformLocation* loc ation, GLboolean transpose, Float32Array* v)
3954 { 3878 {
3955 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix2fv", location, transpose, v, 4)) 3879 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix2fv", location, transpose, v, 4))
3956 return; 3880 return;
3957 m_context->uniformMatrix2fv(location->location(), v->length() / 4, transpose , v->data()); 3881 m_context->uniformMatrix2fv(location->location(), v->length() / 4, transpose , v->data());
3958 } 3882 }
3959 3883
3960 void WebGLRenderingContext::uniformMatrix2fv(const WebGLUniformLocation* locatio n, GLboolean transpose, GLfloat* v, GLsizei size) 3884 void WebGLRenderingContextBase::uniformMatrix2fv(const WebGLUniformLocation* loc ation, GLboolean transpose, GLfloat* v, GLsizei size)
3961 { 3885 {
3962 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix2fv", location, transpose, v, size, 4)) 3886 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix2fv", location, transpose, v, size, 4))
3963 return; 3887 return;
3964 m_context->uniformMatrix2fv(location->location(), size / 4, transpose, v); 3888 m_context->uniformMatrix2fv(location->location(), size / 4, transpose, v);
3965 } 3889 }
3966 3890
3967 void WebGLRenderingContext::uniformMatrix3fv(const WebGLUniformLocation* locatio n, GLboolean transpose, Float32Array* v) 3891 void WebGLRenderingContextBase::uniformMatrix3fv(const WebGLUniformLocation* loc ation, GLboolean transpose, Float32Array* v)
3968 { 3892 {
3969 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix3fv", location, transpose, v, 9)) 3893 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix3fv", location, transpose, v, 9))
3970 return; 3894 return;
3971 m_context->uniformMatrix3fv(location->location(), v->length() / 9, transpose , v->data()); 3895 m_context->uniformMatrix3fv(location->location(), v->length() / 9, transpose , v->data());
3972 } 3896 }
3973 3897
3974 void WebGLRenderingContext::uniformMatrix3fv(const WebGLUniformLocation* locatio n, GLboolean transpose, GLfloat* v, GLsizei size) 3898 void WebGLRenderingContextBase::uniformMatrix3fv(const WebGLUniformLocation* loc ation, GLboolean transpose, GLfloat* v, GLsizei size)
3975 { 3899 {
3976 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix3fv", location, transpose, v, size, 9)) 3900 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix3fv", location, transpose, v, size, 9))
3977 return; 3901 return;
3978 m_context->uniformMatrix3fv(location->location(), size / 9, transpose, v); 3902 m_context->uniformMatrix3fv(location->location(), size / 9, transpose, v);
3979 } 3903 }
3980 3904
3981 void WebGLRenderingContext::uniformMatrix4fv(const WebGLUniformLocation* locatio n, GLboolean transpose, Float32Array* v) 3905 void WebGLRenderingContextBase::uniformMatrix4fv(const WebGLUniformLocation* loc ation, GLboolean transpose, Float32Array* v)
3982 { 3906 {
3983 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix4fv", location, transpose, v, 16)) 3907 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix4fv", location, transpose, v, 16))
3984 return; 3908 return;
3985 m_context->uniformMatrix4fv(location->location(), v->length() / 16, transpos e, v->data()); 3909 m_context->uniformMatrix4fv(location->location(), v->length() / 16, transpos e, v->data());
3986 } 3910 }
3987 3911
3988 void WebGLRenderingContext::uniformMatrix4fv(const WebGLUniformLocation* locatio n, GLboolean transpose, GLfloat* v, GLsizei size) 3912 void WebGLRenderingContextBase::uniformMatrix4fv(const WebGLUniformLocation* loc ation, GLboolean transpose, GLfloat* v, GLsizei size)
3989 { 3913 {
3990 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix4fv", location, transpose, v, size, 16)) 3914 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix4fv", location, transpose, v, size, 16))
3991 return; 3915 return;
3992 m_context->uniformMatrix4fv(location->location(), size / 16, transpose, v); 3916 m_context->uniformMatrix4fv(location->location(), size / 16, transpose, v);
3993 } 3917 }
3994 3918
3995 void WebGLRenderingContext::useProgram(WebGLProgram* program) 3919 void WebGLRenderingContextBase::useProgram(WebGLProgram* program)
3996 { 3920 {
3997 bool deleted; 3921 bool deleted;
3998 if (!checkObjectToBeBound("useProgram", program, deleted)) 3922 if (!checkObjectToBeBound("useProgram", program, deleted))
3999 return; 3923 return;
4000 if (deleted) 3924 if (deleted)
4001 program = 0; 3925 program = 0;
4002 if (program && !program->linkStatus()) { 3926 if (program && !program->linkStatus()) {
4003 synthesizeGLError(GL_INVALID_OPERATION, "useProgram", "program not valid "); 3927 synthesizeGLError(GL_INVALID_OPERATION, "useProgram", "program not valid ");
4004 return; 3928 return;
4005 } 3929 }
4006 if (m_currentProgram != program) { 3930 if (m_currentProgram != program) {
4007 if (m_currentProgram) 3931 if (m_currentProgram)
4008 m_currentProgram->onDetached(m_context.get()); 3932 m_currentProgram->onDetached(m_context.get());
4009 m_currentProgram = program; 3933 m_currentProgram = program;
4010 m_context->useProgram(objectOrZero(program)); 3934 m_context->useProgram(objectOrZero(program));
4011 if (program) 3935 if (program)
4012 program->onAttached(); 3936 program->onAttached();
4013 } 3937 }
4014 } 3938 }
4015 3939
4016 void WebGLRenderingContext::validateProgram(WebGLProgram* program) 3940 void WebGLRenderingContextBase::validateProgram(WebGLProgram* program)
4017 { 3941 {
4018 if (isContextLost() || !validateWebGLObject("validateProgram", program)) 3942 if (isContextLost() || !validateWebGLObject("validateProgram", program))
4019 return; 3943 return;
4020 m_context->validateProgram(objectOrZero(program)); 3944 m_context->validateProgram(objectOrZero(program));
4021 } 3945 }
4022 3946
4023 void WebGLRenderingContext::vertexAttrib1f(GLuint index, GLfloat v0) 3947 void WebGLRenderingContextBase::vertexAttrib1f(GLuint index, GLfloat v0)
4024 { 3948 {
4025 vertexAttribfImpl("vertexAttrib1f", index, 1, v0, 0.0f, 0.0f, 1.0f); 3949 vertexAttribfImpl("vertexAttrib1f", index, 1, v0, 0.0f, 0.0f, 1.0f);
4026 } 3950 }
4027 3951
4028 void WebGLRenderingContext::vertexAttrib1fv(GLuint index, Float32Array* v) 3952 void WebGLRenderingContextBase::vertexAttrib1fv(GLuint index, Float32Array* v)
4029 { 3953 {
4030 vertexAttribfvImpl("vertexAttrib1fv", index, v, 1); 3954 vertexAttribfvImpl("vertexAttrib1fv", index, v, 1);
4031 } 3955 }
4032 3956
4033 void WebGLRenderingContext::vertexAttrib1fv(GLuint index, GLfloat* v, GLsizei si ze) 3957 void WebGLRenderingContextBase::vertexAttrib1fv(GLuint index, GLfloat* v, GLsize i size)
4034 { 3958 {
4035 vertexAttribfvImpl("vertexAttrib1fv", index, v, size, 1); 3959 vertexAttribfvImpl("vertexAttrib1fv", index, v, size, 1);
4036 } 3960 }
4037 3961
4038 void WebGLRenderingContext::vertexAttrib2f(GLuint index, GLfloat v0, GLfloat v1) 3962 void WebGLRenderingContextBase::vertexAttrib2f(GLuint index, GLfloat v0, GLfloat v1)
4039 { 3963 {
4040 vertexAttribfImpl("vertexAttrib2f", index, 2, v0, v1, 0.0f, 1.0f); 3964 vertexAttribfImpl("vertexAttrib2f", index, 2, v0, v1, 0.0f, 1.0f);
4041 } 3965 }
4042 3966
4043 void WebGLRenderingContext::vertexAttrib2fv(GLuint index, Float32Array* v) 3967 void WebGLRenderingContextBase::vertexAttrib2fv(GLuint index, Float32Array* v)
4044 { 3968 {
4045 vertexAttribfvImpl("vertexAttrib2fv", index, v, 2); 3969 vertexAttribfvImpl("vertexAttrib2fv", index, v, 2);
4046 } 3970 }
4047 3971
4048 void WebGLRenderingContext::vertexAttrib2fv(GLuint index, GLfloat* v, GLsizei si ze) 3972 void WebGLRenderingContextBase::vertexAttrib2fv(GLuint index, GLfloat* v, GLsize i size)
4049 { 3973 {
4050 vertexAttribfvImpl("vertexAttrib2fv", index, v, size, 2); 3974 vertexAttribfvImpl("vertexAttrib2fv", index, v, size, 2);
4051 } 3975 }
4052 3976
4053 void WebGLRenderingContext::vertexAttrib3f(GLuint index, GLfloat v0, GLfloat v1, GLfloat v2) 3977 void WebGLRenderingContextBase::vertexAttrib3f(GLuint index, GLfloat v0, GLfloat v1, GLfloat v2)
4054 { 3978 {
4055 vertexAttribfImpl("vertexAttrib3f", index, 3, v0, v1, v2, 1.0f); 3979 vertexAttribfImpl("vertexAttrib3f", index, 3, v0, v1, v2, 1.0f);
4056 } 3980 }
4057 3981
4058 void WebGLRenderingContext::vertexAttrib3fv(GLuint index, Float32Array* v) 3982 void WebGLRenderingContextBase::vertexAttrib3fv(GLuint index, Float32Array* v)
4059 { 3983 {
4060 vertexAttribfvImpl("vertexAttrib3fv", index, v, 3); 3984 vertexAttribfvImpl("vertexAttrib3fv", index, v, 3);
4061 } 3985 }
4062 3986
4063 void WebGLRenderingContext::vertexAttrib3fv(GLuint index, GLfloat* v, GLsizei si ze) 3987 void WebGLRenderingContextBase::vertexAttrib3fv(GLuint index, GLfloat* v, GLsize i size)
4064 { 3988 {
4065 vertexAttribfvImpl("vertexAttrib3fv", index, v, size, 3); 3989 vertexAttribfvImpl("vertexAttrib3fv", index, v, size, 3);
4066 } 3990 }
4067 3991
4068 void WebGLRenderingContext::vertexAttrib4f(GLuint index, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) 3992 void WebGLRenderingContextBase::vertexAttrib4f(GLuint index, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3)
4069 { 3993 {
4070 vertexAttribfImpl("vertexAttrib4f", index, 4, v0, v1, v2, v3); 3994 vertexAttribfImpl("vertexAttrib4f", index, 4, v0, v1, v2, v3);
4071 } 3995 }
4072 3996
4073 void WebGLRenderingContext::vertexAttrib4fv(GLuint index, Float32Array* v) 3997 void WebGLRenderingContextBase::vertexAttrib4fv(GLuint index, Float32Array* v)
4074 { 3998 {
4075 vertexAttribfvImpl("vertexAttrib4fv", index, v, 4); 3999 vertexAttribfvImpl("vertexAttrib4fv", index, v, 4);
4076 } 4000 }
4077 4001
4078 void WebGLRenderingContext::vertexAttrib4fv(GLuint index, GLfloat* v, GLsizei si ze) 4002 void WebGLRenderingContextBase::vertexAttrib4fv(GLuint index, GLfloat* v, GLsize i size)
4079 { 4003 {
4080 vertexAttribfvImpl("vertexAttrib4fv", index, v, size, 4); 4004 vertexAttribfvImpl("vertexAttrib4fv", index, v, size, 4);
4081 } 4005 }
4082 4006
4083 void WebGLRenderingContext::vertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, long long offset) 4007 void WebGLRenderingContextBase::vertexAttribPointer(GLuint index, GLint size, GL enum type, GLboolean normalized, GLsizei stride, long long offset)
4084 { 4008 {
4085 if (isContextLost()) 4009 if (isContextLost())
4086 return; 4010 return;
4087 switch (type) { 4011 switch (type) {
4088 case GL_BYTE: 4012 case GL_BYTE:
4089 case GL_UNSIGNED_BYTE: 4013 case GL_UNSIGNED_BYTE:
4090 case GL_SHORT: 4014 case GL_SHORT:
4091 case GL_UNSIGNED_SHORT: 4015 case GL_UNSIGNED_SHORT:
4092 case GL_FLOAT: 4016 case GL_FLOAT:
4093 break; 4017 break;
(...skipping 22 matching lines...) Expand all
4116 if ((stride % typeSize) || (static_cast<GLintptr>(offset) % typeSize)) { 4040 if ((stride % typeSize) || (static_cast<GLintptr>(offset) % typeSize)) {
4117 synthesizeGLError(GL_INVALID_OPERATION, "vertexAttribPointer", "stride o r offset not valid for type"); 4041 synthesizeGLError(GL_INVALID_OPERATION, "vertexAttribPointer", "stride o r offset not valid for type");
4118 return; 4042 return;
4119 } 4043 }
4120 GLsizei bytesPerElement = size * typeSize; 4044 GLsizei bytesPerElement = size * typeSize;
4121 4045
4122 m_boundVertexArrayObject->setVertexAttribState(index, bytesPerElement, size, type, normalized, stride, static_cast<GLintptr>(offset), m_boundArrayBuffer); 4046 m_boundVertexArrayObject->setVertexAttribState(index, bytesPerElement, size, type, normalized, stride, static_cast<GLintptr>(offset), m_boundArrayBuffer);
4123 m_context->vertexAttribPointer(index, size, type, normalized, stride, static _cast<GLintptr>(offset)); 4047 m_context->vertexAttribPointer(index, size, type, normalized, stride, static _cast<GLintptr>(offset));
4124 } 4048 }
4125 4049
4126 void WebGLRenderingContext::vertexAttribDivisorANGLE(GLuint index, GLuint diviso r) 4050 void WebGLRenderingContextBase::vertexAttribDivisorANGLE(GLuint index, GLuint di visor)
4127 { 4051 {
4128 if (isContextLost()) 4052 if (isContextLost())
4129 return; 4053 return;
4130 4054
4131 if (index >= m_maxVertexAttribs) { 4055 if (index >= m_maxVertexAttribs) {
4132 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribDivisorANGLE", "index o ut of range"); 4056 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribDivisorANGLE", "index o ut of range");
4133 return; 4057 return;
4134 } 4058 }
4135 4059
4136 m_boundVertexArrayObject->setVertexAttribDivisor(index, divisor); 4060 m_boundVertexArrayObject->setVertexAttribDivisor(index, divisor);
4137 m_context->vertexAttribDivisorANGLE(index, divisor); 4061 m_context->vertexAttribDivisorANGLE(index, divisor);
4138 } 4062 }
4139 4063
4140 void WebGLRenderingContext::viewport(GLint x, GLint y, GLsizei width, GLsizei he ight) 4064 void WebGLRenderingContextBase::viewport(GLint x, GLint y, GLsizei width, GLsize i height)
4141 { 4065 {
4142 if (isContextLost()) 4066 if (isContextLost())
4143 return; 4067 return;
4144 if (!validateSize("viewport", width, height)) 4068 if (!validateSize("viewport", width, height))
4145 return; 4069 return;
4146 m_context->viewport(x, y, width, height); 4070 m_context->viewport(x, y, width, height);
4147 } 4071 }
4148 4072
4149 void WebGLRenderingContext::forceLostContext(WebGLRenderingContext::LostContextM ode mode) 4073 void WebGLRenderingContextBase::forceLostContext(WebGLRenderingContextBase::Lost ContextMode mode)
4150 { 4074 {
4151 if (isContextLost()) { 4075 if (isContextLost()) {
4152 synthesizeGLError(GL_INVALID_OPERATION, "loseContext", "context already lost"); 4076 synthesizeGLError(GL_INVALID_OPERATION, "loseContext", "context already lost");
4153 return; 4077 return;
4154 } 4078 }
4155 4079
4156 m_contextGroup->loseContextGroup(mode); 4080 m_contextGroup->loseContextGroup(mode);
4157 } 4081 }
4158 4082
4159 void WebGLRenderingContext::loseContextImpl(WebGLRenderingContext::LostContextMo de mode) 4083 void WebGLRenderingContextBase::loseContextImpl(WebGLRenderingContextBase::LostC ontextMode mode)
4160 { 4084 {
4161 if (isContextLost()) 4085 if (isContextLost())
4162 return; 4086 return;
4163 4087
4164 m_contextLost = true; 4088 m_contextLost = true;
4165 m_contextLostMode = mode; 4089 m_contextLostMode = mode;
4166 4090
4167 if (mode == RealLostContext) { 4091 if (mode == RealLostContext) {
4168 // Inform the embedder that a lost context was received. In response, th e embedder might 4092 // Inform the embedder that a lost context was received. In response, th e embedder might
4169 // decide to take action such as asking the user for permission to use W ebGL again. 4093 // decide to take action such as asking the user for permission to use W ebGL again.
4170 if (Frame* frame = canvas()->document().frame()) 4094 if (Frame* frame = canvas()->document().frame())
4171 frame->loader().client()->didLoseWebGLContext(m_context->getGraphics ResetStatusARB()); 4095 frame->loader().client()->didLoseWebGLContext(m_context->getGraphics ResetStatusARB());
4172 } 4096 }
4173 4097
4174 // Make absolutely sure we do not refer to an already-deleted texture or fra mebuffer. 4098 // Make absolutely sure we do not refer to an already-deleted texture or fra mebuffer.
4175 m_drawingBuffer->setTexture2DBinding(0); 4099 m_drawingBuffer->setTexture2DBinding(0);
4176 m_drawingBuffer->setFramebufferBinding(0); 4100 m_drawingBuffer->setFramebufferBinding(0);
4177 4101
4178 detachAndRemoveAllObjects(); 4102 detachAndRemoveAllObjects();
4179 4103
4180 // Lose all the extensions. 4104 // Lose all the extensions.
4181 for (size_t i = 0; i < m_extensions.size(); ++i) { 4105 for (size_t i = 0; i < m_extensions.size(); ++i) {
4182 ExtensionTracker* tracker = m_extensions[i]; 4106 ExtensionTracker* tracker = m_extensions[i];
4183 tracker->loseExtension(); 4107 tracker->loseExtension();
4184 } 4108 }
4185 4109
4110 for (size_t i = 0; i < WebGLExtensionNameCount; ++i)
4111 m_extensionEnabled[i] = 0;
Ken Russell (switch to Gerrit) 2014/02/21 23:40:20 Use false instead of 0? Can this code be shared w
4112
4186 removeAllCompressedTextureFormats(); 4113 removeAllCompressedTextureFormats();
4187 4114
4188 if (mode != RealLostContext) 4115 if (mode != RealLostContext)
4189 destroyContext(); 4116 destroyContext();
4190 4117
4191 ConsoleDisplayPreference display = (mode == RealLostContext) ? DisplayInCons ole: DontDisplayInConsole; 4118 ConsoleDisplayPreference display = (mode == RealLostContext) ? DisplayInCons ole: DontDisplayInConsole;
4192 synthesizeGLError(GC3D_CONTEXT_LOST_WEBGL, "loseContext", "context lost", di splay); 4119 synthesizeGLError(GC3D_CONTEXT_LOST_WEBGL, "loseContext", "context lost", di splay);
4193 4120
4194 // Don't allow restoration unless the context lost event has both been 4121 // Don't allow restoration unless the context lost event has both been
4195 // dispatched and its default behavior prevented. 4122 // dispatched and its default behavior prevented.
4196 m_restoreAllowed = false; 4123 m_restoreAllowed = false;
4197 4124
4198 // Always defer the dispatch of the context lost event, to implement 4125 // Always defer the dispatch of the context lost event, to implement
4199 // the spec behavior of queueing a task. 4126 // the spec behavior of queueing a task.
4200 m_dispatchContextLostEventTimer.startOneShot(0); 4127 m_dispatchContextLostEventTimer.startOneShot(0);
4201 } 4128 }
4202 4129
4203 void WebGLRenderingContext::forceRestoreContext() 4130 void WebGLRenderingContextBase::forceRestoreContext()
4204 { 4131 {
4205 if (!isContextLost()) { 4132 if (!isContextLost()) {
4206 synthesizeGLError(GL_INVALID_OPERATION, "restoreContext", "context not l ost"); 4133 synthesizeGLError(GL_INVALID_OPERATION, "restoreContext", "context not l ost");
4207 return; 4134 return;
4208 } 4135 }
4209 4136
4210 if (!m_restoreAllowed) { 4137 if (!m_restoreAllowed) {
4211 if (m_contextLostMode == SyntheticLostContext) 4138 if (m_contextLostMode == SyntheticLostContext)
4212 synthesizeGLError(GL_INVALID_OPERATION, "restoreContext", "context r estoration not allowed"); 4139 synthesizeGLError(GL_INVALID_OPERATION, "restoreContext", "context r estoration not allowed");
4213 return; 4140 return;
4214 } 4141 }
4215 4142
4216 if (!m_restoreTimer.isActive()) 4143 if (!m_restoreTimer.isActive())
4217 m_restoreTimer.startOneShot(0); 4144 m_restoreTimer.startOneShot(0);
4218 } 4145 }
4219 4146
4220 blink::WebLayer* WebGLRenderingContext::platformLayer() const 4147 blink::WebLayer* WebGLRenderingContextBase::platformLayer() const
4221 { 4148 {
4222 return m_drawingBuffer->platformLayer(); 4149 return m_drawingBuffer->platformLayer();
4223 } 4150 }
4224 4151
4225 Extensions3DUtil* WebGLRenderingContext::extensionsUtil() 4152 Extensions3DUtil* WebGLRenderingContextBase::extensionsUtil()
4226 { 4153 {
4227 if (!m_extensionsUtil) 4154 if (!m_extensionsUtil)
4228 m_extensionsUtil = adoptPtr(new Extensions3DUtil(m_context.get())); 4155 m_extensionsUtil = adoptPtr(new Extensions3DUtil(m_context.get()));
4229 return m_extensionsUtil.get(); 4156 return m_extensionsUtil.get();
4230 } 4157 }
4231 4158
4232 void WebGLRenderingContext::removeSharedObject(WebGLSharedObject* object) 4159 void WebGLRenderingContextBase::removeSharedObject(WebGLSharedObject* object)
4233 { 4160 {
4234 m_contextGroup->removeObject(object); 4161 m_contextGroup->removeObject(object);
4235 } 4162 }
4236 4163
4237 void WebGLRenderingContext::addSharedObject(WebGLSharedObject* object) 4164 void WebGLRenderingContextBase::addSharedObject(WebGLSharedObject* object)
4238 { 4165 {
4239 ASSERT(!isContextLost()); 4166 ASSERT(!isContextLost());
4240 m_contextGroup->addObject(object); 4167 m_contextGroup->addObject(object);
4241 } 4168 }
4242 4169
4243 void WebGLRenderingContext::removeContextObject(WebGLContextObject* object) 4170 void WebGLRenderingContextBase::removeContextObject(WebGLContextObject* object)
4244 { 4171 {
4245 m_contextObjects.remove(object); 4172 m_contextObjects.remove(object);
4246 } 4173 }
4247 4174
4248 void WebGLRenderingContext::addContextObject(WebGLContextObject* object) 4175 void WebGLRenderingContextBase::addContextObject(WebGLContextObject* object)
4249 { 4176 {
4250 ASSERT(!isContextLost()); 4177 ASSERT(!isContextLost());
4251 m_contextObjects.add(object); 4178 m_contextObjects.add(object);
4252 } 4179 }
4253 4180
4254 void WebGLRenderingContext::detachAndRemoveAllObjects() 4181 void WebGLRenderingContextBase::detachAndRemoveAllObjects()
4255 { 4182 {
4256 while (m_contextObjects.size() > 0) { 4183 while (m_contextObjects.size() > 0) {
4257 HashSet<WebGLContextObject*>::iterator it = m_contextObjects.begin(); 4184 HashSet<WebGLContextObject*>::iterator it = m_contextObjects.begin();
4258 (*it)->detachContext(); 4185 (*it)->detachContext();
4259 } 4186 }
4260 } 4187 }
4261 4188
4262 bool WebGLRenderingContext::hasPendingActivity() const 4189 bool WebGLRenderingContextBase::hasPendingActivity() const
4263 { 4190 {
4264 return false; 4191 return false;
4265 } 4192 }
4266 4193
4267 void WebGLRenderingContext::stop() 4194 void WebGLRenderingContextBase::stop()
4268 { 4195 {
4269 if (!isContextLost()) { 4196 if (!isContextLost()) {
4270 forceLostContext(SyntheticLostContext); 4197 forceLostContext(SyntheticLostContext);
4271 destroyContext(); 4198 destroyContext();
4272 } 4199 }
4273 } 4200 }
4274 4201
4275 WebGLGetInfo WebGLRenderingContext::getBooleanParameter(GLenum pname) 4202 WebGLGetInfo WebGLRenderingContextBase::getBooleanParameter(GLenum pname)
4276 { 4203 {
4277 GLboolean value = 0; 4204 GLboolean value = 0;
4278 if (!isContextLost()) 4205 if (!isContextLost())
4279 m_context->getBooleanv(pname, &value); 4206 m_context->getBooleanv(pname, &value);
4280 return WebGLGetInfo(static_cast<bool>(value)); 4207 return WebGLGetInfo(static_cast<bool>(value));
4281 } 4208 }
4282 4209
4283 WebGLGetInfo WebGLRenderingContext::getBooleanArrayParameter(GLenum pname) 4210 WebGLGetInfo WebGLRenderingContextBase::getBooleanArrayParameter(GLenum pname)
4284 { 4211 {
4285 if (pname != GL_COLOR_WRITEMASK) { 4212 if (pname != GL_COLOR_WRITEMASK) {
4286 notImplemented(); 4213 notImplemented();
4287 return WebGLGetInfo(0, 0); 4214 return WebGLGetInfo(0, 0);
4288 } 4215 }
4289 GLboolean value[4] = {0}; 4216 GLboolean value[4] = {0};
4290 if (!isContextLost()) 4217 if (!isContextLost())
4291 m_context->getBooleanv(pname, value); 4218 m_context->getBooleanv(pname, value);
4292 bool boolValue[4]; 4219 bool boolValue[4];
4293 for (int ii = 0; ii < 4; ++ii) 4220 for (int ii = 0; ii < 4; ++ii)
4294 boolValue[ii] = static_cast<bool>(value[ii]); 4221 boolValue[ii] = static_cast<bool>(value[ii]);
4295 return WebGLGetInfo(boolValue, 4); 4222 return WebGLGetInfo(boolValue, 4);
4296 } 4223 }
4297 4224
4298 WebGLGetInfo WebGLRenderingContext::getFloatParameter(GLenum pname) 4225 WebGLGetInfo WebGLRenderingContextBase::getFloatParameter(GLenum pname)
4299 { 4226 {
4300 GLfloat value = 0; 4227 GLfloat value = 0;
4301 if (!isContextLost()) 4228 if (!isContextLost())
4302 m_context->getFloatv(pname, &value); 4229 m_context->getFloatv(pname, &value);
4303 return WebGLGetInfo(value); 4230 return WebGLGetInfo(value);
4304 } 4231 }
4305 4232
4306 WebGLGetInfo WebGLRenderingContext::getIntParameter(GLenum pname) 4233 WebGLGetInfo WebGLRenderingContextBase::getIntParameter(GLenum pname)
4307 { 4234 {
4308 GLint value = 0; 4235 GLint value = 0;
4309 if (!isContextLost()) 4236 if (!isContextLost())
4310 m_context->getIntegerv(pname, &value); 4237 m_context->getIntegerv(pname, &value);
4311 return WebGLGetInfo(value); 4238 return WebGLGetInfo(value);
4312 } 4239 }
4313 4240
4314 WebGLGetInfo WebGLRenderingContext::getUnsignedIntParameter(GLenum pname) 4241 WebGLGetInfo WebGLRenderingContextBase::getUnsignedIntParameter(GLenum pname)
4315 { 4242 {
4316 GLint value = 0; 4243 GLint value = 0;
4317 if (!isContextLost()) 4244 if (!isContextLost())
4318 m_context->getIntegerv(pname, &value); 4245 m_context->getIntegerv(pname, &value);
4319 return WebGLGetInfo(static_cast<unsigned>(value)); 4246 return WebGLGetInfo(static_cast<unsigned>(value));
4320 } 4247 }
4321 4248
4322 WebGLGetInfo WebGLRenderingContext::getWebGLFloatArrayParameter(GLenum pname) 4249 WebGLGetInfo WebGLRenderingContextBase::getWebGLFloatArrayParameter(GLenum pname )
4323 { 4250 {
4324 GLfloat value[4] = {0}; 4251 GLfloat value[4] = {0};
4325 if (!isContextLost()) 4252 if (!isContextLost())
4326 m_context->getFloatv(pname, value); 4253 m_context->getFloatv(pname, value);
4327 unsigned length = 0; 4254 unsigned length = 0;
4328 switch (pname) { 4255 switch (pname) {
4329 case GL_ALIASED_POINT_SIZE_RANGE: 4256 case GL_ALIASED_POINT_SIZE_RANGE:
4330 case GL_ALIASED_LINE_WIDTH_RANGE: 4257 case GL_ALIASED_LINE_WIDTH_RANGE:
4331 case GL_DEPTH_RANGE: 4258 case GL_DEPTH_RANGE:
4332 length = 2; 4259 length = 2;
4333 break; 4260 break;
4334 case GL_BLEND_COLOR: 4261 case GL_BLEND_COLOR:
4335 case GL_COLOR_CLEAR_VALUE: 4262 case GL_COLOR_CLEAR_VALUE:
4336 length = 4; 4263 length = 4;
4337 break; 4264 break;
4338 default: 4265 default:
4339 notImplemented(); 4266 notImplemented();
4340 } 4267 }
4341 return WebGLGetInfo(Float32Array::create(value, length)); 4268 return WebGLGetInfo(Float32Array::create(value, length));
4342 } 4269 }
4343 4270
4344 WebGLGetInfo WebGLRenderingContext::getWebGLIntArrayParameter(GLenum pname) 4271 WebGLGetInfo WebGLRenderingContextBase::getWebGLIntArrayParameter(GLenum pname)
4345 { 4272 {
4346 GLint value[4] = {0}; 4273 GLint value[4] = {0};
4347 if (!isContextLost()) 4274 if (!isContextLost())
4348 m_context->getIntegerv(pname, value); 4275 m_context->getIntegerv(pname, value);
4349 unsigned length = 0; 4276 unsigned length = 0;
4350 switch (pname) { 4277 switch (pname) {
4351 case GL_MAX_VIEWPORT_DIMS: 4278 case GL_MAX_VIEWPORT_DIMS:
4352 length = 2; 4279 length = 2;
4353 break; 4280 break;
4354 case GL_SCISSOR_BOX: 4281 case GL_SCISSOR_BOX:
4355 case GL_VIEWPORT: 4282 case GL_VIEWPORT:
4356 length = 4; 4283 length = 4;
4357 break; 4284 break;
4358 default: 4285 default:
4359 notImplemented(); 4286 notImplemented();
4360 } 4287 }
4361 return WebGLGetInfo(Int32Array::create(value, length)); 4288 return WebGLGetInfo(Int32Array::create(value, length));
4362 } 4289 }
4363 4290
4364 void WebGLRenderingContext::handleTextureCompleteness(const char* functionName, bool prepareToDraw) 4291 void WebGLRenderingContextBase::handleTextureCompleteness(const char* functionNa me, bool prepareToDraw)
4365 { 4292 {
4366 // All calling functions check isContextLost, so a duplicate check is not ne eded here. 4293 // All calling functions check isContextLost, so a duplicate check is not ne eded here.
4367 bool resetActiveUnit = false; 4294 bool resetActiveUnit = false;
4368 WebGLTexture::TextureExtensionFlag flag = static_cast<WebGLTexture::TextureE xtensionFlag>((m_oesTextureFloatLinear ? WebGLTexture::TextureFloatLinearExtensi onEnabled : 0) 4295 WebGLTexture::TextureExtensionFlag flag = static_cast<WebGLTexture::TextureE xtensionFlag>((extensionEnabled(OESTextureFloatLinearName) ? WebGLTexture::Textu reFloatLinearExtensionEnabled : 0)
4369 | (m_oesTextureHalfFloatLinear ? WebGLTexture::TextureHalfFloatLinearExt ensionEnabled : 0)); 4296 | (extensionEnabled(OESTextureHalfFloatLinearName) ? WebGLTexture::Textu reHalfFloatLinearExtensionEnabled : 0));
4370 for (unsigned ii = 0; ii < m_onePlusMaxNonDefaultTextureUnit; ++ii) { 4297 for (unsigned ii = 0; ii < m_onePlusMaxNonDefaultTextureUnit; ++ii) {
4371 if ((m_textureUnits[ii].m_texture2DBinding.get() && m_textureUnits[ii].m _texture2DBinding->needToUseBlackTexture(flag)) 4298 if ((m_textureUnits[ii].m_texture2DBinding.get() && m_textureUnits[ii].m _texture2DBinding->needToUseBlackTexture(flag))
4372 || (m_textureUnits[ii].m_textureCubeMapBinding.get() && m_textureUni ts[ii].m_textureCubeMapBinding->needToUseBlackTexture(flag))) { 4299 || (m_textureUnits[ii].m_textureCubeMapBinding.get() && m_textureUni ts[ii].m_textureCubeMapBinding->needToUseBlackTexture(flag))) {
4373 if (ii != m_activeTextureUnit) { 4300 if (ii != m_activeTextureUnit) {
4374 m_context->activeTexture(ii); 4301 m_context->activeTexture(ii);
4375 resetActiveUnit = true; 4302 resetActiveUnit = true;
4376 } else if (resetActiveUnit) { 4303 } else if (resetActiveUnit) {
4377 m_context->activeTexture(ii); 4304 m_context->activeTexture(ii);
4378 resetActiveUnit = false; 4305 resetActiveUnit = false;
4379 } 4306 }
(...skipping 13 matching lines...) Expand all
4393 if (m_textureUnits[ii].m_texture2DBinding && m_textureUnits[ii].m_te xture2DBinding->needToUseBlackTexture(flag)) 4320 if (m_textureUnits[ii].m_texture2DBinding && m_textureUnits[ii].m_te xture2DBinding->needToUseBlackTexture(flag))
4394 m_context->bindTexture(GL_TEXTURE_2D, objectOrZero(tex2D)); 4321 m_context->bindTexture(GL_TEXTURE_2D, objectOrZero(tex2D));
4395 if (m_textureUnits[ii].m_textureCubeMapBinding && m_textureUnits[ii] .m_textureCubeMapBinding->needToUseBlackTexture(flag)) 4322 if (m_textureUnits[ii].m_textureCubeMapBinding && m_textureUnits[ii] .m_textureCubeMapBinding->needToUseBlackTexture(flag))
4396 m_context->bindTexture(GL_TEXTURE_CUBE_MAP, objectOrZero(texCube Map)); 4323 m_context->bindTexture(GL_TEXTURE_CUBE_MAP, objectOrZero(texCube Map));
4397 } 4324 }
4398 } 4325 }
4399 if (resetActiveUnit) 4326 if (resetActiveUnit)
4400 m_context->activeTexture(m_activeTextureUnit); 4327 m_context->activeTexture(m_activeTextureUnit);
4401 } 4328 }
4402 4329
4403 void WebGLRenderingContext::createFallbackBlackTextures1x1() 4330 void WebGLRenderingContextBase::createFallbackBlackTextures1x1()
4404 { 4331 {
4405 // All calling functions check isContextLost, so a duplicate check is not ne eded here. 4332 // All calling functions check isContextLost, so a duplicate check is not ne eded here.
4406 unsigned char black[] = {0, 0, 0, 255}; 4333 unsigned char black[] = {0, 0, 0, 255};
4407 m_blackTexture2D = createTexture(); 4334 m_blackTexture2D = createTexture();
4408 m_context->bindTexture(GL_TEXTURE_2D, m_blackTexture2D->object()); 4335 m_context->bindTexture(GL_TEXTURE_2D, m_blackTexture2D->object());
4409 m_context->texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 4336 m_context->texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1,
4410 0, GL_RGBA, GL_UNSIGNED_BYTE, black); 4337 0, GL_RGBA, GL_UNSIGNED_BYTE, black);
4411 m_context->bindTexture(GL_TEXTURE_2D, 0); 4338 m_context->bindTexture(GL_TEXTURE_2D, 0);
4412 m_blackTextureCubeMap = createTexture(); 4339 m_blackTextureCubeMap = createTexture();
4413 m_context->bindTexture(GL_TEXTURE_CUBE_MAP, m_blackTextureCubeMap->object()) ; 4340 m_context->bindTexture(GL_TEXTURE_CUBE_MAP, m_blackTextureCubeMap->object()) ;
4414 m_context->texImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 1, 1, 4341 m_context->texImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 1, 1,
4415 0, GL_RGBA, GL_UNSIGNED_BYTE, black); 4342 0, GL_RGBA, GL_UNSIGNED_BYTE, black);
4416 m_context->texImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 1, 1, 4343 m_context->texImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 1, 1,
4417 0, GL_RGBA, GL_UNSIGNED_BYTE, black); 4344 0, GL_RGBA, GL_UNSIGNED_BYTE, black);
4418 m_context->texImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 1, 1, 4345 m_context->texImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 1, 1,
4419 0, GL_RGBA, GL_UNSIGNED_BYTE, black); 4346 0, GL_RGBA, GL_UNSIGNED_BYTE, black);
4420 m_context->texImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 1, 1, 4347 m_context->texImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 1, 1,
4421 0, GL_RGBA, GL_UNSIGNED_BYTE, black); 4348 0, GL_RGBA, GL_UNSIGNED_BYTE, black);
4422 m_context->texImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 1, 1, 4349 m_context->texImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 1, 1,
4423 0, GL_RGBA, GL_UNSIGNED_BYTE, black); 4350 0, GL_RGBA, GL_UNSIGNED_BYTE, black);
4424 m_context->texImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 1, 1, 4351 m_context->texImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 1, 1,
4425 0, GL_RGBA, GL_UNSIGNED_BYTE, black); 4352 0, GL_RGBA, GL_UNSIGNED_BYTE, black);
4426 m_context->bindTexture(GL_TEXTURE_CUBE_MAP, 0); 4353 m_context->bindTexture(GL_TEXTURE_CUBE_MAP, 0);
4427 } 4354 }
4428 4355
4429 bool WebGLRenderingContext::isTexInternalFormatColorBufferCombinationValid(GLenu m texInternalFormat, GLenum colorBufferFormat) 4356 bool WebGLRenderingContextBase::isTexInternalFormatColorBufferCombinationValid(G Lenum texInternalFormat, GLenum colorBufferFormat)
4430 { 4357 {
4431 unsigned need = WebGLImageConversion::getChannelBitsByFormat(texInternalForm at); 4358 unsigned need = WebGLImageConversion::getChannelBitsByFormat(texInternalForm at);
4432 unsigned have = WebGLImageConversion::getChannelBitsByFormat(colorBufferForm at); 4359 unsigned have = WebGLImageConversion::getChannelBitsByFormat(colorBufferForm at);
4433 return (need & have) == need; 4360 return (need & have) == need;
4434 } 4361 }
4435 4362
4436 GLenum WebGLRenderingContext::boundFramebufferColorFormat() 4363 GLenum WebGLRenderingContextBase::boundFramebufferColorFormat()
4437 { 4364 {
4438 if (m_framebufferBinding && m_framebufferBinding->object()) 4365 if (m_framebufferBinding && m_framebufferBinding->object())
4439 return m_framebufferBinding->colorBufferFormat(); 4366 return m_framebufferBinding->colorBufferFormat();
4440 if (m_requestedAttributes->alpha()) 4367 if (m_requestedAttributes->alpha())
4441 return GL_RGBA; 4368 return GL_RGBA;
4442 return GL_RGB; 4369 return GL_RGB;
4443 } 4370 }
4444 4371
4445 int WebGLRenderingContext::boundFramebufferWidth() 4372 int WebGLRenderingContextBase::boundFramebufferWidth()
4446 { 4373 {
4447 if (m_framebufferBinding && m_framebufferBinding->object()) 4374 if (m_framebufferBinding && m_framebufferBinding->object())
4448 return m_framebufferBinding->colorBufferWidth(); 4375 return m_framebufferBinding->colorBufferWidth();
4449 return m_drawingBuffer->size().width(); 4376 return m_drawingBuffer->size().width();
4450 } 4377 }
4451 4378
4452 int WebGLRenderingContext::boundFramebufferHeight() 4379 int WebGLRenderingContextBase::boundFramebufferHeight()
4453 { 4380 {
4454 if (m_framebufferBinding && m_framebufferBinding->object()) 4381 if (m_framebufferBinding && m_framebufferBinding->object())
4455 return m_framebufferBinding->colorBufferHeight(); 4382 return m_framebufferBinding->colorBufferHeight();
4456 return m_drawingBuffer->size().height(); 4383 return m_drawingBuffer->size().height();
4457 } 4384 }
4458 4385
4459 WebGLTexture* WebGLRenderingContext::validateTextureBinding(const char* function Name, GLenum target, bool useSixEnumsForCubeMap) 4386 WebGLTexture* WebGLRenderingContextBase::validateTextureBinding(const char* func tionName, GLenum target, bool useSixEnumsForCubeMap)
4460 { 4387 {
4461 WebGLTexture* tex = 0; 4388 WebGLTexture* tex = 0;
4462 switch (target) { 4389 switch (target) {
4463 case GL_TEXTURE_2D: 4390 case GL_TEXTURE_2D:
4464 tex = m_textureUnits[m_activeTextureUnit].m_texture2DBinding.get(); 4391 tex = m_textureUnits[m_activeTextureUnit].m_texture2DBinding.get();
4465 break; 4392 break;
4466 case GL_TEXTURE_CUBE_MAP_POSITIVE_X: 4393 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
4467 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: 4394 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
4468 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: 4395 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
4469 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: 4396 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
(...skipping 14 matching lines...) Expand all
4484 break; 4411 break;
4485 default: 4412 default:
4486 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid texture target "); 4413 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid texture target ");
4487 return 0; 4414 return 0;
4488 } 4415 }
4489 if (!tex) 4416 if (!tex)
4490 synthesizeGLError(GL_INVALID_OPERATION, functionName, "no texture"); 4417 synthesizeGLError(GL_INVALID_OPERATION, functionName, "no texture");
4491 return tex; 4418 return tex;
4492 } 4419 }
4493 4420
4494 bool WebGLRenderingContext::validateLocationLength(const char* functionName, con st String& string) 4421 bool WebGLRenderingContextBase::validateLocationLength(const char* functionName, const String& string)
4495 { 4422 {
4496 const unsigned maxWebGLLocationLength = 256; 4423 const unsigned maxWebGLLocationLength = 256;
4497 if (string.length() > maxWebGLLocationLength) { 4424 if (string.length() > maxWebGLLocationLength) {
4498 synthesizeGLError(GL_INVALID_VALUE, functionName, "location length > 256 "); 4425 synthesizeGLError(GL_INVALID_VALUE, functionName, "location length > 256 ");
4499 return false; 4426 return false;
4500 } 4427 }
4501 return true; 4428 return true;
4502 } 4429 }
4503 4430
4504 bool WebGLRenderingContext::validateSize(const char* functionName, GLint x, GLin t y) 4431 bool WebGLRenderingContextBase::validateSize(const char* functionName, GLint x, GLint y)
4505 { 4432 {
4506 if (x < 0 || y < 0) { 4433 if (x < 0 || y < 0) {
4507 synthesizeGLError(GL_INVALID_VALUE, functionName, "size < 0"); 4434 synthesizeGLError(GL_INVALID_VALUE, functionName, "size < 0");
4508 return false; 4435 return false;
4509 } 4436 }
4510 return true; 4437 return true;
4511 } 4438 }
4512 4439
4513 bool WebGLRenderingContext::validateString(const char* functionName, const Strin g& string) 4440 bool WebGLRenderingContextBase::validateString(const char* functionName, const S tring& string)
4514 { 4441 {
4515 for (size_t i = 0; i < string.length(); ++i) { 4442 for (size_t i = 0; i < string.length(); ++i) {
4516 if (!validateCharacter(string[i])) { 4443 if (!validateCharacter(string[i])) {
4517 synthesizeGLError(GL_INVALID_VALUE, functionName, "string not ASCII" ); 4444 synthesizeGLError(GL_INVALID_VALUE, functionName, "string not ASCII" );
4518 return false; 4445 return false;
4519 } 4446 }
4520 } 4447 }
4521 return true; 4448 return true;
4522 } 4449 }
4523 4450
4524 bool WebGLRenderingContext::validateTexFuncFormatAndType(const char* functionNam e, GLenum format, GLenum type, GLint level) 4451 bool WebGLRenderingContextBase::validateTexFuncFormatAndType(const char* functio nName, GLenum format, GLenum type, GLint level)
4525 { 4452 {
4526 switch (format) { 4453 switch (format) {
4527 case GL_ALPHA: 4454 case GL_ALPHA:
4528 case GL_LUMINANCE: 4455 case GL_LUMINANCE:
4529 case GL_LUMINANCE_ALPHA: 4456 case GL_LUMINANCE_ALPHA:
4530 case GL_RGB: 4457 case GL_RGB:
4531 case GL_RGBA: 4458 case GL_RGBA:
4532 break; 4459 break;
4533 case GL_DEPTH_STENCIL_OES: 4460 case GL_DEPTH_STENCIL_OES:
4534 case GL_DEPTH_COMPONENT: 4461 case GL_DEPTH_COMPONENT:
4535 if (m_webglDepthTexture) 4462 if (extensionEnabled(WebGLDepthTextureName))
4536 break; 4463 break;
4537 synthesizeGLError(GL_INVALID_ENUM, functionName, "depth texture formats not enabled"); 4464 synthesizeGLError(GL_INVALID_ENUM, functionName, "depth texture formats not enabled");
4538 return false; 4465 return false;
4539 default: 4466 default:
4540 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid texture format "); 4467 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid texture format ");
4541 return false; 4468 return false;
4542 } 4469 }
4543 4470
4544 switch (type) { 4471 switch (type) {
4545 case GL_UNSIGNED_BYTE: 4472 case GL_UNSIGNED_BYTE:
4546 case GL_UNSIGNED_SHORT_5_6_5: 4473 case GL_UNSIGNED_SHORT_5_6_5:
4547 case GL_UNSIGNED_SHORT_4_4_4_4: 4474 case GL_UNSIGNED_SHORT_4_4_4_4:
4548 case GL_UNSIGNED_SHORT_5_5_5_1: 4475 case GL_UNSIGNED_SHORT_5_5_5_1:
4549 break; 4476 break;
4550 case GL_FLOAT: 4477 case GL_FLOAT:
4551 if (m_oesTextureFloat) 4478 if (extensionEnabled(OESTextureFloatName))
4552 break; 4479 break;
4553 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid texture type") ; 4480 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid texture type") ;
4554 return false; 4481 return false;
4555 case GL_HALF_FLOAT_OES: 4482 case GL_HALF_FLOAT_OES:
4556 if (m_oesTextureHalfFloat) 4483 if (extensionEnabled(OESTextureHalfFloatName))
4557 break; 4484 break;
4558 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid texture type") ; 4485 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid texture type") ;
4559 return false; 4486 return false;
4560 case GL_UNSIGNED_INT: 4487 case GL_UNSIGNED_INT:
4561 case GL_UNSIGNED_INT_24_8_OES: 4488 case GL_UNSIGNED_INT_24_8_OES:
4562 case GL_UNSIGNED_SHORT: 4489 case GL_UNSIGNED_SHORT:
4563 if (m_webglDepthTexture) 4490 if (extensionEnabled(WebGLDepthTextureName))
4564 break; 4491 break;
4565 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid texture type") ; 4492 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid texture type") ;
4566 return false; 4493 return false;
4567 default: 4494 default:
4568 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid texture type") ; 4495 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid texture type") ;
4569 return false; 4496 return false;
4570 } 4497 }
4571 4498
4572 // Verify that the combination of format and type is supported. 4499 // Verify that the combination of format and type is supported.
4573 switch (format) { 4500 switch (format) {
(...skipping 20 matching lines...) Expand all
4594 if (type != GL_UNSIGNED_BYTE 4521 if (type != GL_UNSIGNED_BYTE
4595 && type != GL_UNSIGNED_SHORT_4_4_4_4 4522 && type != GL_UNSIGNED_SHORT_4_4_4_4
4596 && type != GL_UNSIGNED_SHORT_5_5_5_1 4523 && type != GL_UNSIGNED_SHORT_5_5_5_1
4597 && type != GL_FLOAT 4524 && type != GL_FLOAT
4598 && type != GL_HALF_FLOAT_OES) { 4525 && type != GL_HALF_FLOAT_OES) {
4599 synthesizeGLError(GL_INVALID_OPERATION, functionName, "invalid type for RGBA format"); 4526 synthesizeGLError(GL_INVALID_OPERATION, functionName, "invalid type for RGBA format");
4600 return false; 4527 return false;
4601 } 4528 }
4602 break; 4529 break;
4603 case GL_DEPTH_COMPONENT: 4530 case GL_DEPTH_COMPONENT:
4604 if (!m_webglDepthTexture) { 4531 if (!extensionEnabled(WebGLDepthTextureName)) {
4605 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid format. DE PTH_COMPONENT not enabled"); 4532 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid format. DE PTH_COMPONENT not enabled");
4606 return false; 4533 return false;
4607 } 4534 }
4608 if (type != GL_UNSIGNED_SHORT 4535 if (type != GL_UNSIGNED_SHORT
4609 && type != GL_UNSIGNED_INT) { 4536 && type != GL_UNSIGNED_INT) {
4610 synthesizeGLError(GL_INVALID_OPERATION, functionName, "invalid type for DEPTH_COMPONENT format"); 4537 synthesizeGLError(GL_INVALID_OPERATION, functionName, "invalid type for DEPTH_COMPONENT format");
4611 return false; 4538 return false;
4612 } 4539 }
4613 if (level > 0) { 4540 if (level > 0) {
4614 synthesizeGLError(GL_INVALID_OPERATION, functionName, "level must be 0 for DEPTH_COMPONENT format"); 4541 synthesizeGLError(GL_INVALID_OPERATION, functionName, "level must be 0 for DEPTH_COMPONENT format");
4615 return false; 4542 return false;
4616 } 4543 }
4617 break; 4544 break;
4618 case GL_DEPTH_STENCIL_OES: 4545 case GL_DEPTH_STENCIL_OES:
4619 if (!m_webglDepthTexture) { 4546 if (!extensionEnabled(WebGLDepthTextureName)) {
4620 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid format. DE PTH_STENCIL not enabled"); 4547 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid format. DE PTH_STENCIL not enabled");
4621 return false; 4548 return false;
4622 } 4549 }
4623 if (type != GL_UNSIGNED_INT_24_8_OES) { 4550 if (type != GL_UNSIGNED_INT_24_8_OES) {
4624 synthesizeGLError(GL_INVALID_OPERATION, functionName, "invalid type for DEPTH_STENCIL format"); 4551 synthesizeGLError(GL_INVALID_OPERATION, functionName, "invalid type for DEPTH_STENCIL format");
4625 return false; 4552 return false;
4626 } 4553 }
4627 if (level > 0) { 4554 if (level > 0) {
4628 synthesizeGLError(GL_INVALID_OPERATION, functionName, "level must be 0 for DEPTH_STENCIL format"); 4555 synthesizeGLError(GL_INVALID_OPERATION, functionName, "level must be 0 for DEPTH_STENCIL format");
4629 return false; 4556 return false;
4630 } 4557 }
4631 break; 4558 break;
4632 default: 4559 default:
4633 ASSERT_NOT_REACHED(); 4560 ASSERT_NOT_REACHED();
4634 } 4561 }
4635 4562
4636 return true; 4563 return true;
4637 } 4564 }
4638 4565
4639 bool WebGLRenderingContext::validateTexFuncLevel(const char* functionName, GLenu m target, GLint level) 4566 bool WebGLRenderingContextBase::validateTexFuncLevel(const char* functionName, G Lenum target, GLint level)
4640 { 4567 {
4641 if (level < 0) { 4568 if (level < 0) {
4642 synthesizeGLError(GL_INVALID_VALUE, functionName, "level < 0"); 4569 synthesizeGLError(GL_INVALID_VALUE, functionName, "level < 0");
4643 return false; 4570 return false;
4644 } 4571 }
4645 switch (target) { 4572 switch (target) {
4646 case GL_TEXTURE_2D: 4573 case GL_TEXTURE_2D:
4647 if (level >= m_maxTextureLevel) { 4574 if (level >= m_maxTextureLevel) {
4648 synthesizeGLError(GL_INVALID_VALUE, functionName, "level out of rang e"); 4575 synthesizeGLError(GL_INVALID_VALUE, functionName, "level out of rang e");
4649 return false; 4576 return false;
4650 } 4577 }
4651 break; 4578 break;
4652 case GL_TEXTURE_CUBE_MAP_POSITIVE_X: 4579 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
4653 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: 4580 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
4654 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: 4581 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
4655 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: 4582 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
4656 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: 4583 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
4657 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: 4584 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
4658 if (level >= m_maxCubeMapTextureLevel) { 4585 if (level >= m_maxCubeMapTextureLevel) {
4659 synthesizeGLError(GL_INVALID_VALUE, functionName, "level out of rang e"); 4586 synthesizeGLError(GL_INVALID_VALUE, functionName, "level out of rang e");
4660 return false; 4587 return false;
4661 } 4588 }
4662 break; 4589 break;
4663 } 4590 }
4664 // This function only checks if level is legal, so we return true and don't 4591 // This function only checks if level is legal, so we return true and don't
4665 // generate INVALID_ENUM if target is illegal. 4592 // generate INVALID_ENUM if target is illegal.
4666 return true; 4593 return true;
4667 } 4594 }
4668 4595
4669 bool WebGLRenderingContext::validateTexFuncDimensions(const char* functionName, TexFuncValidationFunctionType functionType, 4596 bool WebGLRenderingContextBase::validateTexFuncDimensions(const char* functionNa me, TexFuncValidationFunctionType functionType,
4670 GLenum target, GLint level, GLsizei width, GLsizei height) 4597 GLenum target, GLint level, GLsizei width, GLsizei height)
4671 { 4598 {
4672 if (width < 0 || height < 0) { 4599 if (width < 0 || height < 0) {
4673 synthesizeGLError(GL_INVALID_VALUE, functionName, "width or height < 0") ; 4600 synthesizeGLError(GL_INVALID_VALUE, functionName, "width or height < 0") ;
4674 return false; 4601 return false;
4675 } 4602 }
4676 4603
4677 switch (target) { 4604 switch (target) {
4678 case GL_TEXTURE_2D: 4605 case GL_TEXTURE_2D:
4679 if (width > (m_maxTextureSize >> level) || height > (m_maxTextureSize >> level)) { 4606 if (width > (m_maxTextureSize >> level) || height > (m_maxTextureSize >> level)) {
(...skipping 18 matching lines...) Expand all
4698 return false; 4625 return false;
4699 } 4626 }
4700 break; 4627 break;
4701 default: 4628 default:
4702 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid target"); 4629 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid target");
4703 return false; 4630 return false;
4704 } 4631 }
4705 return true; 4632 return true;
4706 } 4633 }
4707 4634
4708 bool WebGLRenderingContext::validateTexFuncParameters(const char* functionName, TexFuncValidationFunctionType functionType, GLenum target, 4635 bool WebGLRenderingContextBase::validateTexFuncParameters(const char* functionNa me, TexFuncValidationFunctionType functionType, GLenum target,
4709 GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint bor der, GLenum format, GLenum type) 4636 GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint bor der, GLenum format, GLenum type)
4710 { 4637 {
4711 // We absolutely have to validate the format and type combination. 4638 // We absolutely have to validate the format and type combination.
4712 // The texImage2D entry points taking HTMLImage, etc. will produce 4639 // The texImage2D entry points taking HTMLImage, etc. will produce
4713 // temporary data based on this combination, so it must be legal. 4640 // temporary data based on this combination, so it must be legal.
4714 if (!validateTexFuncFormatAndType(functionName, format, type, level) || !val idateTexFuncLevel(functionName, target, level)) 4641 if (!validateTexFuncFormatAndType(functionName, format, type, level) || !val idateTexFuncLevel(functionName, target, level))
4715 return false; 4642 return false;
4716 4643
4717 if (!validateTexFuncDimensions(functionName, functionType, target, level, wi dth, height)) 4644 if (!validateTexFuncDimensions(functionName, functionType, target, level, wi dth, height))
4718 return false; 4645 return false;
4719 4646
4720 if (format != internalformat) { 4647 if (format != internalformat) {
4721 synthesizeGLError(GL_INVALID_OPERATION, functionName, "format != interna lformat"); 4648 synthesizeGLError(GL_INVALID_OPERATION, functionName, "format != interna lformat");
4722 return false; 4649 return false;
4723 } 4650 }
4724 4651
4725 if (border) { 4652 if (border) {
4726 synthesizeGLError(GL_INVALID_VALUE, functionName, "border != 0"); 4653 synthesizeGLError(GL_INVALID_VALUE, functionName, "border != 0");
4727 return false; 4654 return false;
4728 } 4655 }
4729 4656
4730 return true; 4657 return true;
4731 } 4658 }
4732 4659
4733 bool WebGLRenderingContext::validateTexFuncData(const char* functionName, GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, ArrayBufferVie w* pixels, NullDisposition disposition) 4660 bool WebGLRenderingContextBase::validateTexFuncData(const char* functionName, GL int level, GLsizei width, GLsizei height, GLenum format, GLenum type, ArrayBuffe rView* pixels, NullDisposition disposition)
4734 { 4661 {
4735 // All calling functions check isContextLost, so a duplicate check is not ne eded here. 4662 // All calling functions check isContextLost, so a duplicate check is not ne eded here.
4736 if (!pixels) { 4663 if (!pixels) {
4737 if (disposition == NullAllowed) 4664 if (disposition == NullAllowed)
4738 return true; 4665 return true;
4739 synthesizeGLError(GL_INVALID_VALUE, functionName, "no pixels"); 4666 synthesizeGLError(GL_INVALID_VALUE, functionName, "no pixels");
4740 return false; 4667 return false;
4741 } 4668 }
4742 4669
4743 if (!validateTexFuncFormatAndType(functionName, format, type, level)) 4670 if (!validateTexFuncFormatAndType(functionName, format, type, level))
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
4791 synthesizeGLError(GL_INVALID_OPERATION, functionName, "ArrayBuff erView not big enough for request with UNPACK_ALIGNMENT > 1"); 4718 synthesizeGLError(GL_INVALID_OPERATION, functionName, "ArrayBuff erView not big enough for request with UNPACK_ALIGNMENT > 1");
4792 return false; 4719 return false;
4793 } 4720 }
4794 } 4721 }
4795 synthesizeGLError(GL_INVALID_OPERATION, functionName, "ArrayBufferView n ot big enough for request"); 4722 synthesizeGLError(GL_INVALID_OPERATION, functionName, "ArrayBufferView n ot big enough for request");
4796 return false; 4723 return false;
4797 } 4724 }
4798 return true; 4725 return true;
4799 } 4726 }
4800 4727
4801 bool WebGLRenderingContext::validateCompressedTexFormat(GLenum format) 4728 bool WebGLRenderingContextBase::validateCompressedTexFormat(GLenum format)
4802 { 4729 {
4803 return m_compressedTextureFormats.contains(format); 4730 return m_compressedTextureFormats.contains(format);
4804 } 4731 }
4805 4732
4806 bool WebGLRenderingContext::validateCompressedTexFuncData(const char* functionNa me, GLsizei width, GLsizei height, GLenum format, ArrayBufferView* pixels) 4733 bool WebGLRenderingContextBase::validateCompressedTexFuncData(const char* functi onName, GLsizei width, GLsizei height, GLenum format, ArrayBufferView* pixels)
4807 { 4734 {
4808 if (!pixels) { 4735 if (!pixels) {
4809 synthesizeGLError(GL_INVALID_VALUE, functionName, "no pixels"); 4736 synthesizeGLError(GL_INVALID_VALUE, functionName, "no pixels");
4810 return false; 4737 return false;
4811 } 4738 }
4812 if (width < 0 || height < 0) { 4739 if (width < 0 || height < 0) {
4813 synthesizeGLError(GL_INVALID_VALUE, functionName, "width or height < 0") ; 4740 synthesizeGLError(GL_INVALID_VALUE, functionName, "width or height < 0") ;
4814 return false; 4741 return false;
4815 } 4742 }
4816 4743
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
4870 } 4797 }
4871 4798
4872 if (pixels->byteLength() != bytesRequired) { 4799 if (pixels->byteLength() != bytesRequired) {
4873 synthesizeGLError(GL_INVALID_VALUE, functionName, "length of ArrayBuffer View is not correct for dimensions"); 4800 synthesizeGLError(GL_INVALID_VALUE, functionName, "length of ArrayBuffer View is not correct for dimensions");
4874 return false; 4801 return false;
4875 } 4802 }
4876 4803
4877 return true; 4804 return true;
4878 } 4805 }
4879 4806
4880 bool WebGLRenderingContext::validateCompressedTexDimensions(const char* function Name, TexFuncValidationFunctionType functionType, GLenum target, GLint level, GL sizei width, GLsizei height, GLenum format) 4807 bool WebGLRenderingContextBase::validateCompressedTexDimensions(const char* func tionName, TexFuncValidationFunctionType functionType, GLenum target, GLint level , GLsizei width, GLsizei height, GLenum format)
4881 { 4808 {
4882 if (!validateTexFuncDimensions(functionName, functionType, target, level, wi dth, height)) 4809 if (!validateTexFuncDimensions(functionName, functionType, target, level, wi dth, height))
4883 return false; 4810 return false;
4884 4811
4885 switch (format) { 4812 switch (format) {
4886 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: 4813 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
4887 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: 4814 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
4888 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: 4815 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
4889 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: { 4816 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: {
4890 const int kBlockWidth = 4; 4817 const int kBlockWidth = 4;
4891 const int kBlockHeight = 4; 4818 const int kBlockHeight = 4;
4892 bool widthValid = (level && width == 1) || (level && width == 2) || !(wi dth % kBlockWidth); 4819 bool widthValid = (level && width == 1) || (level && width == 2) || !(wi dth % kBlockWidth);
4893 bool heightValid = (level && height == 1) || (level && height == 2) || ! (height % kBlockHeight); 4820 bool heightValid = (level && height == 1) || (level && height == 2) || ! (height % kBlockHeight);
4894 if (!widthValid || !heightValid) { 4821 if (!widthValid || !heightValid) {
4895 synthesizeGLError(GL_INVALID_OPERATION, functionName, "width or heig ht invalid for level"); 4822 synthesizeGLError(GL_INVALID_OPERATION, functionName, "width or heig ht invalid for level");
4896 return false; 4823 return false;
4897 } 4824 }
4898 return true; 4825 return true;
4899 } 4826 }
4900 default: 4827 default:
4901 return false; 4828 return false;
4902 } 4829 }
4903 } 4830 }
4904 4831
4905 bool WebGLRenderingContext::validateCompressedTexSubDimensions(const char* funct ionName, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width , GLsizei height, GLenum format, WebGLTexture* tex) 4832 bool WebGLRenderingContextBase::validateCompressedTexSubDimensions(const char* f unctionName, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei w idth, GLsizei height, GLenum format, WebGLTexture* tex)
4906 { 4833 {
4907 if (xoffset < 0 || yoffset < 0) { 4834 if (xoffset < 0 || yoffset < 0) {
4908 synthesizeGLError(GL_INVALID_VALUE, functionName, "xoffset or yoffset < 0"); 4835 synthesizeGLError(GL_INVALID_VALUE, functionName, "xoffset or yoffset < 0");
4909 return false; 4836 return false;
4910 } 4837 }
4911 4838
4912 switch (format) { 4839 switch (format) {
4913 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: 4840 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
4914 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: 4841 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
4915 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: 4842 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
4916 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: { 4843 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: {
4917 const int kBlockWidth = 4; 4844 const int kBlockWidth = 4;
4918 const int kBlockHeight = 4; 4845 const int kBlockHeight = 4;
4919 if ((xoffset % kBlockWidth) || (yoffset % kBlockHeight)) { 4846 if ((xoffset % kBlockWidth) || (yoffset % kBlockHeight)) {
4920 synthesizeGLError(GL_INVALID_OPERATION, functionName, "xoffset or yo ffset not multiple of 4"); 4847 synthesizeGLError(GL_INVALID_OPERATION, functionName, "xoffset or yo ffset not multiple of 4");
4921 return false; 4848 return false;
4922 } 4849 }
4923 if (width - xoffset > tex->getWidth(target, level) 4850 if (width - xoffset > tex->getWidth(target, level)
4924 || height - yoffset > tex->getHeight(target, level)) { 4851 || height - yoffset > tex->getHeight(target, level)) {
4925 synthesizeGLError(GL_INVALID_OPERATION, functionName, "dimensions ou t of range"); 4852 synthesizeGLError(GL_INVALID_OPERATION, functionName, "dimensions ou t of range");
4926 return false; 4853 return false;
4927 } 4854 }
4928 return validateCompressedTexDimensions(functionName, TexSubImage2D, targ et, level, width, height, format); 4855 return validateCompressedTexDimensions(functionName, TexSubImage2D, targ et, level, width, height, format);
4929 } 4856 }
4930 default: 4857 default:
4931 return false; 4858 return false;
4932 } 4859 }
4933 } 4860 }
4934 4861
4935 bool WebGLRenderingContext::validateDrawMode(const char* functionName, GLenum mo de) 4862 bool WebGLRenderingContextBase::validateDrawMode(const char* functionName, GLenu m mode)
4936 { 4863 {
4937 switch (mode) { 4864 switch (mode) {
4938 case GL_POINTS: 4865 case GL_POINTS:
4939 case GL_LINE_STRIP: 4866 case GL_LINE_STRIP:
4940 case GL_LINE_LOOP: 4867 case GL_LINE_LOOP:
4941 case GL_LINES: 4868 case GL_LINES:
4942 case GL_TRIANGLE_STRIP: 4869 case GL_TRIANGLE_STRIP:
4943 case GL_TRIANGLE_FAN: 4870 case GL_TRIANGLE_FAN:
4944 case GL_TRIANGLES: 4871 case GL_TRIANGLES:
4945 return true; 4872 return true;
4946 default: 4873 default:
4947 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid draw mode"); 4874 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid draw mode");
4948 return false; 4875 return false;
4949 } 4876 }
4950 } 4877 }
4951 4878
4952 bool WebGLRenderingContext::validateStencilSettings(const char* functionName) 4879 bool WebGLRenderingContextBase::validateStencilSettings(const char* functionName )
4953 { 4880 {
4954 if (m_stencilMask != m_stencilMaskBack || m_stencilFuncRef != m_stencilFuncR efBack || m_stencilFuncMask != m_stencilFuncMaskBack) { 4881 if (m_stencilMask != m_stencilMaskBack || m_stencilFuncRef != m_stencilFuncR efBack || m_stencilFuncMask != m_stencilFuncMaskBack) {
4955 synthesizeGLError(GL_INVALID_OPERATION, functionName, "front and back st encils settings do not match"); 4882 synthesizeGLError(GL_INVALID_OPERATION, functionName, "front and back st encils settings do not match");
4956 return false; 4883 return false;
4957 } 4884 }
4958 return true; 4885 return true;
4959 } 4886 }
4960 4887
4961 bool WebGLRenderingContext::validateStencilOrDepthFunc(const char* functionName, GLenum func) 4888 bool WebGLRenderingContextBase::validateStencilOrDepthFunc(const char* functionN ame, GLenum func)
4962 { 4889 {
4963 switch (func) { 4890 switch (func) {
4964 case GL_NEVER: 4891 case GL_NEVER:
4965 case GL_LESS: 4892 case GL_LESS:
4966 case GL_LEQUAL: 4893 case GL_LEQUAL:
4967 case GL_GREATER: 4894 case GL_GREATER:
4968 case GL_GEQUAL: 4895 case GL_GEQUAL:
4969 case GL_EQUAL: 4896 case GL_EQUAL:
4970 case GL_NOTEQUAL: 4897 case GL_NOTEQUAL:
4971 case GL_ALWAYS: 4898 case GL_ALWAYS:
4972 return true; 4899 return true;
4973 default: 4900 default:
4974 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid function"); 4901 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid function");
4975 return false; 4902 return false;
4976 } 4903 }
4977 } 4904 }
4978 4905
4979 void WebGLRenderingContext::printGLErrorToConsole(const String& message) 4906 void WebGLRenderingContextBase::printGLErrorToConsole(const String& message)
4980 { 4907 {
4981 if (!m_numGLErrorsToConsoleAllowed) 4908 if (!m_numGLErrorsToConsoleAllowed)
4982 return; 4909 return;
4983 4910
4984 --m_numGLErrorsToConsoleAllowed; 4911 --m_numGLErrorsToConsoleAllowed;
4985 printWarningToConsole(message); 4912 printWarningToConsole(message);
4986 4913
4987 if (!m_numGLErrorsToConsoleAllowed) 4914 if (!m_numGLErrorsToConsoleAllowed)
4988 printWarningToConsole("WebGL: too many errors, no more errors will be re ported to the console for this context."); 4915 printWarningToConsole("WebGL: too many errors, no more errors will be re ported to the console for this context.");
4989 4916
4990 return; 4917 return;
4991 } 4918 }
4992 4919
4993 void WebGLRenderingContext::printWarningToConsole(const String& message) 4920 void WebGLRenderingContextBase::printWarningToConsole(const String& message)
4994 { 4921 {
4995 if (!canvas()) 4922 if (!canvas())
4996 return; 4923 return;
4997 canvas()->document().addConsoleMessage(RenderingMessageSource, WarningMessag eLevel, message); 4924 canvas()->document().addConsoleMessage(RenderingMessageSource, WarningMessag eLevel, message);
4998 } 4925 }
4999 4926
5000 bool WebGLRenderingContext::validateFramebufferFuncParameters(const char* functi onName, GLenum target, GLenum attachment) 4927 bool WebGLRenderingContextBase::validateFramebufferFuncParameters(const char* fu nctionName, GLenum target, GLenum attachment)
5001 { 4928 {
5002 if (target != GL_FRAMEBUFFER) { 4929 if (target != GL_FRAMEBUFFER) {
5003 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid target"); 4930 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid target");
5004 return false; 4931 return false;
5005 } 4932 }
5006 switch (attachment) { 4933 switch (attachment) {
5007 case GL_COLOR_ATTACHMENT0: 4934 case GL_COLOR_ATTACHMENT0:
5008 case GL_DEPTH_ATTACHMENT: 4935 case GL_DEPTH_ATTACHMENT:
5009 case GL_STENCIL_ATTACHMENT: 4936 case GL_STENCIL_ATTACHMENT:
5010 case GC3D_DEPTH_STENCIL_ATTACHMENT_WEBGL: 4937 case GC3D_DEPTH_STENCIL_ATTACHMENT_WEBGL:
5011 break; 4938 break;
5012 default: 4939 default:
5013 if (m_webglDrawBuffers 4940 if (extensionEnabled(WebGLDrawBuffersName)
5014 && attachment > GL_COLOR_ATTACHMENT0 4941 && attachment > GL_COLOR_ATTACHMENT0
5015 && attachment < static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + maxColorA ttachments())) 4942 && attachment < static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + maxColorA ttachments()))
5016 break; 4943 break;
5017 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid attachment"); 4944 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid attachment");
5018 return false; 4945 return false;
5019 } 4946 }
5020 return true; 4947 return true;
5021 } 4948 }
5022 4949
5023 bool WebGLRenderingContext::validateBlendEquation(const char* functionName, GLen um mode) 4950 bool WebGLRenderingContextBase::validateBlendEquation(const char* functionName, GLenum mode)
5024 { 4951 {
5025 switch (mode) { 4952 switch (mode) {
5026 case GL_FUNC_ADD: 4953 case GL_FUNC_ADD:
5027 case GL_FUNC_SUBTRACT: 4954 case GL_FUNC_SUBTRACT:
5028 case GL_FUNC_REVERSE_SUBTRACT: 4955 case GL_FUNC_REVERSE_SUBTRACT:
5029 return true; 4956 return true;
5030 default: 4957 default:
5031 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid mode"); 4958 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid mode");
5032 return false; 4959 return false;
5033 } 4960 }
5034 } 4961 }
5035 4962
5036 bool WebGLRenderingContext::validateBlendFuncFactors(const char* functionName, G Lenum src, GLenum dst) 4963 bool WebGLRenderingContextBase::validateBlendFuncFactors(const char* functionNam e, GLenum src, GLenum dst)
5037 { 4964 {
5038 if (((src == GL_CONSTANT_COLOR || src == GL_ONE_MINUS_CONSTANT_COLOR) 4965 if (((src == GL_CONSTANT_COLOR || src == GL_ONE_MINUS_CONSTANT_COLOR)
5039 && (dst == GL_CONSTANT_ALPHA || dst == GL_ONE_MINUS_CONSTANT_ALPHA)) 4966 && (dst == GL_CONSTANT_ALPHA || dst == GL_ONE_MINUS_CONSTANT_ALPHA))
5040 || ((dst == GL_CONSTANT_COLOR || dst == GL_ONE_MINUS_CONSTANT_COLOR) 4967 || ((dst == GL_CONSTANT_COLOR || dst == GL_ONE_MINUS_CONSTANT_COLOR)
5041 && (src == GL_CONSTANT_ALPHA || src == GL_ONE_MINUS_CONSTANT_ALPHA))) { 4968 && (src == GL_CONSTANT_ALPHA || src == GL_ONE_MINUS_CONSTANT_ALPHA))) {
5042 synthesizeGLError(GL_INVALID_OPERATION, functionName, "incompatible src and dst"); 4969 synthesizeGLError(GL_INVALID_OPERATION, functionName, "incompatible src and dst");
5043 return false; 4970 return false;
5044 } 4971 }
5045 return true; 4972 return true;
5046 } 4973 }
5047 4974
5048 bool WebGLRenderingContext::validateCapability(const char* functionName, GLenum cap) 4975 bool WebGLRenderingContextBase::validateCapability(const char* functionName, GLe num cap)
5049 { 4976 {
5050 switch (cap) { 4977 switch (cap) {
5051 case GL_BLEND: 4978 case GL_BLEND:
5052 case GL_CULL_FACE: 4979 case GL_CULL_FACE:
5053 case GL_DEPTH_TEST: 4980 case GL_DEPTH_TEST:
5054 case GL_DITHER: 4981 case GL_DITHER:
5055 case GL_POLYGON_OFFSET_FILL: 4982 case GL_POLYGON_OFFSET_FILL:
5056 case GL_SAMPLE_ALPHA_TO_COVERAGE: 4983 case GL_SAMPLE_ALPHA_TO_COVERAGE:
5057 case GL_SAMPLE_COVERAGE: 4984 case GL_SAMPLE_COVERAGE:
5058 case GL_SCISSOR_TEST: 4985 case GL_SCISSOR_TEST:
5059 case GL_STENCIL_TEST: 4986 case GL_STENCIL_TEST:
5060 return true; 4987 return true;
5061 default: 4988 default:
5062 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid capability"); 4989 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid capability");
5063 return false; 4990 return false;
5064 } 4991 }
5065 } 4992 }
5066 4993
5067 bool WebGLRenderingContext::validateUniformParameters(const char* functionName, const WebGLUniformLocation* location, Float32Array* v, GLsizei requiredMinSize) 4994 bool WebGLRenderingContextBase::validateUniformParameters(const char* functionNa me, const WebGLUniformLocation* location, Float32Array* v, GLsizei requiredMinSi ze)
5068 { 4995 {
5069 if (!v) { 4996 if (!v) {
5070 synthesizeGLError(GL_INVALID_VALUE, functionName, "no array"); 4997 synthesizeGLError(GL_INVALID_VALUE, functionName, "no array");
5071 return false; 4998 return false;
5072 } 4999 }
5073 return validateUniformMatrixParameters(functionName, location, false, v->dat a(), v->length(), requiredMinSize); 5000 return validateUniformMatrixParameters(functionName, location, false, v->dat a(), v->length(), requiredMinSize);
5074 } 5001 }
5075 5002
5076 bool WebGLRenderingContext::validateUniformParameters(const char* functionName, const WebGLUniformLocation* location, Int32Array* v, GLsizei requiredMinSize) 5003 bool WebGLRenderingContextBase::validateUniformParameters(const char* functionNa me, const WebGLUniformLocation* location, Int32Array* v, GLsizei requiredMinSize )
5077 { 5004 {
5078 if (!v) { 5005 if (!v) {
5079 synthesizeGLError(GL_INVALID_VALUE, functionName, "no array"); 5006 synthesizeGLError(GL_INVALID_VALUE, functionName, "no array");
5080 return false; 5007 return false;
5081 } 5008 }
5082 return validateUniformMatrixParameters(functionName, location, false, v->dat a(), v->length(), requiredMinSize); 5009 return validateUniformMatrixParameters(functionName, location, false, v->dat a(), v->length(), requiredMinSize);
5083 } 5010 }
5084 5011
5085 bool WebGLRenderingContext::validateUniformParameters(const char* functionName, const WebGLUniformLocation* location, void* v, GLsizei size, GLsizei requiredMin Size) 5012 bool WebGLRenderingContextBase::validateUniformParameters(const char* functionNa me, const WebGLUniformLocation* location, void* v, GLsizei size, GLsizei require dMinSize)
5086 { 5013 {
5087 return validateUniformMatrixParameters(functionName, location, false, v, siz e, requiredMinSize); 5014 return validateUniformMatrixParameters(functionName, location, false, v, siz e, requiredMinSize);
5088 } 5015 }
5089 5016
5090 bool WebGLRenderingContext::validateUniformMatrixParameters(const char* function Name, const WebGLUniformLocation* location, GLboolean transpose, Float32Array* v , GLsizei requiredMinSize) 5017 bool WebGLRenderingContextBase::validateUniformMatrixParameters(const char* func tionName, const WebGLUniformLocation* location, GLboolean transpose, Float32Arra y* v, GLsizei requiredMinSize)
5091 { 5018 {
5092 if (!v) { 5019 if (!v) {
5093 synthesizeGLError(GL_INVALID_VALUE, functionName, "no array"); 5020 synthesizeGLError(GL_INVALID_VALUE, functionName, "no array");
5094 return false; 5021 return false;
5095 } 5022 }
5096 return validateUniformMatrixParameters(functionName, location, transpose, v- >data(), v->length(), requiredMinSize); 5023 return validateUniformMatrixParameters(functionName, location, transpose, v- >data(), v->length(), requiredMinSize);
5097 } 5024 }
5098 5025
5099 bool WebGLRenderingContext::validateUniformMatrixParameters(const char* function Name, const WebGLUniformLocation* location, GLboolean transpose, void* v, GLsize i size, GLsizei requiredMinSize) 5026 bool WebGLRenderingContextBase::validateUniformMatrixParameters(const char* func tionName, const WebGLUniformLocation* location, GLboolean transpose, void* v, GL sizei size, GLsizei requiredMinSize)
5100 { 5027 {
5101 if (!location) 5028 if (!location)
5102 return false; 5029 return false;
5103 if (location->program() != m_currentProgram) { 5030 if (location->program() != m_currentProgram) {
5104 synthesizeGLError(GL_INVALID_OPERATION, functionName, "location is not f rom current program"); 5031 synthesizeGLError(GL_INVALID_OPERATION, functionName, "location is not f rom current program");
5105 return false; 5032 return false;
5106 } 5033 }
5107 if (!v) { 5034 if (!v) {
5108 synthesizeGLError(GL_INVALID_VALUE, functionName, "no array"); 5035 synthesizeGLError(GL_INVALID_VALUE, functionName, "no array");
5109 return false; 5036 return false;
5110 } 5037 }
5111 if (transpose) { 5038 if (transpose) {
5112 synthesizeGLError(GL_INVALID_VALUE, functionName, "transpose not FALSE") ; 5039 synthesizeGLError(GL_INVALID_VALUE, functionName, "transpose not FALSE") ;
5113 return false; 5040 return false;
5114 } 5041 }
5115 if (size < requiredMinSize || (size % requiredMinSize)) { 5042 if (size < requiredMinSize || (size % requiredMinSize)) {
5116 synthesizeGLError(GL_INVALID_VALUE, functionName, "invalid size"); 5043 synthesizeGLError(GL_INVALID_VALUE, functionName, "invalid size");
5117 return false; 5044 return false;
5118 } 5045 }
5119 return true; 5046 return true;
5120 } 5047 }
5121 5048
5122 WebGLBuffer* WebGLRenderingContext::validateBufferDataParameters(const char* fun ctionName, GLenum target, GLenum usage) 5049 WebGLBuffer* WebGLRenderingContextBase::validateBufferDataParameters(const char* functionName, GLenum target, GLenum usage)
5123 { 5050 {
5124 WebGLBuffer* buffer = 0; 5051 WebGLBuffer* buffer = 0;
5125 switch (target) { 5052 switch (target) {
5126 case GL_ELEMENT_ARRAY_BUFFER: 5053 case GL_ELEMENT_ARRAY_BUFFER:
5127 buffer = m_boundVertexArrayObject->boundElementArrayBuffer().get(); 5054 buffer = m_boundVertexArrayObject->boundElementArrayBuffer().get();
5128 break; 5055 break;
5129 case GL_ARRAY_BUFFER: 5056 case GL_ARRAY_BUFFER:
5130 buffer = m_boundArrayBuffer.get(); 5057 buffer = m_boundArrayBuffer.get();
5131 break; 5058 break;
5132 default: 5059 default:
5133 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid target"); 5060 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid target");
5134 return 0; 5061 return 0;
5135 } 5062 }
5136 if (!buffer) { 5063 if (!buffer) {
5137 synthesizeGLError(GL_INVALID_OPERATION, functionName, "no buffer"); 5064 synthesizeGLError(GL_INVALID_OPERATION, functionName, "no buffer");
5138 return 0; 5065 return 0;
5139 } 5066 }
5140 switch (usage) { 5067 switch (usage) {
5141 case GL_STREAM_DRAW: 5068 case GL_STREAM_DRAW:
5142 case GL_STATIC_DRAW: 5069 case GL_STATIC_DRAW:
5143 case GL_DYNAMIC_DRAW: 5070 case GL_DYNAMIC_DRAW:
5144 return buffer; 5071 return buffer;
5145 } 5072 }
5146 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid usage"); 5073 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid usage");
5147 return 0; 5074 return 0;
5148 } 5075 }
5149 5076
5150 bool WebGLRenderingContext::validateHTMLImageElement(const char* functionName, H TMLImageElement* image, ExceptionState& exceptionState) 5077 bool WebGLRenderingContextBase::validateHTMLImageElement(const char* functionNam e, HTMLImageElement* image, ExceptionState& exceptionState)
5151 { 5078 {
5152 if (!image || !image->cachedImage()) { 5079 if (!image || !image->cachedImage()) {
5153 synthesizeGLError(GL_INVALID_VALUE, functionName, "no image"); 5080 synthesizeGLError(GL_INVALID_VALUE, functionName, "no image");
5154 return false; 5081 return false;
5155 } 5082 }
5156 const KURL& url = image->cachedImage()->response().url(); 5083 const KURL& url = image->cachedImage()->response().url();
5157 if (url.isNull() || url.isEmpty() || !url.isValid()) { 5084 if (url.isNull() || url.isEmpty() || !url.isValid()) {
5158 synthesizeGLError(GL_INVALID_VALUE, functionName, "invalid image"); 5085 synthesizeGLError(GL_INVALID_VALUE, functionName, "invalid image");
5159 return false; 5086 return false;
5160 } 5087 }
5161 if (wouldTaintOrigin(image)) { 5088 if (wouldTaintOrigin(image)) {
5162 exceptionState.throwSecurityError("The cross-origin image at " + url.eli dedString() + " may not be loaded."); 5089 exceptionState.throwSecurityError("The cross-origin image at " + url.eli dedString() + " may not be loaded.");
5163 return false; 5090 return false;
5164 } 5091 }
5165 return true; 5092 return true;
5166 } 5093 }
5167 5094
5168 bool WebGLRenderingContext::validateHTMLCanvasElement(const char* functionName, HTMLCanvasElement* canvas, ExceptionState& exceptionState) 5095 bool WebGLRenderingContextBase::validateHTMLCanvasElement(const char* functionNa me, HTMLCanvasElement* canvas, ExceptionState& exceptionState)
5169 { 5096 {
5170 if (!canvas || !canvas->buffer()) { 5097 if (!canvas || !canvas->buffer()) {
5171 synthesizeGLError(GL_INVALID_VALUE, functionName, "no canvas"); 5098 synthesizeGLError(GL_INVALID_VALUE, functionName, "no canvas");
5172 return false; 5099 return false;
5173 } 5100 }
5174 if (wouldTaintOrigin(canvas)) { 5101 if (wouldTaintOrigin(canvas)) {
5175 exceptionState.throwSecurityError("Tainted canvases may not be loaded.") ; 5102 exceptionState.throwSecurityError("Tainted canvases may not be loaded.") ;
5176 return false; 5103 return false;
5177 } 5104 }
5178 return true; 5105 return true;
5179 } 5106 }
5180 5107
5181 bool WebGLRenderingContext::validateHTMLVideoElement(const char* functionName, H TMLVideoElement* video, ExceptionState& exceptionState) 5108 bool WebGLRenderingContextBase::validateHTMLVideoElement(const char* functionNam e, HTMLVideoElement* video, ExceptionState& exceptionState)
5182 { 5109 {
5183 if (!video || !video->videoWidth() || !video->videoHeight()) { 5110 if (!video || !video->videoWidth() || !video->videoHeight()) {
5184 synthesizeGLError(GL_INVALID_VALUE, functionName, "no video"); 5111 synthesizeGLError(GL_INVALID_VALUE, functionName, "no video");
5185 return false; 5112 return false;
5186 } 5113 }
5187 if (wouldTaintOrigin(video)) { 5114 if (wouldTaintOrigin(video)) {
5188 exceptionState.throwSecurityError("The video element contains cross-orig in data, and may not be loaded."); 5115 exceptionState.throwSecurityError("The video element contains cross-orig in data, and may not be loaded.");
5189 return false; 5116 return false;
5190 } 5117 }
5191 return true; 5118 return true;
5192 } 5119 }
5193 5120
5194 bool WebGLRenderingContext::validateDrawArrays(const char* functionName, GLenum mode, GLint first, GLsizei count) 5121 bool WebGLRenderingContextBase::validateDrawArrays(const char* functionName, GLe num mode, GLint first, GLsizei count)
5195 { 5122 {
5196 if (isContextLost() || !validateDrawMode(functionName, mode)) 5123 if (isContextLost() || !validateDrawMode(functionName, mode))
5197 return false; 5124 return false;
5198 5125
5199 if (!validateStencilSettings(functionName)) 5126 if (!validateStencilSettings(functionName))
5200 return false; 5127 return false;
5201 5128
5202 if (first < 0 || count < 0) { 5129 if (first < 0 || count < 0) {
5203 synthesizeGLError(GL_INVALID_VALUE, functionName, "first or count < 0"); 5130 synthesizeGLError(GL_INVALID_VALUE, functionName, "first or count < 0");
5204 return false; 5131 return false;
(...skipping 10 matching lines...) Expand all
5215 5142
5216 const char* reason = "framebuffer incomplete"; 5143 const char* reason = "framebuffer incomplete";
5217 if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context.get(), &reason)) { 5144 if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context.get(), &reason)) {
5218 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, functionName, reason ); 5145 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, functionName, reason );
5219 return false; 5146 return false;
5220 } 5147 }
5221 5148
5222 return true; 5149 return true;
5223 } 5150 }
5224 5151
5225 bool WebGLRenderingContext::validateDrawElements(const char* functionName, GLenu m mode, GLsizei count, GLenum type, long long offset) 5152 bool WebGLRenderingContextBase::validateDrawElements(const char* functionName, G Lenum mode, GLsizei count, GLenum type, long long offset)
5226 { 5153 {
5227 if (isContextLost() || !validateDrawMode(functionName, mode)) 5154 if (isContextLost() || !validateDrawMode(functionName, mode))
5228 return false; 5155 return false;
5229 5156
5230 if (!validateStencilSettings(functionName)) 5157 if (!validateStencilSettings(functionName))
5231 return false; 5158 return false;
5232 5159
5233 switch (type) { 5160 switch (type) {
5234 case GL_UNSIGNED_BYTE: 5161 case GL_UNSIGNED_BYTE:
5235 case GL_UNSIGNED_SHORT: 5162 case GL_UNSIGNED_SHORT:
5236 break; 5163 break;
5237 case GL_UNSIGNED_INT: 5164 case GL_UNSIGNED_INT:
5238 if (m_oesElementIndexUint) 5165 if (extensionEnabled(OESElementIndexUintName))
5239 break; 5166 break;
5240 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid type"); 5167 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid type");
5241 return false; 5168 return false;
5242 default: 5169 default:
5243 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid type"); 5170 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid type");
5244 return false; 5171 return false;
5245 } 5172 }
5246 5173
5247 if (count < 0 || offset < 0) { 5174 if (count < 0 || offset < 0) {
5248 synthesizeGLError(GL_INVALID_VALUE, functionName, "count or offset < 0") ; 5175 synthesizeGLError(GL_INVALID_VALUE, functionName, "count or offset < 0") ;
(...skipping 17 matching lines...) Expand all
5266 const char* reason = "framebuffer incomplete"; 5193 const char* reason = "framebuffer incomplete";
5267 if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context.get(), &reason)) { 5194 if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context.get(), &reason)) {
5268 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, functionName, reason ); 5195 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, functionName, reason );
5269 return false; 5196 return false;
5270 } 5197 }
5271 5198
5272 return true; 5199 return true;
5273 } 5200 }
5274 5201
5275 // Helper function to validate draw*Instanced calls 5202 // Helper function to validate draw*Instanced calls
5276 bool WebGLRenderingContext::validateDrawInstanced(const char* functionName, GLsi zei primcount) 5203 bool WebGLRenderingContextBase::validateDrawInstanced(const char* functionName, GLsizei primcount)
5277 { 5204 {
5278 if (primcount < 0) { 5205 if (primcount < 0) {
5279 synthesizeGLError(GL_INVALID_VALUE, functionName, "primcount < 0"); 5206 synthesizeGLError(GL_INVALID_VALUE, functionName, "primcount < 0");
5280 return false; 5207 return false;
5281 } 5208 }
5282 5209
5283 // Ensure at least one enabled vertex attrib has a divisor of 0. 5210 // Ensure at least one enabled vertex attrib has a divisor of 0.
5284 for (unsigned i = 0; i < m_onePlusMaxEnabledAttribIndex; ++i) { 5211 for (unsigned i = 0; i < m_onePlusMaxEnabledAttribIndex; ++i) {
5285 const WebGLVertexArrayObjectOES::VertexAttribState& state = m_boundVerte xArrayObject->getVertexAttribState(i); 5212 const WebGLVertexArrayObjectOES::VertexAttribState& state = m_boundVerte xArrayObject->getVertexAttribState(i);
5286 if (state.enabled && !state.divisor) 5213 if (state.enabled && !state.divisor)
5287 return true; 5214 return true;
5288 } 5215 }
5289 5216
5290 synthesizeGLError(GL_INVALID_OPERATION, functionName, "at least one enabled attribute must have a divisor of 0"); 5217 synthesizeGLError(GL_INVALID_OPERATION, functionName, "at least one enabled attribute must have a divisor of 0");
5291 return false; 5218 return false;
5292 } 5219 }
5293 5220
5294 void WebGLRenderingContext::vertexAttribfImpl(const char* functionName, GLuint i ndex, GLsizei expectedSize, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) 5221 void WebGLRenderingContextBase::vertexAttribfImpl(const char* functionName, GLui nt index, GLsizei expectedSize, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3)
5295 { 5222 {
5296 if (isContextLost()) 5223 if (isContextLost())
5297 return; 5224 return;
5298 if (index >= m_maxVertexAttribs) { 5225 if (index >= m_maxVertexAttribs) {
5299 synthesizeGLError(GL_INVALID_VALUE, functionName, "index out of range"); 5226 synthesizeGLError(GL_INVALID_VALUE, functionName, "index out of range");
5300 return; 5227 return;
5301 } 5228 }
5302 // In GL, we skip setting vertexAttrib0 values. 5229 // In GL, we skip setting vertexAttrib0 values.
5303 switch (expectedSize) { 5230 switch (expectedSize) {
5304 case 1: 5231 case 1:
5305 m_context->vertexAttrib1f(index, v0); 5232 m_context->vertexAttrib1f(index, v0);
5306 break; 5233 break;
5307 case 2: 5234 case 2:
5308 m_context->vertexAttrib2f(index, v0, v1); 5235 m_context->vertexAttrib2f(index, v0, v1);
5309 break; 5236 break;
5310 case 3: 5237 case 3:
5311 m_context->vertexAttrib3f(index, v0, v1, v2); 5238 m_context->vertexAttrib3f(index, v0, v1, v2);
5312 break; 5239 break;
5313 case 4: 5240 case 4:
5314 m_context->vertexAttrib4f(index, v0, v1, v2, v3); 5241 m_context->vertexAttrib4f(index, v0, v1, v2, v3);
5315 break; 5242 break;
5316 } 5243 }
5317 VertexAttribValue& attribValue = m_vertexAttribValue[index]; 5244 VertexAttribValue& attribValue = m_vertexAttribValue[index];
5318 attribValue.value[0] = v0; 5245 attribValue.value[0] = v0;
5319 attribValue.value[1] = v1; 5246 attribValue.value[1] = v1;
5320 attribValue.value[2] = v2; 5247 attribValue.value[2] = v2;
5321 attribValue.value[3] = v3; 5248 attribValue.value[3] = v3;
5322 } 5249 }
5323 5250
5324 void WebGLRenderingContext::vertexAttribfvImpl(const char* functionName, GLuint index, Float32Array* v, GLsizei expectedSize) 5251 void WebGLRenderingContextBase::vertexAttribfvImpl(const char* functionName, GLu int index, Float32Array* v, GLsizei expectedSize)
5325 { 5252 {
5326 if (isContextLost()) 5253 if (isContextLost())
5327 return; 5254 return;
5328 if (!v) { 5255 if (!v) {
5329 synthesizeGLError(GL_INVALID_VALUE, functionName, "no array"); 5256 synthesizeGLError(GL_INVALID_VALUE, functionName, "no array");
5330 return; 5257 return;
5331 } 5258 }
5332 vertexAttribfvImpl(functionName, index, v->data(), v->length(), expectedSize ); 5259 vertexAttribfvImpl(functionName, index, v->data(), v->length(), expectedSize );
5333 } 5260 }
5334 5261
5335 void WebGLRenderingContext::vertexAttribfvImpl(const char* functionName, GLuint index, GLfloat* v, GLsizei size, GLsizei expectedSize) 5262 void WebGLRenderingContextBase::vertexAttribfvImpl(const char* functionName, GLu int index, GLfloat* v, GLsizei size, GLsizei expectedSize)
5336 { 5263 {
5337 if (isContextLost()) 5264 if (isContextLost())
5338 return; 5265 return;
5339 if (!v) { 5266 if (!v) {
5340 synthesizeGLError(GL_INVALID_VALUE, functionName, "no array"); 5267 synthesizeGLError(GL_INVALID_VALUE, functionName, "no array");
5341 return; 5268 return;
5342 } 5269 }
5343 if (size < expectedSize) { 5270 if (size < expectedSize) {
5344 synthesizeGLError(GL_INVALID_VALUE, functionName, "invalid size"); 5271 synthesizeGLError(GL_INVALID_VALUE, functionName, "invalid size");
5345 return; 5272 return;
(...skipping 16 matching lines...) Expand all
5362 case 4: 5289 case 4:
5363 m_context->vertexAttrib4fv(index, v); 5290 m_context->vertexAttrib4fv(index, v);
5364 break; 5291 break;
5365 } 5292 }
5366 VertexAttribValue& attribValue = m_vertexAttribValue[index]; 5293 VertexAttribValue& attribValue = m_vertexAttribValue[index];
5367 attribValue.initValue(); 5294 attribValue.initValue();
5368 for (int ii = 0; ii < expectedSize; ++ii) 5295 for (int ii = 0; ii < expectedSize; ++ii)
5369 attribValue.value[ii] = v[ii]; 5296 attribValue.value[ii] = v[ii];
5370 } 5297 }
5371 5298
5372 void WebGLRenderingContext::dispatchContextLostEvent(Timer<WebGLRenderingContext >*) 5299 void WebGLRenderingContextBase::dispatchContextLostEvent(Timer<WebGLRenderingCon textBase>*)
5373 { 5300 {
5374 RefPtr<WebGLContextEvent> event = WebGLContextEvent::create(EventTypeNames:: webglcontextlost, false, true, ""); 5301 RefPtr<WebGLContextEvent> event = WebGLContextEvent::create(EventTypeNames:: webglcontextlost, false, true, "");
5375 canvas()->dispatchEvent(event); 5302 canvas()->dispatchEvent(event);
5376 m_restoreAllowed = event->defaultPrevented(); 5303 m_restoreAllowed = event->defaultPrevented();
5377 deactivateContext(this, m_contextLostMode != RealLostContext && m_restoreAll owed); 5304 deactivateContext(this, m_contextLostMode != RealLostContext && m_restoreAll owed);
5378 if ((m_contextLostMode == RealLostContext || m_contextLostMode == AutoRecove rSyntheticLostContext) && m_restoreAllowed) 5305 if ((m_contextLostMode == RealLostContext || m_contextLostMode == AutoRecove rSyntheticLostContext) && m_restoreAllowed)
5379 m_restoreTimer.startOneShot(0); 5306 m_restoreTimer.startOneShot(0);
5380 } 5307 }
5381 5308
5382 void WebGLRenderingContext::maybeRestoreContext(Timer<WebGLRenderingContext>*) 5309 void WebGLRenderingContextBase::maybeRestoreContext(Timer<WebGLRenderingContextB ase>*)
5383 { 5310 {
5384 ASSERT(isContextLost()); 5311 ASSERT(isContextLost());
5385 5312
5386 // The rendering context is not restored unless the default behavior of the 5313 // The rendering context is not restored unless the default behavior of the
5387 // webglcontextlost event was prevented earlier. 5314 // webglcontextlost event was prevented earlier.
5388 // 5315 //
5389 // Because of the way m_restoreTimer is set up for real vs. synthetic lost 5316 // Because of the way m_restoreTimer is set up for real vs. synthetic lost
5390 // context events, we don't have to worry about this test short-circuiting 5317 // context events, we don't have to worry about this test short-circuiting
5391 // the retry loop for real context lost events. 5318 // the retry loop for real context lost events.
5392 if (!m_restoreAllowed) 5319 if (!m_restoreAllowed)
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
5428 m_lostContextErrors.clear(); 5355 m_lostContextErrors.clear();
5429 5356
5430 m_context = context.release(); 5357 m_context = context.release();
5431 m_contextLost = false; 5358 m_contextLost = false;
5432 5359
5433 setupFlags(); 5360 setupFlags();
5434 initializeNewContext(); 5361 initializeNewContext();
5435 canvas()->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglconte xtrestored, false, true, "")); 5362 canvas()->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglconte xtrestored, false, true, ""));
5436 } 5363 }
5437 5364
5438 String WebGLRenderingContext::ensureNotNull(const String& text) const 5365 String WebGLRenderingContextBase::ensureNotNull(const String& text) const
5439 { 5366 {
5440 if (text.isNull()) 5367 if (text.isNull())
5441 return WTF::emptyString(); 5368 return WTF::emptyString();
5442 return text; 5369 return text;
5443 } 5370 }
5444 5371
5445 WebGLRenderingContext::LRUImageBufferCache::LRUImageBufferCache(int capacity) 5372 WebGLRenderingContextBase::LRUImageBufferCache::LRUImageBufferCache(int capacity )
5446 : m_buffers(adoptArrayPtr(new OwnPtr<ImageBuffer>[capacity])) 5373 : m_buffers(adoptArrayPtr(new OwnPtr<ImageBuffer>[capacity]))
5447 , m_capacity(capacity) 5374 , m_capacity(capacity)
5448 { 5375 {
5449 } 5376 }
5450 5377
5451 ImageBuffer* WebGLRenderingContext::LRUImageBufferCache::imageBuffer(const IntSi ze& size) 5378 ImageBuffer* WebGLRenderingContextBase::LRUImageBufferCache::imageBuffer(const I ntSize& size)
5452 { 5379 {
5453 int i; 5380 int i;
5454 for (i = 0; i < m_capacity; ++i) { 5381 for (i = 0; i < m_capacity; ++i) {
5455 ImageBuffer* buf = m_buffers[i].get(); 5382 ImageBuffer* buf = m_buffers[i].get();
5456 if (!buf) 5383 if (!buf)
5457 break; 5384 break;
5458 if (buf->size() != size) 5385 if (buf->size() != size)
5459 continue; 5386 continue;
5460 bubbleToFront(i); 5387 bubbleToFront(i);
5461 return buf; 5388 return buf;
5462 } 5389 }
5463 5390
5464 OwnPtr<ImageBuffer> temp(ImageBuffer::create(size)); 5391 OwnPtr<ImageBuffer> temp(ImageBuffer::create(size));
5465 if (!temp) 5392 if (!temp)
5466 return 0; 5393 return 0;
5467 i = std::min(m_capacity - 1, i); 5394 i = std::min(m_capacity - 1, i);
5468 m_buffers[i] = temp.release(); 5395 m_buffers[i] = temp.release();
5469 5396
5470 ImageBuffer* buf = m_buffers[i].get(); 5397 ImageBuffer* buf = m_buffers[i].get();
5471 bubbleToFront(i); 5398 bubbleToFront(i);
5472 return buf; 5399 return buf;
5473 } 5400 }
5474 5401
5475 void WebGLRenderingContext::LRUImageBufferCache::bubbleToFront(int idx) 5402 void WebGLRenderingContextBase::LRUImageBufferCache::bubbleToFront(int idx)
5476 { 5403 {
5477 for (int i = idx; i > 0; --i) 5404 for (int i = idx; i > 0; --i)
5478 m_buffers[i].swap(m_buffers[i-1]); 5405 m_buffers[i].swap(m_buffers[i-1]);
5479 } 5406 }
5480 5407
5481 namespace { 5408 namespace {
5482 5409
5483 String GetErrorString(GLenum error) 5410 String GetErrorString(GLenum error)
5484 { 5411 {
5485 switch (error) { 5412 switch (error) {
5486 case GL_INVALID_ENUM: 5413 case GL_INVALID_ENUM:
5487 return "INVALID_ENUM"; 5414 return "INVALID_ENUM";
5488 case GL_INVALID_VALUE: 5415 case GL_INVALID_VALUE:
5489 return "INVALID_VALUE"; 5416 return "INVALID_VALUE";
5490 case GL_INVALID_OPERATION: 5417 case GL_INVALID_OPERATION:
5491 return "INVALID_OPERATION"; 5418 return "INVALID_OPERATION";
5492 case GL_OUT_OF_MEMORY: 5419 case GL_OUT_OF_MEMORY:
5493 return "OUT_OF_MEMORY"; 5420 return "OUT_OF_MEMORY";
5494 case GL_INVALID_FRAMEBUFFER_OPERATION: 5421 case GL_INVALID_FRAMEBUFFER_OPERATION:
5495 return "INVALID_FRAMEBUFFER_OPERATION"; 5422 return "INVALID_FRAMEBUFFER_OPERATION";
5496 case GC3D_CONTEXT_LOST_WEBGL: 5423 case GC3D_CONTEXT_LOST_WEBGL:
5497 return "CONTEXT_LOST_WEBGL"; 5424 return "CONTEXT_LOST_WEBGL";
5498 default: 5425 default:
5499 return String::format("WebGL ERROR(0x%04X)", error); 5426 return String::format("WebGL ERROR(0x%04X)", error);
5500 } 5427 }
5501 } 5428 }
5502 5429
5503 } // namespace anonymous 5430 } // namespace anonymous
5504 5431
5505 void WebGLRenderingContext::synthesizeGLError(GLenum error, const char* function Name, const char* description, ConsoleDisplayPreference display) 5432 void WebGLRenderingContextBase::synthesizeGLError(GLenum error, const char* func tionName, const char* description, ConsoleDisplayPreference display)
5506 { 5433 {
5507 String errorType = GetErrorString(error); 5434 String errorType = GetErrorString(error);
5508 if (m_synthesizedErrorsToConsole && display == DisplayInConsole) { 5435 if (m_synthesizedErrorsToConsole && display == DisplayInConsole) {
5509 String message = String("WebGL: ") + errorType + ": " + String(function Name) + ": " + String(description); 5436 String message = String("WebGL: ") + errorType + ": " + String(function Name) + ": " + String(description);
5510 printGLErrorToConsole(message); 5437 printGLErrorToConsole(message);
5511 } 5438 }
5512 if (!isContextLost()) 5439 if (!isContextLost())
5513 m_context->synthesizeGLError(error); 5440 m_context->synthesizeGLError(error);
5514 else { 5441 else {
5515 if (m_lostContextErrors.find(error) == WTF::kNotFound) 5442 if (m_lostContextErrors.find(error) == WTF::kNotFound)
5516 m_lostContextErrors.append(error); 5443 m_lostContextErrors.append(error);
5517 } 5444 }
5518 InspectorInstrumentation::didFireWebGLError(canvas(), errorType); 5445 InspectorInstrumentation::didFireWebGLError(canvas(), errorType);
5519 } 5446 }
5520 5447
5521 void WebGLRenderingContext::emitGLWarning(const char* functionName, const char* description) 5448 void WebGLRenderingContextBase::emitGLWarning(const char* functionName, const ch ar* description)
5522 { 5449 {
5523 if (m_synthesizedErrorsToConsole) { 5450 if (m_synthesizedErrorsToConsole) {
5524 String message = String("WebGL: ") + String(functionName) + ": " + Strin g(description); 5451 String message = String("WebGL: ") + String(functionName) + ": " + Strin g(description);
5525 printGLErrorToConsole(message); 5452 printGLErrorToConsole(message);
5526 } 5453 }
5527 InspectorInstrumentation::didFireWebGLWarning(canvas()); 5454 InspectorInstrumentation::didFireWebGLWarning(canvas());
5528 } 5455 }
5529 5456
5530 void WebGLRenderingContext::applyStencilTest() 5457 void WebGLRenderingContextBase::applyStencilTest()
5531 { 5458 {
5532 bool haveStencilBuffer = false; 5459 bool haveStencilBuffer = false;
5533 5460
5534 if (m_framebufferBinding) 5461 if (m_framebufferBinding)
5535 haveStencilBuffer = m_framebufferBinding->hasStencilBuffer(); 5462 haveStencilBuffer = m_framebufferBinding->hasStencilBuffer();
5536 else { 5463 else {
5537 RefPtr<WebGLContextAttributes> attributes = getContextAttributes(); 5464 RefPtr<WebGLContextAttributes> attributes = getContextAttributes();
5538 haveStencilBuffer = attributes->stencil(); 5465 haveStencilBuffer = attributes->stencil();
5539 } 5466 }
5540 enableOrDisable(GL_STENCIL_TEST, 5467 enableOrDisable(GL_STENCIL_TEST,
5541 m_stencilEnabled && haveStencilBuffer); 5468 m_stencilEnabled && haveStencilBuffer);
5542 } 5469 }
5543 5470
5544 void WebGLRenderingContext::enableOrDisable(GLenum capability, bool enable) 5471 void WebGLRenderingContextBase::enableOrDisable(GLenum capability, bool enable)
5545 { 5472 {
5546 if (isContextLost()) 5473 if (isContextLost())
5547 return; 5474 return;
5548 if (enable) 5475 if (enable)
5549 m_context->enable(capability); 5476 m_context->enable(capability);
5550 else 5477 else
5551 m_context->disable(capability); 5478 m_context->disable(capability);
5552 } 5479 }
5553 5480
5554 IntSize WebGLRenderingContext::clampedCanvasSize() 5481 IntSize WebGLRenderingContextBase::clampedCanvasSize()
5555 { 5482 {
5556 return IntSize(clamp(canvas()->width(), 1, m_maxViewportDims[0]), 5483 return IntSize(clamp(canvas()->width(), 1, m_maxViewportDims[0]),
5557 clamp(canvas()->height(), 1, m_maxViewportDims[1])); 5484 clamp(canvas()->height(), 1, m_maxViewportDims[1]));
5558 } 5485 }
5559 5486
5560 GLint WebGLRenderingContext::maxDrawBuffers() 5487 GLint WebGLRenderingContextBase::maxDrawBuffers()
5561 { 5488 {
5562 if (isContextLost() || !m_webglDrawBuffers) 5489 if (isContextLost() || !extensionEnabled(WebGLDrawBuffersName))
5563 return 0; 5490 return 0;
5564 if (!m_maxDrawBuffers) 5491 if (!m_maxDrawBuffers)
5565 m_context->getIntegerv(GL_MAX_DRAW_BUFFERS_EXT, &m_maxDrawBuffers); 5492 m_context->getIntegerv(GL_MAX_DRAW_BUFFERS_EXT, &m_maxDrawBuffers);
5566 if (!m_maxColorAttachments) 5493 if (!m_maxColorAttachments)
5567 m_context->getIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &m_maxColorAttachme nts); 5494 m_context->getIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &m_maxColorAttachme nts);
5568 // WEBGL_draw_buffers requires MAX_COLOR_ATTACHMENTS >= MAX_DRAW_BUFFERS. 5495 // WEBGL_draw_buffers requires MAX_COLOR_ATTACHMENTS >= MAX_DRAW_BUFFERS.
5569 return std::min(m_maxDrawBuffers, m_maxColorAttachments); 5496 return std::min(m_maxDrawBuffers, m_maxColorAttachments);
5570 } 5497 }
5571 5498
5572 GLint WebGLRenderingContext::maxColorAttachments() 5499 GLint WebGLRenderingContextBase::maxColorAttachments()
5573 { 5500 {
5574 if (isContextLost() || !m_webglDrawBuffers) 5501 if (isContextLost() || !extensionEnabled(WebGLDrawBuffersName))
5575 return 0; 5502 return 0;
5576 if (!m_maxColorAttachments) 5503 if (!m_maxColorAttachments)
5577 m_context->getIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &m_maxColorAttachme nts); 5504 m_context->getIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &m_maxColorAttachme nts);
5578 return m_maxColorAttachments; 5505 return m_maxColorAttachments;
5579 } 5506 }
5580 5507
5581 void WebGLRenderingContext::setBackDrawBuffer(GLenum buf) 5508 void WebGLRenderingContextBase::setBackDrawBuffer(GLenum buf)
5582 { 5509 {
5583 m_backDrawBuffer = buf; 5510 m_backDrawBuffer = buf;
5584 } 5511 }
5585 5512
5586 void WebGLRenderingContext::restoreCurrentFramebuffer() 5513 void WebGLRenderingContextBase::restoreCurrentFramebuffer()
5587 { 5514 {
5588 bindFramebuffer(GL_FRAMEBUFFER, m_framebufferBinding.get()); 5515 bindFramebuffer(GL_FRAMEBUFFER, m_framebufferBinding.get());
5589 } 5516 }
5590 5517
5591 void WebGLRenderingContext::restoreCurrentTexture2D() 5518 void WebGLRenderingContextBase::restoreCurrentTexture2D()
5592 { 5519 {
5593 bindTexture(GL_TEXTURE_2D, m_textureUnits[m_activeTextureUnit].m_texture2DBi nding.get()); 5520 bindTexture(GL_TEXTURE_2D, m_textureUnits[m_activeTextureUnit].m_texture2DBi nding.get());
5594 } 5521 }
5595 5522
5596 void WebGLRenderingContext::multisamplingChanged(bool enabled) 5523 void WebGLRenderingContextBase::multisamplingChanged(bool enabled)
5597 { 5524 {
5598 if (m_multisamplingAllowed != enabled) { 5525 if (m_multisamplingAllowed != enabled) {
5599 m_multisamplingAllowed = enabled; 5526 m_multisamplingAllowed = enabled;
5600 forceLostContext(WebGLRenderingContext::AutoRecoverSyntheticLostContext) ; 5527 forceLostContext(WebGLRenderingContextBase::AutoRecoverSyntheticLostCont ext);
5601 } 5528 }
5602 } 5529 }
5603 5530
5604 void WebGLRenderingContext::findNewMaxEnabledAttribIndex() 5531 void WebGLRenderingContextBase::findNewMaxEnabledAttribIndex()
5605 { 5532 {
5606 // Trace backwards from the current max to find the new max enabled attrib i ndex 5533 // Trace backwards from the current max to find the new max enabled attrib i ndex
5607 int startIndex = m_onePlusMaxEnabledAttribIndex - 1; 5534 int startIndex = m_onePlusMaxEnabledAttribIndex - 1;
5608 for (int i = startIndex; i >= 0; --i) { 5535 for (int i = startIndex; i >= 0; --i) {
5609 if (m_boundVertexArrayObject->getVertexAttribState(i).enabled) { 5536 if (m_boundVertexArrayObject->getVertexAttribState(i).enabled) {
5610 m_onePlusMaxEnabledAttribIndex = i + 1; 5537 m_onePlusMaxEnabledAttribIndex = i + 1;
5611 return; 5538 return;
5612 } 5539 }
5613 } 5540 }
5614 m_onePlusMaxEnabledAttribIndex = 0; 5541 m_onePlusMaxEnabledAttribIndex = 0;
5615 } 5542 }
5616 5543
5617 void WebGLRenderingContext::findNewMaxNonDefaultTextureUnit() 5544 void WebGLRenderingContextBase::findNewMaxNonDefaultTextureUnit()
5618 { 5545 {
5619 // Trace backwards from the current max to find the new max non-default text ure unit 5546 // Trace backwards from the current max to find the new max non-default text ure unit
5620 int startIndex = m_onePlusMaxNonDefaultTextureUnit - 1; 5547 int startIndex = m_onePlusMaxNonDefaultTextureUnit - 1;
5621 for (int i = startIndex; i >= 0; --i) { 5548 for (int i = startIndex; i >= 0; --i) {
5622 if (m_textureUnits[i].m_texture2DBinding 5549 if (m_textureUnits[i].m_texture2DBinding
5623 || m_textureUnits[i].m_textureCubeMapBinding) { 5550 || m_textureUnits[i].m_textureCubeMapBinding) {
5624 m_onePlusMaxNonDefaultTextureUnit = i + 1; 5551 m_onePlusMaxNonDefaultTextureUnit = i + 1;
5625 return; 5552 return;
5626 } 5553 }
5627 } 5554 }
5628 m_onePlusMaxNonDefaultTextureUnit = 0; 5555 m_onePlusMaxNonDefaultTextureUnit = 0;
5629 } 5556 }
5630 5557
5631 } // namespace WebCore 5558 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698