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

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: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2009 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "config.h" 26 #include "config.h"
27 #include "core/html/canvas/WebGLRenderingContext.h" 27 #include "core/html/canvas/WebGLRenderingContextBase.h"
28 28
29 #include "RuntimeEnabledFeatures.h" 29 #include "RuntimeEnabledFeatures.h"
30 #include "bindings/v8/ExceptionMessages.h" 30 #include "bindings/v8/ExceptionMessages.h"
31 #include "bindings/v8/ExceptionState.h" 31 #include "bindings/v8/ExceptionState.h"
32 #include "core/dom/ExceptionCode.h" 32 #include "core/dom/ExceptionCode.h"
33 #include "core/fetch/ImageResource.h" 33 #include "core/fetch/ImageResource.h"
34 #include "core/html/HTMLCanvasElement.h" 34 #include "core/html/HTMLCanvasElement.h"
35 #include "core/html/HTMLImageElement.h" 35 #include "core/html/HTMLImageElement.h"
36 #include "core/html/HTMLVideoElement.h" 36 #include "core/html/HTMLVideoElement.h"
37 #include "core/html/ImageData.h" 37 #include "core/html/ImageData.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 #include "wtf/PassOwnArrayPtr.h" 82 #include "wtf/PassOwnArrayPtr.h"
83 #include "wtf/Uint32Array.h" 83 #include "wtf/Uint32Array.h"
84 #include "wtf/text/StringBuilder.h" 84 #include "wtf/text/StringBuilder.h"
85 85
86 namespace WebCore { 86 namespace WebCore {
87 87
88 const double secondsBetweenRestoreAttempts = 1.0; 88 const double secondsBetweenRestoreAttempts = 1.0;
89 const int maxGLErrorsAllowedToConsole = 256; 89 const int maxGLErrorsAllowedToConsole = 256;
90 const int maxGLActiveContexts = 16; 90 const int maxGLActiveContexts = 16;
91 91
92 Vector<WebGLRenderingContext*>& WebGLRenderingContext::activeContexts() 92 Vector<WebGLRenderingContextBase*>& WebGLRenderingContextBase::activeContexts()
93 { 93 {
94 DEFINE_STATIC_LOCAL(Vector<WebGLRenderingContext*>, activeContexts, ()); 94 DEFINE_STATIC_LOCAL(Vector<WebGLRenderingContextBase*>, activeContexts, ());
95 return activeContexts; 95 return activeContexts;
96 } 96 }
97 97
98 Vector<WebGLRenderingContext*>& WebGLRenderingContext::forciblyEvictedContexts() 98 Vector<WebGLRenderingContextBase*>& WebGLRenderingContextBase::forciblyEvictedCo ntexts()
99 { 99 {
100 DEFINE_STATIC_LOCAL(Vector<WebGLRenderingContext*>, forciblyEvictedContexts, ()); 100 DEFINE_STATIC_LOCAL(Vector<WebGLRenderingContextBase*>, forciblyEvictedConte xts, ());
101 return forciblyEvictedContexts; 101 return forciblyEvictedContexts;
102 } 102 }
103 103
104 void WebGLRenderingContext::forciblyLoseOldestContext(const String& reason) 104 void WebGLRenderingContextBase::forciblyLoseOldestContext(const String& reason)
105 { 105 {
106 if (activeContexts().size()) { 106 if (activeContexts().size()) {
107 WebGLRenderingContext* oldestActiveContext = activeContexts().first(); 107 WebGLRenderingContextBase* oldestActiveContext = activeContexts().first( );
108 activeContexts().remove(0); 108 activeContexts().remove(0);
109 109
110 oldestActiveContext->printWarningToConsole(reason); 110 oldestActiveContext->printWarningToConsole(reason);
111 InspectorInstrumentation::didFireWebGLWarning(oldestActiveContext->canva s()); 111 InspectorInstrumentation::didFireWebGLWarning(oldestActiveContext->canva s());
112 112
113 // This will call deactivateContext once the context has actually been l ost. 113 // This will call deactivateContext once the context has actually been l ost.
114 oldestActiveContext->forceLostContext(WebGLRenderingContext::SyntheticLo stContext); 114 oldestActiveContext->forceLostContext(WebGLRenderingContextBase::Synthet icLostContext);
115 } 115 }
116 } 116 }
117 117
118 IntSize WebGLRenderingContext::oldestContextSize() 118 IntSize WebGLRenderingContextBase::oldestContextSize()
119 { 119 {
120 IntSize size; 120 IntSize size;
121 121
122 if (activeContexts().size()) { 122 if (activeContexts().size()) {
123 WebGLRenderingContext* oldestActiveContext = activeContexts().first(); 123 WebGLRenderingContextBase* oldestActiveContext = activeContexts().first( );
124 size.setWidth(oldestActiveContext->drawingBufferWidth()); 124 size.setWidth(oldestActiveContext->drawingBufferWidth());
125 size.setHeight(oldestActiveContext->drawingBufferHeight()); 125 size.setHeight(oldestActiveContext->drawingBufferHeight());
126 } 126 }
127 127
128 return size; 128 return size;
129 } 129 }
130 130
131 void WebGLRenderingContext::activateContext(WebGLRenderingContext* context) 131 void WebGLRenderingContextBase::activateContext(WebGLRenderingContextBase* conte xt)
132 { 132 {
133 if (!activeContexts().contains(context)) 133 if (!activeContexts().contains(context))
134 activeContexts().append(context); 134 activeContexts().append(context);
135 135
136 if (activeContexts().size() > maxGLActiveContexts) 136 if (activeContexts().size() > maxGLActiveContexts)
137 forciblyLoseOldestContext("WARNING: Too many active WebGL contexts. Olde st context will be lost."); 137 forciblyLoseOldestContext("WARNING: Too many active WebGL contexts. Olde st context will be lost.");
138 } 138 }
139 139
140 void WebGLRenderingContext::deactivateContext(WebGLRenderingContext* context, bo ol addToEvictedList) 140 void WebGLRenderingContextBase::deactivateContext(WebGLRenderingContextBase* con text, bool addToEvictedList)
141 { 141 {
142 size_t position = activeContexts().find(context); 142 size_t position = activeContexts().find(context);
143 if (position != WTF::notFound) 143 if (position != WTF::notFound)
144 activeContexts().remove(position); 144 activeContexts().remove(position);
145 145
146 if (addToEvictedList && !forciblyEvictedContexts().contains(context)) 146 if (addToEvictedList && !forciblyEvictedContexts().contains(context))
147 forciblyEvictedContexts().append(context); 147 forciblyEvictedContexts().append(context);
148 } 148 }
149 149
150 void WebGLRenderingContext::willDestroyContext(WebGLRenderingContext* context) 150 void WebGLRenderingContextBase::willDestroyContext(WebGLRenderingContextBase* co ntext)
151 { 151 {
152 size_t position = forciblyEvictedContexts().find(context); 152 size_t position = forciblyEvictedContexts().find(context);
153 if (position != WTF::notFound) 153 if (position != WTF::notFound)
154 forciblyEvictedContexts().remove(position); 154 forciblyEvictedContexts().remove(position);
155 155
156 deactivateContext(context, false); 156 deactivateContext(context, false);
157 157
158 // Try to re-enable the oldest inactive contexts. 158 // Try to re-enable the oldest inactive contexts.
159 while(activeContexts().size() < maxGLActiveContexts && forciblyEvictedContex ts().size()) { 159 while (activeContexts().size() < maxGLActiveContexts && forciblyEvictedConte xts().size()) {
160 WebGLRenderingContext* evictedContext = forciblyEvictedContexts().first( ); 160 WebGLRenderingContextBase* evictedContext = forciblyEvictedContexts().fi rst();
161 if (!evictedContext->m_restoreAllowed) { 161 if (!evictedContext->m_restoreAllowed) {
162 forciblyEvictedContexts().remove(0); 162 forciblyEvictedContexts().remove(0);
163 continue; 163 continue;
164 } 164 }
165 165
166 IntSize desiredSize = evictedContext->m_drawingBuffer->adjustSize(evicte dContext->clampedCanvasSize()); 166 IntSize desiredSize = evictedContext->m_drawingBuffer->adjustSize(evicte dContext->clampedCanvasSize());
167 167
168 // If there's room in the pixel budget for this context, restore it. 168 // If there's room in the pixel budget for this context, restore it.
169 if (!desiredSize.isEmpty()) { 169 if (!desiredSize.isEmpty()) {
170 forciblyEvictedContexts().remove(0); 170 forciblyEvictedContexts().remove(0);
171 evictedContext->forceRestoreContext(); 171 evictedContext->forceRestoreContext();
172 activeContexts().append(evictedContext); 172 activeContexts().append(evictedContext);
173 } 173 }
174 break; 174 break;
175 } 175 }
176 } 176 }
177 177
178 class WebGLRenderingContextEvictionManager : public ContextEvictionManager { 178 class WebGLRenderingContextEvictionManager : public ContextEvictionManager {
179 public: 179 public:
180 void forciblyLoseOldestContext(const String& reason) { 180 void forciblyLoseOldestContext(const String& reason)
181 WebGLRenderingContext::forciblyLoseOldestContext(reason); 181 {
182 WebGLRenderingContextBase::forciblyLoseOldestContext(reason);
182 }; 183 };
183 IntSize oldestContextSize() { 184 IntSize oldestContextSize()
184 return WebGLRenderingContext::oldestContextSize(); 185 {
186 return WebGLRenderingContextBase::oldestContextSize();
185 }; 187 };
186 }; 188 };
187 189
188 namespace { 190 namespace {
189 191
190 class ScopedDrawingBufferBinder { 192 class ScopedDrawingBufferBinder {
191 public: 193 public:
192 ScopedDrawingBufferBinder(DrawingBuffer* drawingBuffer, WebGLFramebuffer * framebufferBinding) 194 ScopedDrawingBufferBinder(DrawingBuffer* drawingBuffer, WebGLFramebuffer * framebufferBinding)
193 : m_drawingBuffer(drawingBuffer) 195 : m_drawingBuffer(drawingBuffer)
194 , m_framebufferBinding(framebufferBinding) 196 , m_framebufferBinding(framebufferBinding)
(...skipping 29 matching lines...) Expand all
224 } 226 }
225 GC3Dint end = start + range; 227 GC3Dint end = start + range;
226 if (end > sourceRange) 228 if (end > sourceRange)
227 range -= end - sourceRange; 229 range -= end - sourceRange;
228 *clippedStart = start; 230 *clippedStart = start;
229 *clippedRange = range; 231 *clippedRange = range;
230 } 232 }
231 233
232 // Returns false if no clipping is necessary, i.e., x, y, width, height stay the same. 234 // Returns false if no clipping is necessary, i.e., x, y, width, height stay the same.
233 bool clip2D(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, 235 bool clip2D(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height,
234 GC3Dsizei sourceWidth, GC3Dsizei sourceHeight, 236 GC3Dsizei sourceWidth, GC3Dsizei sourceHeight,
235 GC3Dint* clippedX, GC3Dint* clippedY, GC3Dsizei* clippedWidth, G C3Dsizei*clippedHeight) 237 GC3Dint* clippedX, GC3Dint* clippedY, GC3Dsizei* clippedWidth, GC3Dsizei *clippedHeight)
236 { 238 {
237 ASSERT(clippedX && clippedY && clippedWidth && clippedHeight); 239 ASSERT(clippedX && clippedY && clippedWidth && clippedHeight);
238 clip1D(x, width, sourceWidth, clippedX, clippedWidth); 240 clip1D(x, width, sourceWidth, clippedX, clippedWidth);
239 clip1D(y, height, sourceHeight, clippedY, clippedHeight); 241 clip1D(y, height, sourceHeight, clippedY, clippedHeight);
240 return (*clippedX != x || *clippedY != y || *clippedWidth != width || *c lippedHeight != height); 242 return (*clippedX != x || *clippedY != y || *clippedWidth != width || *c lippedHeight != height);
241 } 243 }
242 244
243 GC3Dint clamp(GC3Dint value, GC3Dint min, GC3Dint max) 245 GC3Dint clamp(GC3Dint value, GC3Dint min, GC3Dint max)
244 { 246 {
245 if (value < min) 247 if (value < min)
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 advance(); 449 advance();
448 break; 450 break;
449 } 451 }
450 452
451 // Swallow all other characters. Unclear whether we may 453 // Swallow all other characters. Unclear whether we may
452 // want or need to just emit a space per character to try 454 // want or need to just emit a space per character to try
453 // to preserve column numbers for debugging purposes. 455 // to preserve column numbers for debugging purposes.
454 break; 456 break;
455 } 457 }
456 } 458 }
457
458 GraphicsContext3D::Attributes adjustAttributes(const GraphicsContext3D::Attr ibutes& attributes, Settings* settings)
459 {
460 GraphicsContext3D::Attributes adjustedAttributes = attributes;
461 if (adjustedAttributes.antialias) {
462 if (settings && !settings->openGLMultisamplingEnabled())
463 adjustedAttributes.antialias = false;
464 }
465
466 return adjustedAttributes;
467 }
468 } // namespace anonymous 459 } // namespace anonymous
469 460
470 class WebGLRenderingContextLostCallback : public GraphicsContext3D::ContextLostC allback { 461 class WebGLRenderingContextLostCallback : public GraphicsContext3D::ContextLostC allback {
471 WTF_MAKE_FAST_ALLOCATED; 462 WTF_MAKE_FAST_ALLOCATED;
472 public: 463 public:
473 explicit WebGLRenderingContextLostCallback(WebGLRenderingContext* cb) : m_co ntext(cb) { } 464 explicit WebGLRenderingContextLostCallback(WebGLRenderingContextBase* cb) : m_context(cb) { }
474 virtual void onContextLost() { m_context->forceLostContext(WebGLRenderingCon text::RealLostContext); } 465 virtual void onContextLost() { m_context->forceLostContext(WebGLRenderingCon textBase::RealLostContext); }
475 virtual ~WebGLRenderingContextLostCallback() {} 466 virtual ~WebGLRenderingContextLostCallback() { }
476 private: 467 private:
477 WebGLRenderingContext* m_context; 468 WebGLRenderingContextBase* m_context;
478 }; 469 };
479 470
480 class WebGLRenderingContextErrorMessageCallback : public GraphicsContext3D::Erro rMessageCallback { 471 class WebGLRenderingContextErrorMessageCallback : public GraphicsContext3D::Erro rMessageCallback {
481 WTF_MAKE_FAST_ALLOCATED; 472 WTF_MAKE_FAST_ALLOCATED;
482 public: 473 public:
483 explicit WebGLRenderingContextErrorMessageCallback(WebGLRenderingContext* cb ) : m_context(cb) { } 474 explicit WebGLRenderingContextErrorMessageCallback(WebGLRenderingContextBase * cb) : m_context(cb) { }
484 virtual void onErrorMessage(const String& message, GC3Dint) 475 virtual void onErrorMessage(const String& message, GC3Dint)
485 { 476 {
486 if (m_context->m_synthesizedErrorsToConsole) 477 if (m_context->m_synthesizedErrorsToConsole)
487 m_context->printGLErrorToConsole(message); 478 m_context->printGLErrorToConsole(message);
488 InspectorInstrumentation::didFireWebGLErrorOrWarning(m_context->canvas() , message); 479 InspectorInstrumentation::didFireWebGLErrorOrWarning(m_context->canvas() , message);
489 } 480 }
490 virtual ~WebGLRenderingContextErrorMessageCallback() { } 481 virtual ~WebGLRenderingContextErrorMessageCallback() { }
491 private: 482 private:
492 WebGLRenderingContext* m_context; 483 WebGLRenderingContextBase* m_context;
493 }; 484 };
494 485
495 PassOwnPtr<WebGLRenderingContext> WebGLRenderingContext::create(HTMLCanvasElemen t* canvas, WebGLContextAttributes* attrs) 486 GraphicsContext3D::Attributes WebGLRenderingContextBase::adjustAttributes(const GraphicsContext3D::Attributes& attributes, Settings* settings)
496 { 487 {
497 Document& document = canvas->document(); 488 GraphicsContext3D::Attributes adjustedAttributes = attributes;
498 Frame* frame = document.frame(); 489 if (adjustedAttributes.antialias) {
499 if (!frame) 490 if (settings && !settings->openGLMultisamplingEnabled())
500 return nullptr; 491 adjustedAttributes.antialias = false;
501 Settings* settings = frame->settings();
502
503 // The FrameLoaderClient might block creation of a new WebGL context despite the page settings; in
504 // particular, if WebGL contexts were lost one or more times via the GL_ARB_ robustness extension.
505 if (!frame->loader()->client()->allowWebGL(settings && settings->webGLEnable d())) {
506 canvas->dispatchEvent(WebGLContextEvent::create(eventNames().webglcontex tcreationerrorEvent, false, true, "Web page was not allowed to create a WebGL co ntext."));
507 return nullptr;
508 } 492 }
509 493
510 GraphicsContext3D::Attributes requestedAttributes = attrs ? attrs->attribute s() : GraphicsContext3D::Attributes(); 494 return adjustedAttributes;
511 requestedAttributes.noExtensions = true;
512 requestedAttributes.shareResources = true;
513 requestedAttributes.preferDiscreteGPU = true;
514 requestedAttributes.topDocumentURL = document.topDocument()->url();
515
516 GraphicsContext3D::Attributes attributes = adjustAttributes(requestedAttribu tes, settings);
517
518 RefPtr<GraphicsContext3D> context(GraphicsContext3D::create(attributes));
519
520 if (!context || !context->makeContextCurrent()) {
521 canvas->dispatchEvent(WebGLContextEvent::create(eventNames().webglcontex tcreationerrorEvent, false, true, "Could not create a WebGL context."));
522 return nullptr;
523 }
524
525 Extensions3D* extensions = context->getExtensions();
526 if (extensions->supports("GL_EXT_debug_marker"))
527 extensions->pushGroupMarkerEXT("WebGLRenderingContext");
528
529 OwnPtr<WebGLRenderingContext> renderingContext = adoptPtr(new WebGLRendering Context(canvas, context, attributes, requestedAttributes));
530 renderingContext->suspendIfNeeded();
531
532 if (renderingContext->m_drawingBuffer->isZeroSized()) {
533 canvas->dispatchEvent(WebGLContextEvent::create(eventNames().webglcontex tcreationerrorEvent, false, true, "Could not create a WebGL context."));
534 return nullptr;
535 }
536
537 return renderingContext.release();
538 } 495 }
539 496
540 WebGLRenderingContext::WebGLRenderingContext(HTMLCanvasElement* passedCanvas, Pa ssRefPtr<GraphicsContext3D> context, GraphicsContext3D::Attributes attributes, G raphicsContext3D::Attributes requestedAttributes) 497 WebGLRenderingContextBase::WebGLRenderingContextBase(const String& contextName, HTMLCanvasElement* passedCanvas, PassRefPtr<GraphicsContext3D> context, Graphics Context3D::Attributes attributes, GraphicsContext3D::Attributes requestedAttribu tes)
541 : CanvasRenderingContext(passedCanvas) 498 : CanvasRenderingContext(passedCanvas)
542 , ActiveDOMObject(&passedCanvas->document()) 499 , ActiveDOMObject(&passedCanvas->document())
500 , m_contextName(contextName)
543 , m_context(context) 501 , m_context(context)
544 , m_drawingBuffer(0) 502 , m_drawingBuffer(0)
545 , m_dispatchContextLostEventTimer(this, &WebGLRenderingContext::dispatchCont extLostEvent) 503 , m_dispatchContextLostEventTimer(this, &WebGLRenderingContextBase::dispatch ContextLostEvent)
546 , m_restoreAllowed(false) 504 , m_restoreAllowed(false)
547 , m_restoreTimer(this, &WebGLRenderingContext::maybeRestoreContext) 505 , m_restoreTimer(this, &WebGLRenderingContextBase::maybeRestoreContext)
548 , m_videoCache(4) 506 , m_videoCache(4)
549 , m_contextLost(false) 507 , m_contextLost(false)
550 , m_contextLostMode(SyntheticLostContext) 508 , m_contextLostMode(SyntheticLostContext)
551 , m_attributes(attributes) 509 , m_attributes(attributes)
552 , m_requestedAttributes(requestedAttributes) 510 , m_requestedAttributes(requestedAttributes)
553 , m_synthesizedErrorsToConsole(true) 511 , m_synthesizedErrorsToConsole(true)
554 , m_numGLErrorsToConsoleAllowed(maxGLErrorsAllowedToConsole) 512 , m_numGLErrorsToConsoleAllowed(maxGLErrorsAllowedToConsole)
555 , m_multisamplingAllowed(false) 513 , m_multisamplingAllowed(false)
556 , m_multisamplingObserverRegistered(false) 514 , m_multisamplingObserverRegistered(false)
557 , m_onePlusMaxEnabledAttribIndex(0) 515 , m_onePlusMaxEnabledAttribIndex(0)
(...skipping 12 matching lines...) Expand all
570 528
571 // Create the DrawingBuffer and initialize the platform layer. 529 // Create the DrawingBuffer and initialize the platform layer.
572 DrawingBuffer::PreserveDrawingBuffer preserve = m_attributes.preserveDrawing Buffer ? DrawingBuffer::Preserve : DrawingBuffer::Discard; 530 DrawingBuffer::PreserveDrawingBuffer preserve = m_attributes.preserveDrawing Buffer ? DrawingBuffer::Preserve : DrawingBuffer::Discard;
573 m_drawingBuffer = DrawingBuffer::create(m_context.get(), clampedCanvasSize() , preserve, contextEvictionManager.release()); 531 m_drawingBuffer = DrawingBuffer::create(m_context.get(), clampedCanvasSize() , preserve, contextEvictionManager.release());
574 532
575 if (!m_drawingBuffer->isZeroSized()) { 533 if (!m_drawingBuffer->isZeroSized()) {
576 m_drawingBuffer->bind(); 534 m_drawingBuffer->bind();
577 setupFlags(); 535 setupFlags();
578 initializeNewContext(); 536 initializeNewContext();
579 } 537 }
580
581 // Register extensions.
582 static const char* webkitPrefix[] = { "WEBKIT_", 0, };
583 static const char* bothPrefixes[] = { "", "WEBKIT_", 0, };
584
585 registerExtension<ANGLEInstancedArrays>(m_angleInstancedArrays);
586 registerExtension<EXTTextureFilterAnisotropic>(m_extTextureFilterAnisotropic , PrefixedExtension, webkitPrefix);
587 registerExtension<OESElementIndexUint>(m_oesElementIndexUint);
588 registerExtension<OESStandardDerivatives>(m_oesStandardDerivatives);
589 registerExtension<OESTextureFloat>(m_oesTextureFloat);
590 registerExtension<OESTextureFloatLinear>(m_oesTextureFloatLinear);
591 registerExtension<OESTextureHalfFloat>(m_oesTextureHalfFloat);
592 registerExtension<OESTextureHalfFloatLinear>(m_oesTextureHalfFloatLinear);
593 registerExtension<OESVertexArrayObject>(m_oesVertexArrayObject);
594 registerExtension<WebGLCompressedTextureATC>(m_webglCompressedTextureATC, Pr efixedExtension, webkitPrefix);
595 registerExtension<WebGLCompressedTexturePVRTC>(m_webglCompressedTexturePVRTC , PrefixedExtension, webkitPrefix);
596 registerExtension<WebGLCompressedTextureS3TC>(m_webglCompressedTextureS3TC, PrefixedExtension, bothPrefixes);
597 registerExtension<WebGLDepthTexture>(m_webglDepthTexture, PrefixedExtension, bothPrefixes);
598 registerExtension<WebGLLoseContext>(m_webglLoseContext, ApprovedExtension, b othPrefixes);
599
600 // Register draft extensions.
601 registerExtension<EXTFragDepth>(m_extFragDepth, DraftExtension);
602 registerExtension<WebGLDrawBuffers>(m_webglDrawBuffers, DraftExtension);
603
604 // Register privileged extensions.
605 registerExtension<WebGLDebugRendererInfo>(m_webglDebugRendererInfo, Privileg edExtension);
606 registerExtension<WebGLDebugShaders>(m_webglDebugShaders, PrivilegedExtensio n);
607 } 538 }
608 539
609 void WebGLRenderingContext::initializeNewContext() 540 void WebGLRenderingContextBase::initializeNewContext()
610 { 541 {
611 ASSERT(!isContextLost()); 542 ASSERT(!isContextLost());
612 m_needsUpdate = true; 543 m_needsUpdate = true;
613 m_markedCanvasDirty = false; 544 m_markedCanvasDirty = false;
614 m_activeTextureUnit = 0; 545 m_activeTextureUnit = 0;
615 m_packAlignment = 4; 546 m_packAlignment = 4;
616 m_unpackAlignment = 4; 547 m_unpackAlignment = 4;
617 m_unpackFlipY = false; 548 m_unpackFlipY = false;
618 m_unpackPremultiplyAlpha = false; 549 m_unpackPremultiplyAlpha = false;
619 m_unpackColorspaceConversion = GraphicsContext3D::BROWSER_DEFAULT_WEBGL; 550 m_unpackColorspaceConversion = GraphicsContext3D::BROWSER_DEFAULT_WEBGL;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 606
676 m_context->viewport(0, 0, canvasSize.width(), canvasSize.height()); 607 m_context->viewport(0, 0, canvasSize.width(), canvasSize.height());
677 m_context->scissor(0, 0, canvasSize.width(), canvasSize.height()); 608 m_context->scissor(0, 0, canvasSize.width(), canvasSize.height());
678 609
679 m_context->setContextLostCallback(adoptPtr(new WebGLRenderingContextLostCall back(this))); 610 m_context->setContextLostCallback(adoptPtr(new WebGLRenderingContextLostCall back(this)));
680 m_context->setErrorMessageCallback(adoptPtr(new WebGLRenderingContextErrorMe ssageCallback(this))); 611 m_context->setErrorMessageCallback(adoptPtr(new WebGLRenderingContextErrorMe ssageCallback(this)));
681 612
682 activateContext(this); 613 activateContext(this);
683 } 614 }
684 615
685 void WebGLRenderingContext::setupFlags() 616 void WebGLRenderingContextBase::setupFlags()
686 { 617 {
687 ASSERT(m_context); 618 ASSERT(m_context);
688 if (Page* p = canvas()->document().page()) { 619 if (Page* p = canvas()->document().page()) {
689 m_synthesizedErrorsToConsole = p->settings().webGLErrorsToConsoleEnabled (); 620 m_synthesizedErrorsToConsole = p->settings().webGLErrorsToConsoleEnabled ();
690 621
691 if (!m_multisamplingObserverRegistered && m_requestedAttributes.antialia s) { 622 if (!m_multisamplingObserverRegistered && m_requestedAttributes.antialia s) {
692 m_multisamplingAllowed = m_drawingBuffer->multisample(); 623 m_multisamplingAllowed = m_drawingBuffer->multisample();
693 p->addMultisamplingChangedObserver(this); 624 p->addMultisamplingChangedObserver(this);
694 m_multisamplingObserverRegistered = true; 625 m_multisamplingObserverRegistered = true;
695 } 626 }
696 } 627 }
697 628
698 m_isGLES2NPOTStrict = !m_context->getExtensions()->isEnabled("GL_OES_texture _npot"); 629 m_isGLES2NPOTStrict = !m_context->getExtensions()->isEnabled("GL_OES_texture _npot");
699 m_isDepthStencilSupported = m_context->getExtensions()->isEnabled("GL_OES_pa cked_depth_stencil"); 630 m_isDepthStencilSupported = m_context->getExtensions()->isEnabled("GL_OES_pa cked_depth_stencil");
700 } 631 }
701 632
702 bool WebGLRenderingContext::allowPrivilegedExtensions() const 633 bool WebGLRenderingContextBase::allowPrivilegedExtensions() const
703 { 634 {
704 if (Page* p = canvas()->document().page()) 635 if (Page* p = canvas()->document().page())
705 return p->settings().privilegedWebGLExtensionsEnabled(); 636 return p->settings().privilegedWebGLExtensionsEnabled();
706 return false; 637 return false;
707 } 638 }
708 639
709 void WebGLRenderingContext::addCompressedTextureFormat(GC3Denum format) 640 void WebGLRenderingContextBase::addCompressedTextureFormat(GC3Denum format)
710 { 641 {
711 if (!m_compressedTextureFormats.contains(format)) 642 if (!m_compressedTextureFormats.contains(format))
712 m_compressedTextureFormats.append(format); 643 m_compressedTextureFormats.append(format);
713 } 644 }
714 645
715 void WebGLRenderingContext::removeAllCompressedTextureFormats() 646 void WebGLRenderingContextBase::removeAllCompressedTextureFormats()
716 { 647 {
717 m_compressedTextureFormats.clear(); 648 m_compressedTextureFormats.clear();
718 } 649 }
719 650
720 WebGLRenderingContext::~WebGLRenderingContext() 651 WebGLRenderingContextBase::~WebGLRenderingContextBase()
721 { 652 {
722 // Remove all references to WebGLObjects so if they are the last reference 653 // Remove all references to WebGLObjects so if they are the last reference
723 // they will be freed before the last context is removed from the context gr oup. 654 // they will be freed before the last context is removed from the context gr oup.
724 m_boundArrayBuffer = 0; 655 m_boundArrayBuffer = 0;
725 m_defaultVertexArrayObject = 0; 656 m_defaultVertexArrayObject = 0;
726 m_boundVertexArrayObject = 0; 657 m_boundVertexArrayObject = 0;
727 m_vertexAttrib0Buffer = 0; 658 m_vertexAttrib0Buffer = 0;
728 m_currentProgram = 0; 659 m_currentProgram = 0;
729 m_framebufferBinding = 0; 660 m_framebufferBinding = 0;
730 m_renderbufferBinding = 0; 661 m_renderbufferBinding = 0;
731 662
732 for (size_t i = 0; i < m_textureUnits.size(); ++i) { 663 for (size_t i = 0; i < m_textureUnits.size(); ++i) {
733 m_textureUnits[i].m_texture2DBinding = 0; 664 m_textureUnits[i].m_texture2DBinding = 0;
734 m_textureUnits[i].m_textureCubeMapBinding = 0; 665 m_textureUnits[i].m_textureCubeMapBinding = 0;
735 } 666 }
736 667
737 m_blackTexture2D = 0; 668 m_blackTexture2D = 0;
738 m_blackTextureCubeMap = 0; 669 m_blackTextureCubeMap = 0;
739 670
740 detachAndRemoveAllObjects(); 671 detachAndRemoveAllObjects();
741 672
742 // release all extensions 673 // release all extensions
743 for (size_t i = 0; i < m_extensions.size(); ++i) 674 for (size_t i = 0; i < m_extensions.size(); ++i)
744 delete m_extensions[i]; 675 delete m_extensions[i];
745 676
746 // Context must be removed from the group prior to the destruction of the 677 // Context must be removed from the group prior to the destruction of the
747 // GraphicsContext3D, otherwise shared objects may not be properly deleted. 678 // GraphicsContext3D, otherwise shared objects may not be properly deleted.
748 m_contextGroup->removeContext(this); 679 m_contextGroup->removeContext(this);
749 680
750 destroyGraphicsContext3D(); 681 destroyGraphicsContext3D();
751 682
752 if (m_multisamplingObserverRegistered) { 683 if (m_multisamplingObserverRegistered) {
753 Page* page = canvas()->document().page(); 684 Page* page = canvas()->document().page();
754 if (page) 685 if (page)
755 page->removeMultisamplingChangedObserver(this); 686 page->removeMultisamplingChangedObserver(this);
756 } 687 }
757 688
758 willDestroyContext(this); 689 willDestroyContext(this);
759 } 690 }
760 691
761 void WebGLRenderingContext::destroyGraphicsContext3D() 692 void WebGLRenderingContextBase::destroyGraphicsContext3D()
762 { 693 {
763 m_contextLost = true; 694 m_contextLost = true;
764 695
765 // The drawing buffer holds a context reference. It must also be destroyed 696 // The drawing buffer holds a context reference. It must also be destroyed
766 // in order for the context to be released. 697 // in order for the context to be released.
767 m_drawingBuffer->releaseResources(); 698 m_drawingBuffer->releaseResources();
768 699
769 if (m_context) { 700 if (m_context) {
770 m_context->setContextLostCallback(nullptr); 701 m_context->setContextLostCallback(nullptr);
771 m_context->setErrorMessageCallback(nullptr); 702 m_context->setErrorMessageCallback(nullptr);
772 m_context.clear(); 703 m_context.clear();
773 } 704 }
774 } 705 }
775 706
776 void WebGLRenderingContext::markContextChanged() 707 void WebGLRenderingContextBase::markContextChanged()
777 { 708 {
778 if (m_framebufferBinding || isContextLost()) 709 if (m_framebufferBinding || isContextLost())
779 return; 710 return;
780 711
781 m_context->markContextChanged(); 712 m_context->markContextChanged();
782 m_drawingBuffer->markContentsChanged(); 713 m_drawingBuffer->markContentsChanged();
783 714
784 m_layerCleared = false; 715 m_layerCleared = false;
785 RenderBox* renderBox = canvas()->renderBox(); 716 RenderBox* renderBox = canvas()->renderBox();
786 if (renderBox && renderBox->hasAcceleratedCompositing()) { 717 if (renderBox && renderBox->hasAcceleratedCompositing()) {
787 m_markedCanvasDirty = true; 718 m_markedCanvasDirty = true;
788 canvas()->clearCopiedImage(); 719 canvas()->clearCopiedImage();
789 renderBox->contentChanged(CanvasChanged); 720 renderBox->contentChanged(CanvasChanged);
790 } else { 721 } else {
791 if (!m_markedCanvasDirty) { 722 if (!m_markedCanvasDirty) {
792 m_markedCanvasDirty = true; 723 m_markedCanvasDirty = true;
793 canvas()->didDraw(FloatRect(FloatPoint(0, 0), clampedCanvasSize())); 724 canvas()->didDraw(FloatRect(FloatPoint(0, 0), clampedCanvasSize()));
794 } 725 }
795 } 726 }
796 } 727 }
797 728
798 bool WebGLRenderingContext::clearIfComposited(GC3Dbitfield mask) 729 bool WebGLRenderingContextBase::clearIfComposited(GC3Dbitfield mask)
799 { 730 {
800 if (isContextLost()) 731 if (isContextLost())
801 return false; 732 return false;
802 733
803 if (!m_context->layerComposited() || m_layerCleared 734 if (!m_context->layerComposited() || m_layerCleared
804 || m_attributes.preserveDrawingBuffer || (mask && m_framebufferBinding)) 735 || m_attributes.preserveDrawingBuffer || (mask && m_framebufferBinding))
805 return false; 736 return false;
806 737
807 RefPtr<WebGLContextAttributes> contextAttributes = getContextAttributes(); 738 RefPtr<WebGLContextAttributes> contextAttributes = getContextAttributes();
808 739
809 // Determine if it's possible to combine the clear the user asked for and th is clear. 740 // Determine if it's possible to combine the clear the user asked for and th is clear.
810 bool combinedClear = mask && !m_scissorEnabled; 741 bool combinedClear = mask && !m_scissorEnabled;
811 742
812 m_context->disable(GraphicsContext3D::SCISSOR_TEST); 743 m_context->disable(GraphicsContext3D::SCISSOR_TEST);
813 if (combinedClear && (mask & GraphicsContext3D::COLOR_BUFFER_BIT)) 744 if (combinedClear && (mask & GraphicsContext3D::COLOR_BUFFER_BIT)) {
814 m_context->clearColor(m_colorMask[0] ? m_clearColor[0] : 0, 745 m_context->clearColor(
815 m_colorMask[1] ? m_clearColor[1] : 0, 746 m_colorMask[0] ? m_clearColor[0] : 0,
816 m_colorMask[2] ? m_clearColor[2] : 0, 747 m_colorMask[1] ? m_clearColor[1] : 0,
817 m_colorMask[3] ? m_clearColor[3] : 0); 748 m_colorMask[2] ? m_clearColor[2] : 0,
818 else 749 m_colorMask[3] ? m_clearColor[3] : 0);
750 } else {
819 m_context->clearColor(0, 0, 0, 0); 751 m_context->clearColor(0, 0, 0, 0);
752 }
820 m_context->colorMask(true, true, true, true); 753 m_context->colorMask(true, true, true, true);
821 GC3Dbitfield clearMask = GraphicsContext3D::COLOR_BUFFER_BIT; 754 GC3Dbitfield clearMask = GraphicsContext3D::COLOR_BUFFER_BIT;
822 if (contextAttributes->depth()) { 755 if (contextAttributes->depth()) {
823 if (!combinedClear || !m_depthMask || !(mask & GraphicsContext3D::DEPTH_ BUFFER_BIT)) 756 if (!combinedClear || !m_depthMask || !(mask & GraphicsContext3D::DEPTH_ BUFFER_BIT))
824 m_context->clearDepth(1.0f); 757 m_context->clearDepth(1.0f);
825 clearMask |= GraphicsContext3D::DEPTH_BUFFER_BIT; 758 clearMask |= GraphicsContext3D::DEPTH_BUFFER_BIT;
826 m_context->depthMask(true); 759 m_context->depthMask(true);
827 } 760 }
828 if (contextAttributes->stencil()) { 761 if (contextAttributes->stencil()) {
829 if (combinedClear && (mask & GraphicsContext3D::STENCIL_BUFFER_BIT)) 762 if (combinedClear && (mask & GraphicsContext3D::STENCIL_BUFFER_BIT))
830 m_context->clearStencil(m_clearStencil & m_stencilMask); 763 m_context->clearStencil(m_clearStencil & m_stencilMask);
831 else 764 else
832 m_context->clearStencil(0); 765 m_context->clearStencil(0);
833 clearMask |= GraphicsContext3D::STENCIL_BUFFER_BIT; 766 clearMask |= GraphicsContext3D::STENCIL_BUFFER_BIT;
834 m_context->stencilMaskSeparate(GraphicsContext3D::FRONT, 0xFFFFFFFF); 767 m_context->stencilMaskSeparate(GraphicsContext3D::FRONT, 0xFFFFFFFF);
835 } 768 }
836 769
837 m_drawingBuffer->clearFramebuffers(clearMask); 770 m_drawingBuffer->clearFramebuffers(clearMask);
838 771
839 restoreStateAfterClear(); 772 restoreStateAfterClear();
840 if (m_framebufferBinding) 773 if (m_framebufferBinding)
841 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, objectOrZero( m_framebufferBinding.get())); 774 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, objectOrZero( m_framebufferBinding.get()));
842 m_layerCleared = true; 775 m_layerCleared = true;
843 776
844 return combinedClear; 777 return combinedClear;
845 } 778 }
846 779
847 void WebGLRenderingContext::restoreStateAfterClear() 780 void WebGLRenderingContextBase::restoreStateAfterClear()
848 { 781 {
849 if (isContextLost()) 782 if (isContextLost())
850 return; 783 return;
851 784
852 // Restore the state that the context set. 785 // Restore the state that the context set.
853 if (m_scissorEnabled) 786 if (m_scissorEnabled)
854 m_context->enable(GraphicsContext3D::SCISSOR_TEST); 787 m_context->enable(GraphicsContext3D::SCISSOR_TEST);
855 m_context->clearColor(m_clearColor[0], m_clearColor[1], 788 m_context->clearColor(m_clearColor[0], m_clearColor[1], m_clearColor[2], m_c learColor[3]);
856 m_clearColor[2], m_clearColor[3]); 789 m_context->colorMask(m_colorMask[0], m_colorMask[1], m_colorMask[2], m_color Mask[3]);
857 m_context->colorMask(m_colorMask[0], m_colorMask[1],
858 m_colorMask[2], m_colorMask[3]);
859 m_context->clearDepth(m_clearDepth); 790 m_context->clearDepth(m_clearDepth);
860 m_context->clearStencil(m_clearStencil); 791 m_context->clearStencil(m_clearStencil);
861 m_context->stencilMaskSeparate(GraphicsContext3D::FRONT, m_stencilMask); 792 m_context->stencilMaskSeparate(GraphicsContext3D::FRONT, m_stencilMask);
862 m_context->depthMask(m_depthMask); 793 m_context->depthMask(m_depthMask);
863 } 794 }
864 795
865 void WebGLRenderingContext::markLayerComposited() 796 void WebGLRenderingContextBase::markLayerComposited()
866 { 797 {
867 if (!isContextLost()) 798 if (!isContextLost())
868 m_context->markLayerComposited(); 799 m_context->markLayerComposited();
869 } 800 }
870 801
871 void WebGLRenderingContext::paintRenderingResultsToCanvas() 802 void WebGLRenderingContextBase::paintRenderingResultsToCanvas()
872 { 803 {
873 if (isContextLost()) { 804 if (isContextLost()) {
874 canvas()->clearPresentationCopy(); 805 canvas()->clearPresentationCopy();
875 return; 806 return;
876 } 807 }
877 808
878 if (canvas()->document().printing()) 809 if (canvas()->document().printing())
879 canvas()->clearPresentationCopy(); 810 canvas()->clearPresentationCopy();
880 811
881 // Until the canvas is written to by the application, the clear that 812 // Until the canvas is written to by the application, the clear that
882 // happened after it was composited should be ignored by the compositor. 813 // happened after it was composited should be ignored by the compositor.
883 if (m_context->layerComposited() && !m_attributes.preserveDrawingBuffer) { 814 if (m_context->layerComposited() && !m_attributes.preserveDrawingBuffer) {
884 m_drawingBuffer->paintCompositedResultsToCanvas(canvas()->buffer()); 815 m_drawingBuffer->paintCompositedResultsToCanvas(canvas()->buffer());
885 816
886 canvas()->makePresentationCopy(); 817 canvas()->makePresentationCopy();
887 } else 818 } else {
888 canvas()->clearPresentationCopy(); 819 canvas()->clearPresentationCopy();
820 }
889 clearIfComposited(); 821 clearIfComposited();
890 822
891 if (!m_markedCanvasDirty && !m_layerCleared) 823 if (!m_markedCanvasDirty && !m_layerCleared)
892 return; 824 return;
893 825
894 canvas()->clearCopiedImage(); 826 canvas()->clearCopiedImage();
895 m_markedCanvasDirty = false; 827 m_markedCanvasDirty = false;
896 828
897 m_drawingBuffer->commit(); 829 m_drawingBuffer->commit();
898 m_context->paintRenderingResultsToCanvas(canvas()->buffer(), m_drawingBuffer .get()); 830 m_context->paintRenderingResultsToCanvas(canvas()->buffer(), m_drawingBuffer .get());
899 831
900 if (m_framebufferBinding) 832 if (m_framebufferBinding)
901 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, objectOrZero( m_framebufferBinding.get())); 833 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, objectOrZero( m_framebufferBinding.get()));
902 else 834 else
903 m_drawingBuffer->bind(); 835 m_drawingBuffer->bind();
904 } 836 }
905 837
906 PassRefPtr<ImageData> WebGLRenderingContext::paintRenderingResultsToImageData() 838 PassRefPtr<ImageData> WebGLRenderingContextBase::paintRenderingResultsToImageDat a()
907 { 839 {
908 if (isContextLost()) 840 if (isContextLost())
909 return 0; 841 return 0;
910 842
911 clearIfComposited(); 843 clearIfComposited();
912 m_drawingBuffer->commit(); 844 m_drawingBuffer->commit();
913 RefPtr<ImageData> imageData = m_context->paintRenderingResultsToImageData(m_ drawingBuffer.get()); 845 RefPtr<ImageData> imageData = m_context->paintRenderingResultsToImageData(m_ drawingBuffer.get());
914 846
915 if (m_framebufferBinding) 847 if (m_framebufferBinding)
916 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, objectOrZero( m_framebufferBinding.get())); 848 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, objectOrZero( m_framebufferBinding.get()));
917 else 849 else
918 m_drawingBuffer->bind(); 850 m_drawingBuffer->bind();
919 851
920 return imageData; 852 return imageData;
921 } 853 }
922 854
923 void WebGLRenderingContext::reshape(int width, int height) 855 void WebGLRenderingContextBase::reshape(int width, int height)
924 { 856 {
925 if (isContextLost()) 857 if (isContextLost())
926 return; 858 return;
927 859
928 // This is an approximation because at WebGLRenderingContext level we don't 860 // This is an approximation because at WebGLRenderingContextBase level we do n't
929 // know if the underlying FBO uses textures or renderbuffers. 861 // know if the underlying FBO uses textures or renderbuffers.
930 GC3Dint maxSize = std::min(m_maxTextureSize, m_maxRenderbufferSize); 862 GC3Dint maxSize = std::min(m_maxTextureSize, m_maxRenderbufferSize);
931 // Limit drawing buffer size to 4k to avoid memory exhaustion. 863 // Limit drawing buffer size to 4k to avoid memory exhaustion.
932 const int sizeUpperLimit = 4096; 864 const int sizeUpperLimit = 4096;
933 maxSize = std::min(maxSize, sizeUpperLimit); 865 maxSize = std::min(maxSize, sizeUpperLimit);
934 GC3Dint maxWidth = std::min(maxSize, m_maxViewportDims[0]); 866 GC3Dint maxWidth = std::min(maxSize, m_maxViewportDims[0]);
935 GC3Dint maxHeight = std::min(maxSize, m_maxViewportDims[1]); 867 GC3Dint maxHeight = std::min(maxSize, m_maxViewportDims[1]);
936 width = clamp(width, 1, maxWidth); 868 width = clamp(width, 1, maxWidth);
937 height = clamp(height, 1, maxHeight); 869 height = clamp(height, 1, maxHeight);
938 870
939 if (m_needsUpdate) { 871 if (m_needsUpdate) {
940 RenderBox* renderBox = canvas()->renderBox(); 872 RenderBox* renderBox = canvas()->renderBox();
941 if (renderBox && renderBox->hasAcceleratedCompositing()) 873 if (renderBox && renderBox->hasAcceleratedCompositing())
942 renderBox->contentChanged(CanvasChanged); 874 renderBox->contentChanged(CanvasChanged);
943 m_needsUpdate = false; 875 m_needsUpdate = false;
944 } 876 }
945 877
946 // We don't have to mark the canvas as dirty, since the newly created image buffer will also start off 878 // We don't have to mark the canvas as dirty, since the newly created image buffer will also start off
947 // clear (and this matches what reshape will do). 879 // clear (and this matches what reshape will do).
948 m_drawingBuffer->reset(IntSize(width, height)); 880 m_drawingBuffer->reset(IntSize(width, height));
949 restoreStateAfterClear(); 881 restoreStateAfterClear();
950 882
951 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, objectOrZero(m_texture Units[m_activeTextureUnit].m_texture2DBinding.get())); 883 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, objectOrZero(m_texture Units[m_activeTextureUnit].m_texture2DBinding.get()));
952 m_context->bindRenderbuffer(GraphicsContext3D::RENDERBUFFER, objectOrZero(m_ renderbufferBinding.get())); 884 m_context->bindRenderbuffer(GraphicsContext3D::RENDERBUFFER, objectOrZero(m_ renderbufferBinding.get()));
953 if (m_framebufferBinding) 885 if (m_framebufferBinding)
954 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, objectOrZero(m_ framebufferBinding.get())); 886 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, objectOrZero( m_framebufferBinding.get()));
955 } 887 }
956 888
957 int WebGLRenderingContext::drawingBufferWidth() const 889 int WebGLRenderingContextBase::drawingBufferWidth() const
958 { 890 {
959 return m_drawingBuffer->size().width(); 891 return m_drawingBuffer->size().width();
960 } 892 }
961 893
962 int WebGLRenderingContext::drawingBufferHeight() const 894 int WebGLRenderingContextBase::drawingBufferHeight() const
963 { 895 {
964 return m_drawingBuffer->size().height(); 896 return m_drawingBuffer->size().height();
965 } 897 }
966 898
967 unsigned int WebGLRenderingContext::sizeInBytes(GC3Denum type) 899 unsigned WebGLRenderingContextBase::sizeInBytes(GC3Denum type)
968 { 900 {
969 switch (type) { 901 switch (type) {
970 case GraphicsContext3D::BYTE: 902 case GraphicsContext3D::BYTE:
971 return sizeof(GC3Dbyte); 903 return sizeof(GC3Dbyte);
972 case GraphicsContext3D::UNSIGNED_BYTE: 904 case GraphicsContext3D::UNSIGNED_BYTE:
973 return sizeof(GC3Dubyte); 905 return sizeof(GC3Dubyte);
974 case GraphicsContext3D::SHORT: 906 case GraphicsContext3D::SHORT:
975 return sizeof(GC3Dshort); 907 return sizeof(GC3Dshort);
976 case GraphicsContext3D::UNSIGNED_SHORT: 908 case GraphicsContext3D::UNSIGNED_SHORT:
977 return sizeof(GC3Dushort); 909 return sizeof(GC3Dushort);
978 case GraphicsContext3D::INT: 910 case GraphicsContext3D::INT:
979 return sizeof(GC3Dint); 911 return sizeof(GC3Dint);
980 case GraphicsContext3D::UNSIGNED_INT: 912 case GraphicsContext3D::UNSIGNED_INT:
981 return sizeof(GC3Duint); 913 return sizeof(GC3Duint);
982 case GraphicsContext3D::FLOAT: 914 case GraphicsContext3D::FLOAT:
983 return sizeof(GC3Dfloat); 915 return sizeof(GC3Dfloat);
984 } 916 }
985 ASSERT_NOT_REACHED(); 917 ASSERT_NOT_REACHED();
986 return 0; 918 return 0;
987 } 919 }
988 920
989 void WebGLRenderingContext::activeTexture(GC3Denum texture) 921 void WebGLRenderingContextBase::activeTexture(GC3Denum texture)
990 { 922 {
991 if (isContextLost()) 923 if (isContextLost())
992 return; 924 return;
993 if (texture - GraphicsContext3D::TEXTURE0 >= m_textureUnits.size()) { 925 if (texture - GraphicsContext3D::TEXTURE0 >= m_textureUnits.size()) {
994 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "activeTexture", "tex ture unit out of range"); 926 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "activeTexture", "tex ture unit out of range");
995 return; 927 return;
996 } 928 }
997 m_activeTextureUnit = texture - GraphicsContext3D::TEXTURE0; 929 m_activeTextureUnit = texture - GraphicsContext3D::TEXTURE0;
998 m_context->activeTexture(texture); 930 m_context->activeTexture(texture);
999 931
1000 m_drawingBuffer->setActiveTextureUnit(texture); 932 m_drawingBuffer->setActiveTextureUnit(texture);
1001 933
1002 } 934 }
1003 935
1004 void WebGLRenderingContext::attachShader(WebGLProgram* program, WebGLShader* sha der) 936 void WebGLRenderingContextBase::attachShader(WebGLProgram* program, WebGLShader* shader)
1005 { 937 {
1006 if (isContextLost() || !validateWebGLObject("attachShader", program) || !val idateWebGLObject("attachShader", shader)) 938 if (isContextLost() || !validateWebGLObject("attachShader", program) || !val idateWebGLObject("attachShader", shader))
1007 return; 939 return;
1008 if (!program->attachShader(shader)) { 940 if (!program->attachShader(shader)) {
1009 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "attachShader", "shader attachment already has shader"); 941 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "attachShader", "shader attachment already has shader");
1010 return; 942 return;
1011 } 943 }
1012 m_context->attachShader(objectOrZero(program), objectOrZero(shader)); 944 m_context->attachShader(objectOrZero(program), objectOrZero(shader));
1013 shader->onAttached(); 945 shader->onAttached();
1014 } 946 }
1015 947
1016 void WebGLRenderingContext::bindAttribLocation(WebGLProgram* program, GC3Duint i ndex, const String& name) 948 void WebGLRenderingContextBase::bindAttribLocation(WebGLProgram* program, GC3Dui nt index, const String& name)
1017 { 949 {
1018 if (isContextLost() || !validateWebGLObject("bindAttribLocation", program)) 950 if (isContextLost() || !validateWebGLObject("bindAttribLocation", program))
1019 return; 951 return;
1020 if (!validateLocationLength("bindAttribLocation", name)) 952 if (!validateLocationLength("bindAttribLocation", name))
1021 return; 953 return;
1022 if (!validateString("bindAttribLocation", name)) 954 if (!validateString("bindAttribLocation", name))
1023 return; 955 return;
1024 if (isPrefixReserved(name)) { 956 if (isPrefixReserved(name)) {
1025 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "bindAttribLocat ion", "reserved prefix"); 957 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "bindAttribLocat ion", "reserved prefix");
1026 return; 958 return;
1027 } 959 }
1028 if (index >= m_maxVertexAttribs) { 960 if (index >= m_maxVertexAttribs) {
1029 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "bindAttribLocation" , "index out of range"); 961 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "bindAttribLocation" , "index out of range");
1030 return; 962 return;
1031 } 963 }
1032 m_context->bindAttribLocation(objectOrZero(program), index, name); 964 m_context->bindAttribLocation(objectOrZero(program), index, name);
1033 } 965 }
1034 966
1035 bool WebGLRenderingContext::checkObjectToBeBound(const char* functionName, WebGL Object* object, bool& deleted) 967 bool WebGLRenderingContextBase::checkObjectToBeBound(const char* functionName, W ebGLObject* object, bool& deleted)
1036 { 968 {
1037 deleted = false; 969 deleted = false;
1038 if (isContextLost()) 970 if (isContextLost())
1039 return false; 971 return false;
1040 if (object) { 972 if (object) {
1041 if (!object->validate(contextGroup(), this)) { 973 if (!object->validate(contextGroup(), this)) {
1042 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName , "object not from this context"); 974 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName , "object not from this context");
1043 return false; 975 return false;
1044 } 976 }
1045 deleted = !object->object(); 977 deleted = !object->object();
1046 } 978 }
1047 return true; 979 return true;
1048 } 980 }
1049 981
1050 void WebGLRenderingContext::bindBuffer(GC3Denum target, WebGLBuffer* buffer) 982 void WebGLRenderingContextBase::bindBuffer(GC3Denum target, WebGLBuffer* buffer)
1051 { 983 {
1052 bool deleted; 984 bool deleted;
1053 if (!checkObjectToBeBound("bindBuffer", buffer, deleted)) 985 if (!checkObjectToBeBound("bindBuffer", buffer, deleted))
1054 return; 986 return;
1055 if (deleted) 987 if (deleted)
1056 buffer = 0; 988 buffer = 0;
1057 if (buffer && buffer->getTarget() && buffer->getTarget() != target) { 989 if (buffer && buffer->getTarget() && buffer->getTarget() != target) {
1058 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "bindBuffer", "b uffers can not be used with multiple targets"); 990 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "bindBuffer", "b uffers can not be used with multiple targets");
1059 return; 991 return;
1060 } 992 }
1061 if (target == GraphicsContext3D::ARRAY_BUFFER) 993 if (target == GraphicsContext3D::ARRAY_BUFFER) {
1062 m_boundArrayBuffer = buffer; 994 m_boundArrayBuffer = buffer;
1063 else if (target == GraphicsContext3D::ELEMENT_ARRAY_BUFFER) 995 } else if (target == GraphicsContext3D::ELEMENT_ARRAY_BUFFER) {
1064 m_boundVertexArrayObject->setElementArrayBuffer(buffer); 996 m_boundVertexArrayObject->setElementArrayBuffer(buffer);
1065 else { 997 } else {
1066 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "bindBuffer", "invali d target"); 998 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "bindBuffer", "invali d target");
1067 return; 999 return;
1068 } 1000 }
1069 1001
1070 m_context->bindBuffer(target, objectOrZero(buffer)); 1002 m_context->bindBuffer(target, objectOrZero(buffer));
1071 if (buffer) 1003 if (buffer)
1072 buffer->setTarget(target); 1004 buffer->setTarget(target);
1073 } 1005 }
1074 1006
1075 void WebGLRenderingContext::bindFramebuffer(GC3Denum target, WebGLFramebuffer* b uffer) 1007 void WebGLRenderingContextBase::bindFramebuffer(GC3Denum target, WebGLFramebuffe r* buffer)
1076 { 1008 {
1077 bool deleted; 1009 bool deleted;
1078 if (!checkObjectToBeBound("bindFramebuffer", buffer, deleted)) 1010 if (!checkObjectToBeBound("bindFramebuffer", buffer, deleted))
1079 return; 1011 return;
1080 if (deleted) 1012 if (deleted)
1081 buffer = 0; 1013 buffer = 0;
1082 if (target != GraphicsContext3D::FRAMEBUFFER) { 1014 if (target != GraphicsContext3D::FRAMEBUFFER) {
1083 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "bindFramebuffer", "i nvalid target"); 1015 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "bindFramebuffer", "i nvalid target");
1084 return; 1016 return;
1085 } 1017 }
1086 m_framebufferBinding = buffer; 1018 m_framebufferBinding = buffer;
1087 m_drawingBuffer->setFramebufferBinding(objectOrZero(m_framebufferBinding.get ())); 1019 m_drawingBuffer->setFramebufferBinding(objectOrZero(m_framebufferBinding.get ()));
1088 if (!m_framebufferBinding) { 1020 if (!m_framebufferBinding) {
1089 // Instead of binding fb 0, bind the drawing buffer. 1021 // Instead of binding fb 0, bind the drawing buffer.
1090 m_drawingBuffer->bind(); 1022 m_drawingBuffer->bind();
1091 } else 1023 } else {
1092 m_context->bindFramebuffer(target, objectOrZero(buffer)); 1024 m_context->bindFramebuffer(target, objectOrZero(buffer));
1025 }
1093 if (buffer) 1026 if (buffer)
1094 buffer->setHasEverBeenBound(); 1027 buffer->setHasEverBeenBound();
1095 applyStencilTest(); 1028 applyStencilTest();
1096 } 1029 }
1097 1030
1098 void WebGLRenderingContext::bindRenderbuffer(GC3Denum target, WebGLRenderbuffer* renderBuffer) 1031 void WebGLRenderingContextBase::bindRenderbuffer(GC3Denum target, WebGLRenderbuf fer* renderBuffer)
1099 { 1032 {
1100 bool deleted; 1033 bool deleted;
1101 if (!checkObjectToBeBound("bindRenderbuffer", renderBuffer, deleted)) 1034 if (!checkObjectToBeBound("bindRenderbuffer", renderBuffer, deleted))
1102 return; 1035 return;
1103 if (deleted) 1036 if (deleted)
1104 renderBuffer = 0; 1037 renderBuffer = 0;
1105 if (target != GraphicsContext3D::RENDERBUFFER) { 1038 if (target != GraphicsContext3D::RENDERBUFFER) {
1106 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "bindRenderbuffer", " invalid target"); 1039 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "bindRenderbuffer", " invalid target");
1107 return; 1040 return;
1108 } 1041 }
1109 m_renderbufferBinding = renderBuffer; 1042 m_renderbufferBinding = renderBuffer;
1110 m_context->bindRenderbuffer(target, objectOrZero(renderBuffer)); 1043 m_context->bindRenderbuffer(target, objectOrZero(renderBuffer));
1111 if (renderBuffer) 1044 if (renderBuffer)
1112 renderBuffer->setHasEverBeenBound(); 1045 renderBuffer->setHasEverBeenBound();
1113 } 1046 }
1114 1047
1115 void WebGLRenderingContext::bindTexture(GC3Denum target, WebGLTexture* texture) 1048 void WebGLRenderingContextBase::bindTexture(GC3Denum target, WebGLTexture* textu re)
1116 { 1049 {
1117 bool deleted; 1050 bool deleted;
1118 if (!checkObjectToBeBound("bindTexture", texture, deleted)) 1051 if (!checkObjectToBeBound("bindTexture", texture, deleted))
1119 return; 1052 return;
1120 if (deleted) 1053 if (deleted)
1121 texture = 0; 1054 texture = 0;
1122 if (texture && texture->getTarget() && texture->getTarget() != target) { 1055 if (texture && texture->getTarget() && texture->getTarget() != target) {
1123 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "bindTexture", " textures can not be used with multiple targets"); 1056 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "bindTexture", " textures can not be used with multiple targets");
1124 return; 1057 return;
1125 } 1058 }
(...skipping 28 matching lines...) Expand all
1154 // repeat mode to CLAMP_TO_EDGE for cube map textures, because OpenGL 1087 // repeat mode to CLAMP_TO_EDGE for cube map textures, because OpenGL
1155 // ES 2.0 doesn't expose this flag (a bug in the specification) and 1088 // ES 2.0 doesn't expose this flag (a bug in the specification) and
1156 // otherwise the application has no control over the seams in this 1089 // otherwise the application has no control over the seams in this
1157 // dimension. However, it appears that supporting this properly on all 1090 // dimension. However, it appears that supporting this properly on all
1158 // platforms is fairly involved (will require a HashMap from texture ID 1091 // platforms is fairly involved (will require a HashMap from texture ID
1159 // in all ports), and we have not had any complaints, so the logic has 1092 // in all ports), and we have not had any complaints, so the logic has
1160 // been removed. 1093 // been removed.
1161 1094
1162 } 1095 }
1163 1096
1164 void WebGLRenderingContext::blendColor(GC3Dfloat red, GC3Dfloat green, GC3Dfloat blue, GC3Dfloat alpha) 1097 void WebGLRenderingContextBase::blendColor(GC3Dfloat red, GC3Dfloat green, GC3Df loat blue, GC3Dfloat alpha)
1165 { 1098 {
1166 if (isContextLost()) 1099 if (isContextLost())
1167 return; 1100 return;
1168 m_context->blendColor(red, green, blue, alpha); 1101 m_context->blendColor(red, green, blue, alpha);
1169 } 1102 }
1170 1103
1171 void WebGLRenderingContext::blendEquation(GC3Denum mode) 1104 void WebGLRenderingContextBase::blendEquation(GC3Denum mode)
1172 { 1105 {
1173 if (isContextLost() || !validateBlendEquation("blendEquation", mode)) 1106 if (isContextLost() || !validateBlendEquation("blendEquation", mode))
1174 return; 1107 return;
1175 m_context->blendEquation(mode); 1108 m_context->blendEquation(mode);
1176 } 1109 }
1177 1110
1178 void WebGLRenderingContext::blendEquationSeparate(GC3Denum modeRGB, GC3Denum mod eAlpha) 1111 void WebGLRenderingContextBase::blendEquationSeparate(GC3Denum modeRGB, GC3Denum modeAlpha)
1179 { 1112 {
1180 if (isContextLost() || !validateBlendEquation("blendEquationSeparate", modeR GB) || !validateBlendEquation("blendEquationSeparate", modeAlpha)) 1113 if (isContextLost() || !validateBlendEquation("blendEquationSeparate", modeR GB) || !validateBlendEquation("blendEquationSeparate", modeAlpha))
1181 return; 1114 return;
1182 m_context->blendEquationSeparate(modeRGB, modeAlpha); 1115 m_context->blendEquationSeparate(modeRGB, modeAlpha);
1183 } 1116 }
1184 1117
1185 1118
1186 void WebGLRenderingContext::blendFunc(GC3Denum sfactor, GC3Denum dfactor) 1119 void WebGLRenderingContextBase::blendFunc(GC3Denum sfactor, GC3Denum dfactor)
1187 { 1120 {
1188 if (isContextLost() || !validateBlendFuncFactors("blendFunc", sfactor, dfact or)) 1121 if (isContextLost() || !validateBlendFuncFactors("blendFunc", sfactor, dfact or))
1189 return; 1122 return;
1190 m_context->blendFunc(sfactor, dfactor); 1123 m_context->blendFunc(sfactor, dfactor);
1191 } 1124 }
1192 1125
1193 void WebGLRenderingContext::blendFuncSeparate(GC3Denum srcRGB, GC3Denum dstRGB, GC3Denum srcAlpha, GC3Denum dstAlpha) 1126 void WebGLRenderingContextBase::blendFuncSeparate(GC3Denum srcRGB, GC3Denum dstR GB, GC3Denum srcAlpha, GC3Denum dstAlpha)
1194 { 1127 {
1195 // Note: Alpha does not have the same restrictions as RGB. 1128 // Note: Alpha does not have the same restrictions as RGB.
1196 if (isContextLost() || !validateBlendFuncFactors("blendFuncSeparate", srcRGB , dstRGB)) 1129 if (isContextLost() || !validateBlendFuncFactors("blendFuncSeparate", srcRGB , dstRGB))
1197 return; 1130 return;
1198 m_context->blendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha); 1131 m_context->blendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
1199 } 1132 }
1200 1133
1201 void WebGLRenderingContext::bufferData(GC3Denum target, long long size, GC3Denum usage) 1134 void WebGLRenderingContextBase::bufferData(GC3Denum target, long long size, GC3D enum usage)
1202 { 1135 {
1203 if (isContextLost()) 1136 if (isContextLost())
1204 return; 1137 return;
1205 WebGLBuffer* buffer = validateBufferDataParameters("bufferData", target, usa ge); 1138 WebGLBuffer* buffer = validateBufferDataParameters("bufferData", target, usa ge);
1206 if (!buffer) 1139 if (!buffer)
1207 return; 1140 return;
1208 if (size < 0) { 1141 if (size < 0) {
1209 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "bufferData", "size < 0"); 1142 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "bufferData", "size < 0");
1210 return; 1143 return;
1211 } 1144 }
1212 if (!size) { 1145 if (!size) {
1213 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "bufferData", "size == 0"); 1146 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "bufferData", "size == 0");
1214 return; 1147 return;
1215 } 1148 }
1216 1149
1217 m_context->bufferData(target, static_cast<GC3Dsizeiptr>(size), usage); 1150 m_context->bufferData(target, static_cast<GC3Dsizeiptr>(size), usage);
1218 } 1151 }
1219 1152
1220 void WebGLRenderingContext::bufferData(GC3Denum target, ArrayBuffer* data, GC3De num usage) 1153 void WebGLRenderingContextBase::bufferData(GC3Denum target, ArrayBuffer* data, G C3Denum usage)
1221 { 1154 {
1222 if (isContextLost()) 1155 if (isContextLost())
1223 return; 1156 return;
1224 WebGLBuffer* buffer = validateBufferDataParameters("bufferData", target, usa ge); 1157 WebGLBuffer* buffer = validateBufferDataParameters("bufferData", target, usa ge);
1225 if (!buffer) 1158 if (!buffer)
1226 return; 1159 return;
1227 if (!data) { 1160 if (!data) {
1228 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "bufferData", "no da ta"); 1161 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "bufferData", "no da ta");
1229 return; 1162 return;
1230 } 1163 }
1231 m_context->bufferData(target, data->byteLength(), data->data(), usage); 1164 m_context->bufferData(target, data->byteLength(), data->data(), usage);
1232 } 1165 }
1233 1166
1234 void WebGLRenderingContext::bufferData(GC3Denum target, ArrayBufferView* data, G C3Denum usage) 1167 void WebGLRenderingContextBase::bufferData(GC3Denum target, ArrayBufferView* dat a, GC3Denum usage)
1235 { 1168 {
1236 if (isContextLost()) 1169 if (isContextLost())
1237 return; 1170 return;
1238 WebGLBuffer* buffer = validateBufferDataParameters("bufferData", target, usa ge); 1171 WebGLBuffer* buffer = validateBufferDataParameters("bufferData", target, usa ge);
1239 if (!buffer) 1172 if (!buffer)
1240 return; 1173 return;
1241 if (!data) { 1174 if (!data) {
1242 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "bufferData", "no da ta"); 1175 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "bufferData", "no da ta");
1243 return; 1176 return;
1244 } 1177 }
1245 1178
1246 m_context->bufferData(target, data->byteLength(), data->baseAddress(), usage ); 1179 m_context->bufferData(target, data->byteLength(), data->baseAddress(), usage );
1247 } 1180 }
1248 1181
1249 void WebGLRenderingContext::bufferSubData(GC3Denum target, long long offset, Arr ayBuffer* data) 1182 void WebGLRenderingContextBase::bufferSubData(GC3Denum target, long long offset, ArrayBuffer* data)
1250 { 1183 {
1251 if (isContextLost()) 1184 if (isContextLost())
1252 return; 1185 return;
1253 WebGLBuffer* buffer = validateBufferDataParameters("bufferSubData", target, GraphicsContext3D::STATIC_DRAW); 1186 WebGLBuffer* buffer = validateBufferDataParameters("bufferSubData", target, GraphicsContext3D::STATIC_DRAW);
1254 if (!buffer) 1187 if (!buffer)
1255 return; 1188 return;
1256 if (offset < 0) { 1189 if (offset < 0) {
1257 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "bufferSubData", "of fset < 0"); 1190 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "bufferSubData", "of fset < 0");
1258 return; 1191 return;
1259 } 1192 }
1260 if (!data) 1193 if (!data)
1261 return; 1194 return;
1262 1195
1263 m_context->bufferSubData(target, static_cast<GC3Dintptr>(offset), data->byte Length(), data->data()); 1196 m_context->bufferSubData(target, static_cast<GC3Dintptr>(offset), data->byte Length(), data->data());
1264 } 1197 }
1265 1198
1266 void WebGLRenderingContext::bufferSubData(GC3Denum target, long long offset, Arr ayBufferView* data) 1199 void WebGLRenderingContextBase::bufferSubData(GC3Denum target, long long offset, ArrayBufferView* data)
1267 { 1200 {
1268 if (isContextLost()) 1201 if (isContextLost())
1269 return; 1202 return;
1270 WebGLBuffer* buffer = validateBufferDataParameters("bufferSubData", target, GraphicsContext3D::STATIC_DRAW); 1203 WebGLBuffer* buffer = validateBufferDataParameters("bufferSubData", target, GraphicsContext3D::STATIC_DRAW);
1271 if (!buffer) 1204 if (!buffer)
1272 return; 1205 return;
1273 if (offset < 0) { 1206 if (offset < 0) {
1274 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "bufferSubData", "of fset < 0"); 1207 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "bufferSubData", "of fset < 0");
1275 return; 1208 return;
1276 } 1209 }
1277 if (!data) 1210 if (!data)
1278 return; 1211 return;
1279 1212
1280 m_context->bufferSubData(target, static_cast<GC3Dintptr>(offset), data->byte Length(), data->baseAddress()); 1213 m_context->bufferSubData(target, static_cast<GC3Dintptr>(offset), data->byte Length(), data->baseAddress());
1281 } 1214 }
1282 1215
1283 GC3Denum WebGLRenderingContext::checkFramebufferStatus(GC3Denum target) 1216 GC3Denum WebGLRenderingContextBase::checkFramebufferStatus(GC3Denum target)
1284 { 1217 {
1285 if (isContextLost()) 1218 if (isContextLost())
1286 return GraphicsContext3D::FRAMEBUFFER_UNSUPPORTED; 1219 return GraphicsContext3D::FRAMEBUFFER_UNSUPPORTED;
1287 if (target != GraphicsContext3D::FRAMEBUFFER) { 1220 if (target != GraphicsContext3D::FRAMEBUFFER) {
1288 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "checkFramebufferStat us", "invalid target"); 1221 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "checkFramebufferStat us", "invalid target");
1289 return 0; 1222 return 0;
1290 } 1223 }
1291 if (!m_framebufferBinding || !m_framebufferBinding->object()) 1224 if (!m_framebufferBinding || !m_framebufferBinding->object())
1292 return GraphicsContext3D::FRAMEBUFFER_COMPLETE; 1225 return GraphicsContext3D::FRAMEBUFFER_COMPLETE;
1293 const char* reason = "framebuffer incomplete"; 1226 const char* reason = "framebuffer incomplete";
1294 GC3Denum result = m_framebufferBinding->checkStatus(&reason); 1227 GC3Denum result = m_framebufferBinding->checkStatus(&reason);
1295 if (result != GraphicsContext3D::FRAMEBUFFER_COMPLETE) { 1228 if (result != GraphicsContext3D::FRAMEBUFFER_COMPLETE) {
1296 emitGLWarning("checkFramebufferStatus", reason); 1229 emitGLWarning("checkFramebufferStatus", reason);
1297 return result; 1230 return result;
1298 } 1231 }
1299 result = m_context->checkFramebufferStatus(target); 1232 result = m_context->checkFramebufferStatus(target);
1300 return result; 1233 return result;
1301 } 1234 }
1302 1235
1303 void WebGLRenderingContext::clear(GC3Dbitfield mask) 1236 void WebGLRenderingContextBase::clear(GC3Dbitfield mask)
1304 { 1237 {
1305 if (isContextLost()) 1238 if (isContextLost())
1306 return; 1239 return;
1307 if (mask & ~(GraphicsContext3D::COLOR_BUFFER_BIT | GraphicsContext3D::DEPTH_ BUFFER_BIT | GraphicsContext3D::STENCIL_BUFFER_BIT)) { 1240 if (mask & ~(GraphicsContext3D::COLOR_BUFFER_BIT | GraphicsContext3D::DEPTH_ BUFFER_BIT | GraphicsContext3D::STENCIL_BUFFER_BIT)) {
1308 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "clear", "invalid ma sk"); 1241 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "clear", "invalid ma sk");
1309 return; 1242 return;
1310 } 1243 }
1311 const char* reason = "framebuffer incomplete"; 1244 const char* reason = "framebuffer incomplete";
1312 if (m_framebufferBinding && !m_framebufferBinding->onAccess(graphicsContext3 D(), &reason)) { 1245 if (m_framebufferBinding && !m_framebufferBinding->onAccess(graphicsContext3 D(), &reason)) {
1313 synthesizeGLError(GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION, "cle ar", reason); 1246 synthesizeGLError(GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION, "cle ar", reason);
1314 return; 1247 return;
1315 } 1248 }
1316 if (!clearIfComposited(mask)) 1249 if (!clearIfComposited(mask))
1317 m_context->clear(mask); 1250 m_context->clear(mask);
1318 markContextChanged(); 1251 markContextChanged();
1319 } 1252 }
1320 1253
1321 void WebGLRenderingContext::clearColor(GC3Dfloat r, GC3Dfloat g, GC3Dfloat b, GC 3Dfloat a) 1254 void WebGLRenderingContextBase::clearColor(GC3Dfloat r, GC3Dfloat g, GC3Dfloat b , GC3Dfloat a)
1322 { 1255 {
1323 if (isContextLost()) 1256 if (isContextLost())
1324 return; 1257 return;
1325 if (std::isnan(r)) 1258 if (std::isnan(r))
1326 r = 0; 1259 r = 0;
1327 if (std::isnan(g)) 1260 if (std::isnan(g))
1328 g = 0; 1261 g = 0;
1329 if (std::isnan(b)) 1262 if (std::isnan(b))
1330 b = 0; 1263 b = 0;
1331 if (std::isnan(a)) 1264 if (std::isnan(a))
1332 a = 1; 1265 a = 1;
1333 m_clearColor[0] = r; 1266 m_clearColor[0] = r;
1334 m_clearColor[1] = g; 1267 m_clearColor[1] = g;
1335 m_clearColor[2] = b; 1268 m_clearColor[2] = b;
1336 m_clearColor[3] = a; 1269 m_clearColor[3] = a;
1337 m_context->clearColor(r, g, b, a); 1270 m_context->clearColor(r, g, b, a);
1338 } 1271 }
1339 1272
1340 void WebGLRenderingContext::clearDepth(GC3Dfloat depth) 1273 void WebGLRenderingContextBase::clearDepth(GC3Dfloat depth)
1341 { 1274 {
1342 if (isContextLost()) 1275 if (isContextLost())
1343 return; 1276 return;
1344 m_clearDepth = depth; 1277 m_clearDepth = depth;
1345 m_context->clearDepth(depth); 1278 m_context->clearDepth(depth);
1346 } 1279 }
1347 1280
1348 void WebGLRenderingContext::clearStencil(GC3Dint s) 1281 void WebGLRenderingContextBase::clearStencil(GC3Dint s)
1349 { 1282 {
1350 if (isContextLost()) 1283 if (isContextLost())
1351 return; 1284 return;
1352 m_clearStencil = s; 1285 m_clearStencil = s;
1353 m_context->clearStencil(s); 1286 m_context->clearStencil(s);
1354 } 1287 }
1355 1288
1356 void WebGLRenderingContext::colorMask(GC3Dboolean red, GC3Dboolean green, GC3Dbo olean blue, GC3Dboolean alpha) 1289 void WebGLRenderingContextBase::colorMask(GC3Dboolean red, GC3Dboolean green, GC 3Dboolean blue, GC3Dboolean alpha)
1357 { 1290 {
1358 if (isContextLost()) 1291 if (isContextLost())
1359 return; 1292 return;
1360 m_colorMask[0] = red; 1293 m_colorMask[0] = red;
1361 m_colorMask[1] = green; 1294 m_colorMask[1] = green;
1362 m_colorMask[2] = blue; 1295 m_colorMask[2] = blue;
1363 m_colorMask[3] = alpha; 1296 m_colorMask[3] = alpha;
1364 m_context->colorMask(red, green, blue, alpha); 1297 m_context->colorMask(red, green, blue, alpha);
1365 } 1298 }
1366 1299
1367 void WebGLRenderingContext::compileShader(WebGLShader* shader) 1300 void WebGLRenderingContextBase::compileShader(WebGLShader* shader)
1368 { 1301 {
1369 if (isContextLost() || !validateWebGLObject("compileShader", shader)) 1302 if (isContextLost() || !validateWebGLObject("compileShader", shader))
1370 return; 1303 return;
1371 m_context->compileShader(objectOrZero(shader)); 1304 m_context->compileShader(objectOrZero(shader));
1372 } 1305 }
1373 1306
1374 void WebGLRenderingContext::compressedTexImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, 1307 void WebGLRenderingContextBase::compressedTexImage2D(GC3Denum target, GC3Dint le vel, GC3Denum internalformat, GC3Dsizei width,
1375 GC3Dsizei height, GC3Dint borde r, ArrayBufferView* data) 1308 GC3Dsizei height, GC3Dint border, ArrayBufferView* data)
1376 { 1309 {
1377 if (isContextLost()) 1310 if (isContextLost())
1378 return; 1311 return;
1379 if (!validateTexFuncLevel("compressedTexImage2D", target, level)) 1312 if (!validateTexFuncLevel("compressedTexImage2D", target, level))
1380 return; 1313 return;
1381 1314
1382 if (!validateCompressedTexFormat(internalformat)) { 1315 if (!validateCompressedTexFormat(internalformat)) {
1383 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "compressedTexImage2D ", "invalid internalformat"); 1316 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "compressedTexImage2D ", "invalid internalformat");
1384 return; 1317 return;
1385 } 1318 }
1386 if (border) { 1319 if (border) {
1387 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "compressedTexImage2 D", "border not 0"); 1320 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "compressedTexImage2 D", "border not 0");
1388 return; 1321 return;
1389 } 1322 }
1390 if (!validateCompressedTexDimensions("compressedTexImage2D", NotTexSubImage2 D, target, level, width, height, internalformat)) 1323 if (!validateCompressedTexDimensions("compressedTexImage2D", NotTexSubImage2 D, target, level, width, height, internalformat))
1391 return; 1324 return;
1392 if (!validateCompressedTexFuncData("compressedTexImage2D", width, height, in ternalformat, data)) 1325 if (!validateCompressedTexFuncData("compressedTexImage2D", width, height, in ternalformat, data))
1393 return; 1326 return;
1394 1327
1395 WebGLTexture* tex = validateTextureBinding("compressedTexImage2D", target, t rue); 1328 WebGLTexture* tex = validateTextureBinding("compressedTexImage2D", target, t rue);
1396 if (!tex) 1329 if (!tex)
1397 return; 1330 return;
1398 if (!isGLES2NPOTStrict()) { 1331 if (!isGLES2NPOTStrict()) {
1399 if (level && WebGLTexture::isNPOT(width, height)) { 1332 if (level && WebGLTexture::isNPOT(width, height)) {
1400 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "compressedTexIm age2D", "level > 0 not power of 2"); 1333 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "compressedTexIm age2D", "level > 0 not power of 2");
1401 return; 1334 return;
1402 } 1335 }
1403 } 1336 }
1404 graphicsContext3D()->compressedTexImage2D(target, level, internalformat, wid th, height, 1337 graphicsContext3D()->compressedTexImage2D(target, level, internalformat, wid th, height,
1405 border, data->byteLength(), data-> baseAddress()); 1338 border, data->byteLength(), data->baseAddress());
1406 tex->setLevelInfo(target, level, internalformat, width, height, GraphicsCont ext3D::UNSIGNED_BYTE); 1339 tex->setLevelInfo(target, level, internalformat, width, height, GraphicsCont ext3D::UNSIGNED_BYTE);
1407 } 1340 }
1408 1341
1409 void WebGLRenderingContext::compressedTexSubImage2D(GC3Denum target, GC3Dint lev el, GC3Dint xoffset, GC3Dint yoffset, 1342 void WebGLRenderingContextBase::compressedTexSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset,
1410 GC3Dsizei width, GC3Dsizei h eight, GC3Denum format, ArrayBufferView* data) 1343 GC3Dsizei width, GC3Dsizei height, GC3Denum format, ArrayBufferView* data)
1411 { 1344 {
1412 if (isContextLost()) 1345 if (isContextLost())
1413 return; 1346 return;
1414 if (!validateTexFuncLevel("compressedTexSubImage2D", target, level)) 1347 if (!validateTexFuncLevel("compressedTexSubImage2D", target, level))
1415 return; 1348 return;
1416 if (!validateCompressedTexFormat(format)) { 1349 if (!validateCompressedTexFormat(format)) {
1417 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "compressedTexSubImag e2D", "invalid format"); 1350 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "compressedTexSubImag e2D", "invalid format");
1418 return; 1351 return;
1419 } 1352 }
1420 if (!validateCompressedTexFuncData("compressedTexSubImage2D", width, height, format, data)) 1353 if (!validateCompressedTexFuncData("compressedTexSubImage2D", width, height, format, data))
1421 return; 1354 return;
1422 1355
1423 WebGLTexture* tex = validateTextureBinding("compressedTexSubImage2D", target , true); 1356 WebGLTexture* tex = validateTextureBinding("compressedTexSubImage2D", target , true);
1424 if (!tex) 1357 if (!tex)
1425 return; 1358 return;
1426 1359
1427 if (format != tex->getInternalFormat(target, level)) { 1360 if (format != tex->getInternalFormat(target, level)) {
1428 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "compressedTexSu bImage2D", "format does not match texture format"); 1361 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "compressedTexSu bImage2D", "format does not match texture format");
1429 return; 1362 return;
1430 } 1363 }
1431 1364
1432 if (!validateCompressedTexSubDimensions("compressedTexSubImage2D", target, l evel, xoffset, yoffset, width, height, format, tex)) 1365 if (!validateCompressedTexSubDimensions("compressedTexSubImage2D", target, l evel, xoffset, yoffset, width, height, format, tex))
1433 return; 1366 return;
1434 1367
1435 graphicsContext3D()->compressedTexSubImage2D(target, level, xoffset, yoffset , 1368 graphicsContext3D()->compressedTexSubImage2D(target, level, xoffset, yoffset ,
1436 width, height, format, data->by teLength(), data->baseAddress()); 1369 width, height, format, data->byteLength(), data->baseAddress());
1437 } 1370 }
1438 1371
1439 bool WebGLRenderingContext::validateSettableTexFormat(const char* functionName, GC3Denum format) 1372 bool WebGLRenderingContextBase::validateSettableTexFormat(const char* functionNa me, GC3Denum format)
1440 { 1373 {
1441 if (GraphicsContext3D::getClearBitsByFormat(format) & (GraphicsContext3D::DE PTH_BUFFER_BIT | GraphicsContext3D::STENCIL_BUFFER_BIT)) { 1374 if (GraphicsContext3D::getClearBitsByFormat(format) & (GraphicsContext3D::DE PTH_BUFFER_BIT | GraphicsContext3D::STENCIL_BUFFER_BIT)) {
1442 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "f ormat can not be set, only rendered to"); 1375 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "f ormat can not be set, only rendered to");
1443 return false; 1376 return false;
1444 } 1377 }
1445 return true; 1378 return true;
1446 } 1379 }
1447 1380
1448 void WebGLRenderingContext::copyTexImage2D(GC3Denum target, GC3Dint level, GC3De num internalformat, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3 Dint border) 1381 void WebGLRenderingContextBase::copyTexImage2D(GC3Denum target, GC3Dint level, G C3Denum internalformat, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Dint border)
1449 { 1382 {
1450 if (isContextLost()) 1383 if (isContextLost())
1451 return; 1384 return;
1452 if (!validateTexFuncParameters("copyTexImage2D", NotTexSubImage2D, target, l evel, internalformat, width, height, border, internalformat, GraphicsContext3D:: UNSIGNED_BYTE)) 1385 if (!validateTexFuncParameters("copyTexImage2D", NotTexSubImage2D, target, l evel, internalformat, width, height, border, internalformat, GraphicsContext3D:: UNSIGNED_BYTE))
1453 return; 1386 return;
1454 if (!validateSettableTexFormat("copyTexImage2D", internalformat)) 1387 if (!validateSettableTexFormat("copyTexImage2D", internalformat))
1455 return; 1388 return;
1456 WebGLTexture* tex = validateTextureBinding("copyTexImage2D", target, true); 1389 WebGLTexture* tex = validateTextureBinding("copyTexImage2D", target, true);
1457 if (!tex) 1390 if (!tex)
1458 return; 1391 return;
(...skipping 10 matching lines...) Expand all
1469 synthesizeGLError(GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION, "cop yTexImage2D", reason); 1402 synthesizeGLError(GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION, "cop yTexImage2D", reason);
1470 return; 1403 return;
1471 } 1404 }
1472 clearIfComposited(); 1405 clearIfComposited();
1473 ScopedDrawingBufferBinder binder(m_drawingBuffer.get(), m_framebufferBinding .get()); 1406 ScopedDrawingBufferBinder binder(m_drawingBuffer.get(), m_framebufferBinding .get());
1474 m_context->copyTexImage2D(target, level, internalformat, x, y, width, height , border); 1407 m_context->copyTexImage2D(target, level, internalformat, x, y, width, height , border);
1475 // FIXME: if the framebuffer is not complete, none of the below should be ex ecuted. 1408 // FIXME: if the framebuffer is not complete, none of the below should be ex ecuted.
1476 tex->setLevelInfo(target, level, internalformat, width, height, GraphicsCont ext3D::UNSIGNED_BYTE); 1409 tex->setLevelInfo(target, level, internalformat, width, height, GraphicsCont ext3D::UNSIGNED_BYTE);
1477 } 1410 }
1478 1411
1479 void WebGLRenderingContext::copyTexSubImage2D(GC3Denum target, GC3Dint level, GC 3Dint xoffset, GC3Dint yoffset, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height) 1412 void WebGLRenderingContextBase::copyTexSubImage2D(GC3Denum target, GC3Dint level , GC3Dint xoffset, GC3Dint yoffset, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Ds izei height)
1480 { 1413 {
1481 if (isContextLost()) 1414 if (isContextLost())
1482 return; 1415 return;
1483 if (!validateTexFuncLevel("copyTexSubImage2D", target, level)) 1416 if (!validateTexFuncLevel("copyTexSubImage2D", target, level))
1484 return; 1417 return;
1485 WebGLTexture* tex = validateTextureBinding("copyTexSubImage2D", target, true ); 1418 WebGLTexture* tex = validateTextureBinding("copyTexSubImage2D", target, true );
1486 if (!tex) 1419 if (!tex)
1487 return; 1420 return;
1488 if (!validateSize("copyTexSubImage2D", xoffset, yoffset) || !validateSize("c opyTexSubImage2D", width, height)) 1421 if (!validateSize("copyTexSubImage2D", xoffset, yoffset) || !validateSize("c opyTexSubImage2D", width, height))
1489 return; 1422 return;
(...skipping 16 matching lines...) Expand all
1506 const char* reason = "framebuffer incomplete"; 1439 const char* reason = "framebuffer incomplete";
1507 if (m_framebufferBinding && !m_framebufferBinding->onAccess(graphicsContext3 D(), &reason)) { 1440 if (m_framebufferBinding && !m_framebufferBinding->onAccess(graphicsContext3 D(), &reason)) {
1508 synthesizeGLError(GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION, "cop yTexSubImage2D", reason); 1441 synthesizeGLError(GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION, "cop yTexSubImage2D", reason);
1509 return; 1442 return;
1510 } 1443 }
1511 clearIfComposited(); 1444 clearIfComposited();
1512 ScopedDrawingBufferBinder binder(m_drawingBuffer.get(), m_framebufferBinding .get()); 1445 ScopedDrawingBufferBinder binder(m_drawingBuffer.get(), m_framebufferBinding .get());
1513 m_context->copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, h eight); 1446 m_context->copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, h eight);
1514 } 1447 }
1515 1448
1516 PassRefPtr<WebGLBuffer> WebGLRenderingContext::createBuffer() 1449 PassRefPtr<WebGLBuffer> WebGLRenderingContextBase::createBuffer()
1517 { 1450 {
1518 if (isContextLost()) 1451 if (isContextLost())
1519 return 0; 1452 return 0;
1520 RefPtr<WebGLBuffer> o = WebGLBuffer::create(this); 1453 RefPtr<WebGLBuffer> o = WebGLBuffer::create(this);
1521 addSharedObject(o.get()); 1454 addSharedObject(o.get());
1522 return o; 1455 return o;
1523 } 1456 }
1524 1457
1525 PassRefPtr<WebGLFramebuffer> WebGLRenderingContext::createFramebuffer() 1458 PassRefPtr<WebGLFramebuffer> WebGLRenderingContextBase::createFramebuffer()
1526 { 1459 {
1527 if (isContextLost()) 1460 if (isContextLost())
1528 return 0; 1461 return 0;
1529 RefPtr<WebGLFramebuffer> o = WebGLFramebuffer::create(this); 1462 RefPtr<WebGLFramebuffer> o = WebGLFramebuffer::create(this);
1530 addContextObject(o.get()); 1463 addContextObject(o.get());
1531 return o; 1464 return o;
1532 } 1465 }
1533 1466
1534 PassRefPtr<WebGLTexture> WebGLRenderingContext::createTexture() 1467 PassRefPtr<WebGLTexture> WebGLRenderingContextBase::createTexture()
1535 { 1468 {
1536 if (isContextLost()) 1469 if (isContextLost())
1537 return 0; 1470 return 0;
1538 RefPtr<WebGLTexture> o = WebGLTexture::create(this); 1471 RefPtr<WebGLTexture> o = WebGLTexture::create(this);
1539 addSharedObject(o.get()); 1472 addSharedObject(o.get());
1540 return o; 1473 return o;
1541 } 1474 }
1542 1475
1543 PassRefPtr<WebGLProgram> WebGLRenderingContext::createProgram() 1476 PassRefPtr<WebGLProgram> WebGLRenderingContextBase::createProgram()
1544 { 1477 {
1545 if (isContextLost()) 1478 if (isContextLost())
1546 return 0; 1479 return 0;
1547 RefPtr<WebGLProgram> o = WebGLProgram::create(this); 1480 RefPtr<WebGLProgram> o = WebGLProgram::create(this);
1548 addSharedObject(o.get()); 1481 addSharedObject(o.get());
1549 return o; 1482 return o;
1550 } 1483 }
1551 1484
1552 PassRefPtr<WebGLRenderbuffer> WebGLRenderingContext::createRenderbuffer() 1485 PassRefPtr<WebGLRenderbuffer> WebGLRenderingContextBase::createRenderbuffer()
1553 { 1486 {
1554 if (isContextLost()) 1487 if (isContextLost())
1555 return 0; 1488 return 0;
1556 RefPtr<WebGLRenderbuffer> o = WebGLRenderbuffer::create(this); 1489 RefPtr<WebGLRenderbuffer> o = WebGLRenderbuffer::create(this);
1557 addSharedObject(o.get()); 1490 addSharedObject(o.get());
1558 return o; 1491 return o;
1559 } 1492 }
1560 1493
1561 WebGLRenderbuffer* WebGLRenderingContext::ensureEmulatedStencilBuffer(GC3Denum t arget, WebGLRenderbuffer* renderbuffer) 1494 WebGLRenderbuffer* WebGLRenderingContextBase::ensureEmulatedStencilBuffer(GC3Den um target, WebGLRenderbuffer* renderbuffer)
1562 { 1495 {
1563 if (isContextLost()) 1496 if (isContextLost())
1564 return 0; 1497 return 0;
1565 if (!renderbuffer->emulatedStencilBuffer()) { 1498 if (!renderbuffer->emulatedStencilBuffer()) {
1566 renderbuffer->setEmulatedStencilBuffer(createRenderbuffer()); 1499 renderbuffer->setEmulatedStencilBuffer(createRenderbuffer());
1567 m_context->bindRenderbuffer(target, objectOrZero(renderbuffer->emulatedS tencilBuffer())); 1500 m_context->bindRenderbuffer(target, objectOrZero(renderbuffer->emulatedS tencilBuffer()));
1568 m_context->bindRenderbuffer(target, objectOrZero(m_renderbufferBinding.g et())); 1501 m_context->bindRenderbuffer(target, objectOrZero(m_renderbufferBinding.g et()));
1569 } 1502 }
1570 return renderbuffer->emulatedStencilBuffer(); 1503 return renderbuffer->emulatedStencilBuffer();
1571 } 1504 }
1572 1505
1573 PassRefPtr<WebGLShader> WebGLRenderingContext::createShader(GC3Denum type) 1506 PassRefPtr<WebGLShader> WebGLRenderingContextBase::createShader(GC3Denum type)
1574 { 1507 {
1575 if (isContextLost()) 1508 if (isContextLost())
1576 return 0; 1509 return 0;
1577 if (type != GraphicsContext3D::VERTEX_SHADER && type != GraphicsContext3D::F RAGMENT_SHADER) { 1510 if (type != GraphicsContext3D::VERTEX_SHADER && type != GraphicsContext3D::F RAGMENT_SHADER) {
1578 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "createShader", "inva lid shader type"); 1511 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "createShader", "inva lid shader type");
1579 return 0; 1512 return 0;
1580 } 1513 }
1581 1514
1582 RefPtr<WebGLShader> o = WebGLShader::create(this, type); 1515 RefPtr<WebGLShader> o = WebGLShader::create(this, type);
1583 addSharedObject(o.get()); 1516 addSharedObject(o.get());
1584 return o; 1517 return o;
1585 } 1518 }
1586 1519
1587 void WebGLRenderingContext::cullFace(GC3Denum mode) 1520 void WebGLRenderingContextBase::cullFace(GC3Denum mode)
1588 { 1521 {
1589 if (isContextLost()) 1522 if (isContextLost())
1590 return; 1523 return;
1591 switch (mode) { 1524 switch (mode) {
1592 case GraphicsContext3D::FRONT_AND_BACK: 1525 case GraphicsContext3D::FRONT_AND_BACK:
1593 case GraphicsContext3D::FRONT: 1526 case GraphicsContext3D::FRONT:
1594 case GraphicsContext3D::BACK: 1527 case GraphicsContext3D::BACK:
1595 break; 1528 break;
1596 default: 1529 default:
1597 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "cullFace", "invalid mode"); 1530 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "cullFace", "invalid mode");
1598 return; 1531 return;
1599 } 1532 }
1600 m_context->cullFace(mode); 1533 m_context->cullFace(mode);
1601 } 1534 }
1602 1535
1603 bool WebGLRenderingContext::deleteObject(WebGLObject* object) 1536 bool WebGLRenderingContextBase::deleteObject(WebGLObject* object)
1604 { 1537 {
1605 if (isContextLost() || !object) 1538 if (isContextLost() || !object)
1606 return false; 1539 return false;
1607 if (!object->validate(contextGroup(), this)) { 1540 if (!object->validate(contextGroup(), this)) {
1608 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "delete", "objec t does not belong to this context"); 1541 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "delete", "objec t does not belong to this context");
1609 return false; 1542 return false;
1610 } 1543 }
1611 if (object->object()) 1544 if (object->object()) {
1612 // We need to pass in context here because we want 1545 // We need to pass in context here because we want
1613 // things in this context unbound. 1546 // things in this context unbound.
1614 object->deleteObject(graphicsContext3D()); 1547 object->deleteObject(graphicsContext3D());
1548 }
1615 return true; 1549 return true;
1616 } 1550 }
1617 1551
1618 void WebGLRenderingContext::deleteBuffer(WebGLBuffer* buffer) 1552 void WebGLRenderingContextBase::deleteBuffer(WebGLBuffer* buffer)
1619 { 1553 {
1620 if (!deleteObject(buffer)) 1554 if (!deleteObject(buffer))
1621 return; 1555 return;
1622 if (m_boundArrayBuffer == buffer) 1556 if (m_boundArrayBuffer == buffer)
1623 m_boundArrayBuffer = 0; 1557 m_boundArrayBuffer = 0;
1624 1558
1625 m_boundVertexArrayObject->unbindBuffer(buffer); 1559 m_boundVertexArrayObject->unbindBuffer(buffer);
1626 } 1560 }
1627 1561
1628 void WebGLRenderingContext::deleteFramebuffer(WebGLFramebuffer* framebuffer) 1562 void WebGLRenderingContextBase::deleteFramebuffer(WebGLFramebuffer* framebuffer)
1629 { 1563 {
1630 if (!deleteObject(framebuffer)) 1564 if (!deleteObject(framebuffer))
1631 return; 1565 return;
1632 if (framebuffer == m_framebufferBinding) { 1566 if (framebuffer == m_framebufferBinding) {
1633 m_framebufferBinding = 0; 1567 m_framebufferBinding = 0;
1634 m_drawingBuffer->setFramebufferBinding(0); 1568 m_drawingBuffer->setFramebufferBinding(0);
1635 // Have to call bindFramebuffer here to bind back to internal fbo. 1569 // Have to call bindFramebuffer here to bind back to internal fbo.
1636 m_drawingBuffer->bind(); 1570 m_drawingBuffer->bind();
1637 } 1571 }
1638 } 1572 }
1639 1573
1640 void WebGLRenderingContext::deleteProgram(WebGLProgram* program) 1574 void WebGLRenderingContextBase::deleteProgram(WebGLProgram* program)
1641 { 1575 {
1642 deleteObject(program); 1576 deleteObject(program);
1643 // We don't reset m_currentProgram to 0 here because the deletion of the 1577 // We don't reset m_currentProgram to 0 here because the deletion of the
1644 // current program is delayed. 1578 // current program is delayed.
1645 } 1579 }
1646 1580
1647 void WebGLRenderingContext::deleteRenderbuffer(WebGLRenderbuffer* renderbuffer) 1581 void WebGLRenderingContextBase::deleteRenderbuffer(WebGLRenderbuffer* renderbuff er)
1648 { 1582 {
1649 if (!deleteObject(renderbuffer)) 1583 if (!deleteObject(renderbuffer))
1650 return; 1584 return;
1651 if (renderbuffer == m_renderbufferBinding) 1585 if (renderbuffer == m_renderbufferBinding)
1652 m_renderbufferBinding = 0; 1586 m_renderbufferBinding = 0;
1653 if (m_framebufferBinding) 1587 if (m_framebufferBinding)
1654 m_framebufferBinding->removeAttachmentFromBoundFramebuffer(renderbuffer) ; 1588 m_framebufferBinding->removeAttachmentFromBoundFramebuffer(renderbuffer) ;
1655 } 1589 }
1656 1590
1657 void WebGLRenderingContext::deleteShader(WebGLShader* shader) 1591 void WebGLRenderingContextBase::deleteShader(WebGLShader* shader)
1658 { 1592 {
1659 deleteObject(shader); 1593 deleteObject(shader);
1660 } 1594 }
1661 1595
1662 void WebGLRenderingContext::deleteTexture(WebGLTexture* texture) 1596 void WebGLRenderingContextBase::deleteTexture(WebGLTexture* texture)
1663 { 1597 {
1664 if (!deleteObject(texture)) 1598 if (!deleteObject(texture))
1665 return; 1599 return;
1666 1600
1667 int maxBoundTextureIndex = -1; 1601 int maxBoundTextureIndex = -1;
1668 for (size_t i = 0; i < m_onePlusMaxNonDefaultTextureUnit; ++i) { 1602 for (size_t i = 0; i < m_onePlusMaxNonDefaultTextureUnit; ++i) {
1669 if (texture == m_textureUnits[i].m_texture2DBinding) { 1603 if (texture == m_textureUnits[i].m_texture2DBinding) {
1670 m_textureUnits[i].m_texture2DBinding = 0; 1604 m_textureUnits[i].m_texture2DBinding = 0;
1671 maxBoundTextureIndex = i; 1605 maxBoundTextureIndex = i;
1672 if (!i) 1606 if (!i)
1673 m_drawingBuffer->setTexture2DBinding(0); 1607 m_drawingBuffer->setTexture2DBinding(0);
1674 } 1608 }
1675 if (texture == m_textureUnits[i].m_textureCubeMapBinding) { 1609 if (texture == m_textureUnits[i].m_textureCubeMapBinding) {
1676 m_textureUnits[i].m_textureCubeMapBinding = 0; 1610 m_textureUnits[i].m_textureCubeMapBinding = 0;
1677 maxBoundTextureIndex = i; 1611 maxBoundTextureIndex = i;
1678 } 1612 }
1679 } 1613 }
1680 if (m_framebufferBinding) 1614 if (m_framebufferBinding)
1681 m_framebufferBinding->removeAttachmentFromBoundFramebuffer(texture); 1615 m_framebufferBinding->removeAttachmentFromBoundFramebuffer(texture);
1682 1616
1683 // If the deleted was bound to the the current maximum index, trace backward s to find the new max texture index 1617 // If the deleted was bound to the the current maximum index, trace backward s to find the new max texture index
1684 if (m_onePlusMaxNonDefaultTextureUnit == maxBoundTextureIndex + 1) { 1618 if (m_onePlusMaxNonDefaultTextureUnit == maxBoundTextureIndex + 1) {
1685 findNewMaxNonDefaultTextureUnit(); 1619 findNewMaxNonDefaultTextureUnit();
1686 } 1620 }
1687 } 1621 }
1688 1622
1689 void WebGLRenderingContext::depthFunc(GC3Denum func) 1623 void WebGLRenderingContextBase::depthFunc(GC3Denum func)
1690 { 1624 {
1691 if (isContextLost()) 1625 if (isContextLost())
1692 return; 1626 return;
1693 if (!validateStencilOrDepthFunc("depthFunc", func)) 1627 if (!validateStencilOrDepthFunc("depthFunc", func))
1694 return; 1628 return;
1695 m_context->depthFunc(func); 1629 m_context->depthFunc(func);
1696 } 1630 }
1697 1631
1698 void WebGLRenderingContext::depthMask(GC3Dboolean flag) 1632 void WebGLRenderingContextBase::depthMask(GC3Dboolean flag)
1699 { 1633 {
1700 if (isContextLost()) 1634 if (isContextLost())
1701 return; 1635 return;
1702 m_depthMask = flag; 1636 m_depthMask = flag;
1703 m_context->depthMask(flag); 1637 m_context->depthMask(flag);
1704 } 1638 }
1705 1639
1706 void WebGLRenderingContext::depthRange(GC3Dfloat zNear, GC3Dfloat zFar) 1640 void WebGLRenderingContextBase::depthRange(GC3Dfloat zNear, GC3Dfloat zFar)
1707 { 1641 {
1708 if (isContextLost()) 1642 if (isContextLost())
1709 return; 1643 return;
1710 if (zNear > zFar) { 1644 if (zNear > zFar) {
1711 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "depthRange", "z Near > zFar"); 1645 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "depthRange", "z Near > zFar");
1712 return; 1646 return;
1713 } 1647 }
1714 m_context->depthRange(zNear, zFar); 1648 m_context->depthRange(zNear, zFar);
1715 } 1649 }
1716 1650
1717 void WebGLRenderingContext::detachShader(WebGLProgram* program, WebGLShader* sha der) 1651 void WebGLRenderingContextBase::detachShader(WebGLProgram* program, WebGLShader* shader)
1718 { 1652 {
1719 if (isContextLost() || !validateWebGLObject("detachShader", program) || !val idateWebGLObject("detachShader", shader)) 1653 if (isContextLost() || !validateWebGLObject("detachShader", program) || !val idateWebGLObject("detachShader", shader))
1720 return; 1654 return;
1721 if (!program->detachShader(shader)) { 1655 if (!program->detachShader(shader)) {
1722 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "detachShader", "shader not attached"); 1656 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "detachShader", "shader not attached");
1723 return; 1657 return;
1724 } 1658 }
1725 m_context->detachShader(objectOrZero(program), objectOrZero(shader)); 1659 m_context->detachShader(objectOrZero(program), objectOrZero(shader));
1726 shader->onDetached(graphicsContext3D()); 1660 shader->onDetached(graphicsContext3D());
1727 } 1661 }
1728 1662
1729 void WebGLRenderingContext::disable(GC3Denum cap) 1663 void WebGLRenderingContextBase::disable(GC3Denum cap)
1730 { 1664 {
1731 if (isContextLost() || !validateCapability("disable", cap)) 1665 if (isContextLost() || !validateCapability("disable", cap))
1732 return; 1666 return;
1733 if (cap == GraphicsContext3D::STENCIL_TEST) { 1667 if (cap == GraphicsContext3D::STENCIL_TEST) {
1734 m_stencilEnabled = false; 1668 m_stencilEnabled = false;
1735 applyStencilTest(); 1669 applyStencilTest();
1736 return; 1670 return;
1737 } 1671 }
1738 if (cap == GraphicsContext3D::SCISSOR_TEST) { 1672 if (cap == GraphicsContext3D::SCISSOR_TEST) {
1739 m_scissorEnabled = false; 1673 m_scissorEnabled = false;
1740 m_drawingBuffer->setScissorEnabled(m_scissorEnabled); 1674 m_drawingBuffer->setScissorEnabled(m_scissorEnabled);
1741 } 1675 }
1742 m_context->disable(cap); 1676 m_context->disable(cap);
1743 } 1677 }
1744 1678
1745 void WebGLRenderingContext::disableVertexAttribArray(GC3Duint index) 1679 void WebGLRenderingContextBase::disableVertexAttribArray(GC3Duint index)
1746 { 1680 {
1747 if (isContextLost()) 1681 if (isContextLost())
1748 return; 1682 return;
1749 if (index >= m_maxVertexAttribs) { 1683 if (index >= m_maxVertexAttribs) {
1750 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "disableVertexAttrib Array", "index out of range"); 1684 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "disableVertexAttrib Array", "index out of range");
1751 return; 1685 return;
1752 } 1686 }
1753 1687
1754 WebGLVertexArrayObjectOES::VertexAttribState& state = m_boundVertexArrayObje ct->getVertexAttribState(index); 1688 WebGLVertexArrayObjectOES::VertexAttribState& state = m_boundVertexArrayObje ct->getVertexAttribState(index);
1755 state.enabled = false; 1689 state.enabled = false;
1756 1690
1757 // If the disabled index is the current maximum, trace backwards to find the new max enabled attrib index 1691 // If the disabled index is the current maximum, trace backwards to find the new max enabled attrib index
1758 if (m_onePlusMaxEnabledAttribIndex == index + 1) { 1692 if (m_onePlusMaxEnabledAttribIndex == index + 1) {
1759 findNewMaxEnabledAttribIndex(); 1693 findNewMaxEnabledAttribIndex();
1760 } 1694 }
1761 1695
1762 m_context->disableVertexAttribArray(index); 1696 m_context->disableVertexAttribArray(index);
1763 } 1697 }
1764 1698
1765 bool WebGLRenderingContext::validateRenderingState() 1699 bool WebGLRenderingContextBase::validateRenderingState()
1766 { 1700 {
1767 if (!m_currentProgram) 1701 if (!m_currentProgram)
1768 return false; 1702 return false;
1769 1703
1770 // Look in each enabled vertex attrib and check if they've been bound to a b uffer. 1704 // Look in each enabled vertex attrib and check if they've been bound to a b uffer.
1771 for (unsigned i = 0; i < m_onePlusMaxEnabledAttribIndex; ++i) { 1705 for (unsigned i = 0; i < m_onePlusMaxEnabledAttribIndex; ++i) {
1772 const WebGLVertexArrayObjectOES::VertexAttribState& state = m_boundVerte xArrayObject->getVertexAttribState(i); 1706 const WebGLVertexArrayObjectOES::VertexAttribState& state = m_boundVerte xArrayObject->getVertexAttribState(i);
1773 if (state.enabled 1707 if (state.enabled
1774 && (!state.bufferBinding || !state.bufferBinding->object())) 1708 && (!state.bufferBinding || !state.bufferBinding->object()))
1775 return false; 1709 return false;
1776 } 1710 }
1777 1711
1778 return true; 1712 return true;
1779 } 1713 }
1780 1714
1781 bool WebGLRenderingContext::validateWebGLObject(const char* functionName, WebGLO bject* object) 1715 bool WebGLRenderingContextBase::validateWebGLObject(const char* functionName, We bGLObject* object)
1782 { 1716 {
1783 if (!object || !object->object()) { 1717 if (!object || !object->object()) {
1784 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no ob ject or object deleted"); 1718 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no ob ject or object deleted");
1785 return false; 1719 return false;
1786 } 1720 }
1787 if (!object->validate(contextGroup(), this)) { 1721 if (!object->validate(contextGroup(), this)) {
1788 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "o bject does not belong to this context"); 1722 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "o bject does not belong to this context");
1789 return false; 1723 return false;
1790 } 1724 }
1791 return true; 1725 return true;
1792 } 1726 }
1793 1727
1794 void WebGLRenderingContext::drawArrays(GC3Denum mode, GC3Dint first, GC3Dsizei c ount) 1728 void WebGLRenderingContextBase::drawArrays(GC3Denum mode, GC3Dint first, GC3Dsiz ei count)
1795 { 1729 {
1796 if (!validateDrawArrays("drawArrays", mode, first, count)) 1730 if (!validateDrawArrays("drawArrays", mode, first, count))
1797 return; 1731 return;
1798 1732
1799 clearIfComposited(); 1733 clearIfComposited();
1800 1734
1801 handleTextureCompleteness("drawArrays", true); 1735 handleTextureCompleteness("drawArrays", true);
1802 m_context->drawArrays(mode, first, count); 1736 m_context->drawArrays(mode, first, count);
1803 handleTextureCompleteness("drawArrays", false); 1737 handleTextureCompleteness("drawArrays", false);
1804 markContextChanged(); 1738 markContextChanged();
1805 } 1739 }
1806 1740
1807 void WebGLRenderingContext::drawElements(GC3Denum mode, GC3Dsizei count, GC3Denu m type, long long offset) 1741 void WebGLRenderingContextBase::drawElements(GC3Denum mode, GC3Dsizei count, GC3 Denum type, long long offset)
1808 { 1742 {
1809 if (!validateDrawElements("drawElements", mode, count, type, offset)) 1743 if (!validateDrawElements("drawElements", mode, count, type, offset))
1810 return; 1744 return;
1811 1745
1812 clearIfComposited(); 1746 clearIfComposited();
1813 1747
1814 handleTextureCompleteness("drawElements", true); 1748 handleTextureCompleteness("drawElements", true);
1815 m_context->drawElements(mode, count, type, static_cast<GC3Dintptr>(offset)); 1749 m_context->drawElements(mode, count, type, static_cast<GC3Dintptr>(offset));
1816 handleTextureCompleteness("drawElements", false); 1750 handleTextureCompleteness("drawElements", false);
1817 markContextChanged(); 1751 markContextChanged();
1818 } 1752 }
1819 1753
1820 void WebGLRenderingContext::drawArraysInstancedANGLE(GC3Denum mode, GC3Dint firs t, GC3Dsizei count, GC3Dsizei primcount) 1754 void WebGLRenderingContextBase::drawArraysInstancedANGLE(GC3Denum mode, GC3Dint first, GC3Dsizei count, GC3Dsizei primcount)
1821 { 1755 {
1822 if (!validateDrawArrays("drawArraysInstancedANGLE", mode, first, count)) 1756 if (!validateDrawArrays("drawArraysInstancedANGLE", mode, first, count))
1823 return; 1757 return;
1824 1758
1825 if (!validateDrawInstanced("drawArraysInstancedANGLE", primcount)) 1759 if (!validateDrawInstanced("drawArraysInstancedANGLE", primcount))
1826 return; 1760 return;
1827 1761
1828 clearIfComposited(); 1762 clearIfComposited();
1829 1763
1830 handleTextureCompleteness("drawArraysInstancedANGLE", true); 1764 handleTextureCompleteness("drawArraysInstancedANGLE", true);
1831 m_context->getExtensions()->drawArraysInstancedANGLE(mode, first, count, pri mcount); 1765 m_context->getExtensions()->drawArraysInstancedANGLE(mode, first, count, pri mcount);
1832 handleTextureCompleteness("drawArraysInstancedANGLE", false); 1766 handleTextureCompleteness("drawArraysInstancedANGLE", false);
1833 markContextChanged(); 1767 markContextChanged();
1834 } 1768 }
1835 1769
1836 void WebGLRenderingContext::drawElementsInstancedANGLE(GC3Denum mode, GC3Dsizei count, GC3Denum type, GC3Dintptr offset, GC3Dsizei primcount) 1770 void WebGLRenderingContextBase::drawElementsInstancedANGLE(GC3Denum mode, GC3Dsi zei count, GC3Denum type, GC3Dintptr offset, GC3Dsizei primcount)
1837 { 1771 {
1838 if (!validateDrawElements("drawElementsInstancedANGLE", mode, count, type, o ffset)) 1772 if (!validateDrawElements("drawElementsInstancedANGLE", mode, count, type, o ffset))
1839 return; 1773 return;
1840 1774
1841 if (!validateDrawInstanced("drawElementsInstancedANGLE", primcount)) 1775 if (!validateDrawInstanced("drawElementsInstancedANGLE", primcount))
1842 return; 1776 return;
1843 1777
1844 clearIfComposited(); 1778 clearIfComposited();
1845 1779
1846 handleTextureCompleteness("drawElementsInstancedANGLE", true); 1780 handleTextureCompleteness("drawElementsInstancedANGLE", true);
1847 m_context->getExtensions()->drawElementsInstancedANGLE(mode, count, type, st atic_cast<GC3Dintptr>(offset), primcount); 1781 m_context->getExtensions()->drawElementsInstancedANGLE(mode, count, type, st atic_cast<GC3Dintptr>(offset), primcount);
1848 handleTextureCompleteness("drawElementsInstancedANGLE", false); 1782 handleTextureCompleteness("drawElementsInstancedANGLE", false);
1849 markContextChanged(); 1783 markContextChanged();
1850 } 1784 }
1851 1785
1852 void WebGLRenderingContext::enable(GC3Denum cap) 1786 void WebGLRenderingContextBase::enable(GC3Denum cap)
1853 { 1787 {
1854 if (isContextLost() || !validateCapability("enable", cap)) 1788 if (isContextLost() || !validateCapability("enable", cap))
1855 return; 1789 return;
1856 if (cap == GraphicsContext3D::STENCIL_TEST) { 1790 if (cap == GraphicsContext3D::STENCIL_TEST) {
1857 m_stencilEnabled = true; 1791 m_stencilEnabled = true;
1858 applyStencilTest(); 1792 applyStencilTest();
1859 return; 1793 return;
1860 } 1794 }
1861 if (cap == GraphicsContext3D::SCISSOR_TEST) { 1795 if (cap == GraphicsContext3D::SCISSOR_TEST) {
1862 m_scissorEnabled = true; 1796 m_scissorEnabled = true;
1863 m_drawingBuffer->setScissorEnabled(m_scissorEnabled); 1797 m_drawingBuffer->setScissorEnabled(m_scissorEnabled);
1864 } 1798 }
1865 m_context->enable(cap); 1799 m_context->enable(cap);
1866 } 1800 }
1867 1801
1868 void WebGLRenderingContext::enableVertexAttribArray(GC3Duint index) 1802 void WebGLRenderingContextBase::enableVertexAttribArray(GC3Duint index)
1869 { 1803 {
1870 if (isContextLost()) 1804 if (isContextLost())
1871 return; 1805 return;
1872 if (index >= m_maxVertexAttribs) { 1806 if (index >= m_maxVertexAttribs) {
1873 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "enableVertexAttribA rray", "index out of range"); 1807 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "enableVertexAttribA rray", "index out of range");
1874 return; 1808 return;
1875 } 1809 }
1876 1810
1877 WebGLVertexArrayObjectOES::VertexAttribState& state = m_boundVertexArrayObje ct->getVertexAttribState(index); 1811 WebGLVertexArrayObjectOES::VertexAttribState& state = m_boundVertexArrayObje ct->getVertexAttribState(index);
1878 state.enabled = true; 1812 state.enabled = true;
1879 1813
1880 m_onePlusMaxEnabledAttribIndex = max(index + 1, m_onePlusMaxEnabledAttribInd ex); 1814 m_onePlusMaxEnabledAttribIndex = max(index + 1, m_onePlusMaxEnabledAttribInd ex);
1881 1815
1882 m_context->enableVertexAttribArray(index); 1816 m_context->enableVertexAttribArray(index);
1883 } 1817 }
1884 1818
1885 void WebGLRenderingContext::finish() 1819 void WebGLRenderingContextBase::finish()
1886 { 1820 {
1887 if (isContextLost()) 1821 if (isContextLost())
1888 return; 1822 return;
1889 m_context->flush(); // Intentionally a flush, not a finish. 1823 m_context->flush(); // Intentionally a flush, not a finish.
1890 } 1824 }
1891 1825
1892 void WebGLRenderingContext::flush() 1826 void WebGLRenderingContextBase::flush()
1893 { 1827 {
1894 if (isContextLost()) 1828 if (isContextLost())
1895 return; 1829 return;
1896 m_context->flush(); 1830 m_context->flush();
1897 } 1831 }
1898 1832
1899 void WebGLRenderingContext::framebufferRenderbuffer(GC3Denum target, GC3Denum at tachment, GC3Denum renderbuffertarget, WebGLRenderbuffer* buffer) 1833 void WebGLRenderingContextBase::framebufferRenderbuffer(GC3Denum target, GC3Denu m attachment, GC3Denum renderbuffertarget, WebGLRenderbuffer* buffer)
1900 { 1834 {
1901 if (isContextLost() || !validateFramebufferFuncParameters("framebufferRender buffer", target, attachment)) 1835 if (isContextLost() || !validateFramebufferFuncParameters("framebufferRender buffer", target, attachment))
1902 return; 1836 return;
1903 if (renderbuffertarget != GraphicsContext3D::RENDERBUFFER) { 1837 if (renderbuffertarget != GraphicsContext3D::RENDERBUFFER) {
1904 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "framebufferRenderbuf fer", "invalid target"); 1838 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "framebufferRenderbuf fer", "invalid target");
1905 return; 1839 return;
1906 } 1840 }
1907 if (buffer && !buffer->validate(contextGroup(), this)) { 1841 if (buffer && !buffer->validate(contextGroup(), this)) {
1908 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "framebufferRend erbuffer", "no buffer or buffer not from this context"); 1842 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "framebufferRend erbuffer", "no buffer or buffer not from this context");
1909 return; 1843 return;
(...skipping 21 matching lines...) Expand all
1931 m_context->framebufferRenderbuffer(target, GraphicsContext3D::STENCI L_ATTACHMENT, renderbuffertarget, objectOrZero(emulatedStencilBuffer)); 1865 m_context->framebufferRenderbuffer(target, GraphicsContext3D::STENCI L_ATTACHMENT, renderbuffertarget, objectOrZero(emulatedStencilBuffer));
1932 } 1866 }
1933 break; 1867 break;
1934 default: 1868 default:
1935 m_context->framebufferRenderbuffer(target, attachment, renderbuffertarge t, bufferObject); 1869 m_context->framebufferRenderbuffer(target, attachment, renderbuffertarge t, bufferObject);
1936 } 1870 }
1937 m_framebufferBinding->setAttachmentForBoundFramebuffer(attachment, buffer); 1871 m_framebufferBinding->setAttachmentForBoundFramebuffer(attachment, buffer);
1938 applyStencilTest(); 1872 applyStencilTest();
1939 } 1873 }
1940 1874
1941 void WebGLRenderingContext::framebufferTexture2D(GC3Denum target, GC3Denum attac hment, GC3Denum textarget, WebGLTexture* texture, GC3Dint level) 1875 void WebGLRenderingContextBase::framebufferTexture2D(GC3Denum target, GC3Denum a ttachment, GC3Denum textarget, WebGLTexture* texture, GC3Dint level)
1942 { 1876 {
1943 if (isContextLost() || !validateFramebufferFuncParameters("framebufferTextur e2D", target, attachment)) 1877 if (isContextLost() || !validateFramebufferFuncParameters("framebufferTextur e2D", target, attachment))
1944 return; 1878 return;
1945 if (level) { 1879 if (level) {
1946 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "framebufferTexture2 D", "level not 0"); 1880 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "framebufferTexture2 D", "level not 0");
1947 return; 1881 return;
1948 } 1882 }
1949 if (texture && !texture->validate(contextGroup(), this)) { 1883 if (texture && !texture->validate(contextGroup(), this)) {
1950 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "framebufferText ure2D", "no texture or texture not from this context"); 1884 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "framebufferText ure2D", "no texture or texture not from this context");
1951 return; 1885 return;
(...skipping 17 matching lines...) Expand all
1969 case GraphicsContext3D::STENCIL_ATTACHMENT: 1903 case GraphicsContext3D::STENCIL_ATTACHMENT:
1970 m_context->framebufferTexture2D(target, attachment, textarget, textureOb ject, level); 1904 m_context->framebufferTexture2D(target, attachment, textarget, textureOb ject, level);
1971 break; 1905 break;
1972 default: 1906 default:
1973 m_context->framebufferTexture2D(target, attachment, textarget, textureOb ject, level); 1907 m_context->framebufferTexture2D(target, attachment, textarget, textureOb ject, level);
1974 } 1908 }
1975 m_framebufferBinding->setAttachmentForBoundFramebuffer(attachment, textarget , texture, level); 1909 m_framebufferBinding->setAttachmentForBoundFramebuffer(attachment, textarget , texture, level);
1976 applyStencilTest(); 1910 applyStencilTest();
1977 } 1911 }
1978 1912
1979 void WebGLRenderingContext::frontFace(GC3Denum mode) 1913 void WebGLRenderingContextBase::frontFace(GC3Denum mode)
1980 { 1914 {
1981 if (isContextLost()) 1915 if (isContextLost())
1982 return; 1916 return;
1983 switch (mode) { 1917 switch (mode) {
1984 case GraphicsContext3D::CW: 1918 case GraphicsContext3D::CW:
1985 case GraphicsContext3D::CCW: 1919 case GraphicsContext3D::CCW:
1986 break; 1920 break;
1987 default: 1921 default:
1988 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "frontFace", "invalid mode"); 1922 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "frontFace", "invalid mode");
1989 return; 1923 return;
1990 } 1924 }
1991 m_context->frontFace(mode); 1925 m_context->frontFace(mode);
1992 } 1926 }
1993 1927
1994 void WebGLRenderingContext::generateMipmap(GC3Denum target) 1928 void WebGLRenderingContextBase::generateMipmap(GC3Denum target)
1995 { 1929 {
1996 if (isContextLost()) 1930 if (isContextLost())
1997 return; 1931 return;
1998 WebGLTexture* tex = validateTextureBinding("generateMipmap", target, false); 1932 WebGLTexture* tex = validateTextureBinding("generateMipmap", target, false);
1999 if (!tex) 1933 if (!tex)
2000 return; 1934 return;
2001 if (!tex->canGenerateMipmaps()) { 1935 if (!tex->canGenerateMipmaps()) {
2002 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "generateMipmap" , "level 0 not power of 2 or not all the same size"); 1936 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "generateMipmap" , "level 0 not power of 2 or not all the same size");
2003 return; 1937 return;
2004 } 1938 }
2005 if (!validateSettableTexFormat("generateMipmap", tex->getInternalFormat(targ et, 0))) 1939 if (!validateSettableTexFormat("generateMipmap", tex->getInternalFormat(targ et, 0)))
2006 return; 1940 return;
2007 1941
2008 // generateMipmap won't work properly if minFilter is not NEAREST_MIPMAP_LIN EAR 1942 // generateMipmap won't work properly if minFilter is not NEAREST_MIPMAP_LIN EAR
2009 // on Mac. Remove the hack once this driver bug is fixed. 1943 // on Mac. Remove the hack once this driver bug is fixed.
2010 #if OS(MACOSX) 1944 #if OS(MACOSX)
2011 bool needToResetMinFilter = false; 1945 bool needToResetMinFilter = false;
2012 if (tex->getMinFilter() != GraphicsContext3D::NEAREST_MIPMAP_LINEAR) { 1946 if (tex->getMinFilter() != GraphicsContext3D::NEAREST_MIPMAP_LINEAR) {
2013 m_context->texParameteri(target, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::NEAREST_MIPMAP_LINEAR); 1947 m_context->texParameteri(target, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::NEAREST_MIPMAP_LINEAR);
2014 needToResetMinFilter = true; 1948 needToResetMinFilter = true;
2015 } 1949 }
2016 #endif 1950 #endif
2017 m_context->generateMipmap(target); 1951 m_context->generateMipmap(target);
2018 #if OS(MACOSX) 1952 #if OS(MACOSX)
2019 if (needToResetMinFilter) 1953 if (needToResetMinFilter)
2020 m_context->texParameteri(target, GraphicsContext3D::TEXTURE_MIN_FILTER, tex->getMinFilter()); 1954 m_context->texParameteri(target, GraphicsContext3D::TEXTURE_MIN_FILTER, tex->getMinFilter());
2021 #endif 1955 #endif
2022 tex->generateMipmapLevelInfo(); 1956 tex->generateMipmapLevelInfo();
2023 } 1957 }
2024 1958
2025 PassRefPtr<WebGLActiveInfo> WebGLRenderingContext::getActiveAttrib(WebGLProgram* program, GC3Duint index) 1959 PassRefPtr<WebGLActiveInfo> WebGLRenderingContextBase::getActiveAttrib(WebGLProg ram* program, GC3Duint index)
2026 { 1960 {
2027 if (isContextLost() || !validateWebGLObject("getActiveAttrib", program)) 1961 if (isContextLost() || !validateWebGLObject("getActiveAttrib", program))
2028 return 0; 1962 return 0;
2029 ActiveInfo info; 1963 ActiveInfo info;
2030 if (!m_context->getActiveAttrib(objectOrZero(program), index, info)) 1964 if (!m_context->getActiveAttrib(objectOrZero(program), index, info))
2031 return 0; 1965 return 0;
2032 return WebGLActiveInfo::create(info.name, info.type, info.size); 1966 return WebGLActiveInfo::create(info.name, info.type, info.size);
2033 } 1967 }
2034 1968
2035 PassRefPtr<WebGLActiveInfo> WebGLRenderingContext::getActiveUniform(WebGLProgram * program, GC3Duint index) 1969 PassRefPtr<WebGLActiveInfo> WebGLRenderingContextBase::getActiveUniform(WebGLPro gram* program, GC3Duint index)
2036 { 1970 {
2037 if (isContextLost() || !validateWebGLObject("getActiveUniform", program)) 1971 if (isContextLost() || !validateWebGLObject("getActiveUniform", program))
2038 return 0; 1972 return 0;
2039 ActiveInfo info; 1973 ActiveInfo info;
2040 if (!m_context->getActiveUniform(objectOrZero(program), index, info)) 1974 if (!m_context->getActiveUniform(objectOrZero(program), index, info))
2041 return 0; 1975 return 0;
2042 return WebGLActiveInfo::create(info.name, info.type, info.size); 1976 return WebGLActiveInfo::create(info.name, info.type, info.size);
2043 } 1977 }
2044 1978
2045 bool WebGLRenderingContext::getAttachedShaders(WebGLProgram* program, Vector<Ref Ptr<WebGLShader> >& shaderObjects) 1979 bool WebGLRenderingContextBase::getAttachedShaders(WebGLProgram* program, Vector <RefPtr<WebGLShader> >& shaderObjects)
2046 { 1980 {
2047 shaderObjects.clear(); 1981 shaderObjects.clear();
2048 if (isContextLost() || !validateWebGLObject("getAttachedShaders", program)) 1982 if (isContextLost() || !validateWebGLObject("getAttachedShaders", program))
2049 return false; 1983 return false;
2050 1984
2051 const GC3Denum shaderType[] = { 1985 const GC3Denum shaderType[] = {
2052 GraphicsContext3D::VERTEX_SHADER, 1986 GraphicsContext3D::VERTEX_SHADER,
2053 GraphicsContext3D::FRAGMENT_SHADER 1987 GraphicsContext3D::FRAGMENT_SHADER
2054 }; 1988 };
2055 for (unsigned i = 0; i < sizeof(shaderType) / sizeof(GC3Denum); ++i) { 1989 for (unsigned i = 0; i < sizeof(shaderType) / sizeof(GC3Denum); ++i) {
2056 WebGLShader* shader = program->getAttachedShader(shaderType[i]); 1990 WebGLShader* shader = program->getAttachedShader(shaderType[i]);
2057 if (shader) 1991 if (shader)
2058 shaderObjects.append(shader); 1992 shaderObjects.append(shader);
2059 } 1993 }
2060 return true; 1994 return true;
2061 } 1995 }
2062 1996
2063 GC3Dint WebGLRenderingContext::getAttribLocation(WebGLProgram* program, const St ring& name) 1997 GC3Dint WebGLRenderingContextBase::getAttribLocation(WebGLProgram* program, cons t String& name)
2064 { 1998 {
2065 if (isContextLost() || !validateWebGLObject("getAttribLocation", program)) 1999 if (isContextLost() || !validateWebGLObject("getAttribLocation", program))
2066 return -1; 2000 return -1;
2067 if (!validateLocationLength("getAttribLocation", name)) 2001 if (!validateLocationLength("getAttribLocation", name))
2068 return -1; 2002 return -1;
2069 if (!validateString("getAttribLocation", name)) 2003 if (!validateString("getAttribLocation", name))
2070 return -1; 2004 return -1;
2071 if (isPrefixReserved(name)) 2005 if (isPrefixReserved(name))
2072 return -1; 2006 return -1;
2073 if (!program->getLinkStatus()) { 2007 if (!program->getLinkStatus()) {
2074 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "getAttribLocati on", "program not linked"); 2008 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "getAttribLocati on", "program not linked");
2075 return 0; 2009 return 0;
2076 } 2010 }
2077 return m_context->getAttribLocation(objectOrZero(program), name); 2011 return m_context->getAttribLocation(objectOrZero(program), name);
2078 } 2012 }
2079 2013
2080 WebGLGetInfo WebGLRenderingContext::getBufferParameter(GC3Denum target, GC3Denum pname) 2014 WebGLGetInfo WebGLRenderingContextBase::getBufferParameter(GC3Denum target, GC3D enum pname)
2081 { 2015 {
2082 if (isContextLost()) 2016 if (isContextLost())
2083 return WebGLGetInfo(); 2017 return WebGLGetInfo();
2084 if (target != GraphicsContext3D::ARRAY_BUFFER && target != GraphicsContext3D ::ELEMENT_ARRAY_BUFFER) { 2018 if (target != GraphicsContext3D::ARRAY_BUFFER && target != GraphicsContext3D ::ELEMENT_ARRAY_BUFFER) {
2085 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getBufferParameter", "invalid target"); 2019 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getBufferParameter", "invalid target");
2086 return WebGLGetInfo(); 2020 return WebGLGetInfo();
2087 } 2021 }
2088 2022
2089 if (pname != GraphicsContext3D::BUFFER_SIZE && pname != GraphicsContext3D::B UFFER_USAGE) { 2023 if (pname != GraphicsContext3D::BUFFER_SIZE && pname != GraphicsContext3D::B UFFER_USAGE) {
2090 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getBufferParameter", "invalid parameter name"); 2024 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getBufferParameter", "invalid parameter name");
2091 return WebGLGetInfo(); 2025 return WebGLGetInfo();
2092 } 2026 }
2093 2027
2094 GC3Dint value = 0; 2028 GC3Dint value = 0;
2095 m_context->getBufferParameteriv(target, pname, &value); 2029 m_context->getBufferParameteriv(target, pname, &value);
2096 if (pname == GraphicsContext3D::BUFFER_SIZE) 2030 if (pname == GraphicsContext3D::BUFFER_SIZE)
2097 return WebGLGetInfo(value); 2031 return WebGLGetInfo(value);
2098 return WebGLGetInfo(static_cast<unsigned int>(value)); 2032 return WebGLGetInfo(static_cast<unsigned>(value));
2099 } 2033 }
2100 2034
2101 PassRefPtr<WebGLContextAttributes> WebGLRenderingContext::getContextAttributes() 2035 PassRefPtr<WebGLContextAttributes> WebGLRenderingContextBase::getContextAttribut es()
2102 { 2036 {
2103 if (isContextLost()) 2037 if (isContextLost())
2104 return 0; 2038 return 0;
2105 // We always need to return a new WebGLContextAttributes object to 2039 // We always need to return a new WebGLContextAttributes object to
2106 // prevent the user from mutating any cached version. 2040 // prevent the user from mutating any cached version.
2107 2041
2108 // Also, we need to enforce requested values of "false" for depth 2042 // Also, we need to enforce requested values of "false" for depth
2109 // and stencil, regardless of the properties of the underlying 2043 // and stencil, regardless of the properties of the underlying
2110 // GraphicsContext3D or DrawingBuffer. 2044 // GraphicsContext3D or DrawingBuffer.
2111 RefPtr<WebGLContextAttributes> attributes = WebGLContextAttributes::create(m _context->getContextAttributes()); 2045 RefPtr<WebGLContextAttributes> attributes = WebGLContextAttributes::create(m _context->getContextAttributes());
2112 if (!m_attributes.depth) 2046 if (!m_attributes.depth)
2113 attributes->setDepth(false); 2047 attributes->setDepth(false);
2114 if (!m_attributes.stencil) 2048 if (!m_attributes.stencil)
2115 attributes->setStencil(false); 2049 attributes->setStencil(false);
2116 // The DrawingBuffer obtains its parameters from GraphicsContext3D::getConte xtAttributes(), 2050 // The DrawingBuffer obtains its parameters from GraphicsContext3D::getConte xtAttributes(),
2117 // but it makes its own determination of whether multisampling is supported. 2051 // but it makes its own determination of whether multisampling is supported.
2118 attributes->setAntialias(m_drawingBuffer->multisample()); 2052 attributes->setAntialias(m_drawingBuffer->multisample());
2119 return attributes.release(); 2053 return attributes.release();
2120 } 2054 }
2121 2055
2122 GC3Denum WebGLRenderingContext::getError() 2056 GC3Denum WebGLRenderingContextBase::getError()
2123 { 2057 {
2124 if (lost_context_errors_.size()) { 2058 if (m_lostContextErrors.size()) {
2125 GC3Denum err = lost_context_errors_.first(); 2059 GC3Denum err = m_lostContextErrors.first();
2126 lost_context_errors_.remove(0); 2060 m_lostContextErrors.remove(0);
2127 return err; 2061 return err;
2128 } 2062 }
2129 2063
2130 if (isContextLost()) 2064 if (isContextLost())
2131 return GraphicsContext3D::NO_ERROR; 2065 return GraphicsContext3D::NO_ERROR;
2132 2066
2133 return m_context->getError(); 2067 return m_context->getError();
2134 } 2068 }
2135 2069
2136 bool WebGLRenderingContext::ExtensionTracker::matchesNameWithPrefixes(const Stri ng& name) const 2070 bool WebGLRenderingContextBase::ExtensionTracker::matchesNameWithPrefixes(const String& name) const
2137 { 2071 {
2138 static const char* unprefixed[] = { "", 0, }; 2072 static const char* unprefixed[] = { "", 0, };
2139 2073
2140 const char** prefixes = m_prefixes ? m_prefixes : unprefixed; 2074 const char** prefixes = m_prefixes ? m_prefixes : unprefixed;
2141 for (; *prefixes; ++prefixes) { 2075 for (; *prefixes; ++prefixes) {
2142 String prefixedName = String(*prefixes) + getExtensionName(); 2076 String prefixedName = String(*prefixes) + getExtensionName();
2143 if (equalIgnoringCase(prefixedName, name)) { 2077 if (equalIgnoringCase(prefixedName, name)) {
2144 return true; 2078 return true;
2145 } 2079 }
2146 } 2080 }
2147 return false; 2081 return false;
2148 } 2082 }
2149 2083
2150 PassRefPtr<WebGLExtension> WebGLRenderingContext::getExtension(const String& nam e) 2084 PassRefPtr<WebGLExtension> WebGLRenderingContextBase::getExtension(const String& name)
2151 { 2085 {
2152 if (isContextLost()) 2086 if (isContextLost())
2153 return 0; 2087 return 0;
2154 2088
2155 for (size_t i = 0; i < m_extensions.size(); ++i) { 2089 for (size_t i = 0; i < m_extensions.size(); ++i) {
2156 ExtensionTracker* tracker = m_extensions[i]; 2090 ExtensionTracker* tracker = m_extensions[i];
2157 if (tracker->matchesNameWithPrefixes(name)) { 2091 if (tracker->matchesNameWithPrefixes(name)) {
2158 if (tracker->getPrivileged() && !allowPrivilegedExtensions()) 2092 if (tracker->getPrivileged() && !allowPrivilegedExtensions())
2159 return 0; 2093 return 0;
2160 if (tracker->getDraft() && !RuntimeEnabledFeatures::webGLDraftExtens ionsEnabled()) 2094 if (tracker->getDraft() && !RuntimeEnabledFeatures::webGLDraftExtens ionsEnabled())
2161 return 0; 2095 return 0;
2162 if (!tracker->supported(this)) 2096 if (!tracker->supported(this))
2163 return 0; 2097 return 0;
2164 return tracker->getExtension(this); 2098 return tracker->getExtension(this);
2165 } 2099 }
2166 } 2100 }
2167 2101
2168 return 0; 2102 return 0;
2169 } 2103 }
2170 2104
2171 WebGLGetInfo WebGLRenderingContext::getFramebufferAttachmentParameter(GC3Denum t arget, GC3Denum attachment, GC3Denum pname) 2105 WebGLGetInfo WebGLRenderingContextBase::getFramebufferAttachmentParameter(GC3Den um target, GC3Denum attachment, GC3Denum pname)
2172 { 2106 {
2173 if (isContextLost() || !validateFramebufferFuncParameters("getFramebufferAtt achmentParameter", target, attachment)) 2107 if (isContextLost() || !validateFramebufferFuncParameters("getFramebufferAtt achmentParameter", target, attachment))
2174 return WebGLGetInfo(); 2108 return WebGLGetInfo();
2175 2109
2176 if (!m_framebufferBinding || !m_framebufferBinding->object()) { 2110 if (!m_framebufferBinding || !m_framebufferBinding->object()) {
2177 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "getFramebufferA ttachmentParameter", "no framebuffer bound"); 2111 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "getFramebufferA ttachmentParameter", "no framebuffer bound");
2178 return WebGLGetInfo(); 2112 return WebGLGetInfo();
2179 } 2113 }
2180 2114
2181 WebGLSharedObject* object = m_framebufferBinding->getAttachmentObject(attach ment); 2115 WebGLSharedObject* object = m_framebufferBinding->getAttachmentObject(attach ment);
(...skipping 30 matching lines...) Expand all
2212 return WebGLGetInfo(GraphicsContext3D::RENDERBUFFER); 2146 return WebGLGetInfo(GraphicsContext3D::RENDERBUFFER);
2213 case GraphicsContext3D::FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: 2147 case GraphicsContext3D::FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
2214 return WebGLGetInfo(PassRefPtr<WebGLRenderbuffer>(static_cast<WebGLR enderbuffer*>(object))); 2148 return WebGLGetInfo(PassRefPtr<WebGLRenderbuffer>(static_cast<WebGLR enderbuffer*>(object)));
2215 default: 2149 default:
2216 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getFramebufferAt tachmentParameter", "invalid parameter name for renderbuffer attachment"); 2150 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getFramebufferAt tachmentParameter", "invalid parameter name for renderbuffer attachment");
2217 return WebGLGetInfo(); 2151 return WebGLGetInfo();
2218 } 2152 }
2219 } 2153 }
2220 } 2154 }
2221 2155
2222 WebGLGetInfo WebGLRenderingContext::getParameter(GC3Denum pname) 2156 WebGLGetInfo WebGLRenderingContextBase::getParameter(GC3Denum pname)
2223 { 2157 {
2224 if (isContextLost()) 2158 if (isContextLost())
2225 return WebGLGetInfo(); 2159 return WebGLGetInfo();
2226 const int intZero = 0; 2160 const int intZero = 0;
2227 switch (pname) { 2161 switch (pname) {
2228 case GraphicsContext3D::ACTIVE_TEXTURE: 2162 case GraphicsContext3D::ACTIVE_TEXTURE:
2229 return getUnsignedIntParameter(pname); 2163 return getUnsignedIntParameter(pname);
2230 case GraphicsContext3D::ALIASED_LINE_WIDTH_RANGE: 2164 case GraphicsContext3D::ALIASED_LINE_WIDTH_RANGE:
2231 return getWebGLFloatArrayParameter(pname); 2165 return getWebGLFloatArrayParameter(pname);
2232 case GraphicsContext3D::ALIASED_POINT_SIZE_RANGE: 2166 case GraphicsContext3D::ALIASED_POINT_SIZE_RANGE:
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
2449 value = m_framebufferBinding->getDrawBuffer(pname); 2383 value = m_framebufferBinding->getDrawBuffer(pname);
2450 else // emulated backbuffer 2384 else // emulated backbuffer
2451 value = m_backDrawBuffer; 2385 value = m_backDrawBuffer;
2452 return WebGLGetInfo(value); 2386 return WebGLGetInfo(value);
2453 } 2387 }
2454 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getParameter", "inva lid parameter name"); 2388 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getParameter", "inva lid parameter name");
2455 return WebGLGetInfo(); 2389 return WebGLGetInfo();
2456 } 2390 }
2457 } 2391 }
2458 2392
2459 WebGLGetInfo WebGLRenderingContext::getProgramParameter(WebGLProgram* program, G C3Denum pname) 2393 WebGLGetInfo WebGLRenderingContextBase::getProgramParameter(WebGLProgram* progra m, GC3Denum pname)
2460 { 2394 {
2461 if (isContextLost() || !validateWebGLObject("getProgramParameter", program)) 2395 if (isContextLost() || !validateWebGLObject("getProgramParameter", program))
2462 return WebGLGetInfo(); 2396 return WebGLGetInfo();
2463 2397
2464 GC3Dint value = 0; 2398 GC3Dint value = 0;
2465 switch (pname) { 2399 switch (pname) {
2466 case GraphicsContext3D::DELETE_STATUS: 2400 case GraphicsContext3D::DELETE_STATUS:
2467 return WebGLGetInfo(program->isDeleted()); 2401 return WebGLGetInfo(program->isDeleted());
2468 case GraphicsContext3D::VALIDATE_STATUS: 2402 case GraphicsContext3D::VALIDATE_STATUS:
2469 m_context->getProgramiv(objectOrZero(program), pname, &value); 2403 m_context->getProgramiv(objectOrZero(program), pname, &value);
2470 return WebGLGetInfo(static_cast<bool>(value)); 2404 return WebGLGetInfo(static_cast<bool>(value));
2471 case GraphicsContext3D::LINK_STATUS: 2405 case GraphicsContext3D::LINK_STATUS:
2472 return WebGLGetInfo(program->getLinkStatus()); 2406 return WebGLGetInfo(program->getLinkStatus());
2473 case GraphicsContext3D::ATTACHED_SHADERS: 2407 case GraphicsContext3D::ATTACHED_SHADERS:
2474 case GraphicsContext3D::ACTIVE_ATTRIBUTES: 2408 case GraphicsContext3D::ACTIVE_ATTRIBUTES:
2475 case GraphicsContext3D::ACTIVE_UNIFORMS: 2409 case GraphicsContext3D::ACTIVE_UNIFORMS:
2476 m_context->getProgramiv(objectOrZero(program), pname, &value); 2410 m_context->getProgramiv(objectOrZero(program), pname, &value);
2477 return WebGLGetInfo(value); 2411 return WebGLGetInfo(value);
2478 default: 2412 default:
2479 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getProgramParameter" , "invalid parameter name"); 2413 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getProgramParameter" , "invalid parameter name");
2480 return WebGLGetInfo(); 2414 return WebGLGetInfo();
2481 } 2415 }
2482 } 2416 }
2483 2417
2484 String WebGLRenderingContext::getProgramInfoLog(WebGLProgram* program) 2418 String WebGLRenderingContextBase::getProgramInfoLog(WebGLProgram* program)
2485 { 2419 {
2486 if (isContextLost()) 2420 if (isContextLost())
2487 return String(); 2421 return String();
2488 if (!validateWebGLObject("getProgramInfoLog", program)) 2422 if (!validateWebGLObject("getProgramInfoLog", program))
2489 return ""; 2423 return "";
2490 return ensureNotNull(m_context->getProgramInfoLog(objectOrZero(program))); 2424 return ensureNotNull(m_context->getProgramInfoLog(objectOrZero(program)));
2491 } 2425 }
2492 2426
2493 WebGLGetInfo WebGLRenderingContext::getRenderbufferParameter(GC3Denum target, GC 3Denum pname) 2427 WebGLGetInfo WebGLRenderingContextBase::getRenderbufferParameter(GC3Denum target , GC3Denum pname)
2494 { 2428 {
2495 if (isContextLost()) 2429 if (isContextLost())
2496 return WebGLGetInfo(); 2430 return WebGLGetInfo();
2497 if (target != GraphicsContext3D::RENDERBUFFER) { 2431 if (target != GraphicsContext3D::RENDERBUFFER) {
2498 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getRenderbufferParam eter", "invalid target"); 2432 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getRenderbufferParam eter", "invalid target");
2499 return WebGLGetInfo(); 2433 return WebGLGetInfo();
2500 } 2434 }
2501 if (!m_renderbufferBinding || !m_renderbufferBinding->object()) { 2435 if (!m_renderbufferBinding || !m_renderbufferBinding->object()) {
2502 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "getRenderbuffer Parameter", "no renderbuffer bound"); 2436 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "getRenderbuffer Parameter", "no renderbuffer bound");
2503 return WebGLGetInfo(); 2437 return WebGLGetInfo();
(...skipping 20 matching lines...) Expand all
2524 } 2458 }
2525 return WebGLGetInfo(value); 2459 return WebGLGetInfo(value);
2526 case GraphicsContext3D::RENDERBUFFER_INTERNAL_FORMAT: 2460 case GraphicsContext3D::RENDERBUFFER_INTERNAL_FORMAT:
2527 return WebGLGetInfo(m_renderbufferBinding->getInternalFormat()); 2461 return WebGLGetInfo(m_renderbufferBinding->getInternalFormat());
2528 default: 2462 default:
2529 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getRenderbufferParam eter", "invalid parameter name"); 2463 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getRenderbufferParam eter", "invalid parameter name");
2530 return WebGLGetInfo(); 2464 return WebGLGetInfo();
2531 } 2465 }
2532 } 2466 }
2533 2467
2534 WebGLGetInfo WebGLRenderingContext::getShaderParameter(WebGLShader* shader, GC3D enum pname) 2468 WebGLGetInfo WebGLRenderingContextBase::getShaderParameter(WebGLShader* shader, GC3Denum pname)
2535 { 2469 {
2536 if (isContextLost() || !validateWebGLObject("getShaderParameter", shader)) 2470 if (isContextLost() || !validateWebGLObject("getShaderParameter", shader))
2537 return WebGLGetInfo(); 2471 return WebGLGetInfo();
2538 GC3Dint value = 0; 2472 GC3Dint value = 0;
2539 switch (pname) { 2473 switch (pname) {
2540 case GraphicsContext3D::DELETE_STATUS: 2474 case GraphicsContext3D::DELETE_STATUS:
2541 return WebGLGetInfo(shader->isDeleted()); 2475 return WebGLGetInfo(shader->isDeleted());
2542 case GraphicsContext3D::COMPILE_STATUS: 2476 case GraphicsContext3D::COMPILE_STATUS:
2543 m_context->getShaderiv(objectOrZero(shader), pname, &value); 2477 m_context->getShaderiv(objectOrZero(shader), pname, &value);
2544 return WebGLGetInfo(static_cast<bool>(value)); 2478 return WebGLGetInfo(static_cast<bool>(value));
2545 case GraphicsContext3D::SHADER_TYPE: 2479 case GraphicsContext3D::SHADER_TYPE:
2546 m_context->getShaderiv(objectOrZero(shader), pname, &value); 2480 m_context->getShaderiv(objectOrZero(shader), pname, &value);
2547 return WebGLGetInfo(static_cast<unsigned int>(value)); 2481 return WebGLGetInfo(static_cast<unsigned>(value));
2548 default: 2482 default:
2549 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getShaderParameter", "invalid parameter name"); 2483 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getShaderParameter", "invalid parameter name");
2550 return WebGLGetInfo(); 2484 return WebGLGetInfo();
2551 } 2485 }
2552 } 2486 }
2553 2487
2554 String WebGLRenderingContext::getShaderInfoLog(WebGLShader* shader) 2488 String WebGLRenderingContextBase::getShaderInfoLog(WebGLShader* shader)
2555 { 2489 {
2556 if (isContextLost()) 2490 if (isContextLost())
2557 return String(); 2491 return String();
2558 if (!validateWebGLObject("getShaderInfoLog", shader)) 2492 if (!validateWebGLObject("getShaderInfoLog", shader))
2559 return ""; 2493 return "";
2560 return ensureNotNull(m_context->getShaderInfoLog(objectOrZero(shader))); 2494 return ensureNotNull(m_context->getShaderInfoLog(objectOrZero(shader)));
2561 } 2495 }
2562 2496
2563 PassRefPtr<WebGLShaderPrecisionFormat> WebGLRenderingContext::getShaderPrecision Format(GC3Denum shaderType, GC3Denum precisionType) 2497 PassRefPtr<WebGLShaderPrecisionFormat> WebGLRenderingContextBase::getShaderPreci sionFormat(GC3Denum shaderType, GC3Denum precisionType)
2564 { 2498 {
2565 if (isContextLost()) 2499 if (isContextLost())
2566 return 0; 2500 return 0;
2567 switch (shaderType) { 2501 switch (shaderType) {
2568 case GraphicsContext3D::VERTEX_SHADER: 2502 case GraphicsContext3D::VERTEX_SHADER:
2569 case GraphicsContext3D::FRAGMENT_SHADER: 2503 case GraphicsContext3D::FRAGMENT_SHADER:
2570 break; 2504 break;
2571 default: 2505 default:
2572 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getShaderPrecisionFo rmat", "invalid shader type"); 2506 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getShaderPrecisionFo rmat", "invalid shader type");
2573 return 0; 2507 return 0;
(...skipping 10 matching lines...) Expand all
2584 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getShaderPrecisionFo rmat", "invalid precision type"); 2518 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getShaderPrecisionFo rmat", "invalid precision type");
2585 return 0; 2519 return 0;
2586 } 2520 }
2587 2521
2588 GC3Dint range[2] = {0, 0}; 2522 GC3Dint range[2] = {0, 0};
2589 GC3Dint precision = 0; 2523 GC3Dint precision = 0;
2590 m_context->getShaderPrecisionFormat(shaderType, precisionType, range, &preci sion); 2524 m_context->getShaderPrecisionFormat(shaderType, precisionType, range, &preci sion);
2591 return WebGLShaderPrecisionFormat::create(range[0], range[1], precision); 2525 return WebGLShaderPrecisionFormat::create(range[0], range[1], precision);
2592 } 2526 }
2593 2527
2594 String WebGLRenderingContext::getShaderSource(WebGLShader* shader) 2528 String WebGLRenderingContextBase::getShaderSource(WebGLShader* shader)
2595 { 2529 {
2596 if (isContextLost()) 2530 if (isContextLost())
2597 return String(); 2531 return String();
2598 if (!validateWebGLObject("getShaderSource", shader)) 2532 if (!validateWebGLObject("getShaderSource", shader))
2599 return ""; 2533 return "";
2600 return ensureNotNull(shader->getSource()); 2534 return ensureNotNull(shader->getSource());
2601 } 2535 }
2602 2536
2603 Vector<String> WebGLRenderingContext::getSupportedExtensions() 2537 Vector<String> WebGLRenderingContextBase::getSupportedExtensions()
2604 { 2538 {
2605 Vector<String> result; 2539 Vector<String> result;
2606 if (isContextLost()) 2540 if (isContextLost())
2607 return result; 2541 return result;
2608 2542
2609 for (size_t i = 0; i < m_extensions.size(); ++i) { 2543 for (size_t i = 0; i < m_extensions.size(); ++i) {
2610 ExtensionTracker* tracker = m_extensions[i]; 2544 ExtensionTracker* tracker = m_extensions[i];
2611 if (tracker->getPrivileged() && !allowPrivilegedExtensions()) 2545 if (tracker->getPrivileged() && !allowPrivilegedExtensions())
2612 continue; 2546 continue;
2613 if (tracker->getDraft() && !RuntimeEnabledFeatures::webGLDraftExtensions Enabled()) 2547 if (tracker->getDraft() && !RuntimeEnabledFeatures::webGLDraftExtensions Enabled())
2614 continue; 2548 continue;
2615 if (tracker->supported(this)) 2549 if (tracker->supported(this))
2616 result.append(String(tracker->getPrefixed() ? "WEBKIT_" : "") + tra cker->getExtensionName()); 2550 result.append(String(tracker->getPrefixed() ? "WEBKIT_" : "") + tra cker->getExtensionName());
2617 } 2551 }
2618 2552
2619 return result; 2553 return result;
2620 } 2554 }
2621 2555
2622 WebGLGetInfo WebGLRenderingContext::getTexParameter(GC3Denum target, GC3Denum pn ame) 2556 WebGLGetInfo WebGLRenderingContextBase::getTexParameter(GC3Denum target, GC3Denu m pname)
2623 { 2557 {
2624 if (isContextLost()) 2558 if (isContextLost())
2625 return WebGLGetInfo(); 2559 return WebGLGetInfo();
2626 WebGLTexture* tex = validateTextureBinding("getTexParameter", target, false) ; 2560 WebGLTexture* tex = validateTextureBinding("getTexParameter", target, false) ;
2627 if (!tex) 2561 if (!tex)
2628 return WebGLGetInfo(); 2562 return WebGLGetInfo();
2629 GC3Dint value = 0; 2563 GC3Dint value = 0;
2630 switch (pname) { 2564 switch (pname) {
2631 case GraphicsContext3D::TEXTURE_MAG_FILTER: 2565 case GraphicsContext3D::TEXTURE_MAG_FILTER:
2632 case GraphicsContext3D::TEXTURE_MIN_FILTER: 2566 case GraphicsContext3D::TEXTURE_MIN_FILTER:
2633 case GraphicsContext3D::TEXTURE_WRAP_S: 2567 case GraphicsContext3D::TEXTURE_WRAP_S:
2634 case GraphicsContext3D::TEXTURE_WRAP_T: 2568 case GraphicsContext3D::TEXTURE_WRAP_T:
2635 m_context->getTexParameteriv(target, pname, &value); 2569 m_context->getTexParameteriv(target, pname, &value);
2636 return WebGLGetInfo(static_cast<unsigned int>(value)); 2570 return WebGLGetInfo(static_cast<unsigned>(value));
2637 case Extensions3D::TEXTURE_MAX_ANISOTROPY_EXT: // EXT_texture_filter_anisotr opic 2571 case Extensions3D::TEXTURE_MAX_ANISOTROPY_EXT: // EXT_texture_filter_anisotr opic
2638 if (m_extTextureFilterAnisotropic) { 2572 if (m_extTextureFilterAnisotropic) {
2639 m_context->getTexParameteriv(target, pname, &value); 2573 m_context->getTexParameteriv(target, pname, &value);
2640 return WebGLGetInfo(static_cast<unsigned int>(value)); 2574 return WebGLGetInfo(static_cast<unsigned>(value));
2641 } 2575 }
2642 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getTexParameter", "i nvalid parameter name, EXT_texture_filter_anisotropic not enabled"); 2576 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getTexParameter", "i nvalid parameter name, EXT_texture_filter_anisotropic not enabled");
2643 return WebGLGetInfo(); 2577 return WebGLGetInfo();
2644 default: 2578 default:
2645 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getTexParameter", "i nvalid parameter name"); 2579 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getTexParameter", "i nvalid parameter name");
2646 return WebGLGetInfo(); 2580 return WebGLGetInfo();
2647 } 2581 }
2648 } 2582 }
2649 2583
2650 WebGLGetInfo WebGLRenderingContext::getUniform(WebGLProgram* program, const WebG LUniformLocation* uniformLocation) 2584 WebGLGetInfo WebGLRenderingContextBase::getUniform(WebGLProgram* program, const WebGLUniformLocation* uniformLocation)
2651 { 2585 {
2652 if (isContextLost() || !validateWebGLObject("getUniform", program)) 2586 if (isContextLost() || !validateWebGLObject("getUniform", program))
2653 return WebGLGetInfo(); 2587 return WebGLGetInfo();
2654 if (!uniformLocation || uniformLocation->program() != program) { 2588 if (!uniformLocation || uniformLocation->program() != program) {
2655 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "getUniform", "n o uniformlocation or not valid for this program"); 2589 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "getUniform", "n o uniformlocation or not valid for this program");
2656 return WebGLGetInfo(); 2590 return WebGLGetInfo();
2657 } 2591 }
2658 GC3Dint location = uniformLocation->location(); 2592 GC3Dint location = uniformLocation->location();
2659 2593
2660 // FIXME: make this more efficient using WebGLUniformLocation and caching ty pes in it 2594 // FIXME: make this more efficient using WebGLUniformLocation and caching ty pes in it
(...skipping 12 matching lines...) Expand all
2673 if (info.size > 1 && index >= 1) { 2607 if (info.size > 1 && index >= 1) {
2674 name.append('['); 2608 name.append('[');
2675 name.append(String::number(index)); 2609 name.append(String::number(index));
2676 name.append(']'); 2610 name.append(']');
2677 } 2611 }
2678 // Now need to look this up by name again to find its location 2612 // Now need to look this up by name again to find its location
2679 GC3Dint loc = m_context->getUniformLocation(objectOrZero(program), n ame); 2613 GC3Dint loc = m_context->getUniformLocation(objectOrZero(program), n ame);
2680 if (loc == location) { 2614 if (loc == location) {
2681 // Found it. Use the type in the ActiveInfo to determine the ret urn type. 2615 // Found it. Use the type in the ActiveInfo to determine the ret urn type.
2682 GC3Denum baseType; 2616 GC3Denum baseType;
2683 unsigned int length; 2617 unsigned length;
2684 switch (info.type) { 2618 switch (info.type) {
2685 case GraphicsContext3D::BOOL: 2619 case GraphicsContext3D::BOOL:
2686 baseType = GraphicsContext3D::BOOL; 2620 baseType = GraphicsContext3D::BOOL;
2687 length = 1; 2621 length = 1;
2688 break; 2622 break;
2689 case GraphicsContext3D::BOOL_VEC2: 2623 case GraphicsContext3D::BOOL_VEC2:
2690 baseType = GraphicsContext3D::BOOL; 2624 baseType = GraphicsContext3D::BOOL;
2691 length = 2; 2625 length = 2;
2692 break; 2626 break;
2693 case GraphicsContext3D::BOOL_VEC3: 2627 case GraphicsContext3D::BOOL_VEC3:
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
2782 notImplemented(); 2716 notImplemented();
2783 } 2717 }
2784 } 2718 }
2785 } 2719 }
2786 } 2720 }
2787 // If we get here, something went wrong in our unfortunately complex logic a bove 2721 // If we get here, something went wrong in our unfortunately complex logic a bove
2788 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "getUniform", "unknown e rror"); 2722 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "getUniform", "unknown e rror");
2789 return WebGLGetInfo(); 2723 return WebGLGetInfo();
2790 } 2724 }
2791 2725
2792 PassRefPtr<WebGLUniformLocation> WebGLRenderingContext::getUniformLocation(WebGL Program* program, const String& name) 2726 PassRefPtr<WebGLUniformLocation> WebGLRenderingContextBase::getUniformLocation(W ebGLProgram* program, const String& name)
2793 { 2727 {
2794 if (isContextLost() || !validateWebGLObject("getUniformLocation", program)) 2728 if (isContextLost() || !validateWebGLObject("getUniformLocation", program))
2795 return 0; 2729 return 0;
2796 if (!validateLocationLength("getUniformLocation", name)) 2730 if (!validateLocationLength("getUniformLocation", name))
2797 return 0; 2731 return 0;
2798 if (!validateString("getUniformLocation", name)) 2732 if (!validateString("getUniformLocation", name))
2799 return 0; 2733 return 0;
2800 if (isPrefixReserved(name)) 2734 if (isPrefixReserved(name))
2801 return 0; 2735 return 0;
2802 if (!program->getLinkStatus()) { 2736 if (!program->getLinkStatus()) {
2803 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "getUniformLocat ion", "program not linked"); 2737 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "getUniformLocat ion", "program not linked");
2804 return 0; 2738 return 0;
2805 } 2739 }
2806 GC3Dint uniformLocation = m_context->getUniformLocation(objectOrZero(program ), name); 2740 GC3Dint uniformLocation = m_context->getUniformLocation(objectOrZero(program ), name);
2807 if (uniformLocation == -1) 2741 if (uniformLocation == -1)
2808 return 0; 2742 return 0;
2809 return WebGLUniformLocation::create(program, uniformLocation); 2743 return WebGLUniformLocation::create(program, uniformLocation);
2810 } 2744 }
2811 2745
2812 WebGLGetInfo WebGLRenderingContext::getVertexAttrib(GC3Duint index, GC3Denum pna me) 2746 WebGLGetInfo WebGLRenderingContextBase::getVertexAttrib(GC3Duint index, GC3Denum pname)
2813 { 2747 {
2814 if (isContextLost()) 2748 if (isContextLost())
2815 return WebGLGetInfo(); 2749 return WebGLGetInfo();
2816 if (index >= m_maxVertexAttribs) { 2750 if (index >= m_maxVertexAttribs) {
2817 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "getVertexAttrib", " index out of range"); 2751 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "getVertexAttrib", " index out of range");
2818 return WebGLGetInfo(); 2752 return WebGLGetInfo();
2819 } 2753 }
2820 const WebGLVertexArrayObjectOES::VertexAttribState& state = m_boundVertexArr ayObject->getVertexAttribState(index); 2754 const WebGLVertexArrayObjectOES::VertexAttribState& state = m_boundVertexArr ayObject->getVertexAttribState(index);
2821 2755
2822 if (m_angleInstancedArrays && pname == Extensions3D::VERTEX_ATTRIB_ARRAY_DIV ISOR_ANGLE) 2756 if (m_angleInstancedArrays && pname == Extensions3D::VERTEX_ATTRIB_ARRAY_DIV ISOR_ANGLE)
(...skipping 15 matching lines...) Expand all
2838 case GraphicsContext3D::VERTEX_ATTRIB_ARRAY_TYPE: 2772 case GraphicsContext3D::VERTEX_ATTRIB_ARRAY_TYPE:
2839 return WebGLGetInfo(state.type); 2773 return WebGLGetInfo(state.type);
2840 case GraphicsContext3D::CURRENT_VERTEX_ATTRIB: 2774 case GraphicsContext3D::CURRENT_VERTEX_ATTRIB:
2841 return WebGLGetInfo(Float32Array::create(m_vertexAttribValue[index].valu e, 4)); 2775 return WebGLGetInfo(Float32Array::create(m_vertexAttribValue[index].valu e, 4));
2842 default: 2776 default:
2843 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getVertexAttrib", "i nvalid parameter name"); 2777 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getVertexAttrib", "i nvalid parameter name");
2844 return WebGLGetInfo(); 2778 return WebGLGetInfo();
2845 } 2779 }
2846 } 2780 }
2847 2781
2848 long long WebGLRenderingContext::getVertexAttribOffset(GC3Duint index, GC3Denum pname) 2782 long long WebGLRenderingContextBase::getVertexAttribOffset(GC3Duint index, GC3De num pname)
2849 { 2783 {
2850 if (isContextLost()) 2784 if (isContextLost())
2851 return 0; 2785 return 0;
2852 if (pname != GraphicsContext3D::VERTEX_ATTRIB_ARRAY_POINTER) { 2786 if (pname != GraphicsContext3D::VERTEX_ATTRIB_ARRAY_POINTER) {
2853 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getVertexAttribOffse t", "invalid parameter name"); 2787 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "getVertexAttribOffse t", "invalid parameter name");
2854 return 0; 2788 return 0;
2855 } 2789 }
2856 GC3Dsizeiptr result = m_context->getVertexAttribOffset(index, pname); 2790 GC3Dsizeiptr result = m_context->getVertexAttribOffset(index, pname);
2857 return static_cast<long long>(result); 2791 return static_cast<long long>(result);
2858 } 2792 }
2859 2793
2860 void WebGLRenderingContext::hint(GC3Denum target, GC3Denum mode) 2794 void WebGLRenderingContextBase::hint(GC3Denum target, GC3Denum mode)
2861 { 2795 {
2862 if (isContextLost()) 2796 if (isContextLost())
2863 return; 2797 return;
2864 bool isValid = false; 2798 bool isValid = false;
2865 switch (target) { 2799 switch (target) {
2866 case GraphicsContext3D::GENERATE_MIPMAP_HINT: 2800 case GraphicsContext3D::GENERATE_MIPMAP_HINT:
2867 isValid = true; 2801 isValid = true;
2868 break; 2802 break;
2869 case Extensions3D::FRAGMENT_SHADER_DERIVATIVE_HINT_OES: // OES_standard_deri vatives 2803 case Extensions3D::FRAGMENT_SHADER_DERIVATIVE_HINT_OES: // OES_standard_deri vatives
2870 if (m_oesStandardDerivatives) 2804 if (m_oesStandardDerivatives)
2871 isValid = true; 2805 isValid = true;
2872 break; 2806 break;
2873 } 2807 }
2874 if (!isValid) { 2808 if (!isValid) {
2875 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "hint", "invalid targ et"); 2809 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "hint", "invalid targ et");
2876 return; 2810 return;
2877 } 2811 }
2878 m_context->hint(target, mode); 2812 m_context->hint(target, mode);
2879 } 2813 }
2880 2814
2881 GC3Dboolean WebGLRenderingContext::isBuffer(WebGLBuffer* buffer) 2815 GC3Dboolean WebGLRenderingContextBase::isBuffer(WebGLBuffer* buffer)
2882 { 2816 {
2883 if (!buffer || isContextLost()) 2817 if (!buffer || isContextLost())
2884 return 0; 2818 return 0;
2885 2819
2886 if (!buffer->hasEverBeenBound()) 2820 if (!buffer->hasEverBeenBound())
2887 return 0; 2821 return 0;
2888 2822
2889 return m_context->isBuffer(buffer->object()); 2823 return m_context->isBuffer(buffer->object());
2890 } 2824 }
2891 2825
2892 bool WebGLRenderingContext::isContextLost() 2826 bool WebGLRenderingContextBase::isContextLost()
2893 { 2827 {
2894 return m_contextLost; 2828 return m_contextLost;
2895 } 2829 }
2896 2830
2897 GC3Dboolean WebGLRenderingContext::isEnabled(GC3Denum cap) 2831 GC3Dboolean WebGLRenderingContextBase::isEnabled(GC3Denum cap)
2898 { 2832 {
2899 if (isContextLost() || !validateCapability("isEnabled", cap)) 2833 if (isContextLost() || !validateCapability("isEnabled", cap))
2900 return 0; 2834 return 0;
2901 if (cap == GraphicsContext3D::STENCIL_TEST) 2835 if (cap == GraphicsContext3D::STENCIL_TEST)
2902 return m_stencilEnabled; 2836 return m_stencilEnabled;
2903 return m_context->isEnabled(cap); 2837 return m_context->isEnabled(cap);
2904 } 2838 }
2905 2839
2906 GC3Dboolean WebGLRenderingContext::isFramebuffer(WebGLFramebuffer* framebuffer) 2840 GC3Dboolean WebGLRenderingContextBase::isFramebuffer(WebGLFramebuffer* framebuff er)
2907 { 2841 {
2908 if (!framebuffer || isContextLost()) 2842 if (!framebuffer || isContextLost())
2909 return 0; 2843 return 0;
2910 2844
2911 if (!framebuffer->hasEverBeenBound()) 2845 if (!framebuffer->hasEverBeenBound())
2912 return 0; 2846 return 0;
2913 2847
2914 return m_context->isFramebuffer(framebuffer->object()); 2848 return m_context->isFramebuffer(framebuffer->object());
2915 } 2849 }
2916 2850
2917 GC3Dboolean WebGLRenderingContext::isProgram(WebGLProgram* program) 2851 GC3Dboolean WebGLRenderingContextBase::isProgram(WebGLProgram* program)
2918 { 2852 {
2919 if (!program || isContextLost()) 2853 if (!program || isContextLost())
2920 return 0; 2854 return 0;
2921 2855
2922 return m_context->isProgram(program->object()); 2856 return m_context->isProgram(program->object());
2923 } 2857 }
2924 2858
2925 GC3Dboolean WebGLRenderingContext::isRenderbuffer(WebGLRenderbuffer* renderbuffe r) 2859 GC3Dboolean WebGLRenderingContextBase::isRenderbuffer(WebGLRenderbuffer* renderb uffer)
2926 { 2860 {
2927 if (!renderbuffer || isContextLost()) 2861 if (!renderbuffer || isContextLost())
2928 return 0; 2862 return 0;
2929 2863
2930 if (!renderbuffer->hasEverBeenBound()) 2864 if (!renderbuffer->hasEverBeenBound())
2931 return 0; 2865 return 0;
2932 2866
2933 return m_context->isRenderbuffer(renderbuffer->object()); 2867 return m_context->isRenderbuffer(renderbuffer->object());
2934 } 2868 }
2935 2869
2936 GC3Dboolean WebGLRenderingContext::isShader(WebGLShader* shader) 2870 GC3Dboolean WebGLRenderingContextBase::isShader(WebGLShader* shader)
2937 { 2871 {
2938 if (!shader || isContextLost()) 2872 if (!shader || isContextLost())
2939 return 0; 2873 return 0;
2940 2874
2941 return m_context->isShader(shader->object()); 2875 return m_context->isShader(shader->object());
2942 } 2876 }
2943 2877
2944 GC3Dboolean WebGLRenderingContext::isTexture(WebGLTexture* texture) 2878 GC3Dboolean WebGLRenderingContextBase::isTexture(WebGLTexture* texture)
2945 { 2879 {
2946 if (!texture || isContextLost()) 2880 if (!texture || isContextLost())
2947 return 0; 2881 return 0;
2948 2882
2949 if (!texture->hasEverBeenBound()) 2883 if (!texture->hasEverBeenBound())
2950 return 0; 2884 return 0;
2951 2885
2952 return m_context->isTexture(texture->object()); 2886 return m_context->isTexture(texture->object());
2953 } 2887 }
2954 2888
2955 void WebGLRenderingContext::lineWidth(GC3Dfloat width) 2889 void WebGLRenderingContextBase::lineWidth(GC3Dfloat width)
2956 { 2890 {
2957 if (isContextLost()) 2891 if (isContextLost())
2958 return; 2892 return;
2959 m_context->lineWidth(width); 2893 m_context->lineWidth(width);
2960 } 2894 }
2961 2895
2962 void WebGLRenderingContext::linkProgram(WebGLProgram* program) 2896 void WebGLRenderingContextBase::linkProgram(WebGLProgram* program)
2963 { 2897 {
2964 if (isContextLost() || !validateWebGLObject("linkProgram", program)) 2898 if (isContextLost() || !validateWebGLObject("linkProgram", program))
2965 return; 2899 return;
2966 2900
2967 m_context->linkProgram(objectOrZero(program)); 2901 m_context->linkProgram(objectOrZero(program));
2968 program->increaseLinkCount(); 2902 program->increaseLinkCount();
2969 } 2903 }
2970 2904
2971 void WebGLRenderingContext::pixelStorei(GC3Denum pname, GC3Dint param) 2905 void WebGLRenderingContextBase::pixelStorei(GC3Denum pname, GC3Dint param)
2972 { 2906 {
2973 if (isContextLost()) 2907 if (isContextLost())
2974 return; 2908 return;
2975 switch (pname) { 2909 switch (pname) {
2976 case GraphicsContext3D::UNPACK_FLIP_Y_WEBGL: 2910 case GraphicsContext3D::UNPACK_FLIP_Y_WEBGL:
2977 m_unpackFlipY = param; 2911 m_unpackFlipY = param;
2978 break; 2912 break;
2979 case GraphicsContext3D::UNPACK_PREMULTIPLY_ALPHA_WEBGL: 2913 case GraphicsContext3D::UNPACK_PREMULTIPLY_ALPHA_WEBGL:
2980 m_unpackPremultiplyAlpha = param; 2914 m_unpackPremultiplyAlpha = param;
2981 break; 2915 break;
2982 case GraphicsContext3D::UNPACK_COLORSPACE_CONVERSION_WEBGL: 2916 case GraphicsContext3D::UNPACK_COLORSPACE_CONVERSION_WEBGL:
2983 if (param == GraphicsContext3D::BROWSER_DEFAULT_WEBGL || param == Graphi csContext3D::NONE) 2917 if (param == GraphicsContext3D::BROWSER_DEFAULT_WEBGL || param == Graphi csContext3D::NONE) {
2984 m_unpackColorspaceConversion = static_cast<GC3Denum>(param); 2918 m_unpackColorspaceConversion = static_cast<GC3Denum>(param);
2985 else { 2919 } else {
2986 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "pixelStorei", " invalid parameter for UNPACK_COLORSPACE_CONVERSION_WEBGL"); 2920 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "pixelStorei", " invalid parameter for UNPACK_COLORSPACE_CONVERSION_WEBGL");
2987 return; 2921 return;
2988 } 2922 }
2989 break; 2923 break;
2990 case GraphicsContext3D::PACK_ALIGNMENT: 2924 case GraphicsContext3D::PACK_ALIGNMENT:
2991 case GraphicsContext3D::UNPACK_ALIGNMENT: 2925 case GraphicsContext3D::UNPACK_ALIGNMENT:
2992 if (param == 1 || param == 2 || param == 4 || param == 8) { 2926 if (param == 1 || param == 2 || param == 4 || param == 8) {
2993 if (pname == GraphicsContext3D::PACK_ALIGNMENT) 2927 if (pname == GraphicsContext3D::PACK_ALIGNMENT)
2994 m_packAlignment = param; 2928 m_packAlignment = param;
2995 else // GraphicsContext3D::UNPACK_ALIGNMENT: 2929 else // GraphicsContext3D::UNPACK_ALIGNMENT:
2996 m_unpackAlignment = param; 2930 m_unpackAlignment = param;
2997 m_context->pixelStorei(pname, param); 2931 m_context->pixelStorei(pname, param);
2998 } else { 2932 } else {
2999 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "pixelStorei", " invalid parameter for alignment"); 2933 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "pixelStorei", " invalid parameter for alignment");
3000 return; 2934 return;
3001 } 2935 }
3002 break; 2936 break;
3003 default: 2937 default:
3004 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "pixelStorei", "inval id parameter name"); 2938 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "pixelStorei", "inval id parameter name");
3005 return; 2939 return;
3006 } 2940 }
3007 } 2941 }
3008 2942
3009 void WebGLRenderingContext::polygonOffset(GC3Dfloat factor, GC3Dfloat units) 2943 void WebGLRenderingContextBase::polygonOffset(GC3Dfloat factor, GC3Dfloat units)
3010 { 2944 {
3011 if (isContextLost()) 2945 if (isContextLost())
3012 return; 2946 return;
3013 m_context->polygonOffset(factor, units); 2947 m_context->polygonOffset(factor, units);
3014 } 2948 }
3015 2949
3016 void WebGLRenderingContext::readPixels(GC3Dint x, GC3Dint y, GC3Dsizei width, GC 3Dsizei height, GC3Denum format, GC3Denum type, ArrayBufferView* pixels) 2950 void WebGLRenderingContextBase::readPixels(GC3Dint x, GC3Dint y, GC3Dsizei width , GC3Dsizei height, GC3Denum format, GC3Denum type, ArrayBufferView* pixels)
3017 { 2951 {
3018 if (isContextLost()) 2952 if (isContextLost())
3019 return; 2953 return;
3020 // Due to WebGL's same-origin restrictions, it is not possible to 2954 // Due to WebGL's same-origin restrictions, it is not possible to
3021 // taint the origin using the WebGL API. 2955 // taint the origin using the WebGL API.
3022 ASSERT(canvas()->originClean()); 2956 ASSERT(canvas()->originClean());
3023 // Validate input parameters. 2957 // Validate input parameters.
3024 if (!pixels) { 2958 if (!pixels) {
3025 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "readPixels", "no de stination ArrayBufferView"); 2959 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "readPixels", "no de stination ArrayBufferView");
3026 return; 2960 return;
(...skipping 25 matching lines...) Expand all
3052 if (pixels->getType() != ArrayBufferView::TypeUint8) { 2986 if (pixels->getType() != ArrayBufferView::TypeUint8) {
3053 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "readPixels", "A rrayBufferView not Uint8Array"); 2987 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "readPixels", "A rrayBufferView not Uint8Array");
3054 return; 2988 return;
3055 } 2989 }
3056 const char* reason = "framebuffer incomplete"; 2990 const char* reason = "framebuffer incomplete";
3057 if (m_framebufferBinding && !m_framebufferBinding->onAccess(graphicsContext3 D(), &reason)) { 2991 if (m_framebufferBinding && !m_framebufferBinding->onAccess(graphicsContext3 D(), &reason)) {
3058 synthesizeGLError(GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION, "rea dPixels", reason); 2992 synthesizeGLError(GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION, "rea dPixels", reason);
3059 return; 2993 return;
3060 } 2994 }
3061 // Calculate array size, taking into consideration of PACK_ALIGNMENT. 2995 // Calculate array size, taking into consideration of PACK_ALIGNMENT.
3062 unsigned int totalBytesRequired = 0; 2996 unsigned totalBytesRequired = 0;
3063 unsigned int padding = 0; 2997 unsigned padding = 0;
3064 GC3Denum error = m_context->computeImageSizeInBytes(format, type, width, hei ght, m_packAlignment, &totalBytesRequired, &padding); 2998 GC3Denum error = m_context->computeImageSizeInBytes(format, type, width, hei ght, m_packAlignment, &totalBytesRequired, &padding);
3065 if (error != GraphicsContext3D::NO_ERROR) { 2999 if (error != GraphicsContext3D::NO_ERROR) {
3066 synthesizeGLError(error, "readPixels", "invalid dimensions"); 3000 synthesizeGLError(error, "readPixels", "invalid dimensions");
3067 return; 3001 return;
3068 } 3002 }
3069 if (pixels->byteLength() < totalBytesRequired) { 3003 if (pixels->byteLength() < totalBytesRequired) {
3070 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "readPixels", "A rrayBufferView not large enough for dimensions"); 3004 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "readPixels", "A rrayBufferView not large enough for dimensions");
3071 return; 3005 return;
3072 } 3006 }
3073 3007
(...skipping 14 matching lines...) Expand all
3088 for (GC3Dsizei ix = 0; ix < width; ++ix) { 3022 for (GC3Dsizei ix = 0; ix < width; ++ix) {
3089 pixels[3] = 255; 3023 pixels[3] = 255;
3090 pixels += 4; 3024 pixels += 4;
3091 } 3025 }
3092 pixels += padding; 3026 pixels += padding;
3093 } 3027 }
3094 } 3028 }
3095 #endif 3029 #endif
3096 } 3030 }
3097 3031
3098 void WebGLRenderingContext::renderbufferStorage(GC3Denum target, GC3Denum intern alformat, GC3Dsizei width, GC3Dsizei height) 3032 void WebGLRenderingContextBase::renderbufferStorage(GC3Denum target, GC3Denum in ternalformat, GC3Dsizei width, GC3Dsizei height)
3099 { 3033 {
3100 if (isContextLost()) 3034 if (isContextLost())
3101 return; 3035 return;
3102 if (target != GraphicsContext3D::RENDERBUFFER) { 3036 if (target != GraphicsContext3D::RENDERBUFFER) {
3103 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "renderbufferStorage" , "invalid target"); 3037 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "renderbufferStorage" , "invalid target");
3104 return; 3038 return;
3105 } 3039 }
3106 if (!m_renderbufferBinding || !m_renderbufferBinding->object()) { 3040 if (!m_renderbufferBinding || !m_renderbufferBinding->object()) {
3107 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "renderbufferSto rage", "no bound renderbuffer"); 3041 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "renderbufferSto rage", "no bound renderbuffer");
3108 return; 3042 return;
(...skipping 30 matching lines...) Expand all
3139 m_renderbufferBinding->setSize(width, height); 3073 m_renderbufferBinding->setSize(width, height);
3140 m_renderbufferBinding->setInternalFormat(internalformat); 3074 m_renderbufferBinding->setInternalFormat(internalformat);
3141 break; 3075 break;
3142 default: 3076 default:
3143 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "renderbufferStorage" , "invalid internalformat"); 3077 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "renderbufferStorage" , "invalid internalformat");
3144 return; 3078 return;
3145 } 3079 }
3146 applyStencilTest(); 3080 applyStencilTest();
3147 } 3081 }
3148 3082
3149 void WebGLRenderingContext::sampleCoverage(GC3Dfloat value, GC3Dboolean invert) 3083 void WebGLRenderingContextBase::sampleCoverage(GC3Dfloat value, GC3Dboolean inve rt)
3150 { 3084 {
3151 if (isContextLost()) 3085 if (isContextLost())
3152 return; 3086 return;
3153 m_context->sampleCoverage(value, invert); 3087 m_context->sampleCoverage(value, invert);
3154 } 3088 }
3155 3089
3156 void WebGLRenderingContext::scissor(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Ds izei height) 3090 void WebGLRenderingContextBase::scissor(GC3Dint x, GC3Dint y, GC3Dsizei width, G C3Dsizei height)
3157 { 3091 {
3158 if (isContextLost()) 3092 if (isContextLost())
3159 return; 3093 return;
3160 if (!validateSize("scissor", width, height)) 3094 if (!validateSize("scissor", width, height))
3161 return; 3095 return;
3162 m_context->scissor(x, y, width, height); 3096 m_context->scissor(x, y, width, height);
3163 } 3097 }
3164 3098
3165 void WebGLRenderingContext::shaderSource(WebGLShader* shader, const String& stri ng) 3099 void WebGLRenderingContextBase::shaderSource(WebGLShader* shader, const String& string)
3166 { 3100 {
3167 if (isContextLost() || !validateWebGLObject("shaderSource", shader)) 3101 if (isContextLost() || !validateWebGLObject("shaderSource", shader))
3168 return; 3102 return;
3169 String stringWithoutComments = StripComments(string).result(); 3103 String stringWithoutComments = StripComments(string).result();
3170 if (!validateString("shaderSource", stringWithoutComments)) 3104 if (!validateString("shaderSource", stringWithoutComments))
3171 return; 3105 return;
3172 shader->setSource(string); 3106 shader->setSource(string);
3173 m_context->shaderSource(objectOrZero(shader), stringWithoutComments); 3107 m_context->shaderSource(objectOrZero(shader), stringWithoutComments);
3174 } 3108 }
3175 3109
3176 void WebGLRenderingContext::stencilFunc(GC3Denum func, GC3Dint ref, GC3Duint mas k) 3110 void WebGLRenderingContextBase::stencilFunc(GC3Denum func, GC3Dint ref, GC3Duint mask)
3177 { 3111 {
3178 if (isContextLost()) 3112 if (isContextLost())
3179 return; 3113 return;
3180 if (!validateStencilOrDepthFunc("stencilFunc", func)) 3114 if (!validateStencilOrDepthFunc("stencilFunc", func))
3181 return; 3115 return;
3182 m_stencilFuncRef = ref; 3116 m_stencilFuncRef = ref;
3183 m_stencilFuncRefBack = ref; 3117 m_stencilFuncRefBack = ref;
3184 m_stencilFuncMask = mask; 3118 m_stencilFuncMask = mask;
3185 m_stencilFuncMaskBack = mask; 3119 m_stencilFuncMaskBack = mask;
3186 m_context->stencilFunc(func, ref, mask); 3120 m_context->stencilFunc(func, ref, mask);
3187 } 3121 }
3188 3122
3189 void WebGLRenderingContext::stencilFuncSeparate(GC3Denum face, GC3Denum func, GC 3Dint ref, GC3Duint mask) 3123 void WebGLRenderingContextBase::stencilFuncSeparate(GC3Denum face, GC3Denum func , GC3Dint ref, GC3Duint mask)
3190 { 3124 {
3191 if (isContextLost()) 3125 if (isContextLost())
3192 return; 3126 return;
3193 if (!validateStencilOrDepthFunc("stencilFuncSeparate", func)) 3127 if (!validateStencilOrDepthFunc("stencilFuncSeparate", func))
3194 return; 3128 return;
3195 switch (face) { 3129 switch (face) {
3196 case GraphicsContext3D::FRONT_AND_BACK: 3130 case GraphicsContext3D::FRONT_AND_BACK:
3197 m_stencilFuncRef = ref; 3131 m_stencilFuncRef = ref;
3198 m_stencilFuncRefBack = ref; 3132 m_stencilFuncRefBack = ref;
3199 m_stencilFuncMask = mask; 3133 m_stencilFuncMask = mask;
3200 m_stencilFuncMaskBack = mask; 3134 m_stencilFuncMaskBack = mask;
3201 break; 3135 break;
3202 case GraphicsContext3D::FRONT: 3136 case GraphicsContext3D::FRONT:
3203 m_stencilFuncRef = ref; 3137 m_stencilFuncRef = ref;
3204 m_stencilFuncMask = mask; 3138 m_stencilFuncMask = mask;
3205 break; 3139 break;
3206 case GraphicsContext3D::BACK: 3140 case GraphicsContext3D::BACK:
3207 m_stencilFuncRefBack = ref; 3141 m_stencilFuncRefBack = ref;
3208 m_stencilFuncMaskBack = mask; 3142 m_stencilFuncMaskBack = mask;
3209 break; 3143 break;
3210 default: 3144 default:
3211 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "stencilFuncSeparate" , "invalid face"); 3145 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "stencilFuncSeparate" , "invalid face");
3212 return; 3146 return;
3213 } 3147 }
3214 m_context->stencilFuncSeparate(face, func, ref, mask); 3148 m_context->stencilFuncSeparate(face, func, ref, mask);
3215 } 3149 }
3216 3150
3217 void WebGLRenderingContext::stencilMask(GC3Duint mask) 3151 void WebGLRenderingContextBase::stencilMask(GC3Duint mask)
3218 { 3152 {
3219 if (isContextLost()) 3153 if (isContextLost())
3220 return; 3154 return;
3221 m_stencilMask = mask; 3155 m_stencilMask = mask;
3222 m_stencilMaskBack = mask; 3156 m_stencilMaskBack = mask;
3223 m_context->stencilMask(mask); 3157 m_context->stencilMask(mask);
3224 } 3158 }
3225 3159
3226 void WebGLRenderingContext::stencilMaskSeparate(GC3Denum face, GC3Duint mask) 3160 void WebGLRenderingContextBase::stencilMaskSeparate(GC3Denum face, GC3Duint mask )
3227 { 3161 {
3228 if (isContextLost()) 3162 if (isContextLost())
3229 return; 3163 return;
3230 switch (face) { 3164 switch (face) {
3231 case GraphicsContext3D::FRONT_AND_BACK: 3165 case GraphicsContext3D::FRONT_AND_BACK:
3232 m_stencilMask = mask; 3166 m_stencilMask = mask;
3233 m_stencilMaskBack = mask; 3167 m_stencilMaskBack = mask;
3234 break; 3168 break;
3235 case GraphicsContext3D::FRONT: 3169 case GraphicsContext3D::FRONT:
3236 m_stencilMask = mask; 3170 m_stencilMask = mask;
3237 break; 3171 break;
3238 case GraphicsContext3D::BACK: 3172 case GraphicsContext3D::BACK:
3239 m_stencilMaskBack = mask; 3173 m_stencilMaskBack = mask;
3240 break; 3174 break;
3241 default: 3175 default:
3242 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "stencilMaskSeparate" , "invalid face"); 3176 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "stencilMaskSeparate" , "invalid face");
3243 return; 3177 return;
3244 } 3178 }
3245 m_context->stencilMaskSeparate(face, mask); 3179 m_context->stencilMaskSeparate(face, mask);
3246 } 3180 }
3247 3181
3248 void WebGLRenderingContext::stencilOp(GC3Denum fail, GC3Denum zfail, GC3Denum zp ass) 3182 void WebGLRenderingContextBase::stencilOp(GC3Denum fail, GC3Denum zfail, GC3Denu m zpass)
3249 { 3183 {
3250 if (isContextLost()) 3184 if (isContextLost())
3251 return; 3185 return;
3252 m_context->stencilOp(fail, zfail, zpass); 3186 m_context->stencilOp(fail, zfail, zpass);
3253 } 3187 }
3254 3188
3255 void WebGLRenderingContext::stencilOpSeparate(GC3Denum face, GC3Denum fail, GC3D enum zfail, GC3Denum zpass) 3189 void WebGLRenderingContextBase::stencilOpSeparate(GC3Denum face, GC3Denum fail, GC3Denum zfail, GC3Denum zpass)
3256 { 3190 {
3257 if (isContextLost()) 3191 if (isContextLost())
3258 return; 3192 return;
3259 m_context->stencilOpSeparate(face, fail, zfail, zpass); 3193 m_context->stencilOpSeparate(face, fail, zfail, zpass);
3260 } 3194 }
3261 3195
3262 void WebGLRenderingContext::texImage2DBase(GC3Denum target, GC3Dint level, GC3De num internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type, const void* pixels, ExceptionState& es) 3196 void WebGLRenderingContextBase::texImage2DBase(GC3Denum target, GC3Dint level, G C3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3De num format, GC3Denum type, const void* pixels, ExceptionState& es)
3263 { 3197 {
3264 // All calling functions check isContextLost, so a duplicate check is not ne eded here. 3198 // All calling functions check isContextLost, so a duplicate check is not ne eded here.
3265 // FIXME: Handle errors. 3199 // FIXME: Handle errors.
3266 WebGLTexture* tex = validateTextureBinding("texImage2D", target, true); 3200 WebGLTexture* tex = validateTextureBinding("texImage2D", target, true);
3267 ASSERT(validateTexFuncParameters("texImage2D", NotTexSubImage2D, target, lev el, internalformat, width, height, border, format, type)); 3201 ASSERT(validateTexFuncParameters("texImage2D", NotTexSubImage2D, target, lev el, internalformat, width, height, border, format, type));
3268 ASSERT(tex); 3202 ASSERT(tex);
3269 ASSERT(!level || !WebGLTexture::isNPOT(width, height)); 3203 ASSERT(!level || !WebGLTexture::isNPOT(width, height));
3270 ASSERT(!pixels || validateSettableTexFormat("texImage2D", internalformat)); 3204 ASSERT(!pixels || validateSettableTexFormat("texImage2D", internalformat));
3271 m_context->texImage2D(target, level, internalformat, width, height, 3205 m_context->texImage2D(target, level, internalformat, width, height,
3272 border, format, type, pixels); 3206 border, format, type, pixels);
3273 tex->setLevelInfo(target, level, internalformat, width, height, type); 3207 tex->setLevelInfo(target, level, internalformat, width, height, type);
3274 } 3208 }
3275 3209
3276 void WebGLRenderingContext::texImage2DImpl(GC3Denum target, GC3Dint level, GC3De num internalformat, GC3Denum format, GC3Denum type, Image* image, GraphicsContex t3D::ImageHtmlDomSource domSource, bool flipY, bool premultiplyAlpha, ExceptionS tate& es) 3210 void WebGLRenderingContextBase::texImage2DImpl(GC3Denum target, GC3Dint level, G C3Denum internalformat, GC3Denum format, GC3Denum type, Image* image, GraphicsCo ntext3D::ImageHtmlDomSource domSource, bool flipY, bool premultiplyAlpha, Except ionState& es)
3277 { 3211 {
3278 // All calling functions check isContextLost, so a duplicate check is not ne eded here. 3212 // All calling functions check isContextLost, so a duplicate check is not ne eded here.
3279 Vector<uint8_t> data; 3213 Vector<uint8_t> data;
3280 GraphicsContext3D::ImageExtractor imageExtractor(image, domSource, premultip lyAlpha, m_unpackColorspaceConversion == GraphicsContext3D::NONE); 3214 GraphicsContext3D::ImageExtractor imageExtractor(image, domSource, premultip lyAlpha, m_unpackColorspaceConversion == GraphicsContext3D::NONE);
3281 if (!imageExtractor.extractSucceeded()) { 3215 if (!imageExtractor.extractSucceeded()) {
3282 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texImage2D", "bad i mage data"); 3216 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texImage2D", "bad i mage data");
3283 return; 3217 return;
3284 } 3218 }
3285 GraphicsContext3D::DataFormat sourceDataFormat = imageExtractor.imageSourceF ormat(); 3219 GraphicsContext3D::DataFormat sourceDataFormat = imageExtractor.imageSourceF ormat();
3286 GraphicsContext3D::AlphaOp alphaOp = imageExtractor.imageAlphaOp(); 3220 GraphicsContext3D::AlphaOp alphaOp = imageExtractor.imageAlphaOp();
3287 const void* imagePixelData = imageExtractor.imagePixelData(); 3221 const void* imagePixelData = imageExtractor.imagePixelData();
3288 3222
3289 bool needConversion = true; 3223 bool needConversion = true;
3290 if (type == GraphicsContext3D::UNSIGNED_BYTE && sourceDataFormat == Graphics Context3D::DataFormatRGBA8 && format == GraphicsContext3D::RGBA && alphaOp == Gr aphicsContext3D::AlphaDoNothing && !flipY) 3224 if (type == GraphicsContext3D::UNSIGNED_BYTE && sourceDataFormat == Graphics Context3D::DataFormatRGBA8 && format == GraphicsContext3D::RGBA && alphaOp == Gr aphicsContext3D::AlphaDoNothing && !flipY) {
3291 needConversion = false; 3225 needConversion = false;
3292 else { 3226 } else {
3293 if (!m_context->packImageData(image, imagePixelData, format, type, flipY , alphaOp, sourceDataFormat, imageExtractor.imageWidth(), imageExtractor.imageHe ight(), imageExtractor.imageSourceUnpackAlignment(), data)) { 3227 if (!m_context->packImageData(image, imagePixelData, format, type, flipY , alphaOp, sourceDataFormat, imageExtractor.imageWidth(), imageExtractor.imageHe ight(), imageExtractor.imageSourceUnpackAlignment(), data)) {
3294 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texImage2D", "p ackImage error"); 3228 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texImage2D", "p ackImage error");
3295 return; 3229 return;
3296 } 3230 }
3297 } 3231 }
3298 3232
3299 if (m_unpackAlignment != 1) 3233 if (m_unpackAlignment != 1)
3300 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, 1); 3234 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, 1);
3301 texImage2DBase(target, level, internalformat, image->width(), image->height( ), 0, format, type, needConversion ? data.data() : imagePixelData, es); 3235 texImage2DBase(target, level, internalformat, image->width(), image->height( ), 0, format, type, needConversion ? data.data() : imagePixelData, es);
3302 if (m_unpackAlignment != 1) 3236 if (m_unpackAlignment != 1)
3303 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, m_unpackAlig nment); 3237 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, m_unpackAlig nment);
3304 } 3238 }
3305 3239
3306 bool WebGLRenderingContext::validateTexFunc(const char* functionName, TexFuncVal idationFunctionType functionType, TexFuncValidationSourceType sourceType, GC3Den um target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei he ight, GC3Dint border, GC3Denum format, GC3Denum type, GC3Dint xoffset, GC3Dint y offset) 3240 bool WebGLRenderingContextBase::validateTexFunc(const char* functionName, TexFun cValidationFunctionType functionType, TexFuncValidationSourceType sourceType, GC 3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsize i height, GC3Dint border, GC3Denum format, GC3Denum type, GC3Dint xoffset, GC3Di nt yoffset)
3307 { 3241 {
3308 if (!validateTexFuncParameters(functionName, functionType, target, level, in ternalformat, width, height, border, format, type)) 3242 if (!validateTexFuncParameters(functionName, functionType, target, level, in ternalformat, width, height, border, format, type))
3309 return false; 3243 return false;
3310 3244
3311 WebGLTexture* texture = validateTextureBinding(functionName, target, true); 3245 WebGLTexture* texture = validateTextureBinding(functionName, target, true);
3312 if (!texture) 3246 if (!texture)
3313 return false; 3247 return false;
3314 3248
3315 if (functionType == NotTexSubImage2D) { 3249 if (functionType == NotTexSubImage2D) {
3316 if (level && WebGLTexture::isNPOT(width, height)) { 3250 if (level && WebGLTexture::isNPOT(width, height)) {
(...skipping 22 matching lines...) Expand all
3339 } 3273 }
3340 if (texture->getInternalFormat(target, level) != format || texture->getT ype(target, level) != type) { 3274 if (texture->getInternalFormat(target, level) != format || texture->getT ype(target, level) != type) {
3341 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName , "type and format do not match texture"); 3275 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName , "type and format do not match texture");
3342 return false; 3276 return false;
3343 } 3277 }
3344 } 3278 }
3345 3279
3346 return true; 3280 return true;
3347 } 3281 }
3348 3282
3349 void WebGLRenderingContext::texImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, 3283 void WebGLRenderingContextBase::texImage2D(GC3Denum target, GC3Dint level, GC3De num internalformat,
3350 GC3Dsizei width, GC3Dsizei height, GC3Dint border, 3284 GC3Dsizei width, GC3Dsizei height, GC3Dint border,
3351 GC3Denum format, GC3Denum type, ArrayBufferView* pixels, ExceptionState& es) 3285 GC3Denum format, GC3Denum type, ArrayBufferView* pixels, ExceptionState& es)
3352 { 3286 {
3353 if (isContextLost() || !validateTexFuncData("texImage2D", level, width, heig ht, format, type, pixels, NullAllowed) 3287 if (isContextLost() || !validateTexFuncData("texImage2D", level, width, heig ht, format, type, pixels, NullAllowed)
3354 || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceArrayBufferVie w, target, level, internalformat, width, height, border, format, type, 0, 0)) 3288 || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceArrayBufferVie w, target, level, internalformat, width, height, border, format, type, 0, 0))
3355 return; 3289 return;
3356 void* data = pixels ? pixels->baseAddress() : 0; 3290 void* data = pixels ? pixels->baseAddress() : 0;
3357 Vector<uint8_t> tempData; 3291 Vector<uint8_t> tempData;
3358 bool changeUnpackAlignment = false; 3292 bool changeUnpackAlignment = false;
3359 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) { 3293 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) {
3360 if (!m_context->extractTextureData(width, height, format, type, 3294 if (!m_context->extractTextureData(width, height, format, type,
3361 m_unpackAlignment, 3295 m_unpackAlignment,
3362 m_unpackFlipY, m_unpackPremultiplyAlp ha, 3296 m_unpackFlipY, m_unpackPremultiplyAlpha,
3363 data, 3297 data,
3364 tempData)) 3298 tempData))
3365 return; 3299 return;
3366 data = tempData.data(); 3300 data = tempData.data();
3367 changeUnpackAlignment = true; 3301 changeUnpackAlignment = true;
3368 } 3302 }
3369 if (changeUnpackAlignment) 3303 if (changeUnpackAlignment)
3370 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, 1); 3304 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, 1);
3371 texImage2DBase(target, level, internalformat, width, height, border, format, type, data, es); 3305 texImage2DBase(target, level, internalformat, width, height, border, format, type, data, es);
3372 if (changeUnpackAlignment) 3306 if (changeUnpackAlignment)
3373 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, m_unpackAlig nment); 3307 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, m_unpackAlig nment);
3374 } 3308 }
3375 3309
3376 void WebGLRenderingContext::texImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, 3310 void WebGLRenderingContextBase::texImage2D(GC3Denum target, GC3Dint level, GC3De num internalformat,
3377 GC3Denum format, GC3Denum type, ImageData* pixels, ExceptionState& es) 3311 GC3Denum format, GC3Denum type, ImageData* pixels, ExceptionState& es)
3378 { 3312 {
3379 if (isContextLost() || !pixels || !validateTexFunc("texImage2D", NotTexSubIm age2D, SourceImageData, target, level, internalformat, pixels->width(), pixels-> height(), 0, format, type, 0, 0)) 3313 if (isContextLost() || !pixels || !validateTexFunc("texImage2D", NotTexSubIm age2D, SourceImageData, target, level, internalformat, pixels->width(), pixels-> height(), 0, format, type, 0, 0))
3380 return; 3314 return;
3381 Vector<uint8_t> data; 3315 Vector<uint8_t> data;
3382 bool needConversion = true; 3316 bool needConversion = true;
3383 // The data from ImageData is always of format RGBA8. 3317 // The data from ImageData is always of format RGBA8.
3384 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required. 3318 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required.
3385 if (!m_unpackFlipY && !m_unpackPremultiplyAlpha && format == GraphicsContext 3D::RGBA && type == GraphicsContext3D::UNSIGNED_BYTE) 3319 if (!m_unpackFlipY && !m_unpackPremultiplyAlpha && format == GraphicsContext 3D::RGBA && type == GraphicsContext3D::UNSIGNED_BYTE) {
3386 needConversion = false; 3320 needConversion = false;
3387 else { 3321 } else {
3388 if (!m_context->extractImageData(pixels, format, type, m_unpackFlipY, m_ unpackPremultiplyAlpha, data)) { 3322 if (!m_context->extractImageData(pixels, format, type, m_unpackFlipY, m_ unpackPremultiplyAlpha, data)) {
3389 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texImage2D", "b ad image data"); 3323 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texImage2D", "b ad image data");
3390 return; 3324 return;
3391 } 3325 }
3392 } 3326 }
3393 if (m_unpackAlignment != 1) 3327 if (m_unpackAlignment != 1)
3394 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, 1); 3328 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, 1);
3395 texImage2DBase(target, level, internalformat, pixels->width(), pixels->heigh t(), 0, format, type, needConversion ? data.data() : pixels->data()->data(), es) ; 3329 texImage2DBase(target, level, internalformat, pixels->width(), pixels->heigh t(), 0, format, type, needConversion ? data.data() : pixels->data()->data(), es) ;
3396 if (m_unpackAlignment != 1) 3330 if (m_unpackAlignment != 1)
3397 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, m_unpackAlig nment); 3331 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, m_unpackAlig nment);
3398 } 3332 }
3399 3333
3400 void WebGLRenderingContext::texImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, 3334 void WebGLRenderingContextBase::texImage2D(GC3Denum target, GC3Dint level, GC3De num internalformat,
3401 GC3Denum format, GC3Denum type, HTMLImageElement* image, ExceptionState& es) 3335 GC3Denum format, GC3Denum type, HTMLImageElement* image, ExceptionState& es)
3402 { 3336 {
3403 if (isContextLost() || !validateHTMLImageElement("texImage2D", image, es)) 3337 if (isContextLost() || !validateHTMLImageElement("texImage2D", image, es))
3404 return; 3338 return;
3405 Image* imageForRender = image->cachedImage()->imageForRenderer(image->render er()); 3339 Image* imageForRender = image->cachedImage()->imageForRenderer(image->render er());
3406 if (!imageForRender || !validateTexFunc("texImage2D", NotTexSubImage2D, Sour ceHTMLImageElement, target, level, internalformat, imageForRender->width(), imag eForRender->height(), 0, format, type, 0, 0)) 3340 if (!imageForRender || !validateTexFunc("texImage2D", NotTexSubImage2D, Sour ceHTMLImageElement, target, level, internalformat, imageForRender->width(), imag eForRender->height(), 0, format, type, 0, 0))
3407 return; 3341 return;
3408 3342
3409 texImage2DImpl(target, level, internalformat, format, type, imageForRender, GraphicsContext3D::HtmlDomImage, m_unpackFlipY, m_unpackPremultiplyAlpha, es); 3343 texImage2DImpl(target, level, internalformat, format, type, imageForRender, GraphicsContext3D::HtmlDomImage, m_unpackFlipY, m_unpackPremultiplyAlpha, es);
3410 } 3344 }
3411 3345
3412 void WebGLRenderingContext::texImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, 3346 void WebGLRenderingContextBase::texImage2D(GC3Denum target, GC3Dint level, GC3De num internalformat,
3413 GC3Denum format, GC3Denum type, HTMLCanvasElement* canvas, ExceptionState& e s) 3347 GC3Denum format, GC3Denum type, HTMLCanvasElement* canvas, ExceptionState& e s)
3414 { 3348 {
3415 if (isContextLost() || !validateHTMLCanvasElement("texImage2D", canvas, es) || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLCanvasElement, tar get, level, internalformat, canvas->width(), canvas->height(), 0, format, type, 0, 0)) 3349 if (isContextLost() || !validateHTMLCanvasElement("texImage2D", canvas, es) || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLCanvasElement, tar get, level, internalformat, canvas->width(), canvas->height(), 0, format, type, 0, 0))
3416 return; 3350 return;
3417 3351
3418 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true); 3352 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true);
3419 // If possible, copy from the canvas element directly to the texture 3353 // If possible, copy from the canvas element directly to the texture
3420 // via the GPU, without a read-back to system memory. 3354 // via the GPU, without a read-back to system memory.
3421 if (GraphicsContext3D::TEXTURE_2D == target && texture) { 3355 if (GraphicsContext3D::TEXTURE_2D == target && texture) {
3422 ImageBuffer* buffer = canvas->buffer(); 3356 ImageBuffer* buffer = canvas->buffer();
3423 if (buffer && buffer->copyToPlatformTexture(*m_context.get(), texture->o bject(), internalformat, type, level, m_unpackPremultiplyAlpha, m_unpackFlipY)) { 3357 if (buffer && buffer->copyToPlatformTexture(*m_context.get(), texture->o bject(), internalformat, type, level, m_unpackPremultiplyAlpha, m_unpackFlipY)) {
3424 texture->setLevelInfo(target, level, internalformat, canvas->width() , canvas->height(), type); 3358 texture->setLevelInfo(target, level, internalformat, canvas->width() , canvas->height(), type);
3425 return; 3359 return;
3426 } 3360 }
3427 } 3361 }
3428 3362
3429 RefPtr<ImageData> imageData = canvas->getImageData(); 3363 RefPtr<ImageData> imageData = canvas->getImageData();
3430 if (imageData) 3364 if (imageData)
3431 texImage2D(target, level, internalformat, format, type, imageData.get(), es); 3365 texImage2D(target, level, internalformat, format, type, imageData.get(), es);
3432 else 3366 else
3433 texImage2DImpl(target, level, internalformat, format, type, canvas->copi edImage(), GraphicsContext3D::HtmlDomCanvas, m_unpackFlipY, m_unpackPremultiplyA lpha, es); 3367 texImage2DImpl(target, level, internalformat, format, type, canvas->copi edImage(), GraphicsContext3D::HtmlDomCanvas, m_unpackFlipY, m_unpackPremultiplyA lpha, es);
3434 } 3368 }
3435 3369
3436 PassRefPtr<Image> WebGLRenderingContext::videoFrameToImage(HTMLVideoElement* vid eo, BackingStoreCopy backingStoreCopy) 3370 PassRefPtr<Image> WebGLRenderingContextBase::videoFrameToImage(HTMLVideoElement* video, BackingStoreCopy backingStoreCopy)
3437 { 3371 {
3438 IntSize size(video->videoWidth(), video->videoHeight()); 3372 IntSize size(video->videoWidth(), video->videoHeight());
3439 ImageBuffer* buf = m_videoCache.imageBuffer(size); 3373 ImageBuffer* buf = m_videoCache.imageBuffer(size);
3440 if (!buf) { 3374 if (!buf) {
3441 synthesizeGLError(GraphicsContext3D::OUT_OF_MEMORY, "texImage2D", "out o f memory"); 3375 synthesizeGLError(GraphicsContext3D::OUT_OF_MEMORY, "texImage2D", "out o f memory");
3442 return 0; 3376 return 0;
3443 } 3377 }
3444 IntRect destRect(0, 0, size.width(), size.height()); 3378 IntRect destRect(0, 0, size.width(), size.height());
3445 // FIXME: Turn this into a GPU-GPU texture copy instead of CPU readback. 3379 // FIXME: Turn this into a GPU-GPU texture copy instead of CPU readback.
3446 video->paintCurrentFrameInContext(buf->context(), destRect); 3380 video->paintCurrentFrameInContext(buf->context(), destRect);
3447 return buf->copyImage(backingStoreCopy); 3381 return buf->copyImage(backingStoreCopy);
3448 } 3382 }
3449 3383
3450 void WebGLRenderingContext::texImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, 3384 void WebGLRenderingContextBase::texImage2D(GC3Denum target, GC3Dint level, GC3De num internalformat,
3451 GC3Denum format, GC3Denum type, HTMLVideoElement* video, ExceptionState& es) 3385 GC3Denum format, GC3Denum type, HTMLVideoElement* video, ExceptionState& es)
3452 { 3386 {
3453 if (isContextLost() || !validateHTMLVideoElement("texImage2D", video, es) 3387 if (isContextLost() || !validateHTMLVideoElement("texImage2D", video, es)
3454 || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLVideoEleme nt, target, level, internalformat, video->videoWidth(), video->videoHeight(), 0, format, type, 0, 0)) 3388 || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLVideoEleme nt, target, level, internalformat, video->videoWidth(), video->videoHeight(), 0, format, type, 0, 0))
3455 return; 3389 return;
3456 3390
3457 // Go through the fast path doing a GPU-GPU textures copy without a readback to system memory if possible. 3391 // Go through the fast path doing a GPU-GPU textures copy without a readback to system memory if possible.
3458 // Otherwise, it will fall back to the normal SW path. 3392 // Otherwise, it will fall back to the normal SW path.
3459 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true); 3393 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true);
3460 if (GraphicsContext3D::TEXTURE_2D == target && texture) { 3394 if (GraphicsContext3D::TEXTURE_2D == target && texture) {
3461 if (video->copyVideoTextureToPlatformTexture(m_context.get(), texture->o bject(), level, type, internalformat, m_unpackPremultiplyAlpha, m_unpackFlipY)) { 3395 if (video->copyVideoTextureToPlatformTexture(m_context.get(), texture->o bject(), level, type, internalformat, m_unpackPremultiplyAlpha, m_unpackFlipY)) {
3462 texture->setLevelInfo(target, level, internalformat, video->videoWid th(), video->videoHeight(), type); 3396 texture->setLevelInfo(target, level, internalformat, video->videoWid th(), video->videoHeight(), type);
3463 return; 3397 return;
3464 } 3398 }
3465 } 3399 }
3466 3400
3467 // Normal pure SW path. 3401 // Normal pure SW path.
3468 RefPtr<Image> image = videoFrameToImage(video, ImageBuffer::fastCopyImageMod e()); 3402 RefPtr<Image> image = videoFrameToImage(video, ImageBuffer::fastCopyImageMod e());
3469 if (!image) 3403 if (!image)
3470 return; 3404 return;
3471 texImage2DImpl(target, level, internalformat, format, type, image.get(), Gra phicsContext3D::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha, es); 3405 texImage2DImpl(target, level, internalformat, format, type, image.get(), Gra phicsContext3D::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha, es);
3472 } 3406 }
3473 3407
3474 void WebGLRenderingContext::texParameter(GC3Denum target, GC3Denum pname, GC3Dfl oat paramf, GC3Dint parami, bool isFloat) 3408 void WebGLRenderingContextBase::texParameter(GC3Denum target, GC3Denum pname, GC 3Dfloat paramf, GC3Dint parami, bool isFloat)
3475 { 3409 {
3476 if (isContextLost()) 3410 if (isContextLost())
3477 return; 3411 return;
3478 WebGLTexture* tex = validateTextureBinding("texParameter", target, false); 3412 WebGLTexture* tex = validateTextureBinding("texParameter", target, false);
3479 if (!tex) 3413 if (!tex)
3480 return; 3414 return;
3481 switch (pname) { 3415 switch (pname) {
3482 case GraphicsContext3D::TEXTURE_MIN_FILTER: 3416 case GraphicsContext3D::TEXTURE_MIN_FILTER:
3483 case GraphicsContext3D::TEXTURE_MAG_FILTER: 3417 case GraphicsContext3D::TEXTURE_MAG_FILTER:
3484 break; 3418 break;
(...skipping 17 matching lines...) Expand all
3502 } 3436 }
3503 if (isFloat) { 3437 if (isFloat) {
3504 tex->setParameterf(pname, paramf); 3438 tex->setParameterf(pname, paramf);
3505 m_context->texParameterf(target, pname, paramf); 3439 m_context->texParameterf(target, pname, paramf);
3506 } else { 3440 } else {
3507 tex->setParameteri(pname, parami); 3441 tex->setParameteri(pname, parami);
3508 m_context->texParameteri(target, pname, parami); 3442 m_context->texParameteri(target, pname, parami);
3509 } 3443 }
3510 } 3444 }
3511 3445
3512 void WebGLRenderingContext::texParameterf(GC3Denum target, GC3Denum pname, GC3Df loat param) 3446 void WebGLRenderingContextBase::texParameterf(GC3Denum target, GC3Denum pname, G C3Dfloat param)
3513 { 3447 {
3514 texParameter(target, pname, param, 0, true); 3448 texParameter(target, pname, param, 0, true);
3515 } 3449 }
3516 3450
3517 void WebGLRenderingContext::texParameteri(GC3Denum target, GC3Denum pname, GC3Di nt param) 3451 void WebGLRenderingContextBase::texParameteri(GC3Denum target, GC3Denum pname, G C3Dint param)
3518 { 3452 {
3519 texParameter(target, pname, 0, param, false); 3453 texParameter(target, pname, 0, param, false);
3520 } 3454 }
3521 3455
3522 void WebGLRenderingContext::texSubImage2DBase(GC3Denum target, GC3Dint level, GC 3Dint xoffset, GC3Dint yoffset, GC3Dsizei width, GC3Dsizei height, GC3Denum form at, GC3Denum type, const void* pixels, ExceptionState& es) 3456 void WebGLRenderingContextBase::texSubImage2DBase(GC3Denum target, GC3Dint level , GC3Dint xoffset, GC3Dint yoffset, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, const void* pixels, ExceptionState& es)
3523 { 3457 {
3524 // FIXME: Handle errors. 3458 // FIXME: Handle errors.
3525 ASSERT(!isContextLost()); 3459 ASSERT(!isContextLost());
3526 ASSERT(validateTexFuncParameters("texSubImage2D", TexSubImage2D, target, lev el, format, width, height, 0, format, type)); 3460 ASSERT(validateTexFuncParameters("texSubImage2D", TexSubImage2D, target, lev el, format, width, height, 0, format, type));
3527 ASSERT(validateSize("texSubImage2D", xoffset, yoffset)); 3461 ASSERT(validateSize("texSubImage2D", xoffset, yoffset));
3528 ASSERT(validateSettableTexFormat("texSubImage2D", format)); 3462 ASSERT(validateSettableTexFormat("texSubImage2D", format));
3529 WebGLTexture* tex = validateTextureBinding("texSubImage2D", target, true); 3463 WebGLTexture* tex = validateTextureBinding("texSubImage2D", target, true);
3530 if (!tex) { 3464 if (!tex) {
3531 ASSERT_NOT_REACHED(); 3465 ASSERT_NOT_REACHED();
3532 return; 3466 return;
3533 } 3467 }
3534 ASSERT((xoffset + width) >= 0); 3468 ASSERT((xoffset + width) >= 0);
3535 ASSERT((yoffset + height) >= 0); 3469 ASSERT((yoffset + height) >= 0);
3536 ASSERT(tex->getWidth(target, level) >= (xoffset + width)); 3470 ASSERT(tex->getWidth(target, level) >= (xoffset + width));
3537 ASSERT(tex->getHeight(target, level) >= (yoffset + height)); 3471 ASSERT(tex->getHeight(target, level) >= (yoffset + height));
3538 ASSERT(tex->getInternalFormat(target, level) == format); 3472 ASSERT(tex->getInternalFormat(target, level) == format);
3539 ASSERT(tex->getType(target, level) == type); 3473 ASSERT(tex->getType(target, level) == type);
3540 m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, for mat, type, pixels); 3474 m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, for mat, type, pixels);
3541 } 3475 }
3542 3476
3543 void WebGLRenderingContext::texSubImage2DImpl(GC3Denum target, GC3Dint level, GC 3Dint xoffset, GC3Dint yoffset, GC3Denum format, GC3Denum type, Image* image, Gr aphicsContext3D::ImageHtmlDomSource domSource, bool flipY, bool premultiplyAlpha , ExceptionState& es) 3477 void WebGLRenderingContextBase::texSubImage2DImpl(GC3Denum target, GC3Dint level , GC3Dint xoffset, GC3Dint yoffset, GC3Denum format, GC3Denum type, Image* image , GraphicsContext3D::ImageHtmlDomSource domSource, bool flipY, bool premultiplyA lpha, ExceptionState& es)
3544 { 3478 {
3545 // All calling functions check isContextLost, so a duplicate check is not ne eded here. 3479 // All calling functions check isContextLost, so a duplicate check is not ne eded here.
3546 Vector<uint8_t> data; 3480 Vector<uint8_t> data;
3547 GraphicsContext3D::ImageExtractor imageExtractor(image, domSource, premultip lyAlpha, m_unpackColorspaceConversion == GraphicsContext3D::NONE); 3481 GraphicsContext3D::ImageExtractor imageExtractor(image, domSource, premultip lyAlpha, m_unpackColorspaceConversion == GraphicsContext3D::NONE);
3548 if (!imageExtractor.extractSucceeded()) { 3482 if (!imageExtractor.extractSucceeded()) {
3549 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texSubImage2D", "ba d image"); 3483 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texSubImage2D", "ba d image");
3550 return; 3484 return;
3551 } 3485 }
3552 GraphicsContext3D::DataFormat sourceDataFormat = imageExtractor.imageSourceF ormat(); 3486 GraphicsContext3D::DataFormat sourceDataFormat = imageExtractor.imageSourceF ormat();
3553 GraphicsContext3D::AlphaOp alphaOp = imageExtractor.imageAlphaOp(); 3487 GraphicsContext3D::AlphaOp alphaOp = imageExtractor.imageAlphaOp();
3554 const void* imagePixelData = imageExtractor.imagePixelData(); 3488 const void* imagePixelData = imageExtractor.imagePixelData();
3555 3489
3556 bool needConversion = true; 3490 bool needConversion = true;
3557 if (type == GraphicsContext3D::UNSIGNED_BYTE && sourceDataFormat == Graphics Context3D::DataFormatRGBA8 && format == GraphicsContext3D::RGBA && alphaOp == Gr aphicsContext3D::AlphaDoNothing && !flipY) 3491 if (type == GraphicsContext3D::UNSIGNED_BYTE && sourceDataFormat == Graphics Context3D::DataFormatRGBA8 && format == GraphicsContext3D::RGBA && alphaOp == Gr aphicsContext3D::AlphaDoNothing && !flipY) {
3558 needConversion = false; 3492 needConversion = false;
3559 else { 3493 } else {
3560 if (!m_context->packImageData(image, imagePixelData, format, type, flipY , alphaOp, sourceDataFormat, imageExtractor.imageWidth(), imageExtractor.imageHe ight(), imageExtractor.imageSourceUnpackAlignment(), data)) { 3494 if (!m_context->packImageData(image, imagePixelData, format, type, flipY , alphaOp, sourceDataFormat, imageExtractor.imageWidth(), imageExtractor.imageHe ight(), imageExtractor.imageSourceUnpackAlignment(), data)) {
3561 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texImage2D", "b ad image data"); 3495 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texImage2D", "b ad image data");
3562 return; 3496 return;
3563 } 3497 }
3564 } 3498 }
3565 3499
3566 if (m_unpackAlignment != 1) 3500 if (m_unpackAlignment != 1)
3567 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, 1); 3501 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, 1);
3568 texSubImage2DBase(target, level, xoffset, yoffset, image->width(), image->he ight(), format, type, needConversion ? data.data() : imagePixelData, es); 3502 texSubImage2DBase(target, level, xoffset, yoffset, image->width(), image->he ight(), format, type, needConversion ? data.data() : imagePixelData, es);
3569 if (m_unpackAlignment != 1) 3503 if (m_unpackAlignment != 1)
3570 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, m_unpackAlig nment); 3504 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, m_unpackAlig nment);
3571 } 3505 }
3572 3506
3573 void WebGLRenderingContext::texSubImage2D(GC3Denum target, GC3Dint level, GC3Din t xoffset, GC3Dint yoffset, 3507 void WebGLRenderingContextBase::texSubImage2D(GC3Denum target, GC3Dint level, GC 3Dint xoffset, GC3Dint yoffset,
3574 GC3Dsizei width, GC3Dsizei height, 3508 GC3Dsizei width, GC3Dsizei height,
3575 GC3Denum format, GC3Denum type, ArrayBufferView* pixels, ExceptionState& es) 3509 GC3Denum format, GC3Denum type, ArrayBufferView* pixels, ExceptionState& es)
3576 { 3510 {
3577 if (isContextLost() || !validateTexFuncData("texSubImage2D", level, width, h eight, format, type, pixels, NullNotAllowed) 3511 if (isContextLost() || !validateTexFuncData("texSubImage2D", level, width, h eight, format, type, pixels, NullNotAllowed)
3578 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceArrayBufferVie w, target, level, format, width, height, 0, format, type, xoffset, yoffset)) 3512 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceArrayBufferVie w, target, level, format, width, height, 0, format, type, xoffset, yoffset))
3579 return; 3513 return;
3580 void* data = pixels->baseAddress(); 3514 void* data = pixels->baseAddress();
3581 Vector<uint8_t> tempData; 3515 Vector<uint8_t> tempData;
3582 bool changeUnpackAlignment = false; 3516 bool changeUnpackAlignment = false;
3583 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) { 3517 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) {
3584 if (!m_context->extractTextureData(width, height, format, type, 3518 if (!m_context->extractTextureData(width, height, format, type,
3585 m_unpackAlignment, 3519 m_unpackAlignment,
3586 m_unpackFlipY, m_unpackPremultiplyAlp ha, 3520 m_unpackFlipY, m_unpackPremultiplyAlpha,
3587 data, 3521 data,
3588 tempData)) 3522 tempData))
3589 return; 3523 return;
3590 data = tempData.data(); 3524 data = tempData.data();
3591 changeUnpackAlignment = true; 3525 changeUnpackAlignment = true;
3592 } 3526 }
3593 if (changeUnpackAlignment) 3527 if (changeUnpackAlignment)
3594 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, 1); 3528 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, 1);
3595 texSubImage2DBase(target, level, xoffset, yoffset, width, height, format, ty pe, data, es); 3529 texSubImage2DBase(target, level, xoffset, yoffset, width, height, format, ty pe, data, es);
3596 if (changeUnpackAlignment) 3530 if (changeUnpackAlignment)
3597 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, m_unpackAlig nment); 3531 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, m_unpackAlig nment);
3598 } 3532 }
3599 3533
3600 void WebGLRenderingContext::texSubImage2D(GC3Denum target, GC3Dint level, GC3Din t xoffset, GC3Dint yoffset, 3534 void WebGLRenderingContextBase::texSubImage2D(GC3Denum target, GC3Dint level, GC 3Dint xoffset, GC3Dint yoffset,
3601 GC3Denum format, GC3Denum type, ImageData* pixels, ExceptionState& es) 3535 GC3Denum format, GC3Denum type, ImageData* pixels, ExceptionState& es)
3602 { 3536 {
3603 if (isContextLost() || !pixels || !validateTexFunc("texSubImage2D", TexSubIm age2D, SourceImageData, target, level, format, pixels->width(), pixels->height( ), 0, format, type, xoffset, yoffset)) 3537 if (isContextLost() || !pixels || !validateTexFunc("texSubImage2D", TexSubIm age2D, SourceImageData, target, level, format, pixels->width(), pixels->height( ), 0, format, type, xoffset, yoffset))
3604 return; 3538 return;
3605 3539
3606 Vector<uint8_t> data; 3540 Vector<uint8_t> data;
3607 bool needConversion = true; 3541 bool needConversion = true;
3608 // The data from ImageData is always of format RGBA8. 3542 // The data from ImageData is always of format RGBA8.
3609 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required. 3543 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required.
3610 if (format == GraphicsContext3D::RGBA && type == GraphicsContext3D::UNSIGNED _BYTE && !m_unpackFlipY && !m_unpackPremultiplyAlpha) 3544 if (format == GraphicsContext3D::RGBA && type == GraphicsContext3D::UNSIGNED _BYTE && !m_unpackFlipY && !m_unpackPremultiplyAlpha) {
3611 needConversion = false; 3545 needConversion = false;
3612 else { 3546 } else {
3613 if (!m_context->extractImageData(pixels, format, type, m_unpackFlipY, m_ unpackPremultiplyAlpha, data)) { 3547 if (!m_context->extractImageData(pixels, format, type, m_unpackFlipY, m_ unpackPremultiplyAlpha, data)) {
3614 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texSubImage2D", "bad image data"); 3548 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "texSubImage2D", "bad image data");
3615 return; 3549 return;
3616 } 3550 }
3617 } 3551 }
3618 if (m_unpackAlignment != 1) 3552 if (m_unpackAlignment != 1)
3619 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, 1); 3553 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, 1);
3620 texSubImage2DBase(target, level, xoffset, yoffset, pixels->width(), pixels-> height(), format, type, needConversion ? data.data() : pixels->data()->data(), e s); 3554 texSubImage2DBase(target, level, xoffset, yoffset, pixels->width(), pixels-> height(), format, type, needConversion ? data.data() : pixels->data()->data(), e s);
3621 if (m_unpackAlignment != 1) 3555 if (m_unpackAlignment != 1)
3622 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, m_unpackAlig nment); 3556 m_context->pixelStorei(GraphicsContext3D::UNPACK_ALIGNMENT, m_unpackAlig nment);
3623 } 3557 }
3624 3558
3625 void WebGLRenderingContext::texSubImage2D(GC3Denum target, GC3Dint level, GC3Din t xoffset, GC3Dint yoffset, 3559 void WebGLRenderingContextBase::texSubImage2D(GC3Denum target, GC3Dint level, GC 3Dint xoffset, GC3Dint yoffset,
3626 GC3Denum format, GC3Denum type, HTMLImageElement* image, ExceptionState& es) 3560 GC3Denum format, GC3Denum type, HTMLImageElement* image, ExceptionState& es)
3627 { 3561 {
3628 if (isContextLost() || !validateHTMLImageElement("texSubImage2D", image, es) ) 3562 if (isContextLost() || !validateHTMLImageElement("texSubImage2D", image, es) )
3629 return; 3563 return;
3630 Image* imageForRender = image->cachedImage()->imageForRenderer(image->render er()); 3564 Image* imageForRender = image->cachedImage()->imageForRenderer(image->render er());
3631 if (!imageForRender || !validateTexFunc("texSubImage2D", TexSubImage2D, Sour ceHTMLImageElement, target, level, format, imageForRender->width(), imageForRend er->height(), 0, format, type, xoffset, yoffset)) 3565 if (!imageForRender || !validateTexFunc("texSubImage2D", TexSubImage2D, Sour ceHTMLImageElement, target, level, format, imageForRender->width(), imageForRend er->height(), 0, format, type, xoffset, yoffset))
3632 return; 3566 return;
3633 3567
3634 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, imageForRen der, GraphicsContext3D::HtmlDomImage, m_unpackFlipY, m_unpackPremultiplyAlpha, e s); 3568 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, imageForRen der, GraphicsContext3D::HtmlDomImage, m_unpackFlipY, m_unpackPremultiplyAlpha, e s);
3635 } 3569 }
3636 3570
3637 void WebGLRenderingContext::texSubImage2D(GC3Denum target, GC3Dint level, GC3Din t xoffset, GC3Dint yoffset, 3571 void WebGLRenderingContextBase::texSubImage2D(GC3Denum target, GC3Dint level, GC 3Dint xoffset, GC3Dint yoffset,
3638 GC3Denum format, GC3Denum type, HTMLCanvasElement* canvas, ExceptionState& e s) 3572 GC3Denum format, GC3Denum type, HTMLCanvasElement* canvas, ExceptionState& e s)
3639 { 3573 {
3640 if (isContextLost() || !validateHTMLCanvasElement("texSubImage2D", canvas, e s) 3574 if (isContextLost() || !validateHTMLCanvasElement("texSubImage2D", canvas, e s)
3641 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLCanvasElem ent, target, level, format, canvas->width(), canvas->height(), 0, format, type, xoffset, yoffset)) 3575 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLCanvasElem ent, target, level, format, canvas->width(), canvas->height(), 0, format, type, xoffset, yoffset))
3642 return; 3576 return;
3643 3577
3644 RefPtr<ImageData> imageData = canvas->getImageData(); 3578 RefPtr<ImageData> imageData = canvas->getImageData();
3645 if (imageData) 3579 if (imageData)
3646 texSubImage2D(target, level, xoffset, yoffset, format, type, imageData.g et(), es); 3580 texSubImage2D(target, level, xoffset, yoffset, format, type, imageData.g et(), es);
3647 else 3581 else
3648 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, canvas- >copiedImage(), GraphicsContext3D::HtmlDomCanvas, m_unpackFlipY, m_unpackPremult iplyAlpha, es); 3582 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, canvas- >copiedImage(), GraphicsContext3D::HtmlDomCanvas, m_unpackFlipY, m_unpackPremult iplyAlpha, es);
3649 } 3583 }
3650 3584
3651 void WebGLRenderingContext::texSubImage2D(GC3Denum target, GC3Dint level, GC3Din t xoffset, GC3Dint yoffset, 3585 void WebGLRenderingContextBase::texSubImage2D(GC3Denum target, GC3Dint level, GC 3Dint xoffset, GC3Dint yoffset,
3652 GC3Denum format, GC3Denum type, HTMLVideoElement* video, ExceptionState& es) 3586 GC3Denum format, GC3Denum type, HTMLVideoElement* video, ExceptionState& es)
3653 { 3587 {
3654 if (isContextLost() || !validateHTMLVideoElement("texSubImage2D", video, es) 3588 if (isContextLost() || !validateHTMLVideoElement("texSubImage2D", video, es)
3655 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLVideoEleme nt, target, level, format, video->videoWidth(), video->videoHeight(), 0, format, type, xoffset, yoffset)) 3589 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLVideoEleme nt, target, level, format, video->videoWidth(), video->videoHeight(), 0, format, type, xoffset, yoffset))
3656 return; 3590 return;
3657 3591
3658 RefPtr<Image> image = videoFrameToImage(video, ImageBuffer::fastCopyImageMod e()); 3592 RefPtr<Image> image = videoFrameToImage(video, ImageBuffer::fastCopyImageMod e());
3659 if (!image) 3593 if (!image)
3660 return; 3594 return;
3661 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, image.get() , GraphicsContext3D::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha, es); 3595 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, image.get() , GraphicsContext3D::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha, es);
3662 } 3596 }
3663 3597
3664 void WebGLRenderingContext::uniform1f(const WebGLUniformLocation* location, GC3D float x) 3598 void WebGLRenderingContextBase::uniform1f(const WebGLUniformLocation* location, GC3Dfloat x)
3665 { 3599 {
3666 if (isContextLost() || !location) 3600 if (isContextLost() || !location)
3667 return; 3601 return;
3668 3602
3669 if (location->program() != m_currentProgram) { 3603 if (location->program() != m_currentProgram) {
3670 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "uniform1f", "lo cation not for current program"); 3604 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "uniform1f", "lo cation not for current program");
3671 return; 3605 return;
3672 } 3606 }
3673 3607
3674 m_context->uniform1f(location->location(), x); 3608 m_context->uniform1f(location->location(), x);
3675 } 3609 }
3676 3610
3677 void WebGLRenderingContext::uniform1fv(const WebGLUniformLocation* location, Flo at32Array* v) 3611 void WebGLRenderingContextBase::uniform1fv(const WebGLUniformLocation* location, Float32Array* v)
3678 { 3612 {
3679 if (isContextLost() || !validateUniformParameters("uniform1fv", location, v, 1)) 3613 if (isContextLost() || !validateUniformParameters("uniform1fv", location, v, 1))
3680 return; 3614 return;
3681 3615
3682 m_context->uniform1fv(location->location(), v->length(), v->data()); 3616 m_context->uniform1fv(location->location(), v->length(), v->data());
3683 } 3617 }
3684 3618
3685 void WebGLRenderingContext::uniform1fv(const WebGLUniformLocation* location, GC3 Dfloat* v, GC3Dsizei size) 3619 void WebGLRenderingContextBase::uniform1fv(const WebGLUniformLocation* location, GC3Dfloat* v, GC3Dsizei size)
3686 { 3620 {
3687 if (isContextLost() || !validateUniformParameters("uniform1fv", location, v, size, 1)) 3621 if (isContextLost() || !validateUniformParameters("uniform1fv", location, v, size, 1))
3688 return; 3622 return;
3689 3623
3690 m_context->uniform1fv(location->location(), size, v); 3624 m_context->uniform1fv(location->location(), size, v);
3691 } 3625 }
3692 3626
3693 void WebGLRenderingContext::uniform1i(const WebGLUniformLocation* location, GC3D int x) 3627 void WebGLRenderingContextBase::uniform1i(const WebGLUniformLocation* location, GC3Dint x)
3694 { 3628 {
3695 if (isContextLost() || !location) 3629 if (isContextLost() || !location)
3696 return; 3630 return;
3697 3631
3698 if (location->program() != m_currentProgram) { 3632 if (location->program() != m_currentProgram) {
3699 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "uniform1i", "lo cation not for current program"); 3633 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "uniform1i", "lo cation not for current program");
3700 return; 3634 return;
3701 } 3635 }
3702 3636
3703 m_context->uniform1i(location->location(), x); 3637 m_context->uniform1i(location->location(), x);
3704 } 3638 }
3705 3639
3706 void WebGLRenderingContext::uniform1iv(const WebGLUniformLocation* location, Int 32Array* v) 3640 void WebGLRenderingContextBase::uniform1iv(const WebGLUniformLocation* location, Int32Array* v)
3707 { 3641 {
3708 if (isContextLost() || !validateUniformParameters("uniform1iv", location, v, 1)) 3642 if (isContextLost() || !validateUniformParameters("uniform1iv", location, v, 1))
3709 return; 3643 return;
3710 3644
3711 m_context->uniform1iv(location->location(), v->length(), v->data()); 3645 m_context->uniform1iv(location->location(), v->length(), v->data());
3712 } 3646 }
3713 3647
3714 void WebGLRenderingContext::uniform1iv(const WebGLUniformLocation* location, GC3 Dint* v, GC3Dsizei size) 3648 void WebGLRenderingContextBase::uniform1iv(const WebGLUniformLocation* location, GC3Dint* v, GC3Dsizei size)
3715 { 3649 {
3716 if (isContextLost() || !validateUniformParameters("uniform1iv", location, v, size, 1)) 3650 if (isContextLost() || !validateUniformParameters("uniform1iv", location, v, size, 1))
3717 return; 3651 return;
3718 3652
3719 m_context->uniform1iv(location->location(), size, v); 3653 m_context->uniform1iv(location->location(), size, v);
3720 } 3654 }
3721 3655
3722 void WebGLRenderingContext::uniform2f(const WebGLUniformLocation* location, GC3D float x, GC3Dfloat y) 3656 void WebGLRenderingContextBase::uniform2f(const WebGLUniformLocation* location, GC3Dfloat x, GC3Dfloat y)
3723 { 3657 {
3724 if (isContextLost() || !location) 3658 if (isContextLost() || !location)
3725 return; 3659 return;
3726 3660
3727 if (location->program() != m_currentProgram) { 3661 if (location->program() != m_currentProgram) {
3728 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "uniform2f", "lo cation not for current program"); 3662 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "uniform2f", "lo cation not for current program");
3729 return; 3663 return;
3730 } 3664 }
3731 3665
3732 m_context->uniform2f(location->location(), x, y); 3666 m_context->uniform2f(location->location(), x, y);
3733 } 3667 }
3734 3668
3735 void WebGLRenderingContext::uniform2fv(const WebGLUniformLocation* location, Flo at32Array* v) 3669 void WebGLRenderingContextBase::uniform2fv(const WebGLUniformLocation* location, Float32Array* v)
3736 { 3670 {
3737 if (isContextLost() || !validateUniformParameters("uniform2fv", location, v, 2)) 3671 if (isContextLost() || !validateUniformParameters("uniform2fv", location, v, 2))
3738 return; 3672 return;
3739 3673
3740 m_context->uniform2fv(location->location(), v->length() / 2, v->data()); 3674 m_context->uniform2fv(location->location(), v->length() / 2, v->data());
3741 } 3675 }
3742 3676
3743 void WebGLRenderingContext::uniform2fv(const WebGLUniformLocation* location, GC3 Dfloat* v, GC3Dsizei size) 3677 void WebGLRenderingContextBase::uniform2fv(const WebGLUniformLocation* location, GC3Dfloat* v, GC3Dsizei size)
3744 { 3678 {
3745 if (isContextLost() || !validateUniformParameters("uniform2fv", location, v, size, 2)) 3679 if (isContextLost() || !validateUniformParameters("uniform2fv", location, v, size, 2))
3746 return; 3680 return;
3747 3681
3748 m_context->uniform2fv(location->location(), size / 2, v); 3682 m_context->uniform2fv(location->location(), size / 2, v);
3749 } 3683 }
3750 3684
3751 void WebGLRenderingContext::uniform2i(const WebGLUniformLocation* location, GC3D int x, GC3Dint y) 3685 void WebGLRenderingContextBase::uniform2i(const WebGLUniformLocation* location, GC3Dint x, GC3Dint y)
3752 { 3686 {
3753 if (isContextLost() || !location) 3687 if (isContextLost() || !location)
3754 return; 3688 return;
3755 3689
3756 if (location->program() != m_currentProgram) { 3690 if (location->program() != m_currentProgram) {
3757 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "uniform2i", "lo cation not for current program"); 3691 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "uniform2i", "lo cation not for current program");
3758 return; 3692 return;
3759 } 3693 }
3760 3694
3761 m_context->uniform2i(location->location(), x, y); 3695 m_context->uniform2i(location->location(), x, y);
3762 } 3696 }
3763 3697
3764 void WebGLRenderingContext::uniform2iv(const WebGLUniformLocation* location, Int 32Array* v) 3698 void WebGLRenderingContextBase::uniform2iv(const WebGLUniformLocation* location, Int32Array* v)
3765 { 3699 {
3766 if (isContextLost() || !validateUniformParameters("uniform2iv", location, v, 2)) 3700 if (isContextLost() || !validateUniformParameters("uniform2iv", location, v, 2))
3767 return; 3701 return;
3768 3702
3769 m_context->uniform2iv(location->location(), v->length() / 2, v->data()); 3703 m_context->uniform2iv(location->location(), v->length() / 2, v->data());
3770 } 3704 }
3771 3705
3772 void WebGLRenderingContext::uniform2iv(const WebGLUniformLocation* location, GC3 Dint* v, GC3Dsizei size) 3706 void WebGLRenderingContextBase::uniform2iv(const WebGLUniformLocation* location, GC3Dint* v, GC3Dsizei size)
3773 { 3707 {
3774 if (isContextLost() || !validateUniformParameters("uniform2iv", location, v, size, 2)) 3708 if (isContextLost() || !validateUniformParameters("uniform2iv", location, v, size, 2))
3775 return; 3709 return;
3776 3710
3777 m_context->uniform2iv(location->location(), size / 2, v); 3711 m_context->uniform2iv(location->location(), size / 2, v);
3778 } 3712 }
3779 3713
3780 void WebGLRenderingContext::uniform3f(const WebGLUniformLocation* location, GC3D float x, GC3Dfloat y, GC3Dfloat z) 3714 void WebGLRenderingContextBase::uniform3f(const WebGLUniformLocation* location, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z)
3781 { 3715 {
3782 if (isContextLost() || !location) 3716 if (isContextLost() || !location)
3783 return; 3717 return;
3784 3718
3785 if (location->program() != m_currentProgram) { 3719 if (location->program() != m_currentProgram) {
3786 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "uniform3f", "lo cation not for current program"); 3720 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "uniform3f", "lo cation not for current program");
3787 return; 3721 return;
3788 } 3722 }
3789 3723
3790 m_context->uniform3f(location->location(), x, y, z); 3724 m_context->uniform3f(location->location(), x, y, z);
3791 } 3725 }
3792 3726
3793 void WebGLRenderingContext::uniform3fv(const WebGLUniformLocation* location, Flo at32Array* v) 3727 void WebGLRenderingContextBase::uniform3fv(const WebGLUniformLocation* location, Float32Array* v)
3794 { 3728 {
3795 if (isContextLost() || !validateUniformParameters("uniform3fv", location, v, 3)) 3729 if (isContextLost() || !validateUniformParameters("uniform3fv", location, v, 3))
3796 return; 3730 return;
3797 3731
3798 m_context->uniform3fv(location->location(), v->length() / 3, v->data()); 3732 m_context->uniform3fv(location->location(), v->length() / 3, v->data());
3799 } 3733 }
3800 3734
3801 void WebGLRenderingContext::uniform3fv(const WebGLUniformLocation* location, GC3 Dfloat* v, GC3Dsizei size) 3735 void WebGLRenderingContextBase::uniform3fv(const WebGLUniformLocation* location, GC3Dfloat* v, GC3Dsizei size)
3802 { 3736 {
3803 if (isContextLost() || !validateUniformParameters("uniform3fv", location, v, size, 3)) 3737 if (isContextLost() || !validateUniformParameters("uniform3fv", location, v, size, 3))
3804 return; 3738 return;
3805 3739
3806 m_context->uniform3fv(location->location(), size / 3, v); 3740 m_context->uniform3fv(location->location(), size / 3, v);
3807 } 3741 }
3808 3742
3809 void WebGLRenderingContext::uniform3i(const WebGLUniformLocation* location, GC3D int x, GC3Dint y, GC3Dint z) 3743 void WebGLRenderingContextBase::uniform3i(const WebGLUniformLocation* location, GC3Dint x, GC3Dint y, GC3Dint z)
3810 { 3744 {
3811 if (isContextLost() || !location) 3745 if (isContextLost() || !location)
3812 return; 3746 return;
3813 3747
3814 if (location->program() != m_currentProgram) { 3748 if (location->program() != m_currentProgram) {
3815 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "uniform3i", "lo cation not for current program"); 3749 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "uniform3i", "lo cation not for current program");
3816 return; 3750 return;
3817 } 3751 }
3818 3752
3819 m_context->uniform3i(location->location(), x, y, z); 3753 m_context->uniform3i(location->location(), x, y, z);
3820 } 3754 }
3821 3755
3822 void WebGLRenderingContext::uniform3iv(const WebGLUniformLocation* location, Int 32Array* v) 3756 void WebGLRenderingContextBase::uniform3iv(const WebGLUniformLocation* location, Int32Array* v)
3823 { 3757 {
3824 if (isContextLost() || !validateUniformParameters("uniform3iv", location, v, 3)) 3758 if (isContextLost() || !validateUniformParameters("uniform3iv", location, v, 3))
3825 return; 3759 return;
3826 3760
3827 m_context->uniform3iv(location->location(), v->length() / 3, v->data()); 3761 m_context->uniform3iv(location->location(), v->length() / 3, v->data());
3828 } 3762 }
3829 3763
3830 void WebGLRenderingContext::uniform3iv(const WebGLUniformLocation* location, GC3 Dint* v, GC3Dsizei size) 3764 void WebGLRenderingContextBase::uniform3iv(const WebGLUniformLocation* location, GC3Dint* v, GC3Dsizei size)
3831 { 3765 {
3832 if (isContextLost() || !validateUniformParameters("uniform3iv", location, v, size, 3)) 3766 if (isContextLost() || !validateUniformParameters("uniform3iv", location, v, size, 3))
3833 return; 3767 return;
3834 3768
3835 m_context->uniform3iv(location->location(), size / 3, v); 3769 m_context->uniform3iv(location->location(), size / 3, v);
3836 } 3770 }
3837 3771
3838 void WebGLRenderingContext::uniform4f(const WebGLUniformLocation* location, GC3D float x, GC3Dfloat y, GC3Dfloat z, GC3Dfloat w) 3772 void WebGLRenderingContextBase::uniform4f(const WebGLUniformLocation* location, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z, GC3Dfloat w)
3839 { 3773 {
3840 if (isContextLost() || !location) 3774 if (isContextLost() || !location)
3841 return; 3775 return;
3842 3776
3843 if (location->program() != m_currentProgram) { 3777 if (location->program() != m_currentProgram) {
3844 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "uniform4f", "lo cation not for current program"); 3778 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "uniform4f", "lo cation not for current program");
3845 return; 3779 return;
3846 } 3780 }
3847 3781
3848 m_context->uniform4f(location->location(), x, y, z, w); 3782 m_context->uniform4f(location->location(), x, y, z, w);
3849 } 3783 }
3850 3784
3851 void WebGLRenderingContext::uniform4fv(const WebGLUniformLocation* location, Flo at32Array* v) 3785 void WebGLRenderingContextBase::uniform4fv(const WebGLUniformLocation* location, Float32Array* v)
3852 { 3786 {
3853 if (isContextLost() || !validateUniformParameters("uniform4fv", location, v, 4)) 3787 if (isContextLost() || !validateUniformParameters("uniform4fv", location, v, 4))
3854 return; 3788 return;
3855 3789
3856 m_context->uniform4fv(location->location(), v->length() / 4, v->data()); 3790 m_context->uniform4fv(location->location(), v->length() / 4, v->data());
3857 } 3791 }
3858 3792
3859 void WebGLRenderingContext::uniform4fv(const WebGLUniformLocation* location, GC3 Dfloat* v, GC3Dsizei size) 3793 void WebGLRenderingContextBase::uniform4fv(const WebGLUniformLocation* location, GC3Dfloat* v, GC3Dsizei size)
3860 { 3794 {
3861 if (isContextLost() || !validateUniformParameters("uniform4fv", location, v, size, 4)) 3795 if (isContextLost() || !validateUniformParameters("uniform4fv", location, v, size, 4))
3862 return; 3796 return;
3863 3797
3864 m_context->uniform4fv(location->location(), size / 4, v); 3798 m_context->uniform4fv(location->location(), size / 4, v);
3865 } 3799 }
3866 3800
3867 void WebGLRenderingContext::uniform4i(const WebGLUniformLocation* location, GC3D int x, GC3Dint y, GC3Dint z, GC3Dint w) 3801 void WebGLRenderingContextBase::uniform4i(const WebGLUniformLocation* location, GC3Dint x, GC3Dint y, GC3Dint z, GC3Dint w)
3868 { 3802 {
3869 if (isContextLost() || !location) 3803 if (isContextLost() || !location)
3870 return; 3804 return;
3871 3805
3872 if (location->program() != m_currentProgram) { 3806 if (location->program() != m_currentProgram) {
3873 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "uniform4i", "lo cation not for current program"); 3807 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "uniform4i", "lo cation not for current program");
3874 return; 3808 return;
3875 } 3809 }
3876 3810
3877 m_context->uniform4i(location->location(), x, y, z, w); 3811 m_context->uniform4i(location->location(), x, y, z, w);
3878 } 3812 }
3879 3813
3880 void WebGLRenderingContext::uniform4iv(const WebGLUniformLocation* location, Int 32Array* v) 3814 void WebGLRenderingContextBase::uniform4iv(const WebGLUniformLocation* location, Int32Array* v)
3881 { 3815 {
3882 if (isContextLost() || !validateUniformParameters("uniform4iv", location, v, 4)) 3816 if (isContextLost() || !validateUniformParameters("uniform4iv", location, v, 4))
3883 return; 3817 return;
3884 3818
3885 m_context->uniform4iv(location->location(), v->length() / 4, v->data()); 3819 m_context->uniform4iv(location->location(), v->length() / 4, v->data());
3886 } 3820 }
3887 3821
3888 void WebGLRenderingContext::uniform4iv(const WebGLUniformLocation* location, GC3 Dint* v, GC3Dsizei size) 3822 void WebGLRenderingContextBase::uniform4iv(const WebGLUniformLocation* location, GC3Dint* v, GC3Dsizei size)
3889 { 3823 {
3890 if (isContextLost() || !validateUniformParameters("uniform4iv", location, v, size, 4)) 3824 if (isContextLost() || !validateUniformParameters("uniform4iv", location, v, size, 4))
3891 return; 3825 return;
3892 3826
3893 m_context->uniform4iv(location->location(), size / 4, v); 3827 m_context->uniform4iv(location->location(), size / 4, v);
3894 } 3828 }
3895 3829
3896 void WebGLRenderingContext::uniformMatrix2fv(const WebGLUniformLocation* locatio n, GC3Dboolean transpose, Float32Array* v) 3830 void WebGLRenderingContextBase::uniformMatrix2fv(const WebGLUniformLocation* loc ation, GC3Dboolean transpose, Float32Array* v)
3897 { 3831 {
3898 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix2fv", location, transpose, v, 4)) 3832 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix2fv", location, transpose, v, 4))
3899 return; 3833 return;
3900 m_context->uniformMatrix2fv(location->location(), v->length() / 4, transpose , v->data()); 3834 m_context->uniformMatrix2fv(location->location(), v->length() / 4, transpose , v->data());
3901 } 3835 }
3902 3836
3903 void WebGLRenderingContext::uniformMatrix2fv(const WebGLUniformLocation* locatio n, GC3Dboolean transpose, GC3Dfloat* v, GC3Dsizei size) 3837 void WebGLRenderingContextBase::uniformMatrix2fv(const WebGLUniformLocation* loc ation, GC3Dboolean transpose, GC3Dfloat* v, GC3Dsizei size)
3904 { 3838 {
3905 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix2fv", location, transpose, v, size, 4)) 3839 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix2fv", location, transpose, v, size, 4))
3906 return; 3840 return;
3907 m_context->uniformMatrix2fv(location->location(), size / 4, transpose, v); 3841 m_context->uniformMatrix2fv(location->location(), size / 4, transpose, v);
3908 } 3842 }
3909 3843
3910 void WebGLRenderingContext::uniformMatrix3fv(const WebGLUniformLocation* locatio n, GC3Dboolean transpose, Float32Array* v) 3844 void WebGLRenderingContextBase::uniformMatrix3fv(const WebGLUniformLocation* loc ation, GC3Dboolean transpose, Float32Array* v)
3911 { 3845 {
3912 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix3fv", location, transpose, v, 9)) 3846 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix3fv", location, transpose, v, 9))
3913 return; 3847 return;
3914 m_context->uniformMatrix3fv(location->location(), v->length() / 9, transpose , v->data()); 3848 m_context->uniformMatrix3fv(location->location(), v->length() / 9, transpose , v->data());
3915 } 3849 }
3916 3850
3917 void WebGLRenderingContext::uniformMatrix3fv(const WebGLUniformLocation* locatio n, GC3Dboolean transpose, GC3Dfloat* v, GC3Dsizei size) 3851 void WebGLRenderingContextBase::uniformMatrix3fv(const WebGLUniformLocation* loc ation, GC3Dboolean transpose, GC3Dfloat* v, GC3Dsizei size)
3918 { 3852 {
3919 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix3fv", location, transpose, v, size, 9)) 3853 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix3fv", location, transpose, v, size, 9))
3920 return; 3854 return;
3921 m_context->uniformMatrix3fv(location->location(), size / 9, transpose, v); 3855 m_context->uniformMatrix3fv(location->location(), size / 9, transpose, v);
3922 } 3856 }
3923 3857
3924 void WebGLRenderingContext::uniformMatrix4fv(const WebGLUniformLocation* locatio n, GC3Dboolean transpose, Float32Array* v) 3858 void WebGLRenderingContextBase::uniformMatrix4fv(const WebGLUniformLocation* loc ation, GC3Dboolean transpose, Float32Array* v)
3925 { 3859 {
3926 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix4fv", location, transpose, v, 16)) 3860 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix4fv", location, transpose, v, 16))
3927 return; 3861 return;
3928 m_context->uniformMatrix4fv(location->location(), v->length() / 16, transpos e, v->data()); 3862 m_context->uniformMatrix4fv(location->location(), v->length() / 16, transpos e, v->data());
3929 } 3863 }
3930 3864
3931 void WebGLRenderingContext::uniformMatrix4fv(const WebGLUniformLocation* locatio n, GC3Dboolean transpose, GC3Dfloat* v, GC3Dsizei size) 3865 void WebGLRenderingContextBase::uniformMatrix4fv(const WebGLUniformLocation* loc ation, GC3Dboolean transpose, GC3Dfloat* v, GC3Dsizei size)
3932 { 3866 {
3933 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix4fv", location, transpose, v, size, 16)) 3867 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix4fv", location, transpose, v, size, 16))
3934 return; 3868 return;
3935 m_context->uniformMatrix4fv(location->location(), size / 16, transpose, v); 3869 m_context->uniformMatrix4fv(location->location(), size / 16, transpose, v);
3936 } 3870 }
3937 3871
3938 void WebGLRenderingContext::useProgram(WebGLProgram* program) 3872 void WebGLRenderingContextBase::useProgram(WebGLProgram* program)
3939 { 3873 {
3940 bool deleted; 3874 bool deleted;
3941 if (!checkObjectToBeBound("useProgram", program, deleted)) 3875 if (!checkObjectToBeBound("useProgram", program, deleted))
3942 return; 3876 return;
3943 if (deleted) 3877 if (deleted)
3944 program = 0; 3878 program = 0;
3945 if (program && !program->getLinkStatus()) { 3879 if (program && !program->getLinkStatus()) {
3946 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "useProgram", "p rogram not valid"); 3880 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "useProgram", "p rogram not valid");
3947 return; 3881 return;
3948 } 3882 }
3949 if (m_currentProgram != program) { 3883 if (m_currentProgram != program) {
3950 if (m_currentProgram) 3884 if (m_currentProgram)
3951 m_currentProgram->onDetached(graphicsContext3D()); 3885 m_currentProgram->onDetached(graphicsContext3D());
3952 m_currentProgram = program; 3886 m_currentProgram = program;
3953 m_context->useProgram(objectOrZero(program)); 3887 m_context->useProgram(objectOrZero(program));
3954 if (program) 3888 if (program)
3955 program->onAttached(); 3889 program->onAttached();
3956 } 3890 }
3957 } 3891 }
3958 3892
3959 void WebGLRenderingContext::validateProgram(WebGLProgram* program) 3893 void WebGLRenderingContextBase::validateProgram(WebGLProgram* program)
3960 { 3894 {
3961 if (isContextLost() || !validateWebGLObject("validateProgram", program)) 3895 if (isContextLost() || !validateWebGLObject("validateProgram", program))
3962 return; 3896 return;
3963 m_context->validateProgram(objectOrZero(program)); 3897 m_context->validateProgram(objectOrZero(program));
3964 } 3898 }
3965 3899
3966 void WebGLRenderingContext::vertexAttrib1f(GC3Duint index, GC3Dfloat v0) 3900 void WebGLRenderingContextBase::vertexAttrib1f(GC3Duint index, GC3Dfloat v0)
3967 { 3901 {
3968 vertexAttribfImpl("vertexAttrib1f", index, 1, v0, 0.0f, 0.0f, 1.0f); 3902 vertexAttribfImpl("vertexAttrib1f", index, 1, v0, 0.0f, 0.0f, 1.0f);
3969 } 3903 }
3970 3904
3971 void WebGLRenderingContext::vertexAttrib1fv(GC3Duint index, Float32Array* v) 3905 void WebGLRenderingContextBase::vertexAttrib1fv(GC3Duint index, Float32Array* v)
3972 { 3906 {
3973 vertexAttribfvImpl("vertexAttrib1fv", index, v, 1); 3907 vertexAttribfvImpl("vertexAttrib1fv", index, v, 1);
3974 } 3908 }
3975 3909
3976 void WebGLRenderingContext::vertexAttrib1fv(GC3Duint index, GC3Dfloat* v, GC3Dsi zei size) 3910 void WebGLRenderingContextBase::vertexAttrib1fv(GC3Duint index, GC3Dfloat* v, GC 3Dsizei size)
3977 { 3911 {
3978 vertexAttribfvImpl("vertexAttrib1fv", index, v, size, 1); 3912 vertexAttribfvImpl("vertexAttrib1fv", index, v, size, 1);
3979 } 3913 }
3980 3914
3981 void WebGLRenderingContext::vertexAttrib2f(GC3Duint index, GC3Dfloat v0, GC3Dflo at v1) 3915 void WebGLRenderingContextBase::vertexAttrib2f(GC3Duint index, GC3Dfloat v0, GC3 Dfloat v1)
3982 { 3916 {
3983 vertexAttribfImpl("vertexAttrib2f", index, 2, v0, v1, 0.0f, 1.0f); 3917 vertexAttribfImpl("vertexAttrib2f", index, 2, v0, v1, 0.0f, 1.0f);
3984 } 3918 }
3985 3919
3986 void WebGLRenderingContext::vertexAttrib2fv(GC3Duint index, Float32Array* v) 3920 void WebGLRenderingContextBase::vertexAttrib2fv(GC3Duint index, Float32Array* v)
3987 { 3921 {
3988 vertexAttribfvImpl("vertexAttrib2fv", index, v, 2); 3922 vertexAttribfvImpl("vertexAttrib2fv", index, v, 2);
3989 } 3923 }
3990 3924
3991 void WebGLRenderingContext::vertexAttrib2fv(GC3Duint index, GC3Dfloat* v, GC3Dsi zei size) 3925 void WebGLRenderingContextBase::vertexAttrib2fv(GC3Duint index, GC3Dfloat* v, GC 3Dsizei size)
3992 { 3926 {
3993 vertexAttribfvImpl("vertexAttrib2fv", index, v, size, 2); 3927 vertexAttribfvImpl("vertexAttrib2fv", index, v, size, 2);
3994 } 3928 }
3995 3929
3996 void WebGLRenderingContext::vertexAttrib3f(GC3Duint index, GC3Dfloat v0, GC3Dflo at v1, GC3Dfloat v2) 3930 void WebGLRenderingContextBase::vertexAttrib3f(GC3Duint index, GC3Dfloat v0, GC3 Dfloat v1, GC3Dfloat v2)
3997 { 3931 {
3998 vertexAttribfImpl("vertexAttrib3f", index, 3, v0, v1, v2, 1.0f); 3932 vertexAttribfImpl("vertexAttrib3f", index, 3, v0, v1, v2, 1.0f);
3999 } 3933 }
4000 3934
4001 void WebGLRenderingContext::vertexAttrib3fv(GC3Duint index, Float32Array* v) 3935 void WebGLRenderingContextBase::vertexAttrib3fv(GC3Duint index, Float32Array* v)
4002 { 3936 {
4003 vertexAttribfvImpl("vertexAttrib3fv", index, v, 3); 3937 vertexAttribfvImpl("vertexAttrib3fv", index, v, 3);
4004 } 3938 }
4005 3939
4006 void WebGLRenderingContext::vertexAttrib3fv(GC3Duint index, GC3Dfloat* v, GC3Dsi zei size) 3940 void WebGLRenderingContextBase::vertexAttrib3fv(GC3Duint index, GC3Dfloat* v, GC 3Dsizei size)
4007 { 3941 {
4008 vertexAttribfvImpl("vertexAttrib3fv", index, v, size, 3); 3942 vertexAttribfvImpl("vertexAttrib3fv", index, v, size, 3);
4009 } 3943 }
4010 3944
4011 void WebGLRenderingContext::vertexAttrib4f(GC3Duint index, GC3Dfloat v0, GC3Dflo at v1, GC3Dfloat v2, GC3Dfloat v3) 3945 void WebGLRenderingContextBase::vertexAttrib4f(GC3Duint index, GC3Dfloat v0, GC3 Dfloat v1, GC3Dfloat v2, GC3Dfloat v3)
4012 { 3946 {
4013 vertexAttribfImpl("vertexAttrib4f", index, 4, v0, v1, v2, v3); 3947 vertexAttribfImpl("vertexAttrib4f", index, 4, v0, v1, v2, v3);
4014 } 3948 }
4015 3949
4016 void WebGLRenderingContext::vertexAttrib4fv(GC3Duint index, Float32Array* v) 3950 void WebGLRenderingContextBase::vertexAttrib4fv(GC3Duint index, Float32Array* v)
4017 { 3951 {
4018 vertexAttribfvImpl("vertexAttrib4fv", index, v, 4); 3952 vertexAttribfvImpl("vertexAttrib4fv", index, v, 4);
4019 } 3953 }
4020 3954
4021 void WebGLRenderingContext::vertexAttrib4fv(GC3Duint index, GC3Dfloat* v, GC3Dsi zei size) 3955 void WebGLRenderingContextBase::vertexAttrib4fv(GC3Duint index, GC3Dfloat* v, GC 3Dsizei size)
4022 { 3956 {
4023 vertexAttribfvImpl("vertexAttrib4fv", index, v, size, 4); 3957 vertexAttribfvImpl("vertexAttrib4fv", index, v, size, 4);
4024 } 3958 }
4025 3959
4026 void WebGLRenderingContext::vertexAttribPointer(GC3Duint index, GC3Dint size, GC 3Denum type, GC3Dboolean normalized, GC3Dsizei stride, long long offset) 3960 void WebGLRenderingContextBase::vertexAttribPointer(GC3Duint index, GC3Dint size , GC3Denum type, GC3Dboolean normalized, GC3Dsizei stride, long long offset)
4027 { 3961 {
4028 if (isContextLost()) 3962 if (isContextLost())
4029 return; 3963 return;
4030 switch (type) { 3964 switch (type) {
4031 case GraphicsContext3D::BYTE: 3965 case GraphicsContext3D::BYTE:
4032 case GraphicsContext3D::UNSIGNED_BYTE: 3966 case GraphicsContext3D::UNSIGNED_BYTE:
4033 case GraphicsContext3D::SHORT: 3967 case GraphicsContext3D::SHORT:
4034 case GraphicsContext3D::UNSIGNED_SHORT: 3968 case GraphicsContext3D::UNSIGNED_SHORT:
4035 case GraphicsContext3D::FLOAT: 3969 case GraphicsContext3D::FLOAT:
4036 break; 3970 break;
4037 default: 3971 default:
4038 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "vertexAttribPointer" , "invalid type"); 3972 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "vertexAttribPointer" , "invalid type");
4039 return; 3973 return;
4040 } 3974 }
4041 if (index >= m_maxVertexAttribs) { 3975 if (index >= m_maxVertexAttribs) {
4042 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "vertexAttribPointer ", "index out of range"); 3976 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "vertexAttribPointer ", "index out of range");
4043 return; 3977 return;
4044 } 3978 }
4045 if (size < 1 || size > 4 || stride < 0 || stride > 255 || offset < 0) { 3979 if (size < 1 || size > 4 || stride < 0 || stride > 255 || offset < 0) {
4046 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "vertexAttribPointer ", "bad size, stride or offset"); 3980 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "vertexAttribPointer ", "bad size, stride or offset");
4047 return; 3981 return;
4048 } 3982 }
4049 if (!m_boundArrayBuffer) { 3983 if (!m_boundArrayBuffer) {
4050 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "vertexAttribPoi nter", "no bound ARRAY_BUFFER"); 3984 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "vertexAttribPoi nter", "no bound ARRAY_BUFFER");
4051 return; 3985 return;
4052 } 3986 }
4053 // Determine the number of elements the bound buffer can hold, given the off set, size, type and stride 3987 // Determine the number of elements the bound buffer can hold, given the off set, size, type and stride
4054 unsigned int typeSize = sizeInBytes(type); 3988 unsigned typeSize = sizeInBytes(type);
4055 if (!typeSize) { 3989 if (!typeSize) {
4056 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "vertexAttribPointer" , "invalid type"); 3990 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "vertexAttribPointer" , "invalid type");
4057 return; 3991 return;
4058 } 3992 }
4059 if ((stride % typeSize) || (static_cast<GC3Dintptr>(offset) % typeSize)) { 3993 if ((stride % typeSize) || (static_cast<GC3Dintptr>(offset) % typeSize)) {
4060 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "vertexAttribPoi nter", "stride or offset not valid for type"); 3994 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "vertexAttribPoi nter", "stride or offset not valid for type");
4061 return; 3995 return;
4062 } 3996 }
4063 GC3Dsizei bytesPerElement = size * typeSize; 3997 GC3Dsizei bytesPerElement = size * typeSize;
4064 3998
4065 m_boundVertexArrayObject->setVertexAttribState(index, bytesPerElement, size, type, normalized, stride, static_cast<GC3Dintptr>(offset), m_boundArrayBuffer); 3999 m_boundVertexArrayObject->setVertexAttribState(index, bytesPerElement, size, type, normalized, stride, static_cast<GC3Dintptr>(offset), m_boundArrayBuffer);
4066 m_context->vertexAttribPointer(index, size, type, normalized, stride, static _cast<GC3Dintptr>(offset)); 4000 m_context->vertexAttribPointer(index, size, type, normalized, stride, static _cast<GC3Dintptr>(offset));
4067 } 4001 }
4068 4002
4069 void WebGLRenderingContext::vertexAttribDivisorANGLE(GC3Duint index, GC3Duint di visor) 4003 void WebGLRenderingContextBase::vertexAttribDivisorANGLE(GC3Duint index, GC3Duin t divisor)
4070 { 4004 {
4071 if (isContextLost()) 4005 if (isContextLost())
4072 return; 4006 return;
4073 4007
4074 if (index >= m_maxVertexAttribs) { 4008 if (index >= m_maxVertexAttribs) {
4075 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "vertexAttribDivisor ANGLE", "index out of range"); 4009 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "vertexAttribDivisor ANGLE", "index out of range");
4076 return; 4010 return;
4077 } 4011 }
4078 4012
4079 m_boundVertexArrayObject->setVertexAttribDivisor(index, divisor); 4013 m_boundVertexArrayObject->setVertexAttribDivisor(index, divisor);
4080 m_context->getExtensions()->vertexAttribDivisorANGLE(index, divisor); 4014 m_context->getExtensions()->vertexAttribDivisorANGLE(index, divisor);
4081 } 4015 }
4082 4016
4083 void WebGLRenderingContext::viewport(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3D sizei height) 4017 void WebGLRenderingContextBase::viewport(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height)
4084 { 4018 {
4085 if (isContextLost()) 4019 if (isContextLost())
4086 return; 4020 return;
4087 if (!validateSize("viewport", width, height)) 4021 if (!validateSize("viewport", width, height))
4088 return; 4022 return;
4089 m_context->viewport(x, y, width, height); 4023 m_context->viewport(x, y, width, height);
4090 } 4024 }
4091 4025
4092 void WebGLRenderingContext::forceLostContext(WebGLRenderingContext::LostContextM ode mode) 4026 void WebGLRenderingContextBase::forceLostContext(WebGLRenderingContextBase::Lost ContextMode mode)
4093 { 4027 {
4094 if (isContextLost()) { 4028 if (isContextLost()) {
4095 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "loseContext", " context already lost"); 4029 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "loseContext", " context already lost");
4096 return; 4030 return;
4097 } 4031 }
4098 4032
4099 m_contextGroup->loseContextGroup(mode); 4033 m_contextGroup->loseContextGroup(mode);
4100 } 4034 }
4101 4035
4102 void WebGLRenderingContext::loseContextImpl(WebGLRenderingContext::LostContextMo de mode) 4036 void WebGLRenderingContextBase::loseContextImpl(WebGLRenderingContextBase::LostC ontextMode mode)
4103 { 4037 {
4104 if (isContextLost()) 4038 if (isContextLost())
4105 return; 4039 return;
4106 4040
4107 m_contextLost = true; 4041 m_contextLost = true;
4108 m_contextLostMode = mode; 4042 m_contextLostMode = mode;
4109 4043
4110 if (mode == RealLostContext) { 4044 if (mode == RealLostContext) {
4111 // Inform the embedder that a lost context was received. In response, th e embedder might 4045 // Inform the embedder that a lost context was received. In response, th e embedder might
4112 // decide to take action such as asking the user for permission to use W ebGL again. 4046 // decide to take action such as asking the user for permission to use W ebGL again.
(...skipping 23 matching lines...) Expand all
4136 4070
4137 // Don't allow restoration unless the context lost event has both been 4071 // Don't allow restoration unless the context lost event has both been
4138 // dispatched and its default behavior prevented. 4072 // dispatched and its default behavior prevented.
4139 m_restoreAllowed = false; 4073 m_restoreAllowed = false;
4140 4074
4141 // Always defer the dispatch of the context lost event, to implement 4075 // Always defer the dispatch of the context lost event, to implement
4142 // the spec behavior of queueing a task. 4076 // the spec behavior of queueing a task.
4143 m_dispatchContextLostEventTimer.startOneShot(0); 4077 m_dispatchContextLostEventTimer.startOneShot(0);
4144 } 4078 }
4145 4079
4146 void WebGLRenderingContext::forceRestoreContext() 4080 void WebGLRenderingContextBase::forceRestoreContext()
4147 { 4081 {
4148 if (!isContextLost()) { 4082 if (!isContextLost()) {
4149 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "restoreContext" , "context not lost"); 4083 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "restoreContext" , "context not lost");
4150 return; 4084 return;
4151 } 4085 }
4152 4086
4153 if (!m_restoreAllowed) { 4087 if (!m_restoreAllowed) {
4154 if (m_contextLostMode == SyntheticLostContext) 4088 if (m_contextLostMode == SyntheticLostContext)
4155 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "restoreCont ext", "context restoration not allowed"); 4089 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "restoreCont ext", "context restoration not allowed");
4156 return; 4090 return;
4157 } 4091 }
4158 4092
4159 if (!m_restoreTimer.isActive()) 4093 if (!m_restoreTimer.isActive())
4160 m_restoreTimer.startOneShot(0); 4094 m_restoreTimer.startOneShot(0);
4161 } 4095 }
4162 4096
4163 WebKit::WebLayer* WebGLRenderingContext::platformLayer() const 4097 WebKit::WebLayer* WebGLRenderingContextBase::platformLayer() const
4164 { 4098 {
4165 return m_drawingBuffer->platformLayer(); 4099 return m_drawingBuffer->platformLayer();
4166 } 4100 }
4167 4101
4168 void WebGLRenderingContext::removeSharedObject(WebGLSharedObject* object) 4102 void WebGLRenderingContextBase::removeSharedObject(WebGLSharedObject* object)
4169 { 4103 {
4170 m_contextGroup->removeObject(object); 4104 m_contextGroup->removeObject(object);
4171 } 4105 }
4172 4106
4173 void WebGLRenderingContext::addSharedObject(WebGLSharedObject* object) 4107 void WebGLRenderingContextBase::addSharedObject(WebGLSharedObject* object)
4174 { 4108 {
4175 ASSERT(!isContextLost()); 4109 ASSERT(!isContextLost());
4176 m_contextGroup->addObject(object); 4110 m_contextGroup->addObject(object);
4177 } 4111 }
4178 4112
4179 void WebGLRenderingContext::removeContextObject(WebGLContextObject* object) 4113 void WebGLRenderingContextBase::removeContextObject(WebGLContextObject* object)
4180 { 4114 {
4181 m_contextObjects.remove(object); 4115 m_contextObjects.remove(object);
4182 } 4116 }
4183 4117
4184 void WebGLRenderingContext::addContextObject(WebGLContextObject* object) 4118 void WebGLRenderingContextBase::addContextObject(WebGLContextObject* object)
4185 { 4119 {
4186 ASSERT(!isContextLost()); 4120 ASSERT(!isContextLost());
4187 m_contextObjects.add(object); 4121 m_contextObjects.add(object);
4188 } 4122 }
4189 4123
4190 void WebGLRenderingContext::detachAndRemoveAllObjects() 4124 void WebGLRenderingContextBase::detachAndRemoveAllObjects()
4191 { 4125 {
4192 while (m_contextObjects.size() > 0) { 4126 while (m_contextObjects.size() > 0) {
4193 HashSet<WebGLContextObject*>::iterator it = m_contextObjects.begin(); 4127 HashSet<WebGLContextObject*>::iterator it = m_contextObjects.begin();
4194 (*it)->detachContext(); 4128 (*it)->detachContext();
4195 } 4129 }
4196 } 4130 }
4197 4131
4198 bool WebGLRenderingContext::hasPendingActivity() const 4132 bool WebGLRenderingContextBase::hasPendingActivity() const
4199 { 4133 {
4200 return false; 4134 return false;
4201 } 4135 }
4202 4136
4203 void WebGLRenderingContext::stop() 4137 void WebGLRenderingContextBase::stop()
4204 { 4138 {
4205 if (!isContextLost()) { 4139 if (!isContextLost()) {
4206 forceLostContext(SyntheticLostContext); 4140 forceLostContext(SyntheticLostContext);
4207 destroyGraphicsContext3D(); 4141 destroyGraphicsContext3D();
4208 } 4142 }
4209 } 4143 }
4210 4144
4211 WebGLGetInfo WebGLRenderingContext::getBooleanParameter(GC3Denum pname) 4145 WebGLGetInfo WebGLRenderingContextBase::getBooleanParameter(GC3Denum pname)
4212 { 4146 {
4213 GC3Dboolean value = 0; 4147 GC3Dboolean value = 0;
4214 if (!isContextLost()) 4148 if (!isContextLost())
4215 m_context->getBooleanv(pname, &value); 4149 m_context->getBooleanv(pname, &value);
4216 return WebGLGetInfo(static_cast<bool>(value)); 4150 return WebGLGetInfo(static_cast<bool>(value));
4217 } 4151 }
4218 4152
4219 WebGLGetInfo WebGLRenderingContext::getBooleanArrayParameter(GC3Denum pname) 4153 WebGLGetInfo WebGLRenderingContextBase::getBooleanArrayParameter(GC3Denum pname)
4220 { 4154 {
4221 if (pname != GraphicsContext3D::COLOR_WRITEMASK) { 4155 if (pname != GraphicsContext3D::COLOR_WRITEMASK) {
4222 notImplemented(); 4156 notImplemented();
4223 return WebGLGetInfo(0, 0); 4157 return WebGLGetInfo(0, 0);
4224 } 4158 }
4225 GC3Dboolean value[4] = {0}; 4159 GC3Dboolean value[4] = {0};
4226 if (!isContextLost()) 4160 if (!isContextLost())
4227 m_context->getBooleanv(pname, value); 4161 m_context->getBooleanv(pname, value);
4228 bool boolValue[4]; 4162 bool boolValue[4];
4229 for (int ii = 0; ii < 4; ++ii) 4163 for (int ii = 0; ii < 4; ++ii)
4230 boolValue[ii] = static_cast<bool>(value[ii]); 4164 boolValue[ii] = static_cast<bool>(value[ii]);
4231 return WebGLGetInfo(boolValue, 4); 4165 return WebGLGetInfo(boolValue, 4);
4232 } 4166 }
4233 4167
4234 WebGLGetInfo WebGLRenderingContext::getFloatParameter(GC3Denum pname) 4168 WebGLGetInfo WebGLRenderingContextBase::getFloatParameter(GC3Denum pname)
4235 { 4169 {
4236 GC3Dfloat value = 0; 4170 GC3Dfloat value = 0;
4237 if (!isContextLost()) 4171 if (!isContextLost())
4238 m_context->getFloatv(pname, &value); 4172 m_context->getFloatv(pname, &value);
4239 return WebGLGetInfo(value); 4173 return WebGLGetInfo(value);
4240 } 4174 }
4241 4175
4242 WebGLGetInfo WebGLRenderingContext::getIntParameter(GC3Denum pname) 4176 WebGLGetInfo WebGLRenderingContextBase::getIntParameter(GC3Denum pname)
4243 { 4177 {
4244 GC3Dint value = 0; 4178 GC3Dint value = 0;
4245 if (!isContextLost()) 4179 if (!isContextLost())
4246 m_context->getIntegerv(pname, &value); 4180 m_context->getIntegerv(pname, &value);
4247 return WebGLGetInfo(value); 4181 return WebGLGetInfo(value);
4248 } 4182 }
4249 4183
4250 WebGLGetInfo WebGLRenderingContext::getUnsignedIntParameter(GC3Denum pname) 4184 WebGLGetInfo WebGLRenderingContextBase::getUnsignedIntParameter(GC3Denum pname)
4251 { 4185 {
4252 GC3Dint value = 0; 4186 GC3Dint value = 0;
4253 if (!isContextLost()) 4187 if (!isContextLost())
4254 m_context->getIntegerv(pname, &value); 4188 m_context->getIntegerv(pname, &value);
4255 return WebGLGetInfo(static_cast<unsigned int>(value)); 4189 return WebGLGetInfo(static_cast<unsigned>(value));
4256 } 4190 }
4257 4191
4258 WebGLGetInfo WebGLRenderingContext::getWebGLFloatArrayParameter(GC3Denum pname) 4192 WebGLGetInfo WebGLRenderingContextBase::getWebGLFloatArrayParameter(GC3Denum pna me)
4259 { 4193 {
4260 GC3Dfloat value[4] = {0}; 4194 GC3Dfloat value[4] = {0};
4261 if (!isContextLost()) 4195 if (!isContextLost())
4262 m_context->getFloatv(pname, value); 4196 m_context->getFloatv(pname, value);
4263 unsigned length = 0; 4197 unsigned length = 0;
4264 switch (pname) { 4198 switch (pname) {
4265 case GraphicsContext3D::ALIASED_POINT_SIZE_RANGE: 4199 case GraphicsContext3D::ALIASED_POINT_SIZE_RANGE:
4266 case GraphicsContext3D::ALIASED_LINE_WIDTH_RANGE: 4200 case GraphicsContext3D::ALIASED_LINE_WIDTH_RANGE:
4267 case GraphicsContext3D::DEPTH_RANGE: 4201 case GraphicsContext3D::DEPTH_RANGE:
4268 length = 2; 4202 length = 2;
4269 break; 4203 break;
4270 case GraphicsContext3D::BLEND_COLOR: 4204 case GraphicsContext3D::BLEND_COLOR:
4271 case GraphicsContext3D::COLOR_CLEAR_VALUE: 4205 case GraphicsContext3D::COLOR_CLEAR_VALUE:
4272 length = 4; 4206 length = 4;
4273 break; 4207 break;
4274 default: 4208 default:
4275 notImplemented(); 4209 notImplemented();
4276 } 4210 }
4277 return WebGLGetInfo(Float32Array::create(value, length)); 4211 return WebGLGetInfo(Float32Array::create(value, length));
4278 } 4212 }
4279 4213
4280 WebGLGetInfo WebGLRenderingContext::getWebGLIntArrayParameter(GC3Denum pname) 4214 WebGLGetInfo WebGLRenderingContextBase::getWebGLIntArrayParameter(GC3Denum pname )
4281 { 4215 {
4282 GC3Dint value[4] = {0}; 4216 GC3Dint value[4] = {0};
4283 if (!isContextLost()) 4217 if (!isContextLost())
4284 m_context->getIntegerv(pname, value); 4218 m_context->getIntegerv(pname, value);
4285 unsigned length = 0; 4219 unsigned length = 0;
4286 switch (pname) { 4220 switch (pname) {
4287 case GraphicsContext3D::MAX_VIEWPORT_DIMS: 4221 case GraphicsContext3D::MAX_VIEWPORT_DIMS:
4288 length = 2; 4222 length = 2;
4289 break; 4223 break;
4290 case GraphicsContext3D::SCISSOR_BOX: 4224 case GraphicsContext3D::SCISSOR_BOX:
4291 case GraphicsContext3D::VIEWPORT: 4225 case GraphicsContext3D::VIEWPORT:
4292 length = 4; 4226 length = 4;
4293 break; 4227 break;
4294 default: 4228 default:
4295 notImplemented(); 4229 notImplemented();
4296 } 4230 }
4297 return WebGLGetInfo(Int32Array::create(value, length)); 4231 return WebGLGetInfo(Int32Array::create(value, length));
4298 } 4232 }
4299 4233
4300 void WebGLRenderingContext::handleTextureCompleteness(const char* functionName, bool prepareToDraw) 4234 void WebGLRenderingContextBase::handleTextureCompleteness(const char* functionNa me, bool prepareToDraw)
4301 { 4235 {
4302 // All calling functions check isContextLost, so a duplicate check is not ne eded here. 4236 // All calling functions check isContextLost, so a duplicate check is not ne eded here.
4303 bool resetActiveUnit = false; 4237 bool resetActiveUnit = false;
4304 WebGLTexture::TextureExtensionFlag flag = static_cast<WebGLTexture::TextureE xtensionFlag>((m_oesTextureFloatLinear ? WebGLTexture::TextureFloatLinearExtensi onEnabled : 0) 4238 WebGLTexture::TextureExtensionFlag flag = static_cast<WebGLTexture::TextureE xtensionFlag>((m_oesTextureFloatLinear ? WebGLTexture::TextureFloatLinearExtensi onEnabled : 0)
4305 | (m_oesTextureHalfFloatLinear ? WebGLTexture::TextureHalfFloatLinearExt ensionEnabled : 0)); 4239 | (m_oesTextureHalfFloatLinear ? WebGLTexture::TextureHalfFloatLinearExt ensionEnabled : 0));
4306 for (unsigned ii = 0; ii < m_onePlusMaxNonDefaultTextureUnit; ++ii) { 4240 for (unsigned ii = 0; ii < m_onePlusMaxNonDefaultTextureUnit; ++ii) {
4307 if ((m_textureUnits[ii].m_texture2DBinding.get() && m_textureUnits[ii].m _texture2DBinding->needToUseBlackTexture(flag)) 4241 if ((m_textureUnits[ii].m_texture2DBinding.get() && m_textureUnits[ii].m _texture2DBinding->needToUseBlackTexture(flag))
4308 || (m_textureUnits[ii].m_textureCubeMapBinding.get() && m_textureUni ts[ii].m_textureCubeMapBinding->needToUseBlackTexture(flag))) { 4242 || (m_textureUnits[ii].m_textureCubeMapBinding.get() && m_textureUni ts[ii].m_textureCubeMapBinding->needToUseBlackTexture(flag))) {
4309 if (ii != m_activeTextureUnit) { 4243 if (ii != m_activeTextureUnit) {
4310 m_context->activeTexture(ii); 4244 m_context->activeTexture(ii);
(...skipping 18 matching lines...) Expand all
4329 if (m_textureUnits[ii].m_texture2DBinding && m_textureUnits[ii].m_te xture2DBinding->needToUseBlackTexture(flag)) 4263 if (m_textureUnits[ii].m_texture2DBinding && m_textureUnits[ii].m_te xture2DBinding->needToUseBlackTexture(flag))
4330 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, objectOrZe ro(tex2D)); 4264 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, objectOrZe ro(tex2D));
4331 if (m_textureUnits[ii].m_textureCubeMapBinding && m_textureUnits[ii] .m_textureCubeMapBinding->needToUseBlackTexture(flag)) 4265 if (m_textureUnits[ii].m_textureCubeMapBinding && m_textureUnits[ii] .m_textureCubeMapBinding->needToUseBlackTexture(flag))
4332 m_context->bindTexture(GraphicsContext3D::TEXTURE_CUBE_MAP, obje ctOrZero(texCubeMap)); 4266 m_context->bindTexture(GraphicsContext3D::TEXTURE_CUBE_MAP, obje ctOrZero(texCubeMap));
4333 } 4267 }
4334 } 4268 }
4335 if (resetActiveUnit) 4269 if (resetActiveUnit)
4336 m_context->activeTexture(m_activeTextureUnit); 4270 m_context->activeTexture(m_activeTextureUnit);
4337 } 4271 }
4338 4272
4339 void WebGLRenderingContext::createFallbackBlackTextures1x1() 4273 void WebGLRenderingContextBase::createFallbackBlackTextures1x1()
4340 { 4274 {
4341 // All calling functions check isContextLost, so a duplicate check is not ne eded here. 4275 // All calling functions check isContextLost, so a duplicate check is not ne eded here.
4342 unsigned char black[] = {0, 0, 0, 255}; 4276 unsigned char black[] = {0, 0, 0, 255};
4343 m_blackTexture2D = createTexture(); 4277 m_blackTexture2D = createTexture();
4344 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_blackTexture2D->obje ct()); 4278 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_blackTexture2D->obje ct());
4345 m_context->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, GraphicsContext3D::R GBA, 1, 1, 4279 m_context->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, GraphicsContext3D::R GBA, 1, 1,
4346 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNE D_BYTE, black); 4280 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, black);
4347 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, 0); 4281 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, 0);
4348 m_blackTextureCubeMap = createTexture(); 4282 m_blackTextureCubeMap = createTexture();
4349 m_context->bindTexture(GraphicsContext3D::TEXTURE_CUBE_MAP, m_blackTextureCu beMap->object()); 4283 m_context->bindTexture(GraphicsContext3D::TEXTURE_CUBE_MAP, m_blackTextureCu beMap->object());
4350 m_context->texImage2D(GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_X, 0, Gra phicsContext3D::RGBA, 1, 1, 4284 m_context->texImage2D(GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_X, 0, Gra phicsContext3D::RGBA, 1, 1,
4351 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNE D_BYTE, black); 4285 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, black);
4352 m_context->texImage2D(GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_X, 0, Gra phicsContext3D::RGBA, 1, 1, 4286 m_context->texImage2D(GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_X, 0, Gra phicsContext3D::RGBA, 1, 1,
4353 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNE D_BYTE, black); 4287 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, black);
4354 m_context->texImage2D(GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Y, 0, Gra phicsContext3D::RGBA, 1, 1, 4288 m_context->texImage2D(GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Y, 0, Gra phicsContext3D::RGBA, 1, 1,
4355 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNE D_BYTE, black); 4289 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, black);
4356 m_context->texImage2D(GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, Gra phicsContext3D::RGBA, 1, 1, 4290 m_context->texImage2D(GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, Gra phicsContext3D::RGBA, 1, 1,
4357 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNE D_BYTE, black); 4291 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, black);
4358 m_context->texImage2D(GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Z, 0, Gra phicsContext3D::RGBA, 1, 1, 4292 m_context->texImage2D(GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Z, 0, Gra phicsContext3D::RGBA, 1, 1,
4359 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNE D_BYTE, black); 4293 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, black);
4360 m_context->texImage2D(GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, Gra phicsContext3D::RGBA, 1, 1, 4294 m_context->texImage2D(GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, Gra phicsContext3D::RGBA, 1, 1,
4361 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNE D_BYTE, black); 4295 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, black);
4362 m_context->bindTexture(GraphicsContext3D::TEXTURE_CUBE_MAP, 0); 4296 m_context->bindTexture(GraphicsContext3D::TEXTURE_CUBE_MAP, 0);
4363 } 4297 }
4364 4298
4365 bool WebGLRenderingContext::isTexInternalFormatColorBufferCombinationValid(GC3De num texInternalFormat, 4299 bool WebGLRenderingContextBase::isTexInternalFormatColorBufferCombinationValid(G C3Denum texInternalFormat, GC3Denum colorBufferFormat)
4366 GC3De num colorBufferFormat)
4367 { 4300 {
4368 unsigned need = GraphicsContext3D::getChannelBitsByFormat(texInternalFormat) ; 4301 unsigned need = GraphicsContext3D::getChannelBitsByFormat(texInternalFormat) ;
4369 unsigned have = GraphicsContext3D::getChannelBitsByFormat(colorBufferFormat) ; 4302 unsigned have = GraphicsContext3D::getChannelBitsByFormat(colorBufferFormat) ;
4370 return (need & have) == need; 4303 return (need & have) == need;
4371 } 4304 }
4372 4305
4373 GC3Denum WebGLRenderingContext::getBoundFramebufferColorFormat() 4306 GC3Denum WebGLRenderingContextBase::getBoundFramebufferColorFormat()
4374 { 4307 {
4375 if (m_framebufferBinding && m_framebufferBinding->object()) 4308 if (m_framebufferBinding && m_framebufferBinding->object())
4376 return m_framebufferBinding->getColorBufferFormat(); 4309 return m_framebufferBinding->getColorBufferFormat();
4377 if (m_attributes.alpha) 4310 if (m_attributes.alpha)
4378 return GraphicsContext3D::RGBA; 4311 return GraphicsContext3D::RGBA;
4379 return GraphicsContext3D::RGB; 4312 return GraphicsContext3D::RGB;
4380 } 4313 }
4381 4314
4382 int WebGLRenderingContext::getBoundFramebufferWidth() 4315 int WebGLRenderingContextBase::getBoundFramebufferWidth()
4383 { 4316 {
4384 if (m_framebufferBinding && m_framebufferBinding->object()) 4317 if (m_framebufferBinding && m_framebufferBinding->object())
4385 return m_framebufferBinding->getColorBufferWidth(); 4318 return m_framebufferBinding->getColorBufferWidth();
4386 return m_drawingBuffer->size().width(); 4319 return m_drawingBuffer->size().width();
4387 } 4320 }
4388 4321
4389 int WebGLRenderingContext::getBoundFramebufferHeight() 4322 int WebGLRenderingContextBase::getBoundFramebufferHeight()
4390 { 4323 {
4391 if (m_framebufferBinding && m_framebufferBinding->object()) 4324 if (m_framebufferBinding && m_framebufferBinding->object())
4392 return m_framebufferBinding->getColorBufferHeight(); 4325 return m_framebufferBinding->getColorBufferHeight();
4393 return m_drawingBuffer->size().height(); 4326 return m_drawingBuffer->size().height();
4394 } 4327 }
4395 4328
4396 WebGLTexture* WebGLRenderingContext::validateTextureBinding(const char* function Name, GC3Denum target, bool useSixEnumsForCubeMap) 4329 WebGLTexture* WebGLRenderingContextBase::validateTextureBinding(const char* func tionName, GC3Denum target, bool useSixEnumsForCubeMap)
4397 { 4330 {
4398 WebGLTexture* tex = 0; 4331 WebGLTexture* tex = 0;
4399 switch (target) { 4332 switch (target) {
4400 case GraphicsContext3D::TEXTURE_2D: 4333 case GraphicsContext3D::TEXTURE_2D:
4401 tex = m_textureUnits[m_activeTextureUnit].m_texture2DBinding.get(); 4334 tex = m_textureUnits[m_activeTextureUnit].m_texture2DBinding.get();
4402 break; 4335 break;
4403 case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_X: 4336 case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_X:
4404 case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_X: 4337 case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_X:
4405 case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Y: 4338 case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Y:
4406 case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Y: 4339 case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Y:
(...skipping 14 matching lines...) Expand all
4421 break; 4354 break;
4422 default: 4355 default:
4423 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, "invali d texture target"); 4356 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, "invali d texture target");
4424 return 0; 4357 return 0;
4425 } 4358 }
4426 if (!tex) 4359 if (!tex)
4427 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "n o texture"); 4360 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "n o texture");
4428 return tex; 4361 return tex;
4429 } 4362 }
4430 4363
4431 bool WebGLRenderingContext::validateLocationLength(const char* functionName, con st String& string) 4364 bool WebGLRenderingContextBase::validateLocationLength(const char* functionName, const String& string)
4432 { 4365 {
4433 const unsigned maxWebGLLocationLength = 256; 4366 const unsigned maxWebGLLocationLength = 256;
4434 if (string.length() > maxWebGLLocationLength) { 4367 if (string.length() > maxWebGLLocationLength) {
4435 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "locat ion length > 256"); 4368 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "locat ion length > 256");
4436 return false; 4369 return false;
4437 } 4370 }
4438 return true; 4371 return true;
4439 } 4372 }
4440 4373
4441 bool WebGLRenderingContext::validateSize(const char* functionName, GC3Dint x, GC 3Dint y) 4374 bool WebGLRenderingContextBase::validateSize(const char* functionName, GC3Dint x , GC3Dint y)
4442 { 4375 {
4443 if (x < 0 || y < 0) { 4376 if (x < 0 || y < 0) {
4444 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "size < 0"); 4377 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "size < 0");
4445 return false; 4378 return false;
4446 } 4379 }
4447 return true; 4380 return true;
4448 } 4381 }
4449 4382
4450 bool WebGLRenderingContext::validateString(const char* functionName, const Strin g& string) 4383 bool WebGLRenderingContextBase::validateString(const char* functionName, const S tring& string)
4451 { 4384 {
4452 for (size_t i = 0; i < string.length(); ++i) { 4385 for (size_t i = 0; i < string.length(); ++i) {
4453 if (!validateCharacter(string[i])) { 4386 if (!validateCharacter(string[i])) {
4454 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "s tring not ASCII"); 4387 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "s tring not ASCII");
4455 return false; 4388 return false;
4456 } 4389 }
4457 } 4390 }
4458 return true; 4391 return true;
4459 } 4392 }
4460 4393
4461 bool WebGLRenderingContext::validateTexFuncFormatAndType(const char* functionNam e, GC3Denum format, GC3Denum type, GC3Dint level) 4394 bool WebGLRenderingContextBase::validateTexFuncFormatAndType(const char* functio nName, GC3Denum format, GC3Denum type, GC3Dint level)
4462 { 4395 {
4463 switch (format) { 4396 switch (format) {
4464 case GraphicsContext3D::ALPHA: 4397 case GraphicsContext3D::ALPHA:
4465 case GraphicsContext3D::LUMINANCE: 4398 case GraphicsContext3D::LUMINANCE:
4466 case GraphicsContext3D::LUMINANCE_ALPHA: 4399 case GraphicsContext3D::LUMINANCE_ALPHA:
4467 case GraphicsContext3D::RGB: 4400 case GraphicsContext3D::RGB:
4468 case GraphicsContext3D::RGBA: 4401 case GraphicsContext3D::RGBA:
4469 break; 4402 break;
4470 case GraphicsContext3D::DEPTH_STENCIL: 4403 case GraphicsContext3D::DEPTH_STENCIL:
4471 case GraphicsContext3D::DEPTH_COMPONENT: 4404 case GraphicsContext3D::DEPTH_COMPONENT:
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
4541 if (!m_webglDepthTexture) { 4474 if (!m_webglDepthTexture) {
4542 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, "in valid format. DEPTH_COMPONENT not enabled"); 4475 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, "in valid format. DEPTH_COMPONENT not enabled");
4543 return false; 4476 return false;
4544 } 4477 }
4545 if (type != GraphicsContext3D::UNSIGNED_SHORT 4478 if (type != GraphicsContext3D::UNSIGNED_SHORT
4546 && type != GraphicsContext3D::UNSIGNED_INT) { 4479 && type != GraphicsContext3D::UNSIGNED_INT) {
4547 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName , "invalid type for DEPTH_COMPONENT format"); 4480 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName , "invalid type for DEPTH_COMPONENT format");
4548 return false; 4481 return false;
4549 } 4482 }
4550 if (level > 0) { 4483 if (level > 0) {
4551 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "level must be 0 for DEPTH_COMPONENT format"); 4484 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName , "level must be 0 for DEPTH_COMPONENT format");
4552 return false; 4485 return false;
4553 } 4486 }
4554 break; 4487 break;
4555 case GraphicsContext3D::DEPTH_STENCIL: 4488 case GraphicsContext3D::DEPTH_STENCIL:
4556 if (!m_webglDepthTexture) { 4489 if (!m_webglDepthTexture) {
4557 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, "in valid format. DEPTH_STENCIL not enabled"); 4490 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, "in valid format. DEPTH_STENCIL not enabled");
4558 return false; 4491 return false;
4559 } 4492 }
4560 if (type != GraphicsContext3D::UNSIGNED_INT_24_8) { 4493 if (type != GraphicsContext3D::UNSIGNED_INT_24_8) {
4561 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName , "invalid type for DEPTH_STENCIL format"); 4494 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName , "invalid type for DEPTH_STENCIL format");
4562 return false; 4495 return false;
4563 } 4496 }
4564 if (level > 0) { 4497 if (level > 0) {
4565 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "level must be 0 for DEPTH_STENCIL format"); 4498 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName , "level must be 0 for DEPTH_STENCIL format");
4566 return false; 4499 return false;
4567 } 4500 }
4568 break; 4501 break;
4569 default: 4502 default:
4570 ASSERT_NOT_REACHED(); 4503 ASSERT_NOT_REACHED();
4571 } 4504 }
4572 4505
4573 return true; 4506 return true;
4574 } 4507 }
4575 4508
4576 bool WebGLRenderingContext::validateTexFuncLevel(const char* functionName, GC3De num target, GC3Dint level) 4509 bool WebGLRenderingContextBase::validateTexFuncLevel(const char* functionName, G C3Denum target, GC3Dint level)
4577 { 4510 {
4578 if (level < 0) { 4511 if (level < 0) {
4579 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "level < 0"); 4512 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "level < 0");
4580 return false; 4513 return false;
4581 } 4514 }
4582 switch (target) { 4515 switch (target) {
4583 case GraphicsContext3D::TEXTURE_2D: 4516 case GraphicsContext3D::TEXTURE_2D:
4584 if (level >= m_maxTextureLevel) { 4517 if (level >= m_maxTextureLevel) {
4585 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "l evel out of range"); 4518 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "l evel out of range");
4586 return false; 4519 return false;
4587 } 4520 }
4588 break; 4521 break;
4589 case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_X: 4522 case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_X:
4590 case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_X: 4523 case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_X:
4591 case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Y: 4524 case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Y:
4592 case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Y: 4525 case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Y:
4593 case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Z: 4526 case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Z:
4594 case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Z: 4527 case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Z:
4595 if (level >= m_maxCubeMapTextureLevel) { 4528 if (level >= m_maxCubeMapTextureLevel) {
4596 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "l evel out of range"); 4529 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "l evel out of range");
4597 return false; 4530 return false;
4598 } 4531 }
4599 break; 4532 break;
4600 } 4533 }
4601 // This function only checks if level is legal, so we return true and don't 4534 // This function only checks if level is legal, so we return true and don't
4602 // generate INVALID_ENUM if target is illegal. 4535 // generate INVALID_ENUM if target is illegal.
4603 return true; 4536 return true;
4604 } 4537 }
4605 4538
4606 bool WebGLRenderingContext::validateTexFuncDimensions(const char* functionName, TexFuncValidationFunctionType functionType, 4539 bool WebGLRenderingContextBase::validateTexFuncDimensions(const char* functionNa me, TexFuncValidationFunctionType functionType,
4607 GC3Denum target, GC3Dint level, GC3Dsizei width, GC3Dsizei height) 4540 GC3Denum target, GC3Dint level, GC3Dsizei width, GC3Dsizei height)
4608 { 4541 {
4609 if (width < 0 || height < 0) { 4542 if (width < 0 || height < 0) {
4610 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "width or height < 0"); 4543 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "width or height < 0");
4611 return false; 4544 return false;
4612 } 4545 }
4613 4546
4614 switch (target) { 4547 switch (target) {
4615 case GraphicsContext3D::TEXTURE_2D: 4548 case GraphicsContext3D::TEXTURE_2D:
4616 if (width > (m_maxTextureSize >> level) || height > (m_maxTextureSize >> level)) { 4549 if (width > (m_maxTextureSize >> level) || height > (m_maxTextureSize >> level)) {
4617 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "w idth or height out of range"); 4550 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "w idth or height out of range");
4618 return false; 4551 return false;
4619 } 4552 }
4620 break; 4553 break;
4621 case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_X: 4554 case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_X:
4622 case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_X: 4555 case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_X:
4623 case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Y: 4556 case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Y:
4624 case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Y: 4557 case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Y:
4625 case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Z: 4558 case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Z:
4626 case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Z: 4559 case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Z:
4627 if (functionType != TexSubImage2D && width != height) { 4560 if (functionType != TexSubImage2D && width != height) {
4628 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "wid th != height for cube map"); 4561 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "w idth != height for cube map");
4629 return false; 4562 return false;
4630 } 4563 }
4631 // No need to check height here. For texImage width == height. 4564 // No need to check height here. For texImage width == height.
4632 // For texSubImage that will be checked when checking yoffset + height i s in range. 4565 // For texSubImage that will be checked when checking yoffset + height i s in range.
4633 if (width > (m_maxCubeMapTextureSize >> level)) { 4566 if (width > (m_maxCubeMapTextureSize >> level)) {
4634 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "w idth or height out of range for cube map"); 4567 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "w idth or height out of range for cube map");
4635 return false; 4568 return false;
4636 } 4569 }
4637 break; 4570 break;
4638 default: 4571 default:
4639 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, "invali d target"); 4572 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, "invali d target");
4640 return false; 4573 return false;
4641 } 4574 }
4642 return true; 4575 return true;
4643 } 4576 }
4644 4577
4645 bool WebGLRenderingContext::validateTexFuncParameters(const char* functionName, TexFuncValidationFunctionType functionType, GC3Denum target, 4578 bool WebGLRenderingContextBase::validateTexFuncParameters(const char* functionNa me, TexFuncValidationFunctionType functionType, GC3Denum target,
4646 GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, G C3Dint border, GC3Denum format, GC3Denum type) 4579 GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, G C3Dint border, GC3Denum format, GC3Denum type)
4647 { 4580 {
4648 // We absolutely have to validate the format and type combination. 4581 // We absolutely have to validate the format and type combination.
4649 // The texImage2D entry points taking HTMLImage, etc. will produce 4582 // The texImage2D entry points taking HTMLImage, etc. will produce
4650 // temporary data based on this combination, so it must be legal. 4583 // temporary data based on this combination, so it must be legal.
4651 if (!validateTexFuncFormatAndType(functionName, format, type, level) || !val idateTexFuncLevel(functionName, target, level)) 4584 if (!validateTexFuncFormatAndType(functionName, format, type, level) || !val idateTexFuncLevel(functionName, target, level))
4652 return false; 4585 return false;
4653 4586
4654 if (!validateTexFuncDimensions(functionName, functionType, target, level, wi dth, height)) 4587 if (!validateTexFuncDimensions(functionName, functionType, target, level, wi dth, height))
4655 return false; 4588 return false;
4656 4589
4657 if (format != internalformat) { 4590 if (format != internalformat) {
4658 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "f ormat != internalformat"); 4591 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "f ormat != internalformat");
4659 return false; 4592 return false;
4660 } 4593 }
4661 4594
4662 if (border) { 4595 if (border) {
4663 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "borde r != 0"); 4596 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "borde r != 0");
4664 return false; 4597 return false;
4665 } 4598 }
4666 4599
4667 return true; 4600 return true;
4668 } 4601 }
4669 4602
4670 bool WebGLRenderingContext::validateTexFuncData(const char* functionName, GC3Din t level, 4603 bool WebGLRenderingContextBase::validateTexFuncData(const char* functionName, GC 3Dint level,
4671 GC3Dsizei width, GC3Dsizei heigh t, 4604 GC3Dsizei width, GC3Dsizei height,
4672 GC3Denum format, GC3Denum type, 4605 GC3Denum format, GC3Denum type,
4673 ArrayBufferView* pixels, 4606 ArrayBufferView* pixels,
4674 NullDisposition disposition) 4607 NullDisposition disposition)
4675 { 4608 {
4676 // All calling functions check isContextLost, so a duplicate check is not ne eded here. 4609 // All calling functions check isContextLost, so a duplicate check is not ne eded here.
4677 if (!pixels) { 4610 if (!pixels) {
4678 if (disposition == NullAllowed) 4611 if (disposition == NullAllowed)
4679 return true; 4612 return true;
4680 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no pi xels"); 4613 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no pi xels");
4681 return false; 4614 return false;
4682 } 4615 }
4683 4616
4684 if (!validateTexFuncFormatAndType(functionName, format, type, level)) 4617 if (!validateTexFuncFormatAndType(functionName, format, type, level))
(...skipping 27 matching lines...) Expand all
4712 // OES_texture_half_float is enabled. 4645 // OES_texture_half_float is enabled.
4713 if (pixels) { 4646 if (pixels) {
4714 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName , "type HALF_FLOAT_OES but ArrayBufferView is not NULL"); 4647 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName , "type HALF_FLOAT_OES but ArrayBufferView is not NULL");
4715 return false; 4648 return false;
4716 } 4649 }
4717 break; 4650 break;
4718 default: 4651 default:
4719 ASSERT_NOT_REACHED(); 4652 ASSERT_NOT_REACHED();
4720 } 4653 }
4721 4654
4722 unsigned int totalBytesRequired; 4655 unsigned totalBytesRequired;
4723 GC3Denum error = m_context->computeImageSizeInBytes(format, type, width, hei ght, m_unpackAlignment, &totalBytesRequired, 0); 4656 GC3Denum error = m_context->computeImageSizeInBytes(format, type, width, hei ght, m_unpackAlignment, &totalBytesRequired, 0);
4724 if (error != GraphicsContext3D::NO_ERROR) { 4657 if (error != GraphicsContext3D::NO_ERROR) {
4725 synthesizeGLError(error, functionName, "invalid texture dimensions"); 4658 synthesizeGLError(error, functionName, "invalid texture dimensions");
4726 return false; 4659 return false;
4727 } 4660 }
4728 if (pixels->byteLength() < totalBytesRequired) { 4661 if (pixels->byteLength() < totalBytesRequired) {
4729 if (m_unpackAlignment != 1) { 4662 if (m_unpackAlignment != 1) {
4730 error = m_context->computeImageSizeInBytes(format, type, width, height , 1, &totalBytesRequired, 0); 4663 error = m_context->computeImageSizeInBytes(format, type, width, heig ht, 1, &totalBytesRequired, 0);
4731 if (pixels->byteLength() == totalBytesRequired) { 4664 if (pixels->byteLength() == totalBytesRequired) {
4732 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName , "ArrayBufferView not big enough for request with UNPACK_ALIGNMENT > 1"); 4665 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, function Name, "ArrayBufferView not big enough for request with UNPACK_ALIGNMENT > 1");
4733 return false; 4666 return false;
4734 } 4667 }
4735 } 4668 }
4736 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "A rrayBufferView not big enough for request"); 4669 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "A rrayBufferView not big enough for request");
4737 return false; 4670 return false;
4738 } 4671 }
4739 return true; 4672 return true;
4740 } 4673 }
4741 4674
4742 bool WebGLRenderingContext::validateCompressedTexFormat(GC3Denum format) 4675 bool WebGLRenderingContextBase::validateCompressedTexFormat(GC3Denum format)
4743 { 4676 {
4744 return m_compressedTextureFormats.contains(format); 4677 return m_compressedTextureFormats.contains(format);
4745 } 4678 }
4746 4679
4747 bool WebGLRenderingContext::validateCompressedTexFuncData(const char* functionNa me, 4680 bool WebGLRenderingContextBase::validateCompressedTexFuncData(const char* functi onName,
4748 GC3Dsizei width, GC3Ds izei height, 4681 GC3Dsizei width, GC3Dsizei height,
4749 GC3Denum format, Array BufferView* pixels) 4682 GC3Denum format, ArrayBufferView* pixels)
4750 { 4683 {
4751 if (!pixels) { 4684 if (!pixels) {
4752 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no pi xels"); 4685 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no pi xels");
4753 return false; 4686 return false;
4754 } 4687 }
4755 if (width < 0 || height < 0) { 4688 if (width < 0 || height < 0) {
4756 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "width or height < 0"); 4689 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "width or height < 0");
4757 return false; 4690 return false;
4758 } 4691 }
4759 4692
4760 unsigned int bytesRequired = 0; 4693 unsigned bytesRequired = 0;
4761 4694
4762 switch (format) { 4695 switch (format) {
4763 case Extensions3D::COMPRESSED_RGB_S3TC_DXT1_EXT: 4696 case Extensions3D::COMPRESSED_RGB_S3TC_DXT1_EXT:
4764 case Extensions3D::COMPRESSED_RGBA_S3TC_DXT1_EXT: 4697 case Extensions3D::COMPRESSED_RGBA_S3TC_DXT1_EXT:
4765 { 4698 {
4766 const int kBlockWidth = 4; 4699 const int kBlockWidth = 4;
4767 const int kBlockHeight = 4; 4700 const int kBlockHeight = 4;
4768 const int kBlockSize = 8; 4701 const int kBlockSize = 8;
4769 int numBlocksAcross = (width + kBlockWidth - 1) / kBlockWidth; 4702 int numBlocksAcross = (width + kBlockWidth - 1) / kBlockWidth;
4770 int numBlocksDown = (height + kBlockHeight - 1) / kBlockHeight; 4703 int numBlocksDown = (height + kBlockHeight - 1) / kBlockHeight;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
4812 } 4745 }
4813 4746
4814 if (pixels->byteLength() != bytesRequired) { 4747 if (pixels->byteLength() != bytesRequired) {
4815 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "lengt h of ArrayBufferView is not correct for dimensions"); 4748 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "lengt h of ArrayBufferView is not correct for dimensions");
4816 return false; 4749 return false;
4817 } 4750 }
4818 4751
4819 return true; 4752 return true;
4820 } 4753 }
4821 4754
4822 bool WebGLRenderingContext::validateCompressedTexDimensions(const char* function Name, TexFuncValidationFunctionType functionType, GC3Denum target, GC3Dint level , GC3Dsizei width, GC3Dsizei height, GC3Denum format) 4755 bool WebGLRenderingContextBase::validateCompressedTexDimensions(const char* func tionName, TexFuncValidationFunctionType functionType, GC3Denum target, GC3Dint l evel, GC3Dsizei width, GC3Dsizei height, GC3Denum format)
4823 { 4756 {
4824 if (!validateTexFuncDimensions(functionName, functionType, target, level, wi dth, height)) 4757 if (!validateTexFuncDimensions(functionName, functionType, target, level, wi dth, height))
4825 return false; 4758 return false;
4826 4759
4827 switch (format) { 4760 switch (format) {
4828 case Extensions3D::COMPRESSED_RGB_S3TC_DXT1_EXT: 4761 case Extensions3D::COMPRESSED_RGB_S3TC_DXT1_EXT:
4829 case Extensions3D::COMPRESSED_RGBA_S3TC_DXT1_EXT: 4762 case Extensions3D::COMPRESSED_RGBA_S3TC_DXT1_EXT:
4830 case Extensions3D::COMPRESSED_RGBA_S3TC_DXT3_EXT: 4763 case Extensions3D::COMPRESSED_RGBA_S3TC_DXT3_EXT:
4831 case Extensions3D::COMPRESSED_RGBA_S3TC_DXT5_EXT: { 4764 case Extensions3D::COMPRESSED_RGBA_S3TC_DXT5_EXT: {
4832 const int kBlockWidth = 4; 4765 const int kBlockWidth = 4;
4833 const int kBlockHeight = 4; 4766 const int kBlockHeight = 4;
4834 bool widthValid = (level && width == 1) || (level && width == 2) || !(wi dth % kBlockWidth); 4767 bool widthValid = (level && width == 1) || (level && width == 2) || !(wi dth % kBlockWidth);
4835 bool heightValid = (level && height == 1) || (level && height == 2) || ! (height % kBlockHeight); 4768 bool heightValid = (level && height == 1) || (level && height == 2) || ! (height % kBlockHeight);
4836 if (!widthValid || !heightValid) { 4769 if (!widthValid || !heightValid) {
4837 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "width or height invalid for level"); 4770 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName , "width or height invalid for level");
4838 return false; 4771 return false;
4839 } 4772 }
4840 return true; 4773 return true;
4841 } 4774 }
4842 default: 4775 default:
4843 return false; 4776 return false;
4844 } 4777 }
4845 } 4778 }
4846 4779
4847 bool WebGLRenderingContext::validateCompressedTexSubDimensions(const char* funct ionName, GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset, 4780 bool WebGLRenderingContextBase::validateCompressedTexSubDimensions(const char* f unctionName, GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset,
4848 GC3Dsizei width, GC3Dsizei height, GC3Denum format, WebGLTexture* tex) 4781 GC3Dsizei width, GC3Dsizei height, GC3Denum format, WebGLTexture* tex)
4849 { 4782 {
4850 if (xoffset < 0 || yoffset < 0) { 4783 if (xoffset < 0 || yoffset < 0) {
4851 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "xoffset or yoffset < 0"); 4784 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "xoffs et or yoffset < 0");
4852 return false; 4785 return false;
4853 } 4786 }
4854 4787
4855 switch (format) { 4788 switch (format) {
4856 case Extensions3D::COMPRESSED_RGB_S3TC_DXT1_EXT: 4789 case Extensions3D::COMPRESSED_RGB_S3TC_DXT1_EXT:
4857 case Extensions3D::COMPRESSED_RGBA_S3TC_DXT1_EXT: 4790 case Extensions3D::COMPRESSED_RGBA_S3TC_DXT1_EXT:
4858 case Extensions3D::COMPRESSED_RGBA_S3TC_DXT3_EXT: 4791 case Extensions3D::COMPRESSED_RGBA_S3TC_DXT3_EXT:
4859 case Extensions3D::COMPRESSED_RGBA_S3TC_DXT5_EXT: { 4792 case Extensions3D::COMPRESSED_RGBA_S3TC_DXT5_EXT: {
4860 const int kBlockWidth = 4; 4793 const int kBlockWidth = 4;
4861 const int kBlockHeight = 4; 4794 const int kBlockHeight = 4;
4862 if ((xoffset % kBlockWidth) || (yoffset % kBlockHeight)) { 4795 if ((xoffset % kBlockWidth) || (yoffset % kBlockHeight)) {
4863 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName , "xoffset or yoffset not multiple of 4"); 4796 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName , "xoffset or yoffset not multiple of 4");
4864 return false; 4797 return false;
4865 } 4798 }
4866 if (width - xoffset > tex->getWidth(target, level) 4799 if (width - xoffset > tex->getWidth(target, level)
4867 || height - yoffset > tex->getHeight(target, level)) { 4800 || height - yoffset > tex->getHeight(target, level)) {
4868 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName , "dimensions out of range"); 4801 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName , "dimensions out of range");
4869 return false; 4802 return false;
4870 } 4803 }
4871 return validateCompressedTexDimensions(functionName, TexSubImage2D, targ et, level, width, height, format); 4804 return validateCompressedTexDimensions(functionName, TexSubImage2D, targ et, level, width, height, format);
4872 } 4805 }
4873 default: 4806 default:
4874 return false; 4807 return false;
4875 } 4808 }
4876 } 4809 }
4877 4810
4878 bool WebGLRenderingContext::validateDrawMode(const char* functionName, GC3Denum mode) 4811 bool WebGLRenderingContextBase::validateDrawMode(const char* functionName, GC3De num mode)
4879 { 4812 {
4880 switch (mode) { 4813 switch (mode) {
4881 case GraphicsContext3D::POINTS: 4814 case GraphicsContext3D::POINTS:
4882 case GraphicsContext3D::LINE_STRIP: 4815 case GraphicsContext3D::LINE_STRIP:
4883 case GraphicsContext3D::LINE_LOOP: 4816 case GraphicsContext3D::LINE_LOOP:
4884 case GraphicsContext3D::LINES: 4817 case GraphicsContext3D::LINES:
4885 case GraphicsContext3D::TRIANGLE_STRIP: 4818 case GraphicsContext3D::TRIANGLE_STRIP:
4886 case GraphicsContext3D::TRIANGLE_FAN: 4819 case GraphicsContext3D::TRIANGLE_FAN:
4887 case GraphicsContext3D::TRIANGLES: 4820 case GraphicsContext3D::TRIANGLES:
4888 return true; 4821 return true;
4889 default: 4822 default:
4890 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, "invali d draw mode"); 4823 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, "invali d draw mode");
4891 return false; 4824 return false;
4892 } 4825 }
4893 } 4826 }
4894 4827
4895 bool WebGLRenderingContext::validateStencilSettings(const char* functionName) 4828 bool WebGLRenderingContextBase::validateStencilSettings(const char* functionName )
4896 { 4829 {
4897 if (m_stencilMask != m_stencilMaskBack || m_stencilFuncRef != m_stencilFuncR efBack || m_stencilFuncMask != m_stencilFuncMaskBack) { 4830 if (m_stencilMask != m_stencilMaskBack || m_stencilFuncRef != m_stencilFuncR efBack || m_stencilFuncMask != m_stencilFuncMaskBack) {
4898 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "f ront and back stencils settings do not match"); 4831 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "f ront and back stencils settings do not match");
4899 return false; 4832 return false;
4900 } 4833 }
4901 return true; 4834 return true;
4902 } 4835 }
4903 4836
4904 bool WebGLRenderingContext::validateStencilOrDepthFunc(const char* functionName, GC3Denum func) 4837 bool WebGLRenderingContextBase::validateStencilOrDepthFunc(const char* functionN ame, GC3Denum func)
4905 { 4838 {
4906 switch (func) { 4839 switch (func) {
4907 case GraphicsContext3D::NEVER: 4840 case GraphicsContext3D::NEVER:
4908 case GraphicsContext3D::LESS: 4841 case GraphicsContext3D::LESS:
4909 case GraphicsContext3D::LEQUAL: 4842 case GraphicsContext3D::LEQUAL:
4910 case GraphicsContext3D::GREATER: 4843 case GraphicsContext3D::GREATER:
4911 case GraphicsContext3D::GEQUAL: 4844 case GraphicsContext3D::GEQUAL:
4912 case GraphicsContext3D::EQUAL: 4845 case GraphicsContext3D::EQUAL:
4913 case GraphicsContext3D::NOTEQUAL: 4846 case GraphicsContext3D::NOTEQUAL:
4914 case GraphicsContext3D::ALWAYS: 4847 case GraphicsContext3D::ALWAYS:
4915 return true; 4848 return true;
4916 default: 4849 default:
4917 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, "invali d function"); 4850 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, "invali d function");
4918 return false; 4851 return false;
4919 } 4852 }
4920 } 4853 }
4921 4854
4922 void WebGLRenderingContext::printGLErrorToConsole(const String& message) 4855 void WebGLRenderingContextBase::printGLErrorToConsole(const String& message)
4923 { 4856 {
4924 if (!m_numGLErrorsToConsoleAllowed) 4857 if (!m_numGLErrorsToConsoleAllowed)
4925 return; 4858 return;
4926 4859
4927 --m_numGLErrorsToConsoleAllowed; 4860 --m_numGLErrorsToConsoleAllowed;
4928 printWarningToConsole(message); 4861 printWarningToConsole(message);
4929 4862
4930 if (!m_numGLErrorsToConsoleAllowed) 4863 if (!m_numGLErrorsToConsoleAllowed)
4931 printWarningToConsole("WebGL: too many errors, no more errors will be re ported to the console for this context."); 4864 printWarningToConsole("WebGL: too many errors, no more errors will be re ported to the console for this context.");
4932 4865
4933 return; 4866 return;
4934 } 4867 }
4935 4868
4936 void WebGLRenderingContext::printWarningToConsole(const String& message) 4869 void WebGLRenderingContextBase::printWarningToConsole(const String& message)
4937 { 4870 {
4938 if (!canvas()) 4871 if (!canvas())
4939 return; 4872 return;
4940 canvas()->document().addConsoleMessage(RenderingMessageSource, WarningMessag eLevel, message); 4873 canvas()->document().addConsoleMessage(RenderingMessageSource, WarningMessag eLevel, message);
4941 } 4874 }
4942 4875
4943 bool WebGLRenderingContext::validateFramebufferFuncParameters(const char* functi onName, GC3Denum target, GC3Denum attachment) 4876 bool WebGLRenderingContextBase::validateFramebufferFuncParameters(const char* fu nctionName, GC3Denum target, GC3Denum attachment)
4944 { 4877 {
4945 if (target != GraphicsContext3D::FRAMEBUFFER) { 4878 if (target != GraphicsContext3D::FRAMEBUFFER) {
4946 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, "invali d target"); 4879 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, "invali d target");
4947 return false; 4880 return false;
4948 } 4881 }
4949 switch (attachment) { 4882 switch (attachment) {
4950 case GraphicsContext3D::COLOR_ATTACHMENT0: 4883 case GraphicsContext3D::COLOR_ATTACHMENT0:
4951 case GraphicsContext3D::DEPTH_ATTACHMENT: 4884 case GraphicsContext3D::DEPTH_ATTACHMENT:
4952 case GraphicsContext3D::STENCIL_ATTACHMENT: 4885 case GraphicsContext3D::STENCIL_ATTACHMENT:
4953 case GraphicsContext3D::DEPTH_STENCIL_ATTACHMENT: 4886 case GraphicsContext3D::DEPTH_STENCIL_ATTACHMENT:
4954 break; 4887 break;
4955 default: 4888 default:
4956 if (m_webglDrawBuffers 4889 if (m_webglDrawBuffers
4957 && attachment > GraphicsContext3D::COLOR_ATTACHMENT0 4890 && attachment > GraphicsContext3D::COLOR_ATTACHMENT0
4958 && attachment < static_cast<GC3Denum>(GraphicsContext3D::COLOR_ATTAC HMENT0 + getMaxColorAttachments())) 4891 && attachment < static_cast<GC3Denum>(GraphicsContext3D::COLOR_ATTAC HMENT0 + getMaxColorAttachments()))
4959 break; 4892 break;
4960 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, "invali d attachment"); 4893 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, "invali d attachment");
4961 return false; 4894 return false;
4962 } 4895 }
4963 return true; 4896 return true;
4964 } 4897 }
4965 4898
4966 bool WebGLRenderingContext::validateBlendEquation(const char* functionName, GC3D enum mode) 4899 bool WebGLRenderingContextBase::validateBlendEquation(const char* functionName, GC3Denum mode)
4967 { 4900 {
4968 switch (mode) { 4901 switch (mode) {
4969 case GraphicsContext3D::FUNC_ADD: 4902 case GraphicsContext3D::FUNC_ADD:
4970 case GraphicsContext3D::FUNC_SUBTRACT: 4903 case GraphicsContext3D::FUNC_SUBTRACT:
4971 case GraphicsContext3D::FUNC_REVERSE_SUBTRACT: 4904 case GraphicsContext3D::FUNC_REVERSE_SUBTRACT:
4972 return true; 4905 return true;
4973 default: 4906 default:
4974 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, "invali d mode"); 4907 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, "invali d mode");
4975 return false; 4908 return false;
4976 } 4909 }
4977 } 4910 }
4978 4911
4979 bool WebGLRenderingContext::validateBlendFuncFactors(const char* functionName, G C3Denum src, GC3Denum dst) 4912 bool WebGLRenderingContextBase::validateBlendFuncFactors(const char* functionNam e, GC3Denum src, GC3Denum dst)
4980 { 4913 {
4981 if (((src == GraphicsContext3D::CONSTANT_COLOR || src == GraphicsContext3D:: ONE_MINUS_CONSTANT_COLOR) 4914 if (((src == GraphicsContext3D::CONSTANT_COLOR || src == GraphicsContext3D:: ONE_MINUS_CONSTANT_COLOR)
4982 && (dst == GraphicsContext3D::CONSTANT_ALPHA || dst == GraphicsContext3 D::ONE_MINUS_CONSTANT_ALPHA)) 4915 && (dst == GraphicsContext3D::CONSTANT_ALPHA || dst == GraphicsContext3D ::ONE_MINUS_CONSTANT_ALPHA))
4983 || ((dst == GraphicsContext3D::CONSTANT_COLOR || dst == GraphicsContext3 D::ONE_MINUS_CONSTANT_COLOR) 4916 || ((dst == GraphicsContext3D::CONSTANT_COLOR || dst == GraphicsContext3 D::ONE_MINUS_CONSTANT_COLOR)
4984 && (src == GraphicsContext3D::CONSTANT_ALPHA || src == GraphicsConte xt3D::ONE_MINUS_CONSTANT_ALPHA))) { 4917 && (src == GraphicsContext3D::CONSTANT_ALPHA || src == GraphicsConte xt3D::ONE_MINUS_CONSTANT_ALPHA))) {
4985 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "i ncompatible src and dst"); 4918 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "i ncompatible src and dst");
4986 return false; 4919 return false;
4987 } 4920 }
4988 return true; 4921 return true;
4989 } 4922 }
4990 4923
4991 bool WebGLRenderingContext::validateCapability(const char* functionName, GC3Denu m cap) 4924 bool WebGLRenderingContextBase::validateCapability(const char* functionName, GC3 Denum cap)
4992 { 4925 {
4993 switch (cap) { 4926 switch (cap) {
4994 case GraphicsContext3D::BLEND: 4927 case GraphicsContext3D::BLEND:
4995 case GraphicsContext3D::CULL_FACE: 4928 case GraphicsContext3D::CULL_FACE:
4996 case GraphicsContext3D::DEPTH_TEST: 4929 case GraphicsContext3D::DEPTH_TEST:
4997 case GraphicsContext3D::DITHER: 4930 case GraphicsContext3D::DITHER:
4998 case GraphicsContext3D::POLYGON_OFFSET_FILL: 4931 case GraphicsContext3D::POLYGON_OFFSET_FILL:
4999 case GraphicsContext3D::SAMPLE_ALPHA_TO_COVERAGE: 4932 case GraphicsContext3D::SAMPLE_ALPHA_TO_COVERAGE:
5000 case GraphicsContext3D::SAMPLE_COVERAGE: 4933 case GraphicsContext3D::SAMPLE_COVERAGE:
5001 case GraphicsContext3D::SCISSOR_TEST: 4934 case GraphicsContext3D::SCISSOR_TEST:
5002 case GraphicsContext3D::STENCIL_TEST: 4935 case GraphicsContext3D::STENCIL_TEST:
5003 return true; 4936 return true;
5004 default: 4937 default:
5005 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, "invali d capability"); 4938 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, "invali d capability");
5006 return false; 4939 return false;
5007 } 4940 }
5008 } 4941 }
5009 4942
5010 bool WebGLRenderingContext::validateUniformParameters(const char* functionName, const WebGLUniformLocation* location, Float32Array* v, GC3Dsizei requiredMinSize ) 4943 bool WebGLRenderingContextBase::validateUniformParameters(const char* functionNa me, const WebGLUniformLocation* location, Float32Array* v, GC3Dsizei requiredMin Size)
5011 { 4944 {
5012 if (!v) { 4945 if (!v) {
5013 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no ar ray"); 4946 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no ar ray");
5014 return false; 4947 return false;
5015 } 4948 }
5016 return validateUniformMatrixParameters(functionName, location, false, v->dat a(), v->length(), requiredMinSize); 4949 return validateUniformMatrixParameters(functionName, location, false, v->dat a(), v->length(), requiredMinSize);
5017 } 4950 }
5018 4951
5019 bool WebGLRenderingContext::validateUniformParameters(const char* functionName, const WebGLUniformLocation* location, Int32Array* v, GC3Dsizei requiredMinSize) 4952 bool WebGLRenderingContextBase::validateUniformParameters(const char* functionNa me, const WebGLUniformLocation* location, Int32Array* v, GC3Dsizei requiredMinSi ze)
5020 { 4953 {
5021 if (!v) { 4954 if (!v) {
5022 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no ar ray"); 4955 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no ar ray");
5023 return false; 4956 return false;
5024 } 4957 }
5025 return validateUniformMatrixParameters(functionName, location, false, v->dat a(), v->length(), requiredMinSize); 4958 return validateUniformMatrixParameters(functionName, location, false, v->dat a(), v->length(), requiredMinSize);
5026 } 4959 }
5027 4960
5028 bool WebGLRenderingContext::validateUniformParameters(const char* functionName, const WebGLUniformLocation* location, void* v, GC3Dsizei size, GC3Dsizei require dMinSize) 4961 bool WebGLRenderingContextBase::validateUniformParameters(const char* functionNa me, const WebGLUniformLocation* location, void* v, GC3Dsizei size, GC3Dsizei req uiredMinSize)
5029 { 4962 {
5030 return validateUniformMatrixParameters(functionName, location, false, v, siz e, requiredMinSize); 4963 return validateUniformMatrixParameters(functionName, location, false, v, siz e, requiredMinSize);
5031 } 4964 }
5032 4965
5033 bool WebGLRenderingContext::validateUniformMatrixParameters(const char* function Name, const WebGLUniformLocation* location, GC3Dboolean transpose, Float32Array* v, GC3Dsizei requiredMinSize) 4966 bool WebGLRenderingContextBase::validateUniformMatrixParameters(const char* func tionName, const WebGLUniformLocation* location, GC3Dboolean transpose, Float32Ar ray* v, GC3Dsizei requiredMinSize)
5034 { 4967 {
5035 if (!v) { 4968 if (!v) {
5036 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no ar ray"); 4969 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no ar ray");
5037 return false; 4970 return false;
5038 } 4971 }
5039 return validateUniformMatrixParameters(functionName, location, transpose, v- >data(), v->length(), requiredMinSize); 4972 return validateUniformMatrixParameters(functionName, location, transpose, v- >data(), v->length(), requiredMinSize);
5040 } 4973 }
5041 4974
5042 bool WebGLRenderingContext::validateUniformMatrixParameters(const char* function Name, const WebGLUniformLocation* location, GC3Dboolean transpose, void* v, GC3D sizei size, GC3Dsizei requiredMinSize) 4975 bool WebGLRenderingContextBase::validateUniformMatrixParameters(const char* func tionName, const WebGLUniformLocation* location, GC3Dboolean transpose, void* v, GC3Dsizei size, GC3Dsizei requiredMinSize)
5043 { 4976 {
5044 if (!location) 4977 if (!location)
5045 return false; 4978 return false;
5046 if (location->program() != m_currentProgram) { 4979 if (location->program() != m_currentProgram) {
5047 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "l ocation is not from current program"); 4980 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "l ocation is not from current program");
5048 return false; 4981 return false;
5049 } 4982 }
5050 if (!v) { 4983 if (!v) {
5051 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no ar ray"); 4984 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no ar ray");
5052 return false; 4985 return false;
5053 } 4986 }
5054 if (transpose) { 4987 if (transpose) {
5055 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "trans pose not FALSE"); 4988 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "trans pose not FALSE");
5056 return false; 4989 return false;
5057 } 4990 }
5058 if (size < requiredMinSize || (size % requiredMinSize)) { 4991 if (size < requiredMinSize || (size % requiredMinSize)) {
5059 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "inval id size"); 4992 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "inval id size");
5060 return false; 4993 return false;
5061 } 4994 }
5062 return true; 4995 return true;
5063 } 4996 }
5064 4997
5065 WebGLBuffer* WebGLRenderingContext::validateBufferDataParameters(const char* fun ctionName, GC3Denum target, GC3Denum usage) 4998 WebGLBuffer* WebGLRenderingContextBase::validateBufferDataParameters(const char* functionName, GC3Denum target, GC3Denum usage)
5066 { 4999 {
5067 WebGLBuffer* buffer = 0; 5000 WebGLBuffer* buffer = 0;
5068 switch (target) { 5001 switch (target) {
5069 case GraphicsContext3D::ELEMENT_ARRAY_BUFFER: 5002 case GraphicsContext3D::ELEMENT_ARRAY_BUFFER:
5070 buffer = m_boundVertexArrayObject->getElementArrayBuffer().get(); 5003 buffer = m_boundVertexArrayObject->getElementArrayBuffer().get();
5071 break; 5004 break;
5072 case GraphicsContext3D::ARRAY_BUFFER: 5005 case GraphicsContext3D::ARRAY_BUFFER:
5073 buffer = m_boundArrayBuffer.get(); 5006 buffer = m_boundArrayBuffer.get();
5074 break; 5007 break;
5075 default: 5008 default:
5076 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, "invali d target"); 5009 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, "invali d target");
5077 return 0; 5010 return 0;
5078 } 5011 }
5079 if (!buffer) { 5012 if (!buffer) {
5080 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "n o buffer"); 5013 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "n o buffer");
5081 return 0; 5014 return 0;
5082 } 5015 }
5083 switch (usage) { 5016 switch (usage) {
5084 case GraphicsContext3D::STREAM_DRAW: 5017 case GraphicsContext3D::STREAM_DRAW:
5085 case GraphicsContext3D::STATIC_DRAW: 5018 case GraphicsContext3D::STATIC_DRAW:
5086 case GraphicsContext3D::DYNAMIC_DRAW: 5019 case GraphicsContext3D::DYNAMIC_DRAW:
5087 return buffer; 5020 return buffer;
5088 } 5021 }
5089 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, "invalid us age"); 5022 synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, "invalid us age");
5090 return 0; 5023 return 0;
5091 } 5024 }
5092 5025
5093 bool WebGLRenderingContext::validateHTMLImageElement(const char* functionName, H TMLImageElement* image, ExceptionState& es) 5026 bool WebGLRenderingContextBase::validateHTMLImageElement(const char* functionNam e, HTMLImageElement* image, ExceptionState& es)
5094 { 5027 {
5095 if (!image || !image->cachedImage()) { 5028 if (!image || !image->cachedImage()) {
5096 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no im age"); 5029 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no im age");
5097 return false; 5030 return false;
5098 } 5031 }
5099 const KURL& url = image->cachedImage()->response().url(); 5032 const KURL& url = image->cachedImage()->response().url();
5100 if (url.isNull() || url.isEmpty() || !url.isValid()) { 5033 if (url.isNull() || url.isEmpty() || !url.isValid()) {
5101 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "inval id image"); 5034 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "inval id image");
5102 return false; 5035 return false;
5103 } 5036 }
5104 if (wouldTaintOrigin(image)) { 5037 if (wouldTaintOrigin(image)) {
5105 es.throwSecurityError(ExceptionMessages::failedToExecute(functionName, " WebGLRenderingContext", "the cross-origin image at " + url.elidedString() + " ma y not be loaded.")); 5038 es.throwSecurityError(ExceptionMessages::failedToExecute(functionName, m _contextName, "the cross-origin image at " + url.elidedString() + " may not be l oaded."));
5106 return false; 5039 return false;
5107 } 5040 }
5108 return true; 5041 return true;
5109 } 5042 }
5110 5043
5111 bool WebGLRenderingContext::validateHTMLCanvasElement(const char* functionName, HTMLCanvasElement* canvas, ExceptionState& es) 5044 bool WebGLRenderingContextBase::validateHTMLCanvasElement(const char* functionNa me, HTMLCanvasElement* canvas, ExceptionState& es)
5112 { 5045 {
5113 if (!canvas || !canvas->buffer()) { 5046 if (!canvas || !canvas->buffer()) {
5114 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no ca nvas"); 5047 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no ca nvas");
5115 return false; 5048 return false;
5116 } 5049 }
5117 if (wouldTaintOrigin(canvas)) { 5050 if (wouldTaintOrigin(canvas)) {
5118 es.throwSecurityError(ExceptionMessages::failedToExecute(functionName, " WebGLRenderingContext", "tainted canvases may not be loded.")); 5051 es.throwSecurityError(ExceptionMessages::failedToExecute(functionName, m _contextName, "tainted canvases may not be loded."));
5119 return false; 5052 return false;
5120 } 5053 }
5121 return true; 5054 return true;
5122 } 5055 }
5123 5056
5124 bool WebGLRenderingContext::validateHTMLVideoElement(const char* functionName, H TMLVideoElement* video, ExceptionState& es) 5057 bool WebGLRenderingContextBase::validateHTMLVideoElement(const char* functionNam e, HTMLVideoElement* video, ExceptionState& es)
5125 { 5058 {
5126 if (!video || !video->videoWidth() || !video->videoHeight()) { 5059 if (!video || !video->videoWidth() || !video->videoHeight()) {
5127 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no vi deo"); 5060 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no vi deo");
5128 return false; 5061 return false;
5129 } 5062 }
5130 if (wouldTaintOrigin(video)) { 5063 if (wouldTaintOrigin(video)) {
5131 es.throwSecurityError(ExceptionMessages::failedToExecute(functionName, " WebGLRenderingContext", "the video element contains cross-origin data, and may n ot be loaded.")); 5064 es.throwSecurityError(ExceptionMessages::failedToExecute(functionName, m _contextName, "the video element contains cross-origin data, and may not be load ed."));
5132 return false; 5065 return false;
5133 } 5066 }
5134 return true; 5067 return true;
5135 } 5068 }
5136 5069
5137 bool WebGLRenderingContext::validateDrawArrays(const char* functionName, GC3Denu m mode, GC3Dint first, GC3Dsizei count) 5070 bool WebGLRenderingContextBase::validateDrawArrays(const char* functionName, GC3 Denum mode, GC3Dint first, GC3Dsizei count)
5138 { 5071 {
5139 if (isContextLost() || !validateDrawMode(functionName, mode)) 5072 if (isContextLost() || !validateDrawMode(functionName, mode))
5140 return false; 5073 return false;
5141 5074
5142 if (!validateStencilSettings(functionName)) 5075 if (!validateStencilSettings(functionName))
5143 return false; 5076 return false;
5144 5077
5145 if (first < 0 || count < 0) { 5078 if (first < 0 || count < 0) {
5146 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "first or count < 0"); 5079 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "first or count < 0");
5147 return false; 5080 return false;
(...skipping 11 matching lines...) Expand all
5159 5092
5160 const char* reason = "framebuffer incomplete"; 5093 const char* reason = "framebuffer incomplete";
5161 if (m_framebufferBinding && !m_framebufferBinding->onAccess(graphicsContext3 D(), &reason)) { 5094 if (m_framebufferBinding && !m_framebufferBinding->onAccess(graphicsContext3 D(), &reason)) {
5162 synthesizeGLError(GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION, func tionName, reason); 5095 synthesizeGLError(GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION, func tionName, reason);
5163 return false; 5096 return false;
5164 } 5097 }
5165 5098
5166 return true; 5099 return true;
5167 } 5100 }
5168 5101
5169 bool WebGLRenderingContext::validateDrawElements(const char* functionName, GC3De num mode, GC3Dsizei count, GC3Denum type, long long offset) 5102 bool WebGLRenderingContextBase::validateDrawElements(const char* functionName, G C3Denum mode, GC3Dsizei count, GC3Denum type, long long offset)
5170 { 5103 {
5171 if (isContextLost() || !validateDrawMode(functionName, mode)) 5104 if (isContextLost() || !validateDrawMode(functionName, mode))
5172 return false; 5105 return false;
5173 5106
5174 if (!validateStencilSettings(functionName)) 5107 if (!validateStencilSettings(functionName))
5175 return false; 5108 return false;
5176 5109
5177 switch (type) { 5110 switch (type) {
5178 case GraphicsContext3D::UNSIGNED_BYTE: 5111 case GraphicsContext3D::UNSIGNED_BYTE:
5179 case GraphicsContext3D::UNSIGNED_SHORT: 5112 case GraphicsContext3D::UNSIGNED_SHORT:
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
5211 const char* reason = "framebuffer incomplete"; 5144 const char* reason = "framebuffer incomplete";
5212 if (m_framebufferBinding && !m_framebufferBinding->onAccess(graphicsContext3 D(), &reason)) { 5145 if (m_framebufferBinding && !m_framebufferBinding->onAccess(graphicsContext3 D(), &reason)) {
5213 synthesizeGLError(GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION, func tionName, reason); 5146 synthesizeGLError(GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION, func tionName, reason);
5214 return false; 5147 return false;
5215 } 5148 }
5216 5149
5217 return true; 5150 return true;
5218 } 5151 }
5219 5152
5220 // Helper function to validate draw*Instanced calls 5153 // Helper function to validate draw*Instanced calls
5221 bool WebGLRenderingContext::validateDrawInstanced(const char* functionName, GC3D sizei primcount) 5154 bool WebGLRenderingContextBase::validateDrawInstanced(const char* functionName, GC3Dsizei primcount)
5222 { 5155 {
5223 if (primcount < 0) { 5156 if (primcount < 0) {
5224 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "primc ount < 0"); 5157 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "primc ount < 0");
5225 return false; 5158 return false;
5226 } 5159 }
5227 5160
5228 // Ensure at least one enabled vertex attrib has a divisor of 0. 5161 // Ensure at least one enabled vertex attrib has a divisor of 0.
5229 for (unsigned i = 0; i < m_onePlusMaxEnabledAttribIndex; ++i) { 5162 for (unsigned i = 0; i < m_onePlusMaxEnabledAttribIndex; ++i) {
5230 const WebGLVertexArrayObjectOES::VertexAttribState& state = m_boundVerte xArrayObject->getVertexAttribState(i); 5163 const WebGLVertexArrayObjectOES::VertexAttribState& state = m_boundVerte xArrayObject->getVertexAttribState(i);
5231 if (state.enabled && !state.divisor) 5164 if (state.enabled && !state.divisor)
5232 return true; 5165 return true;
5233 } 5166 }
5234 5167
5235 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "at le ast one enabled attribute must have a divisor of 0"); 5168 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "at le ast one enabled attribute must have a divisor of 0");
5236 return false; 5169 return false;
5237 } 5170 }
5238 5171
5239 void WebGLRenderingContext::vertexAttribfImpl(const char* functionName, GC3Duint index, GC3Dsizei expectedSize, GC3Dfloat v0, GC3Dfloat v1, GC3Dfloat v2, GC3Dfl oat v3) 5172 void WebGLRenderingContextBase::vertexAttribfImpl(const char* functionName, GC3D uint index, GC3Dsizei expectedSize, GC3Dfloat v0, GC3Dfloat v1, GC3Dfloat v2, GC 3Dfloat v3)
5240 { 5173 {
5241 if (isContextLost()) 5174 if (isContextLost())
5242 return; 5175 return;
5243 if (index >= m_maxVertexAttribs) { 5176 if (index >= m_maxVertexAttribs) {
5244 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "index out of range"); 5177 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "index out of range");
5245 return; 5178 return;
5246 } 5179 }
5247 // In GL, we skip setting vertexAttrib0 values. 5180 // In GL, we skip setting vertexAttrib0 values.
5248 switch (expectedSize) { 5181 switch (expectedSize) {
5249 case 1: 5182 case 1:
5250 m_context->vertexAttrib1f(index, v0); 5183 m_context->vertexAttrib1f(index, v0);
5251 break; 5184 break;
5252 case 2: 5185 case 2:
5253 m_context->vertexAttrib2f(index, v0, v1); 5186 m_context->vertexAttrib2f(index, v0, v1);
5254 break; 5187 break;
5255 case 3: 5188 case 3:
5256 m_context->vertexAttrib3f(index, v0, v1, v2); 5189 m_context->vertexAttrib3f(index, v0, v1, v2);
5257 break; 5190 break;
5258 case 4: 5191 case 4:
5259 m_context->vertexAttrib4f(index, v0, v1, v2, v3); 5192 m_context->vertexAttrib4f(index, v0, v1, v2, v3);
5260 break; 5193 break;
5261 } 5194 }
5262 VertexAttribValue& attribValue = m_vertexAttribValue[index]; 5195 VertexAttribValue& attribValue = m_vertexAttribValue[index];
5263 attribValue.value[0] = v0; 5196 attribValue.value[0] = v0;
5264 attribValue.value[1] = v1; 5197 attribValue.value[1] = v1;
5265 attribValue.value[2] = v2; 5198 attribValue.value[2] = v2;
5266 attribValue.value[3] = v3; 5199 attribValue.value[3] = v3;
5267 } 5200 }
5268 5201
5269 void WebGLRenderingContext::vertexAttribfvImpl(const char* functionName, GC3Duin t index, Float32Array* v, GC3Dsizei expectedSize) 5202 void WebGLRenderingContextBase::vertexAttribfvImpl(const char* functionName, GC3 Duint index, Float32Array* v, GC3Dsizei expectedSize)
5270 { 5203 {
5271 if (isContextLost()) 5204 if (isContextLost())
5272 return; 5205 return;
5273 if (!v) { 5206 if (!v) {
5274 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no ar ray"); 5207 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no ar ray");
5275 return; 5208 return;
5276 } 5209 }
5277 vertexAttribfvImpl(functionName, index, v->data(), v->length(), expectedSize ); 5210 vertexAttribfvImpl(functionName, index, v->data(), v->length(), expectedSize );
5278 } 5211 }
5279 5212
5280 void WebGLRenderingContext::vertexAttribfvImpl(const char* functionName, GC3Duin t index, GC3Dfloat* v, GC3Dsizei size, GC3Dsizei expectedSize) 5213 void WebGLRenderingContextBase::vertexAttribfvImpl(const char* functionName, GC3 Duint index, GC3Dfloat* v, GC3Dsizei size, GC3Dsizei expectedSize)
5281 { 5214 {
5282 if (isContextLost()) 5215 if (isContextLost())
5283 return; 5216 return;
5284 if (!v) { 5217 if (!v) {
5285 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no ar ray"); 5218 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "no ar ray");
5286 return; 5219 return;
5287 } 5220 }
5288 if (size < expectedSize) { 5221 if (size < expectedSize) {
5289 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "inval id size"); 5222 synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "inval id size");
5290 return; 5223 return;
(...skipping 16 matching lines...) Expand all
5307 case 4: 5240 case 4:
5308 m_context->vertexAttrib4fv(index, v); 5241 m_context->vertexAttrib4fv(index, v);
5309 break; 5242 break;
5310 } 5243 }
5311 VertexAttribValue& attribValue = m_vertexAttribValue[index]; 5244 VertexAttribValue& attribValue = m_vertexAttribValue[index];
5312 attribValue.initValue(); 5245 attribValue.initValue();
5313 for (int ii = 0; ii < expectedSize; ++ii) 5246 for (int ii = 0; ii < expectedSize; ++ii)
5314 attribValue.value[ii] = v[ii]; 5247 attribValue.value[ii] = v[ii];
5315 } 5248 }
5316 5249
5317 void WebGLRenderingContext::dispatchContextLostEvent(Timer<WebGLRenderingContext >*) 5250 void WebGLRenderingContextBase::dispatchContextLostEvent(Timer<WebGLRenderingCon textBase>*)
5318 { 5251 {
5319 RefPtr<WebGLContextEvent> event = WebGLContextEvent::create(eventNames().web glcontextlostEvent, false, true, ""); 5252 RefPtr<WebGLContextEvent> event = WebGLContextEvent::create(eventNames().web glcontextlostEvent, false, true, "");
5320 canvas()->dispatchEvent(event); 5253 canvas()->dispatchEvent(event);
5321 m_restoreAllowed = event->defaultPrevented(); 5254 m_restoreAllowed = event->defaultPrevented();
5322 deactivateContext(this, m_contextLostMode != RealLostContext && m_restoreAll owed); 5255 deactivateContext(this, m_contextLostMode != RealLostContext && m_restoreAll owed);
5323 if ((m_contextLostMode == RealLostContext || m_contextLostMode == AutoRecove rSyntheticLostContext) && m_restoreAllowed) 5256 if ((m_contextLostMode == RealLostContext || m_contextLostMode == AutoRecove rSyntheticLostContext) && m_restoreAllowed)
5324 m_restoreTimer.startOneShot(0); 5257 m_restoreTimer.startOneShot(0);
5325 } 5258 }
5326 5259
5327 void WebGLRenderingContext::maybeRestoreContext(Timer<WebGLRenderingContext>*) 5260 void WebGLRenderingContextBase::maybeRestoreContext(Timer<WebGLRenderingContextB ase>*)
5328 { 5261 {
5329 ASSERT(isContextLost()); 5262 ASSERT(isContextLost());
5330 5263
5331 // The rendering context is not restored unless the default behavior of the 5264 // The rendering context is not restored unless the default behavior of the
5332 // webglcontextlost event was prevented earlier. 5265 // webglcontextlost event was prevented earlier.
5333 // 5266 //
5334 // Because of the way m_restoreTimer is set up for real vs. synthetic lost 5267 // Because of the way m_restoreTimer is set up for real vs. synthetic lost
5335 // context events, we don't have to worry about this test short-circuiting 5268 // context events, we don't have to worry about this test short-circuiting
5336 // the retry loop for real context lost events. 5269 // the retry loop for real context lost events.
5337 if (!m_restoreAllowed) 5270 if (!m_restoreAllowed)
5338 return; 5271 return;
5339 5272
5340 Frame* frame = canvas()->document().frame(); 5273 Frame* frame = canvas()->document().frame();
5341 if (!frame) 5274 if (!frame)
5342 return; 5275 return;
5343 5276
5344 Settings* settings = frame->settings(); 5277 Settings* settings = frame->settings();
5345 5278
5346 if (!frame->loader()->client()->allowWebGL(settings && settings->webGLEnable d())) 5279 if (!frame->loader()->client()->allowWebGL(settings && settings->webGLEnable d()))
5347 return; 5280 return;
5348 5281
5349 // Reset the context attributes back to the requested attributes and re-appl y restrictions 5282 // Reset the context attributes back to the requested attributes and re-appl y restrictions
5350 m_attributes = adjustAttributes(m_requestedAttributes, settings); 5283 m_attributes = WebGLRenderingContextBase::adjustAttributes(m_requestedAttrib utes, settings);
5351 5284
5352 RefPtr<GraphicsContext3D> context(GraphicsContext3D::create(m_attributes)); 5285 RefPtr<GraphicsContext3D> context(GraphicsContext3D::create(m_attributes));
5353 5286
5354 if (!context) { 5287 if (!context) {
5355 if (m_contextLostMode == RealLostContext) 5288 if (m_contextLostMode == RealLostContext) {
5356 m_restoreTimer.startOneShot(secondsBetweenRestoreAttempts); 5289 m_restoreTimer.startOneShot(secondsBetweenRestoreAttempts);
5357 else 5290 } else {
5358 // This likely shouldn't happen but is the best way to report it to the WebGL app. 5291 // This likely shouldn't happen but is the best way to report it to the WebGL app.
5359 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "", "error r estoring context"); 5292 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "", "error r estoring context");
5293 }
5360 return; 5294 return;
5361 } 5295 }
5362 5296
5363 RefPtr<WebGLRenderingContextEvictionManager> contextEvictionManager = adoptR ef(new WebGLRenderingContextEvictionManager()); 5297 RefPtr<WebGLRenderingContextEvictionManager> contextEvictionManager = adoptR ef(new WebGLRenderingContextEvictionManager());
5364 5298
5365 // Construct a new drawing buffer with the new GraphicsContext3D. 5299 // Construct a new drawing buffer with the new GraphicsContext3D.
5366 m_drawingBuffer->releaseResources(); 5300 m_drawingBuffer->releaseResources();
5367 DrawingBuffer::PreserveDrawingBuffer preserve = m_attributes.preserveDrawing Buffer ? DrawingBuffer::Preserve : DrawingBuffer::Discard; 5301 DrawingBuffer::PreserveDrawingBuffer preserve = m_attributes.preserveDrawing Buffer ? DrawingBuffer::Preserve : DrawingBuffer::Discard;
5368 m_drawingBuffer = DrawingBuffer::create(context.get(), clampedCanvasSize(), preserve, contextEvictionManager.release()); 5302 m_drawingBuffer = DrawingBuffer::create(context.get(), clampedCanvasSize(), preserve, contextEvictionManager.release());
5369 5303
5370 if (m_drawingBuffer->isZeroSized()) 5304 if (m_drawingBuffer->isZeroSized())
5371 return; 5305 return;
5372 5306
5373 m_drawingBuffer->bind(); 5307 m_drawingBuffer->bind();
5374 5308
5375 lost_context_errors_.clear(); 5309 m_lostContextErrors.clear();
5376 5310
5377 m_context = context; 5311 m_context = context;
5378 m_contextLost = false; 5312 m_contextLost = false;
5379 5313
5380 setupFlags(); 5314 setupFlags();
5381 initializeNewContext(); 5315 initializeNewContext();
5382 canvas()->dispatchEvent(WebGLContextEvent::create(eventNames().webglcontextr estoredEvent, false, true, "")); 5316 canvas()->dispatchEvent(WebGLContextEvent::create(eventNames().webglcontextr estoredEvent, false, true, ""));
5383 } 5317 }
5384 5318
5385 String WebGLRenderingContext::ensureNotNull(const String& text) const 5319 String WebGLRenderingContextBase::ensureNotNull(const String& text) const
5386 { 5320 {
5387 if (text.isNull()) 5321 if (text.isNull())
5388 return WTF::emptyString(); 5322 return WTF::emptyString();
5389 return text; 5323 return text;
5390 } 5324 }
5391 5325
5392 WebGLRenderingContext::LRUImageBufferCache::LRUImageBufferCache(int capacity) 5326 WebGLRenderingContextBase::LRUImageBufferCache::LRUImageBufferCache(int capacity )
5393 : m_buffers(adoptArrayPtr(new OwnPtr<ImageBuffer>[capacity])) 5327 : m_buffers(adoptArrayPtr(new OwnPtr<ImageBuffer>[capacity]))
5394 , m_capacity(capacity) 5328 , m_capacity(capacity)
5395 { 5329 {
5396 } 5330 }
5397 5331
5398 ImageBuffer* WebGLRenderingContext::LRUImageBufferCache::imageBuffer(const IntSi ze& size) 5332 ImageBuffer* WebGLRenderingContextBase::LRUImageBufferCache::imageBuffer(const I ntSize& size)
5399 { 5333 {
5400 int i; 5334 int i;
5401 for (i = 0; i < m_capacity; ++i) { 5335 for (i = 0; i < m_capacity; ++i) {
5402 ImageBuffer* buf = m_buffers[i].get(); 5336 ImageBuffer* buf = m_buffers[i].get();
5403 if (!buf) 5337 if (!buf)
5404 break; 5338 break;
5405 if (buf->logicalSize() != size) 5339 if (buf->logicalSize() != size)
5406 continue; 5340 continue;
5407 bubbleToFront(i); 5341 bubbleToFront(i);
5408 return buf; 5342 return buf;
5409 } 5343 }
5410 5344
5411 OwnPtr<ImageBuffer> temp = ImageBuffer::create(size, 1); 5345 OwnPtr<ImageBuffer> temp = ImageBuffer::create(size, 1);
5412 if (!temp) 5346 if (!temp)
5413 return 0; 5347 return 0;
5414 i = std::min(m_capacity - 1, i); 5348 i = std::min(m_capacity - 1, i);
5415 m_buffers[i] = temp.release(); 5349 m_buffers[i] = temp.release();
5416 5350
5417 ImageBuffer* buf = m_buffers[i].get(); 5351 ImageBuffer* buf = m_buffers[i].get();
5418 bubbleToFront(i); 5352 bubbleToFront(i);
5419 return buf; 5353 return buf;
5420 } 5354 }
5421 5355
5422 void WebGLRenderingContext::LRUImageBufferCache::bubbleToFront(int idx) 5356 void WebGLRenderingContextBase::LRUImageBufferCache::bubbleToFront(int idx)
5423 { 5357 {
5424 for (int i = idx; i > 0; --i) 5358 for (int i = idx; i > 0; --i)
5425 m_buffers[i].swap(m_buffers[i-1]); 5359 m_buffers[i].swap(m_buffers[i-1]);
5426 } 5360 }
5427 5361
5428 namespace { 5362 namespace {
5429 5363
5430 String GetErrorString(GC3Denum error) 5364 String GetErrorString(GC3Denum error)
5431 { 5365 {
5432 switch (error) { 5366 switch (error) {
5433 case GraphicsContext3D::INVALID_ENUM: 5367 case GraphicsContext3D::INVALID_ENUM:
5434 return "INVALID_ENUM"; 5368 return "INVALID_ENUM";
5435 case GraphicsContext3D::INVALID_VALUE: 5369 case GraphicsContext3D::INVALID_VALUE:
5436 return "INVALID_VALUE"; 5370 return "INVALID_VALUE";
5437 case GraphicsContext3D::INVALID_OPERATION: 5371 case GraphicsContext3D::INVALID_OPERATION:
5438 return "INVALID_OPERATION"; 5372 return "INVALID_OPERATION";
5439 case GraphicsContext3D::OUT_OF_MEMORY: 5373 case GraphicsContext3D::OUT_OF_MEMORY:
5440 return "OUT_OF_MEMORY"; 5374 return "OUT_OF_MEMORY";
5441 case GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION: 5375 case GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION:
5442 return "INVALID_FRAMEBUFFER_OPERATION"; 5376 return "INVALID_FRAMEBUFFER_OPERATION";
5443 case GraphicsContext3D::CONTEXT_LOST_WEBGL: 5377 case GraphicsContext3D::CONTEXT_LOST_WEBGL:
5444 return "CONTEXT_LOST_WEBGL"; 5378 return "CONTEXT_LOST_WEBGL";
5445 default: 5379 default:
5446 return String::format("WebGL ERROR(0x%04X)", error); 5380 return String::format("WebGL ERROR(0x%04X)", error);
5447 } 5381 }
5448 } 5382 }
5449 5383
5450 } // namespace anonymous 5384 } // namespace anonymous
5451 5385
5452 void WebGLRenderingContext::synthesizeGLError(GC3Denum error, const char* functi onName, const char* description, ConsoleDisplayPreference display) 5386 void WebGLRenderingContextBase::synthesizeGLError(GC3Denum error, const char* fu nctionName, const char* description, ConsoleDisplayPreference display)
5453 { 5387 {
5454 String errorType = GetErrorString(error); 5388 String errorType = GetErrorString(error);
5455 if (m_synthesizedErrorsToConsole && display == DisplayInConsole) { 5389 if (m_synthesizedErrorsToConsole && display == DisplayInConsole) {
5456 String message = String("WebGL: ") + errorType + ": " + String(function Name) + ": " + String(description); 5390 String message = String("WebGL: ") + errorType + ": " + String(function Name) + ": " + String(description);
5457 printGLErrorToConsole(message); 5391 printGLErrorToConsole(message);
5458 } 5392 }
5459 if (!isContextLost()) 5393 if (!isContextLost()) {
5460 m_context->synthesizeGLError(error); 5394 m_context->synthesizeGLError(error);
5461 else { 5395 } else {
5462 if (lost_context_errors_.find(error) == WTF::notFound) 5396 if (m_lostContextErrors.find(error) == WTF::notFound)
5463 lost_context_errors_.append(error); 5397 m_lostContextErrors.append(error);
5464 } 5398 }
5465 InspectorInstrumentation::didFireWebGLError(canvas(), errorType); 5399 InspectorInstrumentation::didFireWebGLError(canvas(), errorType);
5466 } 5400 }
5467 5401
5468 void WebGLRenderingContext::emitGLWarning(const char* functionName, const char* description) 5402 void WebGLRenderingContextBase::emitGLWarning(const char* functionName, const ch ar* description)
5469 { 5403 {
5470 if (m_synthesizedErrorsToConsole) { 5404 if (m_synthesizedErrorsToConsole) {
5471 String message = String("WebGL: ") + String(functionName) + ": " + Strin g(description); 5405 String message = String("WebGL: ") + String(functionName) + ": " + Strin g(description);
5472 printGLErrorToConsole(message); 5406 printGLErrorToConsole(message);
5473 } 5407 }
5474 InspectorInstrumentation::didFireWebGLWarning(canvas()); 5408 InspectorInstrumentation::didFireWebGLWarning(canvas());
5475 } 5409 }
5476 5410
5477 void WebGLRenderingContext::applyStencilTest() 5411 void WebGLRenderingContextBase::applyStencilTest()
5478 { 5412 {
5479 bool haveStencilBuffer = false; 5413 bool haveStencilBuffer = false;
5480 5414
5481 if (m_framebufferBinding) 5415 if (m_framebufferBinding) {
5482 haveStencilBuffer = m_framebufferBinding->hasStencilBuffer(); 5416 haveStencilBuffer = m_framebufferBinding->hasStencilBuffer();
5483 else { 5417 } else {
5484 RefPtr<WebGLContextAttributes> attributes = getContextAttributes(); 5418 RefPtr<WebGLContextAttributes> attributes = getContextAttributes();
5485 haveStencilBuffer = attributes->stencil(); 5419 haveStencilBuffer = attributes->stencil();
5486 } 5420 }
5487 enableOrDisable(GraphicsContext3D::STENCIL_TEST, 5421 enableOrDisable(GraphicsContext3D::STENCIL_TEST, m_stencilEnabled && haveSte ncilBuffer);
5488 m_stencilEnabled && haveStencilBuffer);
5489 } 5422 }
5490 5423
5491 void WebGLRenderingContext::enableOrDisable(GC3Denum capability, bool enable) 5424 void WebGLRenderingContextBase::enableOrDisable(GC3Denum capability, bool enable )
5492 { 5425 {
5493 if (isContextLost()) 5426 if (isContextLost())
5494 return; 5427 return;
5495 if (enable) 5428 if (enable)
5496 m_context->enable(capability); 5429 m_context->enable(capability);
5497 else 5430 else
5498 m_context->disable(capability); 5431 m_context->disable(capability);
5499 } 5432 }
5500 5433
5501 IntSize WebGLRenderingContext::clampedCanvasSize() 5434 IntSize WebGLRenderingContextBase::clampedCanvasSize()
5502 { 5435 {
5503 return IntSize(clamp(canvas()->width(), 1, m_maxViewportDims[0]), 5436 return IntSize(clamp(canvas()->width(), 1, m_maxViewportDims[0]), clamp(canv as()->height(), 1, m_maxViewportDims[1]));
5504 clamp(canvas()->height(), 1, m_maxViewportDims[1]));
5505 } 5437 }
5506 5438
5507 GC3Dint WebGLRenderingContext::getMaxDrawBuffers() 5439 GC3Dint WebGLRenderingContextBase::getMaxDrawBuffers()
5508 { 5440 {
5509 if (isContextLost() || !m_webglDrawBuffers) 5441 if (isContextLost() || !m_webglDrawBuffers)
5510 return 0; 5442 return 0;
5511 if (!m_maxDrawBuffers) 5443 if (!m_maxDrawBuffers)
5512 m_context->getIntegerv(Extensions3D::MAX_DRAW_BUFFERS_EXT, &m_maxDrawBuf fers); 5444 m_context->getIntegerv(Extensions3D::MAX_DRAW_BUFFERS_EXT, &m_maxDrawBuf fers);
5513 if (!m_maxColorAttachments) 5445 if (!m_maxColorAttachments)
5514 m_context->getIntegerv(Extensions3D::MAX_COLOR_ATTACHMENTS_EXT, &m_maxCo lorAttachments); 5446 m_context->getIntegerv(Extensions3D::MAX_COLOR_ATTACHMENTS_EXT, &m_maxCo lorAttachments);
5515 // WEBGL_draw_buffers requires MAX_COLOR_ATTACHMENTS >= MAX_DRAW_BUFFERS. 5447 // WEBGL_draw_buffers requires MAX_COLOR_ATTACHMENTS >= MAX_DRAW_BUFFERS.
5516 return std::min(m_maxDrawBuffers, m_maxColorAttachments); 5448 return std::min(m_maxDrawBuffers, m_maxColorAttachments);
5517 } 5449 }
5518 5450
5519 GC3Dint WebGLRenderingContext::getMaxColorAttachments() 5451 GC3Dint WebGLRenderingContextBase::getMaxColorAttachments()
5520 { 5452 {
5521 if (isContextLost() || !m_webglDrawBuffers) 5453 if (isContextLost() || !m_webglDrawBuffers)
5522 return 0; 5454 return 0;
5523 if (!m_maxColorAttachments) 5455 if (!m_maxColorAttachments)
5524 m_context->getIntegerv(Extensions3D::MAX_COLOR_ATTACHMENTS_EXT, &m_maxCo lorAttachments); 5456 m_context->getIntegerv(Extensions3D::MAX_COLOR_ATTACHMENTS_EXT, &m_maxCo lorAttachments);
5525 return m_maxColorAttachments; 5457 return m_maxColorAttachments;
5526 } 5458 }
5527 5459
5528 void WebGLRenderingContext::setBackDrawBuffer(GC3Denum buf) 5460 void WebGLRenderingContextBase::setBackDrawBuffer(GC3Denum buf)
5529 { 5461 {
5530 m_backDrawBuffer = buf; 5462 m_backDrawBuffer = buf;
5531 } 5463 }
5532 5464
5533 void WebGLRenderingContext::restoreCurrentFramebuffer() 5465 void WebGLRenderingContextBase::restoreCurrentFramebuffer()
5534 { 5466 {
5535 bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_framebufferBinding.get()); 5467 bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_framebufferBinding.get());
5536 } 5468 }
5537 5469
5538 void WebGLRenderingContext::restoreCurrentTexture2D() 5470 void WebGLRenderingContextBase::restoreCurrentTexture2D()
5539 { 5471 {
5540 bindTexture(GraphicsContext3D::TEXTURE_2D, m_textureUnits[m_activeTextureUni t].m_texture2DBinding.get()); 5472 bindTexture(GraphicsContext3D::TEXTURE_2D, m_textureUnits[m_activeTextureUni t].m_texture2DBinding.get());
5541 } 5473 }
5542 5474
5543 void WebGLRenderingContext::multisamplingChanged(bool enabled) 5475 void WebGLRenderingContextBase::multisamplingChanged(bool enabled)
5544 { 5476 {
5545 if (m_multisamplingAllowed != enabled) { 5477 if (m_multisamplingAllowed != enabled) {
5546 m_multisamplingAllowed = enabled; 5478 m_multisamplingAllowed = enabled;
5547 forceLostContext(WebGLRenderingContext::AutoRecoverSyntheticLostContext) ; 5479 forceLostContext(WebGLRenderingContextBase::AutoRecoverSyntheticLostCont ext);
5548 } 5480 }
5549 } 5481 }
5550 5482
5551 void WebGLRenderingContext::findNewMaxEnabledAttribIndex() 5483 void WebGLRenderingContextBase::findNewMaxEnabledAttribIndex()
5552 { 5484 {
5553 // Trace backwards from the current max to find the new max enabled attrib i ndex 5485 // Trace backwards from the current max to find the new max enabled attrib i ndex
5554 int startIndex = m_onePlusMaxEnabledAttribIndex - 1; 5486 int startIndex = m_onePlusMaxEnabledAttribIndex - 1;
5555 for (int i = startIndex; i >= 0; --i) { 5487 for (int i = startIndex; i >= 0; --i) {
5556 if (m_boundVertexArrayObject->getVertexAttribState(i).enabled) { 5488 if (m_boundVertexArrayObject->getVertexAttribState(i).enabled) {
5557 m_onePlusMaxEnabledAttribIndex = i + 1; 5489 m_onePlusMaxEnabledAttribIndex = i + 1;
5558 return; 5490 return;
5559 } 5491 }
5560 } 5492 }
5561 m_onePlusMaxEnabledAttribIndex = 0; 5493 m_onePlusMaxEnabledAttribIndex = 0;
5562 } 5494 }
5563 5495
5564 void WebGLRenderingContext::findNewMaxNonDefaultTextureUnit() 5496 void WebGLRenderingContextBase::findNewMaxNonDefaultTextureUnit()
5565 { 5497 {
5566 // Trace backwards from the current max to find the new max non-default text ure unit 5498 // Trace backwards from the current max to find the new max non-default text ure unit
5567 int startIndex = m_onePlusMaxNonDefaultTextureUnit - 1; 5499 int startIndex = m_onePlusMaxNonDefaultTextureUnit - 1;
5568 for (int i = startIndex; i >= 0; --i) { 5500 for (int i = startIndex; i >= 0; --i) {
5569 if (m_textureUnits[i].m_texture2DBinding 5501 if (m_textureUnits[i].m_texture2DBinding
5570 || m_textureUnits[i].m_textureCubeMapBinding) { 5502 || m_textureUnits[i].m_textureCubeMapBinding) {
5571 m_onePlusMaxNonDefaultTextureUnit = i + 1; 5503 m_onePlusMaxNonDefaultTextureUnit = i + 1;
5572 return; 5504 return;
5573 } 5505 }
5574 } 5506 }
5575 m_onePlusMaxNonDefaultTextureUnit = 0; 5507 m_onePlusMaxNonDefaultTextureUnit = 0;
5576 } 5508 }
5577 5509
5578 } // namespace WebCore 5510 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698