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