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

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

Issue 223223003: Re-land "WebGL: Transfer ownership of WebGraphicsContext3D to DrawingBuffer" (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2009 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 119
120 size_t WebGLRenderingContextBase::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 WebGLRenderingContextBase* 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 WebGLRenderingContextBase* context = activeContexts()[ii]; 128 WebGLRenderingContextBase* context = activeContexts()[ii];
129 if (context->webGraphicsContext3D() && candidate->webGraphicsContext3D() && context->webGraphicsContext3D()->lastFlushID() < candidate->webGraphicsConte xt3D()->lastFlushID()) { 129 if (context->webContext() && candidate->webContext() && context->webCont ext()->lastFlushID() < candidate->webContext()->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 WebGLRenderingContextBase::oldestContextSize() 138 IntSize WebGLRenderingContextBase::oldestContextSize()
139 { 139 {
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 InspectorInstrumentation::didFireWebGLErrorOrWarning(m_context->canvas() , message); 492 InspectorInstrumentation::didFireWebGLErrorOrWarning(m_context->canvas() , message);
493 } 493 }
494 virtual ~WebGLRenderingContextErrorMessageCallback() { } 494 virtual ~WebGLRenderingContextErrorMessageCallback() { }
495 private: 495 private:
496 WebGLRenderingContextBase* m_context; 496 WebGLRenderingContextBase* m_context;
497 }; 497 };
498 498
499 WebGLRenderingContextBase::WebGLRenderingContextBase(HTMLCanvasElement* passedCa nvas, PassOwnPtr<blink::WebGraphicsContext3D> context, WebGLContextAttributes* r equestedAttributes) 499 WebGLRenderingContextBase::WebGLRenderingContextBase(HTMLCanvasElement* passedCa nvas, PassOwnPtr<blink::WebGraphicsContext3D> context, WebGLContextAttributes* r equestedAttributes)
500 : CanvasRenderingContext(passedCanvas) 500 : CanvasRenderingContext(passedCanvas)
501 , ActiveDOMObject(&passedCanvas->document()) 501 , ActiveDOMObject(&passedCanvas->document())
502 , m_context(context)
503 , m_drawingBuffer(nullptr) 502 , m_drawingBuffer(nullptr)
504 , m_dispatchContextLostEventTimer(this, &WebGLRenderingContextBase::dispatch ContextLostEvent) 503 , m_dispatchContextLostEventTimer(this, &WebGLRenderingContextBase::dispatch ContextLostEvent)
505 , m_restoreAllowed(false) 504 , m_restoreAllowed(false)
506 , m_restoreTimer(this, &WebGLRenderingContextBase::maybeRestoreContext) 505 , m_restoreTimer(this, &WebGLRenderingContextBase::maybeRestoreContext)
507 , m_generatedImageCache(4) 506 , m_generatedImageCache(4)
508 , m_contextLost(false) 507 , m_contextLost(false)
509 , m_contextLostMode(SyntheticLostContext) 508 , m_contextLostMode(SyntheticLostContext)
510 , m_requestedAttributes(requestedAttributes->clone()) 509 , m_requestedAttributes(requestedAttributes->clone())
511 , m_synthesizedErrorsToConsole(true) 510 , m_synthesizedErrorsToConsole(true)
512 , m_numGLErrorsToConsoleAllowed(maxGLErrorsAllowedToConsole) 511 , m_numGLErrorsToConsoleAllowed(maxGLErrorsAllowedToConsole)
513 , m_multisamplingAllowed(false) 512 , m_multisamplingAllowed(false)
514 , m_multisamplingObserverRegistered(false) 513 , m_multisamplingObserverRegistered(false)
515 , m_onePlusMaxEnabledAttribIndex(0) 514 , m_onePlusMaxEnabledAttribIndex(0)
516 , m_onePlusMaxNonDefaultTextureUnit(0) 515 , m_onePlusMaxNonDefaultTextureUnit(0)
517 { 516 {
518 ASSERT(m_context); 517 ASSERT(context);
519 518
520 m_contextGroup = WebGLContextGroup::create(); 519 m_contextGroup = WebGLContextGroup::create();
521 m_contextGroup->addContext(this); 520 m_contextGroup->addContext(this);
522 521
523 m_maxViewportDims[0] = m_maxViewportDims[1] = 0; 522 m_maxViewportDims[0] = m_maxViewportDims[1] = 0;
524 m_context->getIntegerv(GL_MAX_VIEWPORT_DIMS, m_maxViewportDims); 523 context->getIntegerv(GL_MAX_VIEWPORT_DIMS, m_maxViewportDims);
525 524
526 RefPtr<WebGLRenderingContextEvictionManager> contextEvictionManager = adoptR ef(new WebGLRenderingContextEvictionManager()); 525 RefPtr<WebGLRenderingContextEvictionManager> contextEvictionManager = adoptR ef(new WebGLRenderingContextEvictionManager());
527 526
528 // Create the DrawingBuffer and initialize the platform layer. 527 // Create the DrawingBuffer and initialize the platform layer.
529 DrawingBuffer::PreserveDrawingBuffer preserve = requestedAttributes->preserv eDrawingBuffer() ? DrawingBuffer::Preserve : DrawingBuffer::Discard; 528 DrawingBuffer::PreserveDrawingBuffer preserve = requestedAttributes->preserv eDrawingBuffer() ? DrawingBuffer::Preserve : DrawingBuffer::Discard;
530 m_drawingBuffer = DrawingBuffer::create(m_context.get(), clampedCanvasSize() , preserve, contextEvictionManager.release()); 529 m_drawingBuffer = DrawingBuffer::create(context, clampedCanvasSize(), preser ve, contextEvictionManager.release());
530 if (!m_drawingBuffer)
531 return;
531 532
532 if (!m_drawingBuffer->isZeroSized()) { 533 m_drawingBuffer->bind();
533 m_drawingBuffer->bind(); 534 setupFlags();
534 setupFlags(); 535 initializeNewContext();
535 initializeNewContext();
536 }
537 } 536 }
538 537
539 void WebGLRenderingContextBase::initializeNewContext() 538 void WebGLRenderingContextBase::initializeNewContext()
540 { 539 {
541 ASSERT(!isContextLost()); 540 ASSERT(!isContextLost());
542 m_needsUpdate = true; 541 m_needsUpdate = true;
543 m_markedCanvasDirty = false; 542 m_markedCanvasDirty = false;
544 m_activeTextureUnit = 0; 543 m_activeTextureUnit = 0;
545 m_packAlignment = 4; 544 m_packAlignment = 4;
546 m_unpackAlignment = 4; 545 m_unpackAlignment = 4;
(...skipping 15 matching lines...) Expand all
562 m_layerCleared = false; 561 m_layerCleared = false;
563 m_numGLErrorsToConsoleAllowed = maxGLErrorsAllowedToConsole; 562 m_numGLErrorsToConsoleAllowed = maxGLErrorsAllowedToConsole;
564 563
565 m_clearColor[0] = m_clearColor[1] = m_clearColor[2] = m_clearColor[3] = 0; 564 m_clearColor[0] = m_clearColor[1] = m_clearColor[2] = m_clearColor[3] = 0;
566 m_scissorEnabled = false; 565 m_scissorEnabled = false;
567 m_clearDepth = 1; 566 m_clearDepth = 1;
568 m_clearStencil = 0; 567 m_clearStencil = 0;
569 m_colorMask[0] = m_colorMask[1] = m_colorMask[2] = m_colorMask[3] = true; 568 m_colorMask[0] = m_colorMask[1] = m_colorMask[2] = m_colorMask[3] = true;
570 569
571 GLint numCombinedTextureImageUnits = 0; 570 GLint numCombinedTextureImageUnits = 0;
572 m_context->getIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &numCombinedText ureImageUnits); 571 webContext()->getIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &numCombinedT extureImageUnits);
573 m_textureUnits.clear(); 572 m_textureUnits.clear();
574 m_textureUnits.resize(numCombinedTextureImageUnits); 573 m_textureUnits.resize(numCombinedTextureImageUnits);
575 574
576 GLint numVertexAttribs = 0; 575 GLint numVertexAttribs = 0;
577 m_context->getIntegerv(GL_MAX_VERTEX_ATTRIBS, &numVertexAttribs); 576 webContext()->getIntegerv(GL_MAX_VERTEX_ATTRIBS, &numVertexAttribs);
578 m_maxVertexAttribs = numVertexAttribs; 577 m_maxVertexAttribs = numVertexAttribs;
579 578
580 m_maxTextureSize = 0; 579 m_maxTextureSize = 0;
581 m_context->getIntegerv(GL_MAX_TEXTURE_SIZE, &m_maxTextureSize); 580 webContext()->getIntegerv(GL_MAX_TEXTURE_SIZE, &m_maxTextureSize);
582 m_maxTextureLevel = WebGLTexture::computeLevelCount(m_maxTextureSize, m_maxT extureSize); 581 m_maxTextureLevel = WebGLTexture::computeLevelCount(m_maxTextureSize, m_maxT extureSize);
583 m_maxCubeMapTextureSize = 0; 582 m_maxCubeMapTextureSize = 0;
584 m_context->getIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, &m_maxCubeMapTextureSiz e); 583 webContext()->getIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, &m_maxCubeMapTexture Size);
585 m_maxCubeMapTextureLevel = WebGLTexture::computeLevelCount(m_maxCubeMapTextu reSize, m_maxCubeMapTextureSize); 584 m_maxCubeMapTextureLevel = WebGLTexture::computeLevelCount(m_maxCubeMapTextu reSize, m_maxCubeMapTextureSize);
586 m_maxRenderbufferSize = 0; 585 m_maxRenderbufferSize = 0;
587 m_context->getIntegerv(GL_MAX_RENDERBUFFER_SIZE, &m_maxRenderbufferSize); 586 webContext()->getIntegerv(GL_MAX_RENDERBUFFER_SIZE, &m_maxRenderbufferSize);
588 587
589 // These two values from EXT_draw_buffers are lazily queried. 588 // These two values from EXT_draw_buffers are lazily queried.
590 m_maxDrawBuffers = 0; 589 m_maxDrawBuffers = 0;
591 m_maxColorAttachments = 0; 590 m_maxColorAttachments = 0;
592 591
593 m_backDrawBuffer = GL_BACK; 592 m_backDrawBuffer = GL_BACK;
594 593
595 m_defaultVertexArrayObject = WebGLVertexArrayObjectOES::create(this, WebGLVe rtexArrayObjectOES::VaoTypeDefault); 594 m_defaultVertexArrayObject = WebGLVertexArrayObjectOES::create(this, WebGLVe rtexArrayObjectOES::VaoTypeDefault);
596 addContextObject(m_defaultVertexArrayObject.get()); 595 addContextObject(m_defaultVertexArrayObject.get());
597 m_boundVertexArrayObject = m_defaultVertexArrayObject; 596 m_boundVertexArrayObject = m_defaultVertexArrayObject;
598 597
599 m_vertexAttribValue.resize(m_maxVertexAttribs); 598 m_vertexAttribValue.resize(m_maxVertexAttribs);
600 599
601 createFallbackBlackTextures1x1(); 600 createFallbackBlackTextures1x1();
602 601
603 m_drawingBuffer->reset(clampedCanvasSize()); 602 webContext()->viewport(0, 0, drawingBufferWidth(), drawingBufferHeight());
604 603 webContext()->scissor(0, 0, drawingBufferWidth(), drawingBufferHeight());
605 m_context->viewport(0, 0, drawingBufferWidth(), drawingBufferHeight());
606 m_context->scissor(0, 0, drawingBufferWidth(), drawingBufferHeight());
607 604
608 m_contextLostCallbackAdapter = adoptPtr(new WebGLRenderingContextLostCallbac k(this)); 605 m_contextLostCallbackAdapter = adoptPtr(new WebGLRenderingContextLostCallbac k(this));
609 m_errorMessageCallbackAdapter = adoptPtr(new WebGLRenderingContextErrorMessa geCallback(this)); 606 m_errorMessageCallbackAdapter = adoptPtr(new WebGLRenderingContextErrorMessa geCallback(this));
610 607
611 m_context->setContextLostCallback(m_contextLostCallbackAdapter.get()); 608 webContext()->setContextLostCallback(m_contextLostCallbackAdapter.get());
612 m_context->setErrorMessageCallback(m_errorMessageCallbackAdapter.get()); 609 webContext()->setErrorMessageCallback(m_errorMessageCallbackAdapter.get());
613 610
614 // This ensures that the context has a valid "lastFlushID" and won't be mist akenly identified as the "least recently used" context. 611 // This ensures that the context has a valid "lastFlushID" and won't be mist akenly identified as the "least recently used" context.
615 m_context->flush(); 612 webContext()->flush();
616 613
617 for (int i = 0; i < WebGLExtensionNameCount; ++i) 614 for (int i = 0; i < WebGLExtensionNameCount; ++i)
618 m_extensionEnabled[i] = false; 615 m_extensionEnabled[i] = false;
619 616
620 activateContext(this); 617 activateContext(this);
621 } 618 }
622 619
623 void WebGLRenderingContextBase::setupFlags() 620 void WebGLRenderingContextBase::setupFlags()
624 { 621 {
625 ASSERT(m_context); 622 ASSERT(m_drawingBuffer);
626 if (Page* p = canvas()->document().page()) { 623 if (Page* p = canvas()->document().page()) {
627 m_synthesizedErrorsToConsole = p->settings().webGLErrorsToConsoleEnabled (); 624 m_synthesizedErrorsToConsole = p->settings().webGLErrorsToConsoleEnabled ();
628 625
629 if (!m_multisamplingObserverRegistered && m_requestedAttributes->antiali as()) { 626 if (!m_multisamplingObserverRegistered && m_requestedAttributes->antiali as()) {
630 m_multisamplingAllowed = m_drawingBuffer->multisample(); 627 m_multisamplingAllowed = m_drawingBuffer->multisample();
631 p->addMultisamplingChangedObserver(this); 628 p->addMultisamplingChangedObserver(this);
632 m_multisamplingObserverRegistered = true; 629 m_multisamplingObserverRegistered = true;
633 } 630 }
634 } 631 }
635 632
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 page->removeMultisamplingChangedObserver(this); 703 page->removeMultisamplingChangedObserver(this);
707 } 704 }
708 705
709 willDestroyContext(this); 706 willDestroyContext(this);
710 } 707 }
711 708
712 void WebGLRenderingContextBase::destroyContext() 709 void WebGLRenderingContextBase::destroyContext()
713 { 710 {
714 m_contextLost = true; 711 m_contextLost = true;
715 712
716 // The drawing buffer holds a context reference. It must also be destroyed 713 if (!m_drawingBuffer)
717 // in order for the context to be released. 714 return;
718 m_drawingBuffer->releaseResources();
719 715
720 m_extensionsUtil.clear(); 716 m_extensionsUtil.clear();
721 717
722 if (m_context) { 718 webContext()->setContextLostCallback(0);
723 m_context->setContextLostCallback(0); 719 webContext()->setErrorMessageCallback(0);
724 m_context->setErrorMessageCallback(0); 720
725 m_context.clear(); 721 ASSERT(m_drawingBuffer);
726 } 722 m_drawingBuffer.clear();
727 } 723 }
728 724
729 void WebGLRenderingContextBase::markContextChanged(ContentChangeType changeType) 725 void WebGLRenderingContextBase::markContextChanged(ContentChangeType changeType)
730 { 726 {
731 if (m_framebufferBinding || isContextLost()) 727 if (m_framebufferBinding || isContextLost())
732 return; 728 return;
733 729
734 m_drawingBuffer->markContentsChanged(); 730 m_drawingBuffer->markContentsChanged();
735 731
736 m_layerCleared = false; 732 m_layerCleared = false;
(...skipping 17 matching lines...) Expand all
754 750
755 if (!m_drawingBuffer->layerComposited() || m_layerCleared 751 if (!m_drawingBuffer->layerComposited() || m_layerCleared
756 || m_requestedAttributes->preserveDrawingBuffer() || (mask && m_framebuf ferBinding)) 752 || m_requestedAttributes->preserveDrawingBuffer() || (mask && m_framebuf ferBinding))
757 return false; 753 return false;
758 754
759 RefPtr<WebGLContextAttributes> contextAttributes = getContextAttributes(); 755 RefPtr<WebGLContextAttributes> contextAttributes = getContextAttributes();
760 756
761 // Determine if it's possible to combine the clear the user asked for and th is clear. 757 // Determine if it's possible to combine the clear the user asked for and th is clear.
762 bool combinedClear = mask && !m_scissorEnabled; 758 bool combinedClear = mask && !m_scissorEnabled;
763 759
764 m_context->disable(GL_SCISSOR_TEST); 760 webContext()->disable(GL_SCISSOR_TEST);
765 if (combinedClear && (mask & GL_COLOR_BUFFER_BIT)) 761 if (combinedClear && (mask & GL_COLOR_BUFFER_BIT)) {
766 m_context->clearColor(m_colorMask[0] ? m_clearColor[0] : 0, 762 webContext()->clearColor(m_colorMask[0] ? m_clearColor[0] : 0,
767 m_colorMask[1] ? m_clearColor[1] : 0, 763 m_colorMask[1] ? m_clearColor[1] : 0,
768 m_colorMask[2] ? m_clearColor[2] : 0, 764 m_colorMask[2] ? m_clearColor[2] : 0,
769 m_colorMask[3] ? m_clearColor[3] : 0); 765 m_colorMask[3] ? m_clearColor[3] : 0);
770 else 766 } else {
771 m_context->clearColor(0, 0, 0, 0); 767 webContext()->clearColor(0, 0, 0, 0);
772 m_context->colorMask(true, true, true, true); 768 }
769 webContext()->colorMask(true, true, true, true);
773 GLbitfield clearMask = GL_COLOR_BUFFER_BIT; 770 GLbitfield clearMask = GL_COLOR_BUFFER_BIT;
774 if (contextAttributes->depth()) { 771 if (contextAttributes->depth()) {
775 if (!combinedClear || !m_depthMask || !(mask & GL_DEPTH_BUFFER_BIT)) 772 if (!combinedClear || !m_depthMask || !(mask & GL_DEPTH_BUFFER_BIT))
776 m_context->clearDepth(1.0f); 773 webContext()->clearDepth(1.0f);
777 clearMask |= GL_DEPTH_BUFFER_BIT; 774 clearMask |= GL_DEPTH_BUFFER_BIT;
778 m_context->depthMask(true); 775 webContext()->depthMask(true);
779 } 776 }
780 if (contextAttributes->stencil()) { 777 if (contextAttributes->stencil()) {
781 if (combinedClear && (mask & GL_STENCIL_BUFFER_BIT)) 778 if (combinedClear && (mask & GL_STENCIL_BUFFER_BIT))
782 m_context->clearStencil(m_clearStencil & m_stencilMask); 779 webContext()->clearStencil(m_clearStencil & m_stencilMask);
783 else 780 else
784 m_context->clearStencil(0); 781 webContext()->clearStencil(0);
785 clearMask |= GL_STENCIL_BUFFER_BIT; 782 clearMask |= GL_STENCIL_BUFFER_BIT;
786 m_context->stencilMaskSeparate(GL_FRONT, 0xFFFFFFFF); 783 webContext()->stencilMaskSeparate(GL_FRONT, 0xFFFFFFFF);
787 } 784 }
788 785
789 m_drawingBuffer->clearFramebuffers(clearMask); 786 m_drawingBuffer->clearFramebuffers(clearMask);
790 787
791 restoreStateAfterClear(); 788 restoreStateAfterClear();
792 if (m_framebufferBinding) 789 if (m_framebufferBinding)
793 m_context->bindFramebuffer(GL_FRAMEBUFFER, objectOrZero(m_framebufferBin ding.get())); 790 webContext()->bindFramebuffer(GL_FRAMEBUFFER, objectOrZero(m_framebuffer Binding.get()));
794 m_layerCleared = true; 791 m_layerCleared = true;
795 792
796 return combinedClear; 793 return combinedClear;
797 } 794 }
798 795
799 void WebGLRenderingContextBase::restoreStateAfterClear() 796 void WebGLRenderingContextBase::restoreStateAfterClear()
800 { 797 {
801 if (isContextLost()) 798 if (isContextLost())
802 return; 799 return;
803 800
804 // Restore the state that the context set. 801 // Restore the state that the context set.
805 if (m_scissorEnabled) 802 if (m_scissorEnabled)
806 m_context->enable(GL_SCISSOR_TEST); 803 webContext()->enable(GL_SCISSOR_TEST);
807 m_context->clearColor(m_clearColor[0], m_clearColor[1], 804 webContext()->clearColor(m_clearColor[0], m_clearColor[1],
808 m_clearColor[2], m_clearColor[3]); 805 m_clearColor[2], m_clearColor[3]);
809 m_context->colorMask(m_colorMask[0], m_colorMask[1], 806 webContext()->colorMask(m_colorMask[0], m_colorMask[1],
810 m_colorMask[2], m_colorMask[3]); 807 m_colorMask[2], m_colorMask[3]);
811 m_context->clearDepth(m_clearDepth); 808 webContext()->clearDepth(m_clearDepth);
812 m_context->clearStencil(m_clearStencil); 809 webContext()->clearStencil(m_clearStencil);
813 m_context->stencilMaskSeparate(GL_FRONT, m_stencilMask); 810 webContext()->stencilMaskSeparate(GL_FRONT, m_stencilMask);
814 m_context->depthMask(m_depthMask); 811 webContext()->depthMask(m_depthMask);
815 } 812 }
816 813
817 void WebGLRenderingContextBase::markLayerComposited() 814 void WebGLRenderingContextBase::markLayerComposited()
818 { 815 {
819 if (!isContextLost()) 816 if (!isContextLost())
820 m_drawingBuffer->markLayerComposited(); 817 m_drawingBuffer->markLayerComposited();
821 } 818 }
822 819
823 void WebGLRenderingContextBase::paintRenderingResultsToCanvas() 820 void WebGLRenderingContextBase::paintRenderingResultsToCanvas()
824 { 821 {
(...skipping 24 matching lines...) Expand all
849 ScopedTexture2DRestorer restorer(this); 846 ScopedTexture2DRestorer restorer(this);
850 847
851 m_drawingBuffer->commit(); 848 m_drawingBuffer->commit();
852 if (!(canvas()->buffer())->copyRenderingResultsFromDrawingBuffer(m_drawingBu ffer.get())) { 849 if (!(canvas()->buffer())->copyRenderingResultsFromDrawingBuffer(m_drawingBu ffer.get())) {
853 canvas()->ensureUnacceleratedImageBuffer(); 850 canvas()->ensureUnacceleratedImageBuffer();
854 if (canvas()->hasImageBuffer()) 851 if (canvas()->hasImageBuffer())
855 m_drawingBuffer->paintRenderingResultsToCanvas(canvas()->buffer()); 852 m_drawingBuffer->paintRenderingResultsToCanvas(canvas()->buffer());
856 } 853 }
857 854
858 if (m_framebufferBinding) 855 if (m_framebufferBinding)
859 m_context->bindFramebuffer(GL_FRAMEBUFFER, objectOrZero(m_framebufferBin ding.get())); 856 webContext()->bindFramebuffer(GL_FRAMEBUFFER, objectOrZero(m_framebuffer Binding.get()));
860 else 857 else
861 m_drawingBuffer->bind(); 858 m_drawingBuffer->bind();
862 } 859 }
863 860
864 PassRefPtrWillBeRawPtr<ImageData> WebGLRenderingContextBase::paintRenderingResul tsToImageData() 861 PassRefPtrWillBeRawPtr<ImageData> WebGLRenderingContextBase::paintRenderingResul tsToImageData()
865 { 862 {
866 if (isContextLost()) 863 if (isContextLost())
867 return nullptr; 864 return nullptr;
868 865
869 clearIfComposited(); 866 clearIfComposited();
870 m_drawingBuffer->commit(); 867 m_drawingBuffer->commit();
871 int width, height; 868 int width, height;
872 RefPtr<Uint8ClampedArray> imageDataPixels = m_drawingBuffer->paintRenderingR esultsToImageData(width, height); 869 RefPtr<Uint8ClampedArray> imageDataPixels = m_drawingBuffer->paintRenderingR esultsToImageData(width, height);
873 if (!imageDataPixels) 870 if (!imageDataPixels)
874 return nullptr; 871 return nullptr;
875 872
876 if (m_framebufferBinding) 873 if (m_framebufferBinding)
877 m_context->bindFramebuffer(GL_FRAMEBUFFER, objectOrZero(m_framebufferBin ding.get())); 874 webContext()->bindFramebuffer(GL_FRAMEBUFFER, objectOrZero(m_framebuffer Binding.get()));
878 else 875 else
879 m_drawingBuffer->bind(); 876 m_drawingBuffer->bind();
880 877
881 return ImageData::create(IntSize(width, height), imageDataPixels); 878 return ImageData::create(IntSize(width, height), imageDataPixels);
882 } 879 }
883 880
884 void WebGLRenderingContextBase::reshape(int width, int height) 881 void WebGLRenderingContextBase::reshape(int width, int height)
885 { 882 {
886 if (isContextLost()) 883 if (isContextLost())
887 return; 884 return;
(...skipping 14 matching lines...) Expand all
902 if (renderBox && renderBox->hasAcceleratedCompositing()) 899 if (renderBox && renderBox->hasAcceleratedCompositing())
903 renderBox->contentChanged(CanvasChanged); 900 renderBox->contentChanged(CanvasChanged);
904 m_needsUpdate = false; 901 m_needsUpdate = false;
905 } 902 }
906 903
907 // We don't have to mark the canvas as dirty, since the newly created image buffer will also start off 904 // We don't have to mark the canvas as dirty, since the newly created image buffer will also start off
908 // clear (and this matches what reshape will do). 905 // clear (and this matches what reshape will do).
909 m_drawingBuffer->reset(IntSize(width, height)); 906 m_drawingBuffer->reset(IntSize(width, height));
910 restoreStateAfterClear(); 907 restoreStateAfterClear();
911 908
912 m_context->bindTexture(GL_TEXTURE_2D, objectOrZero(m_textureUnits[m_activeTe xtureUnit].m_texture2DBinding.get())); 909 webContext()->bindTexture(GL_TEXTURE_2D, objectOrZero(m_textureUnits[m_activ eTextureUnit].m_texture2DBinding.get()));
913 m_context->bindRenderbuffer(GL_RENDERBUFFER, objectOrZero(m_renderbufferBind ing.get())); 910 webContext()->bindRenderbuffer(GL_RENDERBUFFER, objectOrZero(m_renderbufferB inding.get()));
914 if (m_framebufferBinding) 911 if (m_framebufferBinding)
915 m_context->bindFramebuffer(GL_FRAMEBUFFER, objectOrZero(m_framebufferBin ding.get())); 912 webContext()->bindFramebuffer(GL_FRAMEBUFFER, objectOrZero(m_framebuffer Binding.get()));
916 } 913 }
917 914
918 int WebGLRenderingContextBase::drawingBufferWidth() const 915 int WebGLRenderingContextBase::drawingBufferWidth() const
919 { 916 {
920 return m_drawingBuffer->size().width(); 917 return isContextLost() ? 0 : m_drawingBuffer->size().width();
921 } 918 }
922 919
923 int WebGLRenderingContextBase::drawingBufferHeight() const 920 int WebGLRenderingContextBase::drawingBufferHeight() const
924 { 921 {
925 return m_drawingBuffer->size().height(); 922 return isContextLost() ? 0 : m_drawingBuffer->size().height();
926 } 923 }
927 924
928 unsigned WebGLRenderingContextBase::sizeInBytes(GLenum type) 925 unsigned WebGLRenderingContextBase::sizeInBytes(GLenum type)
929 { 926 {
930 switch (type) { 927 switch (type) {
931 case GL_BYTE: 928 case GL_BYTE:
932 return sizeof(GLbyte); 929 return sizeof(GLbyte);
933 case GL_UNSIGNED_BYTE: 930 case GL_UNSIGNED_BYTE:
934 return sizeof(GLubyte); 931 return sizeof(GLubyte);
935 case GL_SHORT: 932 case GL_SHORT:
(...skipping 13 matching lines...) Expand all
949 946
950 void WebGLRenderingContextBase::activeTexture(GLenum texture) 947 void WebGLRenderingContextBase::activeTexture(GLenum texture)
951 { 948 {
952 if (isContextLost()) 949 if (isContextLost())
953 return; 950 return;
954 if (texture - GL_TEXTURE0 >= m_textureUnits.size()) { 951 if (texture - GL_TEXTURE0 >= m_textureUnits.size()) {
955 synthesizeGLError(GL_INVALID_ENUM, "activeTexture", "texture unit out of range"); 952 synthesizeGLError(GL_INVALID_ENUM, "activeTexture", "texture unit out of range");
956 return; 953 return;
957 } 954 }
958 m_activeTextureUnit = texture - GL_TEXTURE0; 955 m_activeTextureUnit = texture - GL_TEXTURE0;
959 m_context->activeTexture(texture); 956 webContext()->activeTexture(texture);
960 957
961 m_drawingBuffer->setActiveTextureUnit(texture); 958 m_drawingBuffer->setActiveTextureUnit(texture);
962 959
963 } 960 }
964 961
965 void WebGLRenderingContextBase::attachShader(WebGLProgram* program, WebGLShader* shader) 962 void WebGLRenderingContextBase::attachShader(WebGLProgram* program, WebGLShader* shader)
966 { 963 {
967 if (isContextLost() || !validateWebGLObject("attachShader", program) || !val idateWebGLObject("attachShader", shader)) 964 if (isContextLost() || !validateWebGLObject("attachShader", program) || !val idateWebGLObject("attachShader", shader))
968 return; 965 return;
969 if (!program->attachShader(shader)) { 966 if (!program->attachShader(shader)) {
970 synthesizeGLError(GL_INVALID_OPERATION, "attachShader", "shader attachme nt already has shader"); 967 synthesizeGLError(GL_INVALID_OPERATION, "attachShader", "shader attachme nt already has shader");
971 return; 968 return;
972 } 969 }
973 m_context->attachShader(objectOrZero(program), objectOrZero(shader)); 970 webContext()->attachShader(objectOrZero(program), objectOrZero(shader));
974 shader->onAttached(); 971 shader->onAttached();
975 } 972 }
976 973
977 void WebGLRenderingContextBase::bindAttribLocation(WebGLProgram* program, GLuint index, const String& name) 974 void WebGLRenderingContextBase::bindAttribLocation(WebGLProgram* program, GLuint index, const String& name)
978 { 975 {
979 if (isContextLost() || !validateWebGLObject("bindAttribLocation", program)) 976 if (isContextLost() || !validateWebGLObject("bindAttribLocation", program))
980 return; 977 return;
981 if (!validateLocationLength("bindAttribLocation", name)) 978 if (!validateLocationLength("bindAttribLocation", name))
982 return; 979 return;
983 if (!validateString("bindAttribLocation", name)) 980 if (!validateString("bindAttribLocation", name))
984 return; 981 return;
985 if (isPrefixReserved(name)) { 982 if (isPrefixReserved(name)) {
986 synthesizeGLError(GL_INVALID_OPERATION, "bindAttribLocation", "reserved prefix"); 983 synthesizeGLError(GL_INVALID_OPERATION, "bindAttribLocation", "reserved prefix");
987 return; 984 return;
988 } 985 }
989 if (index >= m_maxVertexAttribs) { 986 if (index >= m_maxVertexAttribs) {
990 synthesizeGLError(GL_INVALID_VALUE, "bindAttribLocation", "index out of range"); 987 synthesizeGLError(GL_INVALID_VALUE, "bindAttribLocation", "index out of range");
991 return; 988 return;
992 } 989 }
993 m_context->bindAttribLocation(objectOrZero(program), index, name.utf8().data ()); 990 webContext()->bindAttribLocation(objectOrZero(program), index, name.utf8().d ata());
994 } 991 }
995 992
996 bool WebGLRenderingContextBase::checkObjectToBeBound(const char* functionName, W ebGLObject* object, bool& deleted) 993 bool WebGLRenderingContextBase::checkObjectToBeBound(const char* functionName, W ebGLObject* object, bool& deleted)
997 { 994 {
998 deleted = false; 995 deleted = false;
999 if (isContextLost()) 996 if (isContextLost())
1000 return false; 997 return false;
1001 if (object) { 998 if (object) {
1002 if (!object->validate(contextGroup(), this)) { 999 if (!object->validate(contextGroup(), this)) {
1003 synthesizeGLError(GL_INVALID_OPERATION, functionName, "object not fr om this context"); 1000 synthesizeGLError(GL_INVALID_OPERATION, functionName, "object not fr om this context");
(...skipping 17 matching lines...) Expand all
1021 } 1018 }
1022 if (target == GL_ARRAY_BUFFER) 1019 if (target == GL_ARRAY_BUFFER)
1023 m_boundArrayBuffer = buffer; 1020 m_boundArrayBuffer = buffer;
1024 else if (target == GL_ELEMENT_ARRAY_BUFFER) 1021 else if (target == GL_ELEMENT_ARRAY_BUFFER)
1025 m_boundVertexArrayObject->setElementArrayBuffer(buffer); 1022 m_boundVertexArrayObject->setElementArrayBuffer(buffer);
1026 else { 1023 else {
1027 synthesizeGLError(GL_INVALID_ENUM, "bindBuffer", "invalid target"); 1024 synthesizeGLError(GL_INVALID_ENUM, "bindBuffer", "invalid target");
1028 return; 1025 return;
1029 } 1026 }
1030 1027
1031 m_context->bindBuffer(target, objectOrZero(buffer)); 1028 webContext()->bindBuffer(target, objectOrZero(buffer));
1032 if (buffer) 1029 if (buffer)
1033 buffer->setTarget(target); 1030 buffer->setTarget(target);
1034 } 1031 }
1035 1032
1036 void WebGLRenderingContextBase::bindFramebuffer(GLenum target, WebGLFramebuffer* buffer) 1033 void WebGLRenderingContextBase::bindFramebuffer(GLenum target, WebGLFramebuffer* buffer)
1037 { 1034 {
1038 bool deleted; 1035 bool deleted;
1039 if (!checkObjectToBeBound("bindFramebuffer", buffer, deleted)) 1036 if (!checkObjectToBeBound("bindFramebuffer", buffer, deleted))
1040 return; 1037 return;
1041 if (deleted) 1038 if (deleted)
1042 buffer = 0; 1039 buffer = 0;
1043 if (target != GL_FRAMEBUFFER) { 1040 if (target != GL_FRAMEBUFFER) {
1044 synthesizeGLError(GL_INVALID_ENUM, "bindFramebuffer", "invalid target"); 1041 synthesizeGLError(GL_INVALID_ENUM, "bindFramebuffer", "invalid target");
1045 return; 1042 return;
1046 } 1043 }
1047 m_framebufferBinding = buffer; 1044 m_framebufferBinding = buffer;
1048 m_drawingBuffer->setFramebufferBinding(objectOrZero(m_framebufferBinding.get ())); 1045 m_drawingBuffer->setFramebufferBinding(objectOrZero(m_framebufferBinding.get ()));
1049 if (!m_framebufferBinding) { 1046 if (!m_framebufferBinding) {
1050 // Instead of binding fb 0, bind the drawing buffer. 1047 // Instead of binding fb 0, bind the drawing buffer.
1051 m_drawingBuffer->bind(); 1048 m_drawingBuffer->bind();
1052 } else 1049 } else {
1053 m_context->bindFramebuffer(target, objectOrZero(buffer)); 1050 webContext()->bindFramebuffer(target, objectOrZero(buffer));
1051 }
1054 if (buffer) 1052 if (buffer)
1055 buffer->setHasEverBeenBound(); 1053 buffer->setHasEverBeenBound();
1056 applyStencilTest(); 1054 applyStencilTest();
1057 } 1055 }
1058 1056
1059 void WebGLRenderingContextBase::bindRenderbuffer(GLenum target, WebGLRenderbuffe r* renderBuffer) 1057 void WebGLRenderingContextBase::bindRenderbuffer(GLenum target, WebGLRenderbuffe r* renderBuffer)
1060 { 1058 {
1061 bool deleted; 1059 bool deleted;
1062 if (!checkObjectToBeBound("bindRenderbuffer", renderBuffer, deleted)) 1060 if (!checkObjectToBeBound("bindRenderbuffer", renderBuffer, deleted))
1063 return; 1061 return;
1064 if (deleted) 1062 if (deleted)
1065 renderBuffer = 0; 1063 renderBuffer = 0;
1066 if (target != GL_RENDERBUFFER) { 1064 if (target != GL_RENDERBUFFER) {
1067 synthesizeGLError(GL_INVALID_ENUM, "bindRenderbuffer", "invalid target") ; 1065 synthesizeGLError(GL_INVALID_ENUM, "bindRenderbuffer", "invalid target") ;
1068 return; 1066 return;
1069 } 1067 }
1070 m_renderbufferBinding = renderBuffer; 1068 m_renderbufferBinding = renderBuffer;
1071 m_context->bindRenderbuffer(target, objectOrZero(renderBuffer)); 1069 webContext()->bindRenderbuffer(target, objectOrZero(renderBuffer));
1072 if (renderBuffer) 1070 if (renderBuffer)
1073 renderBuffer->setHasEverBeenBound(); 1071 renderBuffer->setHasEverBeenBound();
1074 } 1072 }
1075 1073
1076 void WebGLRenderingContextBase::bindTexture(GLenum target, WebGLTexture* texture ) 1074 void WebGLRenderingContextBase::bindTexture(GLenum target, WebGLTexture* texture )
1077 { 1075 {
1078 bool deleted; 1076 bool deleted;
1079 if (!checkObjectToBeBound("bindTexture", texture, deleted)) 1077 if (!checkObjectToBeBound("bindTexture", texture, deleted))
1080 return; 1078 return;
1081 if (deleted) 1079 if (deleted)
(...skipping 11 matching lines...) Expand all
1093 m_drawingBuffer->setTexture2DBinding(objectOrZero(texture)); 1091 m_drawingBuffer->setTexture2DBinding(objectOrZero(texture));
1094 1092
1095 } else if (target == GL_TEXTURE_CUBE_MAP) { 1093 } else if (target == GL_TEXTURE_CUBE_MAP) {
1096 m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding = texture; 1094 m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding = texture;
1097 maxLevel = m_maxCubeMapTextureLevel; 1095 maxLevel = m_maxCubeMapTextureLevel;
1098 } else { 1096 } else {
1099 synthesizeGLError(GL_INVALID_ENUM, "bindTexture", "invalid target"); 1097 synthesizeGLError(GL_INVALID_ENUM, "bindTexture", "invalid target");
1100 return; 1098 return;
1101 } 1099 }
1102 1100
1103 m_context->bindTexture(target, objectOrZero(texture)); 1101 webContext()->bindTexture(target, objectOrZero(texture));
1104 if (texture) { 1102 if (texture) {
1105 texture->setTarget(target, maxLevel); 1103 texture->setTarget(target, maxLevel);
1106 m_onePlusMaxNonDefaultTextureUnit = max(m_activeTextureUnit + 1, m_onePl usMaxNonDefaultTextureUnit); 1104 m_onePlusMaxNonDefaultTextureUnit = max(m_activeTextureUnit + 1, m_onePl usMaxNonDefaultTextureUnit);
1107 } else { 1105 } else {
1108 // If the disabled index is the current maximum, trace backwards to find the new max enabled texture index 1106 // If the disabled index is the current maximum, trace backwards to find the new max enabled texture index
1109 if (m_onePlusMaxNonDefaultTextureUnit == m_activeTextureUnit + 1) { 1107 if (m_onePlusMaxNonDefaultTextureUnit == m_activeTextureUnit + 1) {
1110 findNewMaxNonDefaultTextureUnit(); 1108 findNewMaxNonDefaultTextureUnit();
1111 } 1109 }
1112 } 1110 }
1113 1111
1114 // Note: previously we used to automatically set the TEXTURE_WRAP_R 1112 // Note: previously we used to automatically set the TEXTURE_WRAP_R
1115 // repeat mode to CLAMP_TO_EDGE for cube map textures, because OpenGL 1113 // repeat mode to CLAMP_TO_EDGE for cube map textures, because OpenGL
1116 // ES 2.0 doesn't expose this flag (a bug in the specification) and 1114 // ES 2.0 doesn't expose this flag (a bug in the specification) and
1117 // otherwise the application has no control over the seams in this 1115 // otherwise the application has no control over the seams in this
1118 // dimension. However, it appears that supporting this properly on all 1116 // dimension. However, it appears that supporting this properly on all
1119 // platforms is fairly involved (will require a HashMap from texture ID 1117 // platforms is fairly involved (will require a HashMap from texture ID
1120 // in all ports), and we have not had any complaints, so the logic has 1118 // in all ports), and we have not had any complaints, so the logic has
1121 // been removed. 1119 // been removed.
1122 1120
1123 } 1121 }
1124 1122
1125 void WebGLRenderingContextBase::blendColor(GLfloat red, GLfloat green, GLfloat b lue, GLfloat alpha) 1123 void WebGLRenderingContextBase::blendColor(GLfloat red, GLfloat green, GLfloat b lue, GLfloat alpha)
1126 { 1124 {
1127 if (isContextLost()) 1125 if (isContextLost())
1128 return; 1126 return;
1129 m_context->blendColor(red, green, blue, alpha); 1127 webContext()->blendColor(red, green, blue, alpha);
1130 } 1128 }
1131 1129
1132 void WebGLRenderingContextBase::blendEquation(GLenum mode) 1130 void WebGLRenderingContextBase::blendEquation(GLenum mode)
1133 { 1131 {
1134 if (isContextLost() || !validateBlendEquation("blendEquation", mode)) 1132 if (isContextLost() || !validateBlendEquation("blendEquation", mode))
1135 return; 1133 return;
1136 m_context->blendEquation(mode); 1134 webContext()->blendEquation(mode);
1137 } 1135 }
1138 1136
1139 void WebGLRenderingContextBase::blendEquationSeparate(GLenum modeRGB, GLenum mod eAlpha) 1137 void WebGLRenderingContextBase::blendEquationSeparate(GLenum modeRGB, GLenum mod eAlpha)
1140 { 1138 {
1141 if (isContextLost() || !validateBlendEquation("blendEquationSeparate", modeR GB) || !validateBlendEquation("blendEquationSeparate", modeAlpha)) 1139 if (isContextLost() || !validateBlendEquation("blendEquationSeparate", modeR GB) || !validateBlendEquation("blendEquationSeparate", modeAlpha))
1142 return; 1140 return;
1143 m_context->blendEquationSeparate(modeRGB, modeAlpha); 1141 webContext()->blendEquationSeparate(modeRGB, modeAlpha);
1144 } 1142 }
1145 1143
1146 1144
1147 void WebGLRenderingContextBase::blendFunc(GLenum sfactor, GLenum dfactor) 1145 void WebGLRenderingContextBase::blendFunc(GLenum sfactor, GLenum dfactor)
1148 { 1146 {
1149 if (isContextLost() || !validateBlendFuncFactors("blendFunc", sfactor, dfact or)) 1147 if (isContextLost() || !validateBlendFuncFactors("blendFunc", sfactor, dfact or))
1150 return; 1148 return;
1151 m_context->blendFunc(sfactor, dfactor); 1149 webContext()->blendFunc(sfactor, dfactor);
1152 } 1150 }
1153 1151
1154 void WebGLRenderingContextBase::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha) 1152 void WebGLRenderingContextBase::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
1155 { 1153 {
1156 // Note: Alpha does not have the same restrictions as RGB. 1154 // Note: Alpha does not have the same restrictions as RGB.
1157 if (isContextLost() || !validateBlendFuncFactors("blendFuncSeparate", srcRGB , dstRGB)) 1155 if (isContextLost() || !validateBlendFuncFactors("blendFuncSeparate", srcRGB , dstRGB))
1158 return; 1156 return;
1159 m_context->blendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha); 1157 webContext()->blendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
1160 } 1158 }
1161 1159
1162 void WebGLRenderingContextBase::bufferData(GLenum target, long long size, GLenum usage) 1160 void WebGLRenderingContextBase::bufferData(GLenum target, long long size, GLenum usage)
1163 { 1161 {
1164 if (isContextLost()) 1162 if (isContextLost())
1165 return; 1163 return;
1166 WebGLBuffer* buffer = validateBufferDataParameters("bufferData", target, usa ge); 1164 WebGLBuffer* buffer = validateBufferDataParameters("bufferData", target, usa ge);
1167 if (!buffer) 1165 if (!buffer)
1168 return; 1166 return;
1169 if (size < 0) { 1167 if (size < 0) {
1170 synthesizeGLError(GL_INVALID_VALUE, "bufferData", "size < 0"); 1168 synthesizeGLError(GL_INVALID_VALUE, "bufferData", "size < 0");
1171 return; 1169 return;
1172 } 1170 }
1173 if (!size) { 1171 if (!size) {
1174 synthesizeGLError(GL_INVALID_VALUE, "bufferData", "size == 0"); 1172 synthesizeGLError(GL_INVALID_VALUE, "bufferData", "size == 0");
1175 return; 1173 return;
1176 } 1174 }
1177 1175
1178 m_context->bufferData(target, static_cast<GLsizeiptr>(size), 0, usage); 1176 webContext()->bufferData(target, static_cast<GLsizeiptr>(size), 0, usage);
1179 } 1177 }
1180 1178
1181 void WebGLRenderingContextBase::bufferData(GLenum target, ArrayBuffer* data, GLe num usage) 1179 void WebGLRenderingContextBase::bufferData(GLenum target, ArrayBuffer* data, GLe num usage)
1182 { 1180 {
1183 if (isContextLost()) 1181 if (isContextLost())
1184 return; 1182 return;
1185 WebGLBuffer* buffer = validateBufferDataParameters("bufferData", target, usa ge); 1183 WebGLBuffer* buffer = validateBufferDataParameters("bufferData", target, usa ge);
1186 if (!buffer) 1184 if (!buffer)
1187 return; 1185 return;
1188 if (!data) { 1186 if (!data) {
1189 synthesizeGLError(GL_INVALID_VALUE, "bufferData", "no data"); 1187 synthesizeGLError(GL_INVALID_VALUE, "bufferData", "no data");
1190 return; 1188 return;
1191 } 1189 }
1192 m_context->bufferData(target, data->byteLength(), data->data(), usage); 1190 webContext()->bufferData(target, data->byteLength(), data->data(), usage);
1193 } 1191 }
1194 1192
1195 void WebGLRenderingContextBase::bufferData(GLenum target, ArrayBufferView* data, GLenum usage) 1193 void WebGLRenderingContextBase::bufferData(GLenum target, ArrayBufferView* data, GLenum usage)
1196 { 1194 {
1197 if (isContextLost()) 1195 if (isContextLost())
1198 return; 1196 return;
1199 WebGLBuffer* buffer = validateBufferDataParameters("bufferData", target, usa ge); 1197 WebGLBuffer* buffer = validateBufferDataParameters("bufferData", target, usa ge);
1200 if (!buffer) 1198 if (!buffer)
1201 return; 1199 return;
1202 if (!data) { 1200 if (!data) {
1203 synthesizeGLError(GL_INVALID_VALUE, "bufferData", "no data"); 1201 synthesizeGLError(GL_INVALID_VALUE, "bufferData", "no data");
1204 return; 1202 return;
1205 } 1203 }
1206 1204
1207 m_context->bufferData(target, data->byteLength(), data->baseAddress(), usage ); 1205 webContext()->bufferData(target, data->byteLength(), data->baseAddress(), us age);
1208 } 1206 }
1209 1207
1210 void WebGLRenderingContextBase::bufferSubData(GLenum target, long long offset, A rrayBuffer* data) 1208 void WebGLRenderingContextBase::bufferSubData(GLenum target, long long offset, A rrayBuffer* data)
1211 { 1209 {
1212 if (isContextLost()) 1210 if (isContextLost())
1213 return; 1211 return;
1214 WebGLBuffer* buffer = validateBufferDataParameters("bufferSubData", target, GL_STATIC_DRAW); 1212 WebGLBuffer* buffer = validateBufferDataParameters("bufferSubData", target, GL_STATIC_DRAW);
1215 if (!buffer) 1213 if (!buffer)
1216 return; 1214 return;
1217 if (offset < 0) { 1215 if (offset < 0) {
1218 synthesizeGLError(GL_INVALID_VALUE, "bufferSubData", "offset < 0"); 1216 synthesizeGLError(GL_INVALID_VALUE, "bufferSubData", "offset < 0");
1219 return; 1217 return;
1220 } 1218 }
1221 if (!data) 1219 if (!data)
1222 return; 1220 return;
1223 1221
1224 m_context->bufferSubData(target, static_cast<GLintptr>(offset), data->byteLe ngth(), data->data()); 1222 webContext()->bufferSubData(target, static_cast<GLintptr>(offset), data->byt eLength(), data->data());
1225 } 1223 }
1226 1224
1227 void WebGLRenderingContextBase::bufferSubData(GLenum target, long long offset, A rrayBufferView* data) 1225 void WebGLRenderingContextBase::bufferSubData(GLenum target, long long offset, A rrayBufferView* data)
1228 { 1226 {
1229 if (isContextLost()) 1227 if (isContextLost())
1230 return; 1228 return;
1231 WebGLBuffer* buffer = validateBufferDataParameters("bufferSubData", target, GL_STATIC_DRAW); 1229 WebGLBuffer* buffer = validateBufferDataParameters("bufferSubData", target, GL_STATIC_DRAW);
1232 if (!buffer) 1230 if (!buffer)
1233 return; 1231 return;
1234 if (offset < 0) { 1232 if (offset < 0) {
1235 synthesizeGLError(GL_INVALID_VALUE, "bufferSubData", "offset < 0"); 1233 synthesizeGLError(GL_INVALID_VALUE, "bufferSubData", "offset < 0");
1236 return; 1234 return;
1237 } 1235 }
1238 if (!data) 1236 if (!data)
1239 return; 1237 return;
1240 1238
1241 m_context->bufferSubData(target, static_cast<GLintptr>(offset), data->byteLe ngth(), data->baseAddress()); 1239 webContext()->bufferSubData(target, static_cast<GLintptr>(offset), data->byt eLength(), data->baseAddress());
1242 } 1240 }
1243 1241
1244 GLenum WebGLRenderingContextBase::checkFramebufferStatus(GLenum target) 1242 GLenum WebGLRenderingContextBase::checkFramebufferStatus(GLenum target)
1245 { 1243 {
1246 if (isContextLost()) 1244 if (isContextLost())
1247 return GL_FRAMEBUFFER_UNSUPPORTED; 1245 return GL_FRAMEBUFFER_UNSUPPORTED;
1248 if (target != GL_FRAMEBUFFER) { 1246 if (target != GL_FRAMEBUFFER) {
1249 synthesizeGLError(GL_INVALID_ENUM, "checkFramebufferStatus", "invalid ta rget"); 1247 synthesizeGLError(GL_INVALID_ENUM, "checkFramebufferStatus", "invalid ta rget");
1250 return 0; 1248 return 0;
1251 } 1249 }
1252 if (!m_framebufferBinding || !m_framebufferBinding->object()) 1250 if (!m_framebufferBinding || !m_framebufferBinding->object())
1253 return GL_FRAMEBUFFER_COMPLETE; 1251 return GL_FRAMEBUFFER_COMPLETE;
1254 const char* reason = "framebuffer incomplete"; 1252 const char* reason = "framebuffer incomplete";
1255 GLenum result = m_framebufferBinding->checkStatus(&reason); 1253 GLenum result = m_framebufferBinding->checkStatus(&reason);
1256 if (result != GL_FRAMEBUFFER_COMPLETE) { 1254 if (result != GL_FRAMEBUFFER_COMPLETE) {
1257 emitGLWarning("checkFramebufferStatus", reason); 1255 emitGLWarning("checkFramebufferStatus", reason);
1258 return result; 1256 return result;
1259 } 1257 }
1260 result = m_context->checkFramebufferStatus(target); 1258 result = webContext()->checkFramebufferStatus(target);
1261 return result; 1259 return result;
1262 } 1260 }
1263 1261
1264 void WebGLRenderingContextBase::clear(GLbitfield mask) 1262 void WebGLRenderingContextBase::clear(GLbitfield mask)
1265 { 1263 {
1266 if (isContextLost()) 1264 if (isContextLost())
1267 return; 1265 return;
1268 if (mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_B IT)) { 1266 if (mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_B IT)) {
1269 synthesizeGLError(GL_INVALID_VALUE, "clear", "invalid mask"); 1267 synthesizeGLError(GL_INVALID_VALUE, "clear", "invalid mask");
1270 return; 1268 return;
1271 } 1269 }
1272 const char* reason = "framebuffer incomplete"; 1270 const char* reason = "framebuffer incomplete";
1273 if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context.get(), &reason)) { 1271 if (m_framebufferBinding && !m_framebufferBinding->onAccess(webContext(), &r eason)) {
1274 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "clear", reason); 1272 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "clear", reason);
1275 return; 1273 return;
1276 } 1274 }
1277 if (!clearIfComposited(mask)) 1275 if (!clearIfComposited(mask))
1278 m_context->clear(mask); 1276 webContext()->clear(mask);
1279 markContextChanged(CanvasChanged); 1277 markContextChanged(CanvasChanged);
1280 } 1278 }
1281 1279
1282 void WebGLRenderingContextBase::clearColor(GLfloat r, GLfloat g, GLfloat b, GLfl oat a) 1280 void WebGLRenderingContextBase::clearColor(GLfloat r, GLfloat g, GLfloat b, GLfl oat a)
1283 { 1281 {
1284 if (isContextLost()) 1282 if (isContextLost())
1285 return; 1283 return;
1286 if (std::isnan(r)) 1284 if (std::isnan(r))
1287 r = 0; 1285 r = 0;
1288 if (std::isnan(g)) 1286 if (std::isnan(g))
1289 g = 0; 1287 g = 0;
1290 if (std::isnan(b)) 1288 if (std::isnan(b))
1291 b = 0; 1289 b = 0;
1292 if (std::isnan(a)) 1290 if (std::isnan(a))
1293 a = 1; 1291 a = 1;
1294 m_clearColor[0] = r; 1292 m_clearColor[0] = r;
1295 m_clearColor[1] = g; 1293 m_clearColor[1] = g;
1296 m_clearColor[2] = b; 1294 m_clearColor[2] = b;
1297 m_clearColor[3] = a; 1295 m_clearColor[3] = a;
1298 m_context->clearColor(r, g, b, a); 1296 webContext()->clearColor(r, g, b, a);
1299 } 1297 }
1300 1298
1301 void WebGLRenderingContextBase::clearDepth(GLfloat depth) 1299 void WebGLRenderingContextBase::clearDepth(GLfloat depth)
1302 { 1300 {
1303 if (isContextLost()) 1301 if (isContextLost())
1304 return; 1302 return;
1305 m_clearDepth = depth; 1303 m_clearDepth = depth;
1306 m_context->clearDepth(depth); 1304 webContext()->clearDepth(depth);
1307 } 1305 }
1308 1306
1309 void WebGLRenderingContextBase::clearStencil(GLint s) 1307 void WebGLRenderingContextBase::clearStencil(GLint s)
1310 { 1308 {
1311 if (isContextLost()) 1309 if (isContextLost())
1312 return; 1310 return;
1313 m_clearStencil = s; 1311 m_clearStencil = s;
1314 m_context->clearStencil(s); 1312 webContext()->clearStencil(s);
1315 } 1313 }
1316 1314
1317 void WebGLRenderingContextBase::colorMask(GLboolean red, GLboolean green, GLbool ean blue, GLboolean alpha) 1315 void WebGLRenderingContextBase::colorMask(GLboolean red, GLboolean green, GLbool ean blue, GLboolean alpha)
1318 { 1316 {
1319 if (isContextLost()) 1317 if (isContextLost())
1320 return; 1318 return;
1321 m_colorMask[0] = red; 1319 m_colorMask[0] = red;
1322 m_colorMask[1] = green; 1320 m_colorMask[1] = green;
1323 m_colorMask[2] = blue; 1321 m_colorMask[2] = blue;
1324 m_colorMask[3] = alpha; 1322 m_colorMask[3] = alpha;
1325 m_context->colorMask(red, green, blue, alpha); 1323 webContext()->colorMask(red, green, blue, alpha);
1326 } 1324 }
1327 1325
1328 void WebGLRenderingContextBase::compileShader(WebGLShader* shader) 1326 void WebGLRenderingContextBase::compileShader(WebGLShader* shader)
1329 { 1327 {
1330 if (isContextLost() || !validateWebGLObject("compileShader", shader)) 1328 if (isContextLost() || !validateWebGLObject("compileShader", shader))
1331 return; 1329 return;
1332 m_context->compileShader(objectOrZero(shader)); 1330 webContext()->compileShader(objectOrZero(shader));
1333 } 1331 }
1334 1332
1335 void WebGLRenderingContextBase::compressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, ArrayBuffer View* data) 1333 void WebGLRenderingContextBase::compressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, ArrayBuffer View* data)
1336 { 1334 {
1337 if (isContextLost()) 1335 if (isContextLost())
1338 return; 1336 return;
1339 if (!validateTexFuncLevel("compressedTexImage2D", target, level)) 1337 if (!validateTexFuncLevel("compressedTexImage2D", target, level))
1340 return; 1338 return;
1341 1339
1342 if (!validateCompressedTexFormat(internalformat)) { 1340 if (!validateCompressedTexFormat(internalformat)) {
(...skipping 11 matching lines...) Expand all
1354 1352
1355 WebGLTexture* tex = validateTextureBinding("compressedTexImage2D", target, t rue); 1353 WebGLTexture* tex = validateTextureBinding("compressedTexImage2D", target, t rue);
1356 if (!tex) 1354 if (!tex)
1357 return; 1355 return;
1358 if (!isGLES2NPOTStrict()) { 1356 if (!isGLES2NPOTStrict()) {
1359 if (level && WebGLTexture::isNPOT(width, height)) { 1357 if (level && WebGLTexture::isNPOT(width, height)) {
1360 synthesizeGLError(GL_INVALID_VALUE, "compressedTexImage2D", "level > 0 not power of 2"); 1358 synthesizeGLError(GL_INVALID_VALUE, "compressedTexImage2D", "level > 0 not power of 2");
1361 return; 1359 return;
1362 } 1360 }
1363 } 1361 }
1364 m_context->compressedTexImage2D(target, level, internalformat, width, height , 1362 webContext()->compressedTexImage2D(target, level, internalformat, width, hei ght,
1365 border, data->byteLength(), data-> baseAddress()); 1363 border, data->byteLength(), data->baseAddress());
1366 tex->setLevelInfo(target, level, internalformat, width, height, GL_UNSIGNED_ BYTE); 1364 tex->setLevelInfo(target, level, internalformat, width, height, GL_UNSIGNED_ BYTE);
1367 } 1365 }
1368 1366
1369 void WebGLRenderingContextBase::compressedTexSubImage2D(GLenum target, GLint lev el, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, ArrayBufferView* data) 1367 void WebGLRenderingContextBase::compressedTexSubImage2D(GLenum target, GLint lev el, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, ArrayBufferView* data)
1370 { 1368 {
1371 if (isContextLost()) 1369 if (isContextLost())
1372 return; 1370 return;
1373 if (!validateTexFuncLevel("compressedTexSubImage2D", target, level)) 1371 if (!validateTexFuncLevel("compressedTexSubImage2D", target, level))
1374 return; 1372 return;
1375 if (!validateCompressedTexFormat(format)) { 1373 if (!validateCompressedTexFormat(format)) {
1376 synthesizeGLError(GL_INVALID_ENUM, "compressedTexSubImage2D", "invalid f ormat"); 1374 synthesizeGLError(GL_INVALID_ENUM, "compressedTexSubImage2D", "invalid f ormat");
1377 return; 1375 return;
1378 } 1376 }
1379 if (!validateCompressedTexFuncData("compressedTexSubImage2D", width, height, format, data)) 1377 if (!validateCompressedTexFuncData("compressedTexSubImage2D", width, height, format, data))
1380 return; 1378 return;
1381 1379
1382 WebGLTexture* tex = validateTextureBinding("compressedTexSubImage2D", target , true); 1380 WebGLTexture* tex = validateTextureBinding("compressedTexSubImage2D", target , true);
1383 if (!tex) 1381 if (!tex)
1384 return; 1382 return;
1385 1383
1386 if (format != tex->getInternalFormat(target, level)) { 1384 if (format != tex->getInternalFormat(target, level)) {
1387 synthesizeGLError(GL_INVALID_OPERATION, "compressedTexSubImage2D", "form at does not match texture format"); 1385 synthesizeGLError(GL_INVALID_OPERATION, "compressedTexSubImage2D", "form at does not match texture format");
1388 return; 1386 return;
1389 } 1387 }
1390 1388
1391 if (!validateCompressedTexSubDimensions("compressedTexSubImage2D", target, l evel, xoffset, yoffset, width, height, format, tex)) 1389 if (!validateCompressedTexSubDimensions("compressedTexSubImage2D", target, l evel, xoffset, yoffset, width, height, format, tex))
1392 return; 1390 return;
1393 1391
1394 m_context->compressedTexSubImage2D(target, level, xoffset, yoffset, 1392 webContext()->compressedTexSubImage2D(target, level, xoffset, yoffset,
1395 width, height, format, data->by teLength(), data->baseAddress()); 1393 width, height, format, data->byteLength(), data->baseAddress());
1396 } 1394 }
1397 1395
1398 bool WebGLRenderingContextBase::validateSettableTexFormat(const char* functionNa me, GLenum format) 1396 bool WebGLRenderingContextBase::validateSettableTexFormat(const char* functionNa me, GLenum format)
1399 { 1397 {
1400 if (WebGLImageConversion::getClearBitsByFormat(format) & (GL_DEPTH_BUFFER_BI T | GL_STENCIL_BUFFER_BIT)) { 1398 if (WebGLImageConversion::getClearBitsByFormat(format) & (GL_DEPTH_BUFFER_BI T | GL_STENCIL_BUFFER_BIT)) {
1401 synthesizeGLError(GL_INVALID_OPERATION, functionName, "format can not be set, only rendered to"); 1399 synthesizeGLError(GL_INVALID_OPERATION, functionName, "format can not be set, only rendered to");
1402 return false; 1400 return false;
1403 } 1401 }
1404 return true; 1402 return true;
1405 } 1403 }
(...skipping 11 matching lines...) Expand all
1417 return; 1415 return;
1418 if (!isTexInternalFormatColorBufferCombinationValid(internalformat, boundFra mebufferColorFormat())) { 1416 if (!isTexInternalFormatColorBufferCombinationValid(internalformat, boundFra mebufferColorFormat())) {
1419 synthesizeGLError(GL_INVALID_OPERATION, "copyTexImage2D", "framebuffer i s incompatible format"); 1417 synthesizeGLError(GL_INVALID_OPERATION, "copyTexImage2D", "framebuffer i s incompatible format");
1420 return; 1418 return;
1421 } 1419 }
1422 if (!isGLES2NPOTStrict() && level && WebGLTexture::isNPOT(width, height)) { 1420 if (!isGLES2NPOTStrict() && level && WebGLTexture::isNPOT(width, height)) {
1423 synthesizeGLError(GL_INVALID_VALUE, "copyTexImage2D", "level > 0 not pow er of 2"); 1421 synthesizeGLError(GL_INVALID_VALUE, "copyTexImage2D", "level > 0 not pow er of 2");
1424 return; 1422 return;
1425 } 1423 }
1426 const char* reason = "framebuffer incomplete"; 1424 const char* reason = "framebuffer incomplete";
1427 if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context.get(), &reason)) { 1425 if (m_framebufferBinding && !m_framebufferBinding->onAccess(webContext(), &r eason)) {
1428 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "copyTexImage2D", re ason); 1426 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "copyTexImage2D", re ason);
1429 return; 1427 return;
1430 } 1428 }
1431 clearIfComposited(); 1429 clearIfComposited();
1432 ScopedDrawingBufferBinder binder(m_drawingBuffer.get(), m_framebufferBinding .get()); 1430 ScopedDrawingBufferBinder binder(m_drawingBuffer.get(), m_framebufferBinding .get());
1433 m_context->copyTexImage2D(target, level, internalformat, x, y, width, height , border); 1431 webContext()->copyTexImage2D(target, level, internalformat, x, y, width, hei ght, border);
1434 // FIXME: if the framebuffer is not complete, none of the below should be ex ecuted. 1432 // FIXME: if the framebuffer is not complete, none of the below should be ex ecuted.
1435 tex->setLevelInfo(target, level, internalformat, width, height, GL_UNSIGNED_ BYTE); 1433 tex->setLevelInfo(target, level, internalformat, width, height, GL_UNSIGNED_ BYTE);
1436 } 1434 }
1437 1435
1438 void WebGLRenderingContextBase::copyTexSubImage2D(GLenum target, GLint level, GL int xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) 1436 void WebGLRenderingContextBase::copyTexSubImage2D(GLenum target, GLint level, GL int xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
1439 { 1437 {
1440 if (isContextLost()) 1438 if (isContextLost())
1441 return; 1439 return;
1442 if (!validateTexFuncLevel("copyTexSubImage2D", target, level)) 1440 if (!validateTexFuncLevel("copyTexSubImage2D", target, level))
1443 return; 1441 return;
(...skipping 16 matching lines...) Expand all
1460 return; 1458 return;
1461 } 1459 }
1462 GLenum internalformat = tex->getInternalFormat(target, level); 1460 GLenum internalformat = tex->getInternalFormat(target, level);
1463 if (!validateSettableTexFormat("copyTexSubImage2D", internalformat)) 1461 if (!validateSettableTexFormat("copyTexSubImage2D", internalformat))
1464 return; 1462 return;
1465 if (!isTexInternalFormatColorBufferCombinationValid(internalformat, boundFra mebufferColorFormat())) { 1463 if (!isTexInternalFormatColorBufferCombinationValid(internalformat, boundFra mebufferColorFormat())) {
1466 synthesizeGLError(GL_INVALID_OPERATION, "copyTexSubImage2D", "framebuffe r is incompatible format"); 1464 synthesizeGLError(GL_INVALID_OPERATION, "copyTexSubImage2D", "framebuffe r is incompatible format");
1467 return; 1465 return;
1468 } 1466 }
1469 const char* reason = "framebuffer incomplete"; 1467 const char* reason = "framebuffer incomplete";
1470 if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context.get(), &reason)) { 1468 if (m_framebufferBinding && !m_framebufferBinding->onAccess(webContext(), &r eason)) {
1471 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "copyTexSubImage2D", reason); 1469 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "copyTexSubImage2D", reason);
1472 return; 1470 return;
1473 } 1471 }
1474 clearIfComposited(); 1472 clearIfComposited();
1475 ScopedDrawingBufferBinder binder(m_drawingBuffer.get(), m_framebufferBinding .get()); 1473 ScopedDrawingBufferBinder binder(m_drawingBuffer.get(), m_framebufferBinding .get());
1476 m_context->copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, h eight); 1474 webContext()->copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width , height);
1477 } 1475 }
1478 1476
1479 PassRefPtr<WebGLBuffer> WebGLRenderingContextBase::createBuffer() 1477 PassRefPtr<WebGLBuffer> WebGLRenderingContextBase::createBuffer()
1480 { 1478 {
1481 if (isContextLost()) 1479 if (isContextLost())
1482 return nullptr; 1480 return nullptr;
1483 RefPtr<WebGLBuffer> o = WebGLBuffer::create(this); 1481 RefPtr<WebGLBuffer> o = WebGLBuffer::create(this);
1484 addSharedObject(o.get()); 1482 addSharedObject(o.get());
1485 return o; 1483 return o;
1486 } 1484 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1520 addSharedObject(o.get()); 1518 addSharedObject(o.get());
1521 return o; 1519 return o;
1522 } 1520 }
1523 1521
1524 WebGLRenderbuffer* WebGLRenderingContextBase::ensureEmulatedStencilBuffer(GLenum target, WebGLRenderbuffer* renderbuffer) 1522 WebGLRenderbuffer* WebGLRenderingContextBase::ensureEmulatedStencilBuffer(GLenum target, WebGLRenderbuffer* renderbuffer)
1525 { 1523 {
1526 if (isContextLost()) 1524 if (isContextLost())
1527 return 0; 1525 return 0;
1528 if (!renderbuffer->emulatedStencilBuffer()) { 1526 if (!renderbuffer->emulatedStencilBuffer()) {
1529 renderbuffer->setEmulatedStencilBuffer(createRenderbuffer()); 1527 renderbuffer->setEmulatedStencilBuffer(createRenderbuffer());
1530 m_context->bindRenderbuffer(target, objectOrZero(renderbuffer->emulatedS tencilBuffer())); 1528 webContext()->bindRenderbuffer(target, objectOrZero(renderbuffer->emulat edStencilBuffer()));
1531 m_context->bindRenderbuffer(target, objectOrZero(m_renderbufferBinding.g et())); 1529 webContext()->bindRenderbuffer(target, objectOrZero(m_renderbufferBindin g.get()));
1532 } 1530 }
1533 return renderbuffer->emulatedStencilBuffer(); 1531 return renderbuffer->emulatedStencilBuffer();
1534 } 1532 }
1535 1533
1536 PassRefPtr<WebGLShader> WebGLRenderingContextBase::createShader(GLenum type) 1534 PassRefPtr<WebGLShader> WebGLRenderingContextBase::createShader(GLenum type)
1537 { 1535 {
1538 if (isContextLost()) 1536 if (isContextLost())
1539 return nullptr; 1537 return nullptr;
1540 if (type != GL_VERTEX_SHADER && type != GL_FRAGMENT_SHADER) { 1538 if (type != GL_VERTEX_SHADER && type != GL_FRAGMENT_SHADER) {
1541 synthesizeGLError(GL_INVALID_ENUM, "createShader", "invalid shader type" ); 1539 synthesizeGLError(GL_INVALID_ENUM, "createShader", "invalid shader type" );
(...skipping 11 matching lines...) Expand all
1553 return; 1551 return;
1554 switch (mode) { 1552 switch (mode) {
1555 case GL_FRONT_AND_BACK: 1553 case GL_FRONT_AND_BACK:
1556 case GL_FRONT: 1554 case GL_FRONT:
1557 case GL_BACK: 1555 case GL_BACK:
1558 break; 1556 break;
1559 default: 1557 default:
1560 synthesizeGLError(GL_INVALID_ENUM, "cullFace", "invalid mode"); 1558 synthesizeGLError(GL_INVALID_ENUM, "cullFace", "invalid mode");
1561 return; 1559 return;
1562 } 1560 }
1563 m_context->cullFace(mode); 1561 webContext()->cullFace(mode);
1564 } 1562 }
1565 1563
1566 bool WebGLRenderingContextBase::deleteObject(WebGLObject* object) 1564 bool WebGLRenderingContextBase::deleteObject(WebGLObject* object)
1567 { 1565 {
1568 if (isContextLost() || !object) 1566 if (isContextLost() || !object)
1569 return false; 1567 return false;
1570 if (!object->validate(contextGroup(), this)) { 1568 if (!object->validate(contextGroup(), this)) {
1571 synthesizeGLError(GL_INVALID_OPERATION, "delete", "object does not belon g to this context"); 1569 synthesizeGLError(GL_INVALID_OPERATION, "delete", "object does not belon g to this context");
1572 return false; 1570 return false;
1573 } 1571 }
1574 if (object->object()) { 1572 if (object->object()) {
1575 // We need to pass in context here because we want 1573 // We need to pass in context here because we want
1576 // things in this context unbound. 1574 // things in this context unbound.
1577 object->deleteObject(m_context.get()); 1575 object->deleteObject(webContext());
1578 } 1576 }
1579 return true; 1577 return true;
1580 } 1578 }
1581 1579
1582 void WebGLRenderingContextBase::deleteBuffer(WebGLBuffer* buffer) 1580 void WebGLRenderingContextBase::deleteBuffer(WebGLBuffer* buffer)
1583 { 1581 {
1584 if (!deleteObject(buffer)) 1582 if (!deleteObject(buffer))
1585 return; 1583 return;
1586 if (m_boundArrayBuffer == buffer) 1584 if (m_boundArrayBuffer == buffer)
1587 m_boundArrayBuffer = nullptr; 1585 m_boundArrayBuffer = nullptr;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1649 findNewMaxNonDefaultTextureUnit(); 1647 findNewMaxNonDefaultTextureUnit();
1650 } 1648 }
1651 } 1649 }
1652 1650
1653 void WebGLRenderingContextBase::depthFunc(GLenum func) 1651 void WebGLRenderingContextBase::depthFunc(GLenum func)
1654 { 1652 {
1655 if (isContextLost()) 1653 if (isContextLost())
1656 return; 1654 return;
1657 if (!validateStencilOrDepthFunc("depthFunc", func)) 1655 if (!validateStencilOrDepthFunc("depthFunc", func))
1658 return; 1656 return;
1659 m_context->depthFunc(func); 1657 webContext()->depthFunc(func);
1660 } 1658 }
1661 1659
1662 void WebGLRenderingContextBase::depthMask(GLboolean flag) 1660 void WebGLRenderingContextBase::depthMask(GLboolean flag)
1663 { 1661 {
1664 if (isContextLost()) 1662 if (isContextLost())
1665 return; 1663 return;
1666 m_depthMask = flag; 1664 m_depthMask = flag;
1667 m_context->depthMask(flag); 1665 webContext()->depthMask(flag);
1668 } 1666 }
1669 1667
1670 void WebGLRenderingContextBase::depthRange(GLfloat zNear, GLfloat zFar) 1668 void WebGLRenderingContextBase::depthRange(GLfloat zNear, GLfloat zFar)
1671 { 1669 {
1672 if (isContextLost()) 1670 if (isContextLost())
1673 return; 1671 return;
1674 if (zNear > zFar) { 1672 if (zNear > zFar) {
1675 synthesizeGLError(GL_INVALID_OPERATION, "depthRange", "zNear > zFar"); 1673 synthesizeGLError(GL_INVALID_OPERATION, "depthRange", "zNear > zFar");
1676 return; 1674 return;
1677 } 1675 }
1678 m_context->depthRange(zNear, zFar); 1676 webContext()->depthRange(zNear, zFar);
1679 } 1677 }
1680 1678
1681 void WebGLRenderingContextBase::detachShader(WebGLProgram* program, WebGLShader* shader) 1679 void WebGLRenderingContextBase::detachShader(WebGLProgram* program, WebGLShader* shader)
1682 { 1680 {
1683 if (isContextLost() || !validateWebGLObject("detachShader", program) || !val idateWebGLObject("detachShader", shader)) 1681 if (isContextLost() || !validateWebGLObject("detachShader", program) || !val idateWebGLObject("detachShader", shader))
1684 return; 1682 return;
1685 if (!program->detachShader(shader)) { 1683 if (!program->detachShader(shader)) {
1686 synthesizeGLError(GL_INVALID_OPERATION, "detachShader", "shader not atta ched"); 1684 synthesizeGLError(GL_INVALID_OPERATION, "detachShader", "shader not atta ched");
1687 return; 1685 return;
1688 } 1686 }
1689 m_context->detachShader(objectOrZero(program), objectOrZero(shader)); 1687 webContext()->detachShader(objectOrZero(program), objectOrZero(shader));
1690 shader->onDetached(m_context.get()); 1688 shader->onDetached(webContext());
1691 } 1689 }
1692 1690
1693 void WebGLRenderingContextBase::disable(GLenum cap) 1691 void WebGLRenderingContextBase::disable(GLenum cap)
1694 { 1692 {
1695 if (isContextLost() || !validateCapability("disable", cap)) 1693 if (isContextLost() || !validateCapability("disable", cap))
1696 return; 1694 return;
1697 if (cap == GL_STENCIL_TEST) { 1695 if (cap == GL_STENCIL_TEST) {
1698 m_stencilEnabled = false; 1696 m_stencilEnabled = false;
1699 applyStencilTest(); 1697 applyStencilTest();
1700 return; 1698 return;
1701 } 1699 }
1702 if (cap == GL_SCISSOR_TEST) { 1700 if (cap == GL_SCISSOR_TEST) {
1703 m_scissorEnabled = false; 1701 m_scissorEnabled = false;
1704 m_drawingBuffer->setScissorEnabled(m_scissorEnabled); 1702 m_drawingBuffer->setScissorEnabled(m_scissorEnabled);
1705 } 1703 }
1706 m_context->disable(cap); 1704 webContext()->disable(cap);
1707 } 1705 }
1708 1706
1709 void WebGLRenderingContextBase::disableVertexAttribArray(GLuint index) 1707 void WebGLRenderingContextBase::disableVertexAttribArray(GLuint index)
1710 { 1708 {
1711 if (isContextLost()) 1709 if (isContextLost())
1712 return; 1710 return;
1713 if (index >= m_maxVertexAttribs) { 1711 if (index >= m_maxVertexAttribs) {
1714 synthesizeGLError(GL_INVALID_VALUE, "disableVertexAttribArray", "index o ut of range"); 1712 synthesizeGLError(GL_INVALID_VALUE, "disableVertexAttribArray", "index o ut of range");
1715 return; 1713 return;
1716 } 1714 }
1717 1715
1718 WebGLVertexArrayObjectOES::VertexAttribState& state = m_boundVertexArrayObje ct->getVertexAttribState(index); 1716 WebGLVertexArrayObjectOES::VertexAttribState& state = m_boundVertexArrayObje ct->getVertexAttribState(index);
1719 state.enabled = false; 1717 state.enabled = false;
1720 1718
1721 // If the disabled index is the current maximum, trace backwards to find the new max enabled attrib index 1719 // If the disabled index is the current maximum, trace backwards to find the new max enabled attrib index
1722 if (m_onePlusMaxEnabledAttribIndex == index + 1) { 1720 if (m_onePlusMaxEnabledAttribIndex == index + 1) {
1723 findNewMaxEnabledAttribIndex(); 1721 findNewMaxEnabledAttribIndex();
1724 } 1722 }
1725 1723
1726 m_context->disableVertexAttribArray(index); 1724 webContext()->disableVertexAttribArray(index);
1727 } 1725 }
1728 1726
1729 bool WebGLRenderingContextBase::validateRenderingState(const char* functionName) 1727 bool WebGLRenderingContextBase::validateRenderingState(const char* functionName)
1730 { 1728 {
1731 if (!m_currentProgram) { 1729 if (!m_currentProgram) {
1732 synthesizeGLError(GL_INVALID_OPERATION, functionName, "no valid shader p rogram in use"); 1730 synthesizeGLError(GL_INVALID_OPERATION, functionName, "no valid shader p rogram in use");
1733 return false; 1731 return false;
1734 } 1732 }
1735 1733
1736 // Look in each enabled vertex attrib and check if they've been bound to a b uffer. 1734 // Look in each enabled vertex attrib and check if they've been bound to a b uffer.
(...skipping 23 matching lines...) Expand all
1760 } 1758 }
1761 1759
1762 void WebGLRenderingContextBase::drawArrays(GLenum mode, GLint first, GLsizei cou nt) 1760 void WebGLRenderingContextBase::drawArrays(GLenum mode, GLint first, GLsizei cou nt)
1763 { 1761 {
1764 if (!validateDrawArrays("drawArrays", mode, first, count)) 1762 if (!validateDrawArrays("drawArrays", mode, first, count))
1765 return; 1763 return;
1766 1764
1767 clearIfComposited(); 1765 clearIfComposited();
1768 1766
1769 handleTextureCompleteness("drawArrays", true); 1767 handleTextureCompleteness("drawArrays", true);
1770 m_context->drawArrays(mode, first, count); 1768 webContext()->drawArrays(mode, first, count);
1771 handleTextureCompleteness("drawArrays", false); 1769 handleTextureCompleteness("drawArrays", false);
1772 markContextChanged(CanvasChanged); 1770 markContextChanged(CanvasChanged);
1773 } 1771 }
1774 1772
1775 void WebGLRenderingContextBase::drawElements(GLenum mode, GLsizei count, GLenum type, long long offset) 1773 void WebGLRenderingContextBase::drawElements(GLenum mode, GLsizei count, GLenum type, long long offset)
1776 { 1774 {
1777 if (!validateDrawElements("drawElements", mode, count, type, offset)) 1775 if (!validateDrawElements("drawElements", mode, count, type, offset))
1778 return; 1776 return;
1779 1777
1780 clearIfComposited(); 1778 clearIfComposited();
1781 1779
1782 handleTextureCompleteness("drawElements", true); 1780 handleTextureCompleteness("drawElements", true);
1783 m_context->drawElements(mode, count, type, static_cast<GLintptr>(offset)); 1781 webContext()->drawElements(mode, count, type, static_cast<GLintptr>(offset)) ;
1784 handleTextureCompleteness("drawElements", false); 1782 handleTextureCompleteness("drawElements", false);
1785 markContextChanged(CanvasChanged); 1783 markContextChanged(CanvasChanged);
1786 } 1784 }
1787 1785
1788 void WebGLRenderingContextBase::drawArraysInstancedANGLE(GLenum mode, GLint firs t, GLsizei count, GLsizei primcount) 1786 void WebGLRenderingContextBase::drawArraysInstancedANGLE(GLenum mode, GLint firs t, GLsizei count, GLsizei primcount)
1789 { 1787 {
1790 if (!validateDrawArrays("drawArraysInstancedANGLE", mode, first, count)) 1788 if (!validateDrawArrays("drawArraysInstancedANGLE", mode, first, count))
1791 return; 1789 return;
1792 1790
1793 if (!validateDrawInstanced("drawArraysInstancedANGLE", primcount)) 1791 if (!validateDrawInstanced("drawArraysInstancedANGLE", primcount))
1794 return; 1792 return;
1795 1793
1796 clearIfComposited(); 1794 clearIfComposited();
1797 1795
1798 handleTextureCompleteness("drawArraysInstancedANGLE", true); 1796 handleTextureCompleteness("drawArraysInstancedANGLE", true);
1799 m_context->drawArraysInstancedANGLE(mode, first, count, primcount); 1797 webContext()->drawArraysInstancedANGLE(mode, first, count, primcount);
1800 handleTextureCompleteness("drawArraysInstancedANGLE", false); 1798 handleTextureCompleteness("drawArraysInstancedANGLE", false);
1801 markContextChanged(CanvasChanged); 1799 markContextChanged(CanvasChanged);
1802 } 1800 }
1803 1801
1804 void WebGLRenderingContextBase::drawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, GLintptr offset, GLsizei primcount) 1802 void WebGLRenderingContextBase::drawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, GLintptr offset, GLsizei primcount)
1805 { 1803 {
1806 if (!validateDrawElements("drawElementsInstancedANGLE", mode, count, type, o ffset)) 1804 if (!validateDrawElements("drawElementsInstancedANGLE", mode, count, type, o ffset))
1807 return; 1805 return;
1808 1806
1809 if (!validateDrawInstanced("drawElementsInstancedANGLE", primcount)) 1807 if (!validateDrawInstanced("drawElementsInstancedANGLE", primcount))
1810 return; 1808 return;
1811 1809
1812 clearIfComposited(); 1810 clearIfComposited();
1813 1811
1814 handleTextureCompleteness("drawElementsInstancedANGLE", true); 1812 handleTextureCompleteness("drawElementsInstancedANGLE", true);
1815 m_context->drawElementsInstancedANGLE(mode, count, type, static_cast<GLintpt r>(offset), primcount); 1813 webContext()->drawElementsInstancedANGLE(mode, count, type, static_cast<GLin tptr>(offset), primcount);
1816 handleTextureCompleteness("drawElementsInstancedANGLE", false); 1814 handleTextureCompleteness("drawElementsInstancedANGLE", false);
1817 markContextChanged(CanvasChanged); 1815 markContextChanged(CanvasChanged);
1818 } 1816 }
1819 1817
1820 void WebGLRenderingContextBase::enable(GLenum cap) 1818 void WebGLRenderingContextBase::enable(GLenum cap)
1821 { 1819 {
1822 if (isContextLost() || !validateCapability("enable", cap)) 1820 if (isContextLost() || !validateCapability("enable", cap))
1823 return; 1821 return;
1824 if (cap == GL_STENCIL_TEST) { 1822 if (cap == GL_STENCIL_TEST) {
1825 m_stencilEnabled = true; 1823 m_stencilEnabled = true;
1826 applyStencilTest(); 1824 applyStencilTest();
1827 return; 1825 return;
1828 } 1826 }
1829 if (cap == GL_SCISSOR_TEST) { 1827 if (cap == GL_SCISSOR_TEST) {
1830 m_scissorEnabled = true; 1828 m_scissorEnabled = true;
1831 m_drawingBuffer->setScissorEnabled(m_scissorEnabled); 1829 m_drawingBuffer->setScissorEnabled(m_scissorEnabled);
1832 } 1830 }
1833 m_context->enable(cap); 1831 webContext()->enable(cap);
1834 } 1832 }
1835 1833
1836 void WebGLRenderingContextBase::enableVertexAttribArray(GLuint index) 1834 void WebGLRenderingContextBase::enableVertexAttribArray(GLuint index)
1837 { 1835 {
1838 if (isContextLost()) 1836 if (isContextLost())
1839 return; 1837 return;
1840 if (index >= m_maxVertexAttribs) { 1838 if (index >= m_maxVertexAttribs) {
1841 synthesizeGLError(GL_INVALID_VALUE, "enableVertexAttribArray", "index ou t of range"); 1839 synthesizeGLError(GL_INVALID_VALUE, "enableVertexAttribArray", "index ou t of range");
1842 return; 1840 return;
1843 } 1841 }
1844 1842
1845 WebGLVertexArrayObjectOES::VertexAttribState& state = m_boundVertexArrayObje ct->getVertexAttribState(index); 1843 WebGLVertexArrayObjectOES::VertexAttribState& state = m_boundVertexArrayObje ct->getVertexAttribState(index);
1846 state.enabled = true; 1844 state.enabled = true;
1847 1845
1848 m_onePlusMaxEnabledAttribIndex = max(index + 1, m_onePlusMaxEnabledAttribInd ex); 1846 m_onePlusMaxEnabledAttribIndex = max(index + 1, m_onePlusMaxEnabledAttribInd ex);
1849 1847
1850 m_context->enableVertexAttribArray(index); 1848 webContext()->enableVertexAttribArray(index);
1851 } 1849 }
1852 1850
1853 void WebGLRenderingContextBase::finish() 1851 void WebGLRenderingContextBase::finish()
1854 { 1852 {
1855 if (isContextLost()) 1853 if (isContextLost())
1856 return; 1854 return;
1857 m_context->flush(); // Intentionally a flush, not a finish. 1855 webContext()->flush(); // Intentionally a flush, not a finish.
1858 } 1856 }
1859 1857
1860 void WebGLRenderingContextBase::flush() 1858 void WebGLRenderingContextBase::flush()
1861 { 1859 {
1862 if (isContextLost()) 1860 if (isContextLost())
1863 return; 1861 return;
1864 m_context->flush(); 1862 webContext()->flush();
1865 } 1863 }
1866 1864
1867 void WebGLRenderingContextBase::framebufferRenderbuffer(GLenum target, GLenum at tachment, GLenum renderbuffertarget, WebGLRenderbuffer* buffer) 1865 void WebGLRenderingContextBase::framebufferRenderbuffer(GLenum target, GLenum at tachment, GLenum renderbuffertarget, WebGLRenderbuffer* buffer)
1868 { 1866 {
1869 if (isContextLost() || !validateFramebufferFuncParameters("framebufferRender buffer", target, attachment)) 1867 if (isContextLost() || !validateFramebufferFuncParameters("framebufferRender buffer", target, attachment))
1870 return; 1868 return;
1871 if (renderbuffertarget != GL_RENDERBUFFER) { 1869 if (renderbuffertarget != GL_RENDERBUFFER) {
1872 synthesizeGLError(GL_INVALID_ENUM, "framebufferRenderbuffer", "invalid t arget"); 1870 synthesizeGLError(GL_INVALID_ENUM, "framebufferRenderbuffer", "invalid t arget");
1873 return; 1871 return;
1874 } 1872 }
1875 if (buffer && !buffer->validate(contextGroup(), this)) { 1873 if (buffer && !buffer->validate(contextGroup(), this)) {
1876 synthesizeGLError(GL_INVALID_OPERATION, "framebufferRenderbuffer", "no b uffer or buffer not from this context"); 1874 synthesizeGLError(GL_INVALID_OPERATION, "framebufferRenderbuffer", "no b uffer or buffer not from this context");
1877 return; 1875 return;
1878 } 1876 }
1879 // Don't allow the default framebuffer to be mutated; all current 1877 // Don't allow the default framebuffer to be mutated; all current
1880 // implementations use an FBO internally in place of the default 1878 // implementations use an FBO internally in place of the default
1881 // FBO. 1879 // FBO.
1882 if (!m_framebufferBinding || !m_framebufferBinding->object()) { 1880 if (!m_framebufferBinding || !m_framebufferBinding->object()) {
1883 synthesizeGLError(GL_INVALID_OPERATION, "framebufferRenderbuffer", "no f ramebuffer bound"); 1881 synthesizeGLError(GL_INVALID_OPERATION, "framebufferRenderbuffer", "no f ramebuffer bound");
1884 return; 1882 return;
1885 } 1883 }
1886 Platform3DObject bufferObject = objectOrZero(buffer); 1884 Platform3DObject bufferObject = objectOrZero(buffer);
1887 switch (attachment) { 1885 switch (attachment) {
1888 case GC3D_DEPTH_STENCIL_ATTACHMENT_WEBGL: 1886 case GC3D_DEPTH_STENCIL_ATTACHMENT_WEBGL:
1889 if (isDepthStencilSupported() || !buffer) { 1887 if (isDepthStencilSupported() || !buffer) {
1890 m_context->framebufferRenderbuffer(target, GL_DEPTH_ATTACHMENT, rend erbuffertarget, bufferObject); 1888 webContext()->framebufferRenderbuffer(target, GL_DEPTH_ATTACHMENT, r enderbuffertarget, bufferObject);
1891 m_context->framebufferRenderbuffer(target, GL_STENCIL_ATTACHMENT, re nderbuffertarget, bufferObject); 1889 webContext()->framebufferRenderbuffer(target, GL_STENCIL_ATTACHMENT, renderbuffertarget, bufferObject);
1892 } else { 1890 } else {
1893 WebGLRenderbuffer* emulatedStencilBuffer = ensureEmulatedStencilBuff er(renderbuffertarget, buffer); 1891 WebGLRenderbuffer* emulatedStencilBuffer = ensureEmulatedStencilBuff er(renderbuffertarget, buffer);
1894 if (!emulatedStencilBuffer) { 1892 if (!emulatedStencilBuffer) {
1895 synthesizeGLError(GL_OUT_OF_MEMORY, "framebufferRenderbuffer", " out of memory"); 1893 synthesizeGLError(GL_OUT_OF_MEMORY, "framebufferRenderbuffer", " out of memory");
1896 return; 1894 return;
1897 } 1895 }
1898 m_context->framebufferRenderbuffer(target, GL_DEPTH_ATTACHMENT, rend erbuffertarget, bufferObject); 1896 webContext()->framebufferRenderbuffer(target, GL_DEPTH_ATTACHMENT, r enderbuffertarget, bufferObject);
1899 m_context->framebufferRenderbuffer(target, GL_STENCIL_ATTACHMENT, re nderbuffertarget, objectOrZero(emulatedStencilBuffer)); 1897 webContext()->framebufferRenderbuffer(target, GL_STENCIL_ATTACHMENT, renderbuffertarget, objectOrZero(emulatedStencilBuffer));
1900 } 1898 }
1901 break; 1899 break;
1902 default: 1900 default:
1903 m_context->framebufferRenderbuffer(target, attachment, renderbuffertarge t, bufferObject); 1901 webContext()->framebufferRenderbuffer(target, attachment, renderbufferta rget, bufferObject);
1904 } 1902 }
1905 m_framebufferBinding->setAttachmentForBoundFramebuffer(attachment, buffer); 1903 m_framebufferBinding->setAttachmentForBoundFramebuffer(attachment, buffer);
1906 applyStencilTest(); 1904 applyStencilTest();
1907 } 1905 }
1908 1906
1909 void WebGLRenderingContextBase::framebufferTexture2D(GLenum target, GLenum attac hment, GLenum textarget, WebGLTexture* texture, GLint level) 1907 void WebGLRenderingContextBase::framebufferTexture2D(GLenum target, GLenum attac hment, GLenum textarget, WebGLTexture* texture, GLint level)
1910 { 1908 {
1911 if (isContextLost() || !validateFramebufferFuncParameters("framebufferTextur e2D", target, attachment)) 1909 if (isContextLost() || !validateFramebufferFuncParameters("framebufferTextur e2D", target, attachment))
1912 return; 1910 return;
1913 if (level) { 1911 if (level) {
1914 synthesizeGLError(GL_INVALID_VALUE, "framebufferTexture2D", "level not 0 "); 1912 synthesizeGLError(GL_INVALID_VALUE, "framebufferTexture2D", "level not 0 ");
1915 return; 1913 return;
1916 } 1914 }
1917 if (texture && !texture->validate(contextGroup(), this)) { 1915 if (texture && !texture->validate(contextGroup(), this)) {
1918 synthesizeGLError(GL_INVALID_OPERATION, "framebufferTexture2D", "no text ure or texture not from this context"); 1916 synthesizeGLError(GL_INVALID_OPERATION, "framebufferTexture2D", "no text ure or texture not from this context");
1919 return; 1917 return;
1920 } 1918 }
1921 // Don't allow the default framebuffer to be mutated; all current 1919 // Don't allow the default framebuffer to be mutated; all current
1922 // implementations use an FBO internally in place of the default 1920 // implementations use an FBO internally in place of the default
1923 // FBO. 1921 // FBO.
1924 if (!m_framebufferBinding || !m_framebufferBinding->object()) { 1922 if (!m_framebufferBinding || !m_framebufferBinding->object()) {
1925 synthesizeGLError(GL_INVALID_OPERATION, "framebufferTexture2D", "no fram ebuffer bound"); 1923 synthesizeGLError(GL_INVALID_OPERATION, "framebufferTexture2D", "no fram ebuffer bound");
1926 return; 1924 return;
1927 } 1925 }
1928 Platform3DObject textureObject = objectOrZero(texture); 1926 Platform3DObject textureObject = objectOrZero(texture);
1929 switch (attachment) { 1927 switch (attachment) {
1930 case GC3D_DEPTH_STENCIL_ATTACHMENT_WEBGL: 1928 case GC3D_DEPTH_STENCIL_ATTACHMENT_WEBGL:
1931 m_context->framebufferTexture2D(target, GL_DEPTH_ATTACHMENT, textarget, textureObject, level); 1929 webContext()->framebufferTexture2D(target, GL_DEPTH_ATTACHMENT, textarge t, textureObject, level);
1932 m_context->framebufferTexture2D(target, GL_STENCIL_ATTACHMENT, textarget , textureObject, level); 1930 webContext()->framebufferTexture2D(target, GL_STENCIL_ATTACHMENT, textar get, textureObject, level);
1933 break; 1931 break;
1934 case GL_DEPTH_ATTACHMENT: 1932 case GL_DEPTH_ATTACHMENT:
1935 m_context->framebufferTexture2D(target, attachment, textarget, textureOb ject, level); 1933 webContext()->framebufferTexture2D(target, attachment, textarget, textur eObject, level);
1936 break; 1934 break;
1937 case GL_STENCIL_ATTACHMENT: 1935 case GL_STENCIL_ATTACHMENT:
1938 m_context->framebufferTexture2D(target, attachment, textarget, textureOb ject, level); 1936 webContext()->framebufferTexture2D(target, attachment, textarget, textur eObject, level);
1939 break; 1937 break;
1940 default: 1938 default:
1941 m_context->framebufferTexture2D(target, attachment, textarget, textureOb ject, level); 1939 webContext()->framebufferTexture2D(target, attachment, textarget, textur eObject, level);
1942 } 1940 }
1943 m_framebufferBinding->setAttachmentForBoundFramebuffer(attachment, textarget , texture, level); 1941 m_framebufferBinding->setAttachmentForBoundFramebuffer(attachment, textarget , texture, level);
1944 applyStencilTest(); 1942 applyStencilTest();
1945 } 1943 }
1946 1944
1947 void WebGLRenderingContextBase::frontFace(GLenum mode) 1945 void WebGLRenderingContextBase::frontFace(GLenum mode)
1948 { 1946 {
1949 if (isContextLost()) 1947 if (isContextLost())
1950 return; 1948 return;
1951 switch (mode) { 1949 switch (mode) {
1952 case GL_CW: 1950 case GL_CW:
1953 case GL_CCW: 1951 case GL_CCW:
1954 break; 1952 break;
1955 default: 1953 default:
1956 synthesizeGLError(GL_INVALID_ENUM, "frontFace", "invalid mode"); 1954 synthesizeGLError(GL_INVALID_ENUM, "frontFace", "invalid mode");
1957 return; 1955 return;
1958 } 1956 }
1959 m_context->frontFace(mode); 1957 webContext()->frontFace(mode);
1960 } 1958 }
1961 1959
1962 void WebGLRenderingContextBase::generateMipmap(GLenum target) 1960 void WebGLRenderingContextBase::generateMipmap(GLenum target)
1963 { 1961 {
1964 if (isContextLost()) 1962 if (isContextLost())
1965 return; 1963 return;
1966 WebGLTexture* tex = validateTextureBinding("generateMipmap", target, false); 1964 WebGLTexture* tex = validateTextureBinding("generateMipmap", target, false);
1967 if (!tex) 1965 if (!tex)
1968 return; 1966 return;
1969 if (!tex->canGenerateMipmaps()) { 1967 if (!tex->canGenerateMipmaps()) {
1970 synthesizeGLError(GL_INVALID_OPERATION, "generateMipmap", "level 0 not p ower of 2 or not all the same size"); 1968 synthesizeGLError(GL_INVALID_OPERATION, "generateMipmap", "level 0 not p ower of 2 or not all the same size");
1971 return; 1969 return;
1972 } 1970 }
1973 if (!validateSettableTexFormat("generateMipmap", tex->getInternalFormat(targ et, 0))) 1971 if (!validateSettableTexFormat("generateMipmap", tex->getInternalFormat(targ et, 0)))
1974 return; 1972 return;
1975 1973
1976 // generateMipmap won't work properly if minFilter is not NEAREST_MIPMAP_LIN EAR 1974 // generateMipmap won't work properly if minFilter is not NEAREST_MIPMAP_LIN EAR
1977 // on Mac. Remove the hack once this driver bug is fixed. 1975 // on Mac. Remove the hack once this driver bug is fixed.
1978 #if OS(MACOSX) 1976 #if OS(MACOSX)
1979 bool needToResetMinFilter = false; 1977 bool needToResetMinFilter = false;
1980 if (tex->getMinFilter() != GL_NEAREST_MIPMAP_LINEAR) { 1978 if (tex->getMinFilter() != GL_NEAREST_MIPMAP_LINEAR) {
1981 m_context->texParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMA P_LINEAR); 1979 webContext()->texParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MI PMAP_LINEAR);
1982 needToResetMinFilter = true; 1980 needToResetMinFilter = true;
1983 } 1981 }
1984 #endif 1982 #endif
1985 m_context->generateMipmap(target); 1983 webContext()->generateMipmap(target);
1986 #if OS(MACOSX) 1984 #if OS(MACOSX)
1987 if (needToResetMinFilter) 1985 if (needToResetMinFilter)
1988 m_context->texParameteri(target, GL_TEXTURE_MIN_FILTER, tex->getMinFilte r()); 1986 webContext()->texParameteri(target, GL_TEXTURE_MIN_FILTER, tex->getMinFi lter());
1989 #endif 1987 #endif
1990 tex->generateMipmapLevelInfo(); 1988 tex->generateMipmapLevelInfo();
1991 } 1989 }
1992 1990
1993 PassRefPtr<WebGLActiveInfo> WebGLRenderingContextBase::getActiveAttrib(WebGLProg ram* program, GLuint index) 1991 PassRefPtr<WebGLActiveInfo> WebGLRenderingContextBase::getActiveAttrib(WebGLProg ram* program, GLuint index)
1994 { 1992 {
1995 if (isContextLost() || !validateWebGLObject("getActiveAttrib", program)) 1993 if (isContextLost() || !validateWebGLObject("getActiveAttrib", program))
1996 return nullptr; 1994 return nullptr;
1997 blink::WebGraphicsContext3D::ActiveInfo info; 1995 blink::WebGraphicsContext3D::ActiveInfo info;
1998 if (!m_context->getActiveAttrib(objectOrZero(program), index, info)) 1996 if (!webContext()->getActiveAttrib(objectOrZero(program), index, info))
1999 return nullptr; 1997 return nullptr;
2000 return WebGLActiveInfo::create(info.name, info.type, info.size); 1998 return WebGLActiveInfo::create(info.name, info.type, info.size);
2001 } 1999 }
2002 2000
2003 PassRefPtr<WebGLActiveInfo> WebGLRenderingContextBase::getActiveUniform(WebGLPro gram* program, GLuint index) 2001 PassRefPtr<WebGLActiveInfo> WebGLRenderingContextBase::getActiveUniform(WebGLPro gram* program, GLuint index)
2004 { 2002 {
2005 if (isContextLost() || !validateWebGLObject("getActiveUniform", program)) 2003 if (isContextLost() || !validateWebGLObject("getActiveUniform", program))
2006 return nullptr; 2004 return nullptr;
2007 blink::WebGraphicsContext3D::ActiveInfo info; 2005 blink::WebGraphicsContext3D::ActiveInfo info;
2008 if (!m_context->getActiveUniform(objectOrZero(program), index, info)) 2006 if (!webContext()->getActiveUniform(objectOrZero(program), index, info))
2009 return nullptr; 2007 return nullptr;
2010 return WebGLActiveInfo::create(info.name, info.type, info.size); 2008 return WebGLActiveInfo::create(info.name, info.type, info.size);
2011 } 2009 }
2012 2010
2013 bool WebGLRenderingContextBase::getAttachedShaders(WebGLProgram* program, Vector <RefPtr<WebGLShader> >& shaderObjects) 2011 bool WebGLRenderingContextBase::getAttachedShaders(WebGLProgram* program, Vector <RefPtr<WebGLShader> >& shaderObjects)
2014 { 2012 {
2015 shaderObjects.clear(); 2013 shaderObjects.clear();
2016 if (isContextLost() || !validateWebGLObject("getAttachedShaders", program)) 2014 if (isContextLost() || !validateWebGLObject("getAttachedShaders", program))
2017 return false; 2015 return false;
2018 2016
(...skipping 16 matching lines...) Expand all
2035 if (!validateLocationLength("getAttribLocation", name)) 2033 if (!validateLocationLength("getAttribLocation", name))
2036 return -1; 2034 return -1;
2037 if (!validateString("getAttribLocation", name)) 2035 if (!validateString("getAttribLocation", name))
2038 return -1; 2036 return -1;
2039 if (isPrefixReserved(name)) 2037 if (isPrefixReserved(name))
2040 return -1; 2038 return -1;
2041 if (!program->linkStatus()) { 2039 if (!program->linkStatus()) {
2042 synthesizeGLError(GL_INVALID_OPERATION, "getAttribLocation", "program no t linked"); 2040 synthesizeGLError(GL_INVALID_OPERATION, "getAttribLocation", "program no t linked");
2043 return 0; 2041 return 0;
2044 } 2042 }
2045 return m_context->getAttribLocation(objectOrZero(program), name.utf8().data( )); 2043 return webContext()->getAttribLocation(objectOrZero(program), name.utf8().da ta());
2046 } 2044 }
2047 2045
2048 WebGLGetInfo WebGLRenderingContextBase::getBufferParameter(GLenum target, GLenum pname) 2046 WebGLGetInfo WebGLRenderingContextBase::getBufferParameter(GLenum target, GLenum pname)
2049 { 2047 {
2050 if (isContextLost()) 2048 if (isContextLost())
2051 return WebGLGetInfo(); 2049 return WebGLGetInfo();
2052 if (target != GL_ARRAY_BUFFER && target != GL_ELEMENT_ARRAY_BUFFER) { 2050 if (target != GL_ARRAY_BUFFER && target != GL_ELEMENT_ARRAY_BUFFER) {
2053 synthesizeGLError(GL_INVALID_ENUM, "getBufferParameter", "invalid target "); 2051 synthesizeGLError(GL_INVALID_ENUM, "getBufferParameter", "invalid target ");
2054 return WebGLGetInfo(); 2052 return WebGLGetInfo();
2055 } 2053 }
2056 2054
2057 if (pname != GL_BUFFER_SIZE && pname != GL_BUFFER_USAGE) { 2055 if (pname != GL_BUFFER_SIZE && pname != GL_BUFFER_USAGE) {
2058 synthesizeGLError(GL_INVALID_ENUM, "getBufferParameter", "invalid parame ter name"); 2056 synthesizeGLError(GL_INVALID_ENUM, "getBufferParameter", "invalid parame ter name");
2059 return WebGLGetInfo(); 2057 return WebGLGetInfo();
2060 } 2058 }
2061 2059
2062 GLint value = 0; 2060 GLint value = 0;
2063 m_context->getBufferParameteriv(target, pname, &value); 2061 webContext()->getBufferParameteriv(target, pname, &value);
2064 if (pname == GL_BUFFER_SIZE) 2062 if (pname == GL_BUFFER_SIZE)
2065 return WebGLGetInfo(value); 2063 return WebGLGetInfo(value);
2066 return WebGLGetInfo(static_cast<unsigned>(value)); 2064 return WebGLGetInfo(static_cast<unsigned>(value));
2067 } 2065 }
2068 2066
2069 PassRefPtr<WebGLContextAttributes> WebGLRenderingContextBase::getContextAttribut es() 2067 PassRefPtr<WebGLContextAttributes> WebGLRenderingContextBase::getContextAttribut es()
2070 { 2068 {
2071 if (isContextLost()) 2069 if (isContextLost())
2072 return nullptr; 2070 return nullptr;
2073 // We always need to return a new WebGLContextAttributes object to 2071 // We always need to return a new WebGLContextAttributes object to
2074 // prevent the user from mutating any cached version. 2072 // prevent the user from mutating any cached version.
2075 blink::WebGraphicsContext3D::Attributes attrs = m_context->getContextAttribu tes(); 2073 blink::WebGraphicsContext3D::Attributes attrs = webContext()->getContextAttr ibutes();
2076 RefPtr<WebGLContextAttributes> attributes = m_requestedAttributes->clone(); 2074 RefPtr<WebGLContextAttributes> attributes = m_requestedAttributes->clone();
2077 // Some requested attributes may not be honored, so we need to query the und erlying 2075 // Some requested attributes may not be honored, so we need to query the und erlying
2078 // context/drawing buffer and adjust accordingly. 2076 // context/drawing buffer and adjust accordingly.
2079 if (m_requestedAttributes->depth() && !attrs.depth) 2077 if (m_requestedAttributes->depth() && !attrs.depth)
2080 attributes->setDepth(false); 2078 attributes->setDepth(false);
2081 if (m_requestedAttributes->stencil() && !attrs.stencil) 2079 if (m_requestedAttributes->stencil() && !attrs.stencil)
2082 attributes->setStencil(false); 2080 attributes->setStencil(false);
2083 attributes->setAntialias(m_drawingBuffer->multisample()); 2081 attributes->setAntialias(m_drawingBuffer->multisample());
2084 return attributes.release(); 2082 return attributes.release();
2085 } 2083 }
2086 2084
2087 GLenum WebGLRenderingContextBase::getError() 2085 GLenum WebGLRenderingContextBase::getError()
2088 { 2086 {
2089 if (m_lostContextErrors.size()) { 2087 if (m_lostContextErrors.size()) {
2090 GLenum err = m_lostContextErrors.first(); 2088 GLenum err = m_lostContextErrors.first();
2091 m_lostContextErrors.remove(0); 2089 m_lostContextErrors.remove(0);
2092 return err; 2090 return err;
2093 } 2091 }
2094 2092
2095 if (isContextLost()) 2093 if (isContextLost())
2096 return GL_NO_ERROR; 2094 return GL_NO_ERROR;
2097 2095
2098 return m_context->getError(); 2096 return webContext()->getError();
2099 } 2097 }
2100 2098
2101 const char* const* WebGLRenderingContextBase::ExtensionTracker::prefixes() const 2099 const char* const* WebGLRenderingContextBase::ExtensionTracker::prefixes() const
2102 { 2100 {
2103 static const char* const unprefixed[] = { "", 0, }; 2101 static const char* const unprefixed[] = { "", 0, };
2104 return m_prefixes ? m_prefixes : unprefixed; 2102 return m_prefixes ? m_prefixes : unprefixed;
2105 } 2103 }
2106 2104
2107 bool WebGLRenderingContextBase::ExtensionTracker::matchesNameWithPrefixes(const String& name) const 2105 bool WebGLRenderingContextBase::ExtensionTracker::matchesNameWithPrefixes(const String& name) const
2108 { 2106 {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
2175 if (object->isTexture()) { 2173 if (object->isTexture()) {
2176 switch (pname) { 2174 switch (pname) {
2177 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: 2175 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
2178 return WebGLGetInfo(GL_TEXTURE); 2176 return WebGLGetInfo(GL_TEXTURE);
2179 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: 2177 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
2180 return WebGLGetInfo(PassRefPtr<WebGLTexture>(static_cast<WebGLTextur e*>(object))); 2178 return WebGLGetInfo(PassRefPtr<WebGLTexture>(static_cast<WebGLTextur e*>(object)));
2181 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: 2179 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
2182 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: 2180 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
2183 { 2181 {
2184 GLint value = 0; 2182 GLint value = 0;
2185 m_context->getFramebufferAttachmentParameteriv(target, attachmen t, pname, &value); 2183 webContext()->getFramebufferAttachmentParameteriv(target, attach ment, pname, &value);
2186 return WebGLGetInfo(value); 2184 return WebGLGetInfo(value);
2187 } 2185 }
2188 default: 2186 default:
2189 synthesizeGLError(GL_INVALID_ENUM, "getFramebufferAttachmentParamete r", "invalid parameter name for texture attachment"); 2187 synthesizeGLError(GL_INVALID_ENUM, "getFramebufferAttachmentParamete r", "invalid parameter name for texture attachment");
2190 return WebGLGetInfo(); 2188 return WebGLGetInfo();
2191 } 2189 }
2192 } else { 2190 } else {
2193 switch (pname) { 2191 switch (pname) {
2194 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: 2192 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
2195 return WebGLGetInfo(GL_RENDERBUFFER); 2193 return WebGLGetInfo(GL_RENDERBUFFER);
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
2321 return getBooleanParameter(pname); 2319 return getBooleanParameter(pname);
2322 case GL_SAMPLE_COVERAGE_VALUE: 2320 case GL_SAMPLE_COVERAGE_VALUE:
2323 return getFloatParameter(pname); 2321 return getFloatParameter(pname);
2324 case GL_SAMPLES: 2322 case GL_SAMPLES:
2325 return getIntParameter(pname); 2323 return getIntParameter(pname);
2326 case GL_SCISSOR_BOX: 2324 case GL_SCISSOR_BOX:
2327 return getWebGLIntArrayParameter(pname); 2325 return getWebGLIntArrayParameter(pname);
2328 case GL_SCISSOR_TEST: 2326 case GL_SCISSOR_TEST:
2329 return getBooleanParameter(pname); 2327 return getBooleanParameter(pname);
2330 case GL_SHADING_LANGUAGE_VERSION: 2328 case GL_SHADING_LANGUAGE_VERSION:
2331 return WebGLGetInfo("WebGL GLSL ES 1.0 (" + String(m_context->getString( GL_SHADING_LANGUAGE_VERSION)) + ")"); 2329 return WebGLGetInfo("WebGL GLSL ES 1.0 (" + String(webContext()->getStri ng(GL_SHADING_LANGUAGE_VERSION)) + ")");
2332 case GL_STENCIL_BACK_FAIL: 2330 case GL_STENCIL_BACK_FAIL:
2333 return getUnsignedIntParameter(pname); 2331 return getUnsignedIntParameter(pname);
2334 case GL_STENCIL_BACK_FUNC: 2332 case GL_STENCIL_BACK_FUNC:
2335 return getUnsignedIntParameter(pname); 2333 return getUnsignedIntParameter(pname);
2336 case GL_STENCIL_BACK_PASS_DEPTH_FAIL: 2334 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
2337 return getUnsignedIntParameter(pname); 2335 return getUnsignedIntParameter(pname);
2338 case GL_STENCIL_BACK_PASS_DEPTH_PASS: 2336 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
2339 return getUnsignedIntParameter(pname); 2337 return getUnsignedIntParameter(pname);
2340 case GL_STENCIL_BACK_REF: 2338 case GL_STENCIL_BACK_REF:
2341 return getIntParameter(pname); 2339 return getIntParameter(pname);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2375 return getIntParameter(pname); 2373 return getIntParameter(pname);
2376 case GC3D_UNPACK_FLIP_Y_WEBGL: 2374 case GC3D_UNPACK_FLIP_Y_WEBGL:
2377 return WebGLGetInfo(m_unpackFlipY); 2375 return WebGLGetInfo(m_unpackFlipY);
2378 case GC3D_UNPACK_PREMULTIPLY_ALPHA_WEBGL: 2376 case GC3D_UNPACK_PREMULTIPLY_ALPHA_WEBGL:
2379 return WebGLGetInfo(m_unpackPremultiplyAlpha); 2377 return WebGLGetInfo(m_unpackPremultiplyAlpha);
2380 case GC3D_UNPACK_COLORSPACE_CONVERSION_WEBGL: 2378 case GC3D_UNPACK_COLORSPACE_CONVERSION_WEBGL:
2381 return WebGLGetInfo(m_unpackColorspaceConversion); 2379 return WebGLGetInfo(m_unpackColorspaceConversion);
2382 case GL_VENDOR: 2380 case GL_VENDOR:
2383 return WebGLGetInfo(String("WebKit")); 2381 return WebGLGetInfo(String("WebKit"));
2384 case GL_VERSION: 2382 case GL_VERSION:
2385 return WebGLGetInfo("WebGL 1.0 (" + String(m_context->getString(GL_VERSI ON)) + ")"); 2383 return WebGLGetInfo("WebGL 1.0 (" + String(webContext()->getString(GL_VE RSION)) + ")");
2386 case GL_VIEWPORT: 2384 case GL_VIEWPORT:
2387 return getWebGLIntArrayParameter(pname); 2385 return getWebGLIntArrayParameter(pname);
2388 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES: // OES_standard_derivatives 2386 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES: // OES_standard_derivatives
2389 if (extensionEnabled(OESStandardDerivativesName)) 2387 if (extensionEnabled(OESStandardDerivativesName))
2390 return getUnsignedIntParameter(GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OE S); 2388 return getUnsignedIntParameter(GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OE S);
2391 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me, OES_standard_derivatives not enabled"); 2389 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me, OES_standard_derivatives not enabled");
2392 return WebGLGetInfo(); 2390 return WebGLGetInfo();
2393 case WebGLDebugRendererInfo::UNMASKED_RENDERER_WEBGL: 2391 case WebGLDebugRendererInfo::UNMASKED_RENDERER_WEBGL:
2394 if (extensionEnabled(WebGLDebugRendererInfoName)) 2392 if (extensionEnabled(WebGLDebugRendererInfoName))
2395 return WebGLGetInfo(m_context->getString(GL_RENDERER)); 2393 return WebGLGetInfo(webContext()->getString(GL_RENDERER));
2396 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me, WEBGL_debug_renderer_info not enabled"); 2394 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me, WEBGL_debug_renderer_info not enabled");
2397 return WebGLGetInfo(); 2395 return WebGLGetInfo();
2398 case WebGLDebugRendererInfo::UNMASKED_VENDOR_WEBGL: 2396 case WebGLDebugRendererInfo::UNMASKED_VENDOR_WEBGL:
2399 if (extensionEnabled(WebGLDebugRendererInfoName)) 2397 if (extensionEnabled(WebGLDebugRendererInfoName))
2400 return WebGLGetInfo(m_context->getString(GL_VENDOR)); 2398 return WebGLGetInfo(webContext()->getString(GL_VENDOR));
2401 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me, WEBGL_debug_renderer_info not enabled"); 2399 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me, WEBGL_debug_renderer_info not enabled");
2402 return WebGLGetInfo(); 2400 return WebGLGetInfo();
2403 case GL_VERTEX_ARRAY_BINDING_OES: // OES_vertex_array_object 2401 case GL_VERTEX_ARRAY_BINDING_OES: // OES_vertex_array_object
2404 if (extensionEnabled(OESVertexArrayObjectName)) { 2402 if (extensionEnabled(OESVertexArrayObjectName)) {
2405 if (!m_boundVertexArrayObject->isDefaultObject()) 2403 if (!m_boundVertexArrayObject->isDefaultObject())
2406 return WebGLGetInfo(PassRefPtr<WebGLVertexArrayObjectOES>(m_boun dVertexArrayObject)); 2404 return WebGLGetInfo(PassRefPtr<WebGLVertexArrayObjectOES>(m_boun dVertexArrayObject));
2407 return WebGLGetInfo(); 2405 return WebGLGetInfo();
2408 } 2406 }
2409 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me, OES_vertex_array_object not enabled"); 2407 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me, OES_vertex_array_object not enabled");
2410 return WebGLGetInfo(); 2408 return WebGLGetInfo();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2442 WebGLGetInfo WebGLRenderingContextBase::getProgramParameter(WebGLProgram* progra m, GLenum pname) 2440 WebGLGetInfo WebGLRenderingContextBase::getProgramParameter(WebGLProgram* progra m, GLenum pname)
2443 { 2441 {
2444 if (isContextLost() || !validateWebGLObject("getProgramParameter", program)) 2442 if (isContextLost() || !validateWebGLObject("getProgramParameter", program))
2445 return WebGLGetInfo(); 2443 return WebGLGetInfo();
2446 2444
2447 GLint value = 0; 2445 GLint value = 0;
2448 switch (pname) { 2446 switch (pname) {
2449 case GL_DELETE_STATUS: 2447 case GL_DELETE_STATUS:
2450 return WebGLGetInfo(program->isDeleted()); 2448 return WebGLGetInfo(program->isDeleted());
2451 case GL_VALIDATE_STATUS: 2449 case GL_VALIDATE_STATUS:
2452 m_context->getProgramiv(objectOrZero(program), pname, &value); 2450 webContext()->getProgramiv(objectOrZero(program), pname, &value);
2453 return WebGLGetInfo(static_cast<bool>(value)); 2451 return WebGLGetInfo(static_cast<bool>(value));
2454 case GL_LINK_STATUS: 2452 case GL_LINK_STATUS:
2455 return WebGLGetInfo(program->linkStatus()); 2453 return WebGLGetInfo(program->linkStatus());
2456 case GL_ATTACHED_SHADERS: 2454 case GL_ATTACHED_SHADERS:
2457 case GL_ACTIVE_ATTRIBUTES: 2455 case GL_ACTIVE_ATTRIBUTES:
2458 case GL_ACTIVE_UNIFORMS: 2456 case GL_ACTIVE_UNIFORMS:
2459 m_context->getProgramiv(objectOrZero(program), pname, &value); 2457 webContext()->getProgramiv(objectOrZero(program), pname, &value);
2460 return WebGLGetInfo(value); 2458 return WebGLGetInfo(value);
2461 default: 2459 default:
2462 synthesizeGLError(GL_INVALID_ENUM, "getProgramParameter", "invalid param eter name"); 2460 synthesizeGLError(GL_INVALID_ENUM, "getProgramParameter", "invalid param eter name");
2463 return WebGLGetInfo(); 2461 return WebGLGetInfo();
2464 } 2462 }
2465 } 2463 }
2466 2464
2467 String WebGLRenderingContextBase::getProgramInfoLog(WebGLProgram* program) 2465 String WebGLRenderingContextBase::getProgramInfoLog(WebGLProgram* program)
2468 { 2466 {
2469 if (isContextLost()) 2467 if (isContextLost())
2470 return String(); 2468 return String();
2471 if (!validateWebGLObject("getProgramInfoLog", program)) 2469 if (!validateWebGLObject("getProgramInfoLog", program))
2472 return ""; 2470 return "";
2473 return ensureNotNull(m_context->getProgramInfoLog(objectOrZero(program))); 2471 return ensureNotNull(webContext()->getProgramInfoLog(objectOrZero(program))) ;
2474 } 2472 }
2475 2473
2476 WebGLGetInfo WebGLRenderingContextBase::getRenderbufferParameter(GLenum target, GLenum pname) 2474 WebGLGetInfo WebGLRenderingContextBase::getRenderbufferParameter(GLenum target, GLenum pname)
2477 { 2475 {
2478 if (isContextLost()) 2476 if (isContextLost())
2479 return WebGLGetInfo(); 2477 return WebGLGetInfo();
2480 if (target != GL_RENDERBUFFER) { 2478 if (target != GL_RENDERBUFFER) {
2481 synthesizeGLError(GL_INVALID_ENUM, "getRenderbufferParameter", "invalid target"); 2479 synthesizeGLError(GL_INVALID_ENUM, "getRenderbufferParameter", "invalid target");
2482 return WebGLGetInfo(); 2480 return WebGLGetInfo();
2483 } 2481 }
2484 if (!m_renderbufferBinding || !m_renderbufferBinding->object()) { 2482 if (!m_renderbufferBinding || !m_renderbufferBinding->object()) {
2485 synthesizeGLError(GL_INVALID_OPERATION, "getRenderbufferParameter", "no renderbuffer bound"); 2483 synthesizeGLError(GL_INVALID_OPERATION, "getRenderbufferParameter", "no renderbuffer bound");
2486 return WebGLGetInfo(); 2484 return WebGLGetInfo();
2487 } 2485 }
2488 2486
2489 GLint value = 0; 2487 GLint value = 0;
2490 switch (pname) { 2488 switch (pname) {
2491 case GL_RENDERBUFFER_WIDTH: 2489 case GL_RENDERBUFFER_WIDTH:
2492 case GL_RENDERBUFFER_HEIGHT: 2490 case GL_RENDERBUFFER_HEIGHT:
2493 case GL_RENDERBUFFER_RED_SIZE: 2491 case GL_RENDERBUFFER_RED_SIZE:
2494 case GL_RENDERBUFFER_GREEN_SIZE: 2492 case GL_RENDERBUFFER_GREEN_SIZE:
2495 case GL_RENDERBUFFER_BLUE_SIZE: 2493 case GL_RENDERBUFFER_BLUE_SIZE:
2496 case GL_RENDERBUFFER_ALPHA_SIZE: 2494 case GL_RENDERBUFFER_ALPHA_SIZE:
2497 case GL_RENDERBUFFER_DEPTH_SIZE: 2495 case GL_RENDERBUFFER_DEPTH_SIZE:
2498 m_context->getRenderbufferParameteriv(target, pname, &value); 2496 webContext()->getRenderbufferParameteriv(target, pname, &value);
2499 return WebGLGetInfo(value); 2497 return WebGLGetInfo(value);
2500 case GL_RENDERBUFFER_STENCIL_SIZE: 2498 case GL_RENDERBUFFER_STENCIL_SIZE:
2501 if (m_renderbufferBinding->emulatedStencilBuffer()) { 2499 if (m_renderbufferBinding->emulatedStencilBuffer()) {
2502 m_context->bindRenderbuffer(target, objectOrZero(m_renderbufferBindi ng->emulatedStencilBuffer())); 2500 webContext()->bindRenderbuffer(target, objectOrZero(m_renderbufferBi nding->emulatedStencilBuffer()));
2503 m_context->getRenderbufferParameteriv(target, pname, &value); 2501 webContext()->getRenderbufferParameteriv(target, pname, &value);
2504 m_context->bindRenderbuffer(target, objectOrZero(m_renderbufferBindi ng.get())); 2502 webContext()->bindRenderbuffer(target, objectOrZero(m_renderbufferBi nding.get()));
2505 } else { 2503 } else {
2506 m_context->getRenderbufferParameteriv(target, pname, &value); 2504 webContext()->getRenderbufferParameteriv(target, pname, &value);
2507 } 2505 }
2508 return WebGLGetInfo(value); 2506 return WebGLGetInfo(value);
2509 case GL_RENDERBUFFER_INTERNAL_FORMAT: 2507 case GL_RENDERBUFFER_INTERNAL_FORMAT:
2510 return WebGLGetInfo(m_renderbufferBinding->internalFormat()); 2508 return WebGLGetInfo(m_renderbufferBinding->internalFormat());
2511 default: 2509 default:
2512 synthesizeGLError(GL_INVALID_ENUM, "getRenderbufferParameter", "invalid parameter name"); 2510 synthesizeGLError(GL_INVALID_ENUM, "getRenderbufferParameter", "invalid parameter name");
2513 return WebGLGetInfo(); 2511 return WebGLGetInfo();
2514 } 2512 }
2515 } 2513 }
2516 2514
2517 WebGLGetInfo WebGLRenderingContextBase::getShaderParameter(WebGLShader* shader, GLenum pname) 2515 WebGLGetInfo WebGLRenderingContextBase::getShaderParameter(WebGLShader* shader, GLenum pname)
2518 { 2516 {
2519 if (isContextLost() || !validateWebGLObject("getShaderParameter", shader)) 2517 if (isContextLost() || !validateWebGLObject("getShaderParameter", shader))
2520 return WebGLGetInfo(); 2518 return WebGLGetInfo();
2521 GLint value = 0; 2519 GLint value = 0;
2522 switch (pname) { 2520 switch (pname) {
2523 case GL_DELETE_STATUS: 2521 case GL_DELETE_STATUS:
2524 return WebGLGetInfo(shader->isDeleted()); 2522 return WebGLGetInfo(shader->isDeleted());
2525 case GL_COMPILE_STATUS: 2523 case GL_COMPILE_STATUS:
2526 m_context->getShaderiv(objectOrZero(shader), pname, &value); 2524 webContext()->getShaderiv(objectOrZero(shader), pname, &value);
2527 return WebGLGetInfo(static_cast<bool>(value)); 2525 return WebGLGetInfo(static_cast<bool>(value));
2528 case GL_SHADER_TYPE: 2526 case GL_SHADER_TYPE:
2529 m_context->getShaderiv(objectOrZero(shader), pname, &value); 2527 webContext()->getShaderiv(objectOrZero(shader), pname, &value);
2530 return WebGLGetInfo(static_cast<unsigned>(value)); 2528 return WebGLGetInfo(static_cast<unsigned>(value));
2531 default: 2529 default:
2532 synthesizeGLError(GL_INVALID_ENUM, "getShaderParameter", "invalid parame ter name"); 2530 synthesizeGLError(GL_INVALID_ENUM, "getShaderParameter", "invalid parame ter name");
2533 return WebGLGetInfo(); 2531 return WebGLGetInfo();
2534 } 2532 }
2535 } 2533 }
2536 2534
2537 String WebGLRenderingContextBase::getShaderInfoLog(WebGLShader* shader) 2535 String WebGLRenderingContextBase::getShaderInfoLog(WebGLShader* shader)
2538 { 2536 {
2539 if (isContextLost()) 2537 if (isContextLost())
2540 return String(); 2538 return String();
2541 if (!validateWebGLObject("getShaderInfoLog", shader)) 2539 if (!validateWebGLObject("getShaderInfoLog", shader))
2542 return ""; 2540 return "";
2543 return ensureNotNull(m_context->getShaderInfoLog(objectOrZero(shader))); 2541 return ensureNotNull(webContext()->getShaderInfoLog(objectOrZero(shader)));
2544 } 2542 }
2545 2543
2546 PassRefPtr<WebGLShaderPrecisionFormat> WebGLRenderingContextBase::getShaderPreci sionFormat(GLenum shaderType, GLenum precisionType) 2544 PassRefPtr<WebGLShaderPrecisionFormat> WebGLRenderingContextBase::getShaderPreci sionFormat(GLenum shaderType, GLenum precisionType)
2547 { 2545 {
2548 if (isContextLost()) 2546 if (isContextLost())
2549 return nullptr; 2547 return nullptr;
2550 switch (shaderType) { 2548 switch (shaderType) {
2551 case GL_VERTEX_SHADER: 2549 case GL_VERTEX_SHADER:
2552 case GL_FRAGMENT_SHADER: 2550 case GL_FRAGMENT_SHADER:
2553 break; 2551 break;
2554 default: 2552 default:
2555 synthesizeGLError(GL_INVALID_ENUM, "getShaderPrecisionFormat", "invalid shader type"); 2553 synthesizeGLError(GL_INVALID_ENUM, "getShaderPrecisionFormat", "invalid shader type");
2556 return nullptr; 2554 return nullptr;
2557 } 2555 }
2558 switch (precisionType) { 2556 switch (precisionType) {
2559 case GL_LOW_FLOAT: 2557 case GL_LOW_FLOAT:
2560 case GL_MEDIUM_FLOAT: 2558 case GL_MEDIUM_FLOAT:
2561 case GL_HIGH_FLOAT: 2559 case GL_HIGH_FLOAT:
2562 case GL_LOW_INT: 2560 case GL_LOW_INT:
2563 case GL_MEDIUM_INT: 2561 case GL_MEDIUM_INT:
2564 case GL_HIGH_INT: 2562 case GL_HIGH_INT:
2565 break; 2563 break;
2566 default: 2564 default:
2567 synthesizeGLError(GL_INVALID_ENUM, "getShaderPrecisionFormat", "invalid precision type"); 2565 synthesizeGLError(GL_INVALID_ENUM, "getShaderPrecisionFormat", "invalid precision type");
2568 return nullptr; 2566 return nullptr;
2569 } 2567 }
2570 2568
2571 GLint range[2] = {0, 0}; 2569 GLint range[2] = {0, 0};
2572 GLint precision = 0; 2570 GLint precision = 0;
2573 m_context->getShaderPrecisionFormat(shaderType, precisionType, range, &preci sion); 2571 webContext()->getShaderPrecisionFormat(shaderType, precisionType, range, &pr ecision);
2574 return WebGLShaderPrecisionFormat::create(range[0], range[1], precision); 2572 return WebGLShaderPrecisionFormat::create(range[0], range[1], precision);
2575 } 2573 }
2576 2574
2577 String WebGLRenderingContextBase::getShaderSource(WebGLShader* shader) 2575 String WebGLRenderingContextBase::getShaderSource(WebGLShader* shader)
2578 { 2576 {
2579 if (isContextLost()) 2577 if (isContextLost())
2580 return String(); 2578 return String();
2581 if (!validateWebGLObject("getShaderSource", shader)) 2579 if (!validateWebGLObject("getShaderSource", shader))
2582 return ""; 2580 return "";
2583 return ensureNotNull(shader->source()); 2581 return ensureNotNull(shader->source());
(...skipping 26 matching lines...) Expand all
2610 WebGLTexture* tex = validateTextureBinding("getTexParameter", target, false) ; 2608 WebGLTexture* tex = validateTextureBinding("getTexParameter", target, false) ;
2611 if (!tex) 2609 if (!tex)
2612 return WebGLGetInfo(); 2610 return WebGLGetInfo();
2613 switch (pname) { 2611 switch (pname) {
2614 case GL_TEXTURE_MAG_FILTER: 2612 case GL_TEXTURE_MAG_FILTER:
2615 case GL_TEXTURE_MIN_FILTER: 2613 case GL_TEXTURE_MIN_FILTER:
2616 case GL_TEXTURE_WRAP_S: 2614 case GL_TEXTURE_WRAP_S:
2617 case GL_TEXTURE_WRAP_T: 2615 case GL_TEXTURE_WRAP_T:
2618 { 2616 {
2619 GLint value = 0; 2617 GLint value = 0;
2620 m_context->getTexParameteriv(target, pname, &value); 2618 webContext()->getTexParameteriv(target, pname, &value);
2621 return WebGLGetInfo(static_cast<unsigned>(value)); 2619 return WebGLGetInfo(static_cast<unsigned>(value));
2622 } 2620 }
2623 case GL_TEXTURE_MAX_ANISOTROPY_EXT: // EXT_texture_filter_anisotropic 2621 case GL_TEXTURE_MAX_ANISOTROPY_EXT: // EXT_texture_filter_anisotropic
2624 if (extensionEnabled(EXTTextureFilterAnisotropicName)) { 2622 if (extensionEnabled(EXTTextureFilterAnisotropicName)) {
2625 GLfloat value = 0.f; 2623 GLfloat value = 0.f;
2626 m_context->getTexParameterfv(target, pname, &value); 2624 webContext()->getTexParameterfv(target, pname, &value);
2627 return WebGLGetInfo(value); 2625 return WebGLGetInfo(value);
2628 } 2626 }
2629 synthesizeGLError(GL_INVALID_ENUM, "getTexParameter", "invalid parameter name, EXT_texture_filter_anisotropic not enabled"); 2627 synthesizeGLError(GL_INVALID_ENUM, "getTexParameter", "invalid parameter name, EXT_texture_filter_anisotropic not enabled");
2630 return WebGLGetInfo(); 2628 return WebGLGetInfo();
2631 default: 2629 default:
2632 synthesizeGLError(GL_INVALID_ENUM, "getTexParameter", "invalid parameter name"); 2630 synthesizeGLError(GL_INVALID_ENUM, "getTexParameter", "invalid parameter name");
2633 return WebGLGetInfo(); 2631 return WebGLGetInfo();
2634 } 2632 }
2635 } 2633 }
2636 2634
2637 WebGLGetInfo WebGLRenderingContextBase::getUniform(WebGLProgram* program, const WebGLUniformLocation* uniformLocation) 2635 WebGLGetInfo WebGLRenderingContextBase::getUniform(WebGLProgram* program, const WebGLUniformLocation* uniformLocation)
2638 { 2636 {
2639 if (isContextLost() || !validateWebGLObject("getUniform", program)) 2637 if (isContextLost() || !validateWebGLObject("getUniform", program))
2640 return WebGLGetInfo(); 2638 return WebGLGetInfo();
2641 if (!uniformLocation || uniformLocation->program() != program) { 2639 if (!uniformLocation || uniformLocation->program() != program) {
2642 synthesizeGLError(GL_INVALID_OPERATION, "getUniform", "no uniformlocatio n or not valid for this program"); 2640 synthesizeGLError(GL_INVALID_OPERATION, "getUniform", "no uniformlocatio n or not valid for this program");
2643 return WebGLGetInfo(); 2641 return WebGLGetInfo();
2644 } 2642 }
2645 GLint location = uniformLocation->location(); 2643 GLint location = uniformLocation->location();
2646 2644
2647 // FIXME: make this more efficient using WebGLUniformLocation and caching ty pes in it 2645 // FIXME: make this more efficient using WebGLUniformLocation and caching ty pes in it
2648 GLint activeUniforms = 0; 2646 GLint activeUniforms = 0;
2649 m_context->getProgramiv(objectOrZero(program), GL_ACTIVE_UNIFORMS, &activeUn iforms); 2647 webContext()->getProgramiv(objectOrZero(program), GL_ACTIVE_UNIFORMS, &activ eUniforms);
2650 for (GLint i = 0; i < activeUniforms; i++) { 2648 for (GLint i = 0; i < activeUniforms; i++) {
2651 blink::WebGraphicsContext3D::ActiveInfo info; 2649 blink::WebGraphicsContext3D::ActiveInfo info;
2652 if (!m_context->getActiveUniform(objectOrZero(program), i, info)) 2650 if (!webContext()->getActiveUniform(objectOrZero(program), i, info))
2653 return WebGLGetInfo(); 2651 return WebGLGetInfo();
2654 String name = info.name; 2652 String name = info.name;
2655 StringBuilder nameBuilder; 2653 StringBuilder nameBuilder;
2656 // Strip "[0]" from the name if it's an array. 2654 // Strip "[0]" from the name if it's an array.
2657 if (info.size > 1 && name.endsWith("[0]")) 2655 if (info.size > 1 && name.endsWith("[0]"))
2658 info.name = name.left(name.length() - 3); 2656 info.name = name.left(name.length() - 3);
2659 // If it's an array, we need to iterate through each element, appending "[index]" to the name. 2657 // If it's an array, we need to iterate through each element, appending "[index]" to the name.
2660 for (GLint index = 0; index < info.size; ++index) { 2658 for (GLint index = 0; index < info.size; ++index) {
2661 nameBuilder.clear(); 2659 nameBuilder.clear();
2662 nameBuilder.append(info.name); 2660 nameBuilder.append(info.name);
2663 if (info.size > 1 && index >= 1) { 2661 if (info.size > 1 && index >= 1) {
2664 nameBuilder.append('['); 2662 nameBuilder.append('[');
2665 nameBuilder.append(String::number(index)); 2663 nameBuilder.append(String::number(index));
2666 nameBuilder.append(']'); 2664 nameBuilder.append(']');
2667 } 2665 }
2668 // Now need to look this up by name again to find its location 2666 // Now need to look this up by name again to find its location
2669 GLint loc = m_context->getUniformLocation(objectOrZero(program), nam eBuilder.toString().utf8().data()); 2667 GLint loc = webContext()->getUniformLocation(objectOrZero(program), nameBuilder.toString().utf8().data());
2670 if (loc == location) { 2668 if (loc == location) {
2671 // Found it. Use the type in the ActiveInfo to determine the ret urn type. 2669 // Found it. Use the type in the ActiveInfo to determine the ret urn type.
2672 GLenum baseType; 2670 GLenum baseType;
2673 unsigned length; 2671 unsigned length;
2674 switch (info.type) { 2672 switch (info.type) {
2675 case GL_BOOL: 2673 case GL_BOOL:
2676 baseType = GL_BOOL; 2674 baseType = GL_BOOL;
2677 length = 1; 2675 length = 1;
2678 break; 2676 break;
2679 case GL_BOOL_VEC2: 2677 case GL_BOOL_VEC2:
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
2738 length = 1; 2736 length = 1;
2739 break; 2737 break;
2740 default: 2738 default:
2741 // Can't handle this type 2739 // Can't handle this type
2742 synthesizeGLError(GL_INVALID_VALUE, "getUniform", "unhandled type"); 2740 synthesizeGLError(GL_INVALID_VALUE, "getUniform", "unhandled type");
2743 return WebGLGetInfo(); 2741 return WebGLGetInfo();
2744 } 2742 }
2745 switch (baseType) { 2743 switch (baseType) {
2746 case GL_FLOAT: { 2744 case GL_FLOAT: {
2747 GLfloat value[16] = {0}; 2745 GLfloat value[16] = {0};
2748 m_context->getUniformfv(objectOrZero(program), location, val ue); 2746 webContext()->getUniformfv(objectOrZero(program), location, value);
2749 if (length == 1) 2747 if (length == 1)
2750 return WebGLGetInfo(value[0]); 2748 return WebGLGetInfo(value[0]);
2751 return WebGLGetInfo(Float32Array::create(value, length)); 2749 return WebGLGetInfo(Float32Array::create(value, length));
2752 } 2750 }
2753 case GL_INT: { 2751 case GL_INT: {
2754 GLint value[4] = {0}; 2752 GLint value[4] = {0};
2755 m_context->getUniformiv(objectOrZero(program), location, val ue); 2753 webContext()->getUniformiv(objectOrZero(program), location, value);
2756 if (length == 1) 2754 if (length == 1)
2757 return WebGLGetInfo(value[0]); 2755 return WebGLGetInfo(value[0]);
2758 return WebGLGetInfo(Int32Array::create(value, length)); 2756 return WebGLGetInfo(Int32Array::create(value, length));
2759 } 2757 }
2760 case GL_BOOL: { 2758 case GL_BOOL: {
2761 GLint value[4] = {0}; 2759 GLint value[4] = {0};
2762 m_context->getUniformiv(objectOrZero(program), location, val ue); 2760 webContext()->getUniformiv(objectOrZero(program), location, value);
2763 if (length > 1) { 2761 if (length > 1) {
2764 bool boolValue[16] = {0}; 2762 bool boolValue[16] = {0};
2765 for (unsigned j = 0; j < length; j++) 2763 for (unsigned j = 0; j < length; j++)
2766 boolValue[j] = static_cast<bool>(value[j]); 2764 boolValue[j] = static_cast<bool>(value[j]);
2767 return WebGLGetInfo(boolValue, length); 2765 return WebGLGetInfo(boolValue, length);
2768 } 2766 }
2769 return WebGLGetInfo(static_cast<bool>(value[0])); 2767 return WebGLGetInfo(static_cast<bool>(value[0]));
2770 } 2768 }
2771 default: 2769 default:
2772 notImplemented(); 2770 notImplemented();
(...skipping 13 matching lines...) Expand all
2786 if (!validateLocationLength("getUniformLocation", name)) 2784 if (!validateLocationLength("getUniformLocation", name))
2787 return nullptr; 2785 return nullptr;
2788 if (!validateString("getUniformLocation", name)) 2786 if (!validateString("getUniformLocation", name))
2789 return nullptr; 2787 return nullptr;
2790 if (isPrefixReserved(name)) 2788 if (isPrefixReserved(name))
2791 return nullptr; 2789 return nullptr;
2792 if (!program->linkStatus()) { 2790 if (!program->linkStatus()) {
2793 synthesizeGLError(GL_INVALID_OPERATION, "getUniformLocation", "program n ot linked"); 2791 synthesizeGLError(GL_INVALID_OPERATION, "getUniformLocation", "program n ot linked");
2794 return nullptr; 2792 return nullptr;
2795 } 2793 }
2796 GLint uniformLocation = m_context->getUniformLocation(objectOrZero(program), name.utf8().data()); 2794 GLint uniformLocation = webContext()->getUniformLocation(objectOrZero(progra m), name.utf8().data());
2797 if (uniformLocation == -1) 2795 if (uniformLocation == -1)
2798 return nullptr; 2796 return nullptr;
2799 return WebGLUniformLocation::create(program, uniformLocation); 2797 return WebGLUniformLocation::create(program, uniformLocation);
2800 } 2798 }
2801 2799
2802 WebGLGetInfo WebGLRenderingContextBase::getVertexAttrib(GLuint index, GLenum pna me) 2800 WebGLGetInfo WebGLRenderingContextBase::getVertexAttrib(GLuint index, GLenum pna me)
2803 { 2801 {
2804 if (isContextLost()) 2802 if (isContextLost())
2805 return WebGLGetInfo(); 2803 return WebGLGetInfo();
2806 if (index >= m_maxVertexAttribs) { 2804 if (index >= m_maxVertexAttribs) {
(...skipping 29 matching lines...) Expand all
2836 } 2834 }
2837 2835
2838 long long WebGLRenderingContextBase::getVertexAttribOffset(GLuint index, GLenum pname) 2836 long long WebGLRenderingContextBase::getVertexAttribOffset(GLuint index, GLenum pname)
2839 { 2837 {
2840 if (isContextLost()) 2838 if (isContextLost())
2841 return 0; 2839 return 0;
2842 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER) { 2840 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER) {
2843 synthesizeGLError(GL_INVALID_ENUM, "getVertexAttribOffset", "invalid par ameter name"); 2841 synthesizeGLError(GL_INVALID_ENUM, "getVertexAttribOffset", "invalid par ameter name");
2844 return 0; 2842 return 0;
2845 } 2843 }
2846 GLsizeiptr result = m_context->getVertexAttribOffset(index, pname); 2844 GLsizeiptr result = webContext()->getVertexAttribOffset(index, pname);
2847 return static_cast<long long>(result); 2845 return static_cast<long long>(result);
2848 } 2846 }
2849 2847
2850 void WebGLRenderingContextBase::hint(GLenum target, GLenum mode) 2848 void WebGLRenderingContextBase::hint(GLenum target, GLenum mode)
2851 { 2849 {
2852 if (isContextLost()) 2850 if (isContextLost())
2853 return; 2851 return;
2854 bool isValid = false; 2852 bool isValid = false;
2855 switch (target) { 2853 switch (target) {
2856 case GL_GENERATE_MIPMAP_HINT: 2854 case GL_GENERATE_MIPMAP_HINT:
2857 isValid = true; 2855 isValid = true;
2858 break; 2856 break;
2859 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES: // OES_standard_derivatives 2857 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES: // OES_standard_derivatives
2860 if (extensionEnabled(OESStandardDerivativesName)) 2858 if (extensionEnabled(OESStandardDerivativesName))
2861 isValid = true; 2859 isValid = true;
2862 break; 2860 break;
2863 } 2861 }
2864 if (!isValid) { 2862 if (!isValid) {
2865 synthesizeGLError(GL_INVALID_ENUM, "hint", "invalid target"); 2863 synthesizeGLError(GL_INVALID_ENUM, "hint", "invalid target");
2866 return; 2864 return;
2867 } 2865 }
2868 m_context->hint(target, mode); 2866 webContext()->hint(target, mode);
2869 } 2867 }
2870 2868
2871 GLboolean WebGLRenderingContextBase::isBuffer(WebGLBuffer* buffer) 2869 GLboolean WebGLRenderingContextBase::isBuffer(WebGLBuffer* buffer)
2872 { 2870 {
2873 if (!buffer || isContextLost()) 2871 if (!buffer || isContextLost())
2874 return 0; 2872 return 0;
2875 2873
2876 if (!buffer->hasEverBeenBound()) 2874 if (!buffer->hasEverBeenBound())
2877 return 0; 2875 return 0;
2878 2876
2879 return m_context->isBuffer(buffer->object()); 2877 return webContext()->isBuffer(buffer->object());
2880 } 2878 }
2881 2879
2882 bool WebGLRenderingContextBase::isContextLost() 2880 bool WebGLRenderingContextBase::isContextLost() const
2883 { 2881 {
2884 return m_contextLost; 2882 return m_contextLost;
2885 } 2883 }
2886 2884
2887 GLboolean WebGLRenderingContextBase::isEnabled(GLenum cap) 2885 GLboolean WebGLRenderingContextBase::isEnabled(GLenum cap)
2888 { 2886 {
2889 if (isContextLost() || !validateCapability("isEnabled", cap)) 2887 if (isContextLost() || !validateCapability("isEnabled", cap))
2890 return 0; 2888 return 0;
2891 if (cap == GL_STENCIL_TEST) 2889 if (cap == GL_STENCIL_TEST)
2892 return m_stencilEnabled; 2890 return m_stencilEnabled;
2893 return m_context->isEnabled(cap); 2891 return webContext()->isEnabled(cap);
2894 } 2892 }
2895 2893
2896 GLboolean WebGLRenderingContextBase::isFramebuffer(WebGLFramebuffer* framebuffer ) 2894 GLboolean WebGLRenderingContextBase::isFramebuffer(WebGLFramebuffer* framebuffer )
2897 { 2895 {
2898 if (!framebuffer || isContextLost()) 2896 if (!framebuffer || isContextLost())
2899 return 0; 2897 return 0;
2900 2898
2901 if (!framebuffer->hasEverBeenBound()) 2899 if (!framebuffer->hasEverBeenBound())
2902 return 0; 2900 return 0;
2903 2901
2904 return m_context->isFramebuffer(framebuffer->object()); 2902 return webContext()->isFramebuffer(framebuffer->object());
2905 } 2903 }
2906 2904
2907 GLboolean WebGLRenderingContextBase::isProgram(WebGLProgram* program) 2905 GLboolean WebGLRenderingContextBase::isProgram(WebGLProgram* program)
2908 { 2906 {
2909 if (!program || isContextLost()) 2907 if (!program || isContextLost())
2910 return 0; 2908 return 0;
2911 2909
2912 return m_context->isProgram(program->object()); 2910 return webContext()->isProgram(program->object());
2913 } 2911 }
2914 2912
2915 GLboolean WebGLRenderingContextBase::isRenderbuffer(WebGLRenderbuffer* renderbuf fer) 2913 GLboolean WebGLRenderingContextBase::isRenderbuffer(WebGLRenderbuffer* renderbuf fer)
2916 { 2914 {
2917 if (!renderbuffer || isContextLost()) 2915 if (!renderbuffer || isContextLost())
2918 return 0; 2916 return 0;
2919 2917
2920 if (!renderbuffer->hasEverBeenBound()) 2918 if (!renderbuffer->hasEverBeenBound())
2921 return 0; 2919 return 0;
2922 2920
2923 return m_context->isRenderbuffer(renderbuffer->object()); 2921 return webContext()->isRenderbuffer(renderbuffer->object());
2924 } 2922 }
2925 2923
2926 GLboolean WebGLRenderingContextBase::isShader(WebGLShader* shader) 2924 GLboolean WebGLRenderingContextBase::isShader(WebGLShader* shader)
2927 { 2925 {
2928 if (!shader || isContextLost()) 2926 if (!shader || isContextLost())
2929 return 0; 2927 return 0;
2930 2928
2931 return m_context->isShader(shader->object()); 2929 return webContext()->isShader(shader->object());
2932 } 2930 }
2933 2931
2934 GLboolean WebGLRenderingContextBase::isTexture(WebGLTexture* texture) 2932 GLboolean WebGLRenderingContextBase::isTexture(WebGLTexture* texture)
2935 { 2933 {
2936 if (!texture || isContextLost()) 2934 if (!texture || isContextLost())
2937 return 0; 2935 return 0;
2938 2936
2939 if (!texture->hasEverBeenBound()) 2937 if (!texture->hasEverBeenBound())
2940 return 0; 2938 return 0;
2941 2939
2942 return m_context->isTexture(texture->object()); 2940 return webContext()->isTexture(texture->object());
2943 } 2941 }
2944 2942
2945 void WebGLRenderingContextBase::lineWidth(GLfloat width) 2943 void WebGLRenderingContextBase::lineWidth(GLfloat width)
2946 { 2944 {
2947 if (isContextLost()) 2945 if (isContextLost())
2948 return; 2946 return;
2949 m_context->lineWidth(width); 2947 webContext()->lineWidth(width);
2950 } 2948 }
2951 2949
2952 void WebGLRenderingContextBase::linkProgram(WebGLProgram* program) 2950 void WebGLRenderingContextBase::linkProgram(WebGLProgram* program)
2953 { 2951 {
2954 if (isContextLost() || !validateWebGLObject("linkProgram", program)) 2952 if (isContextLost() || !validateWebGLObject("linkProgram", program))
2955 return; 2953 return;
2956 2954
2957 m_context->linkProgram(objectOrZero(program)); 2955 webContext()->linkProgram(objectOrZero(program));
2958 program->increaseLinkCount(); 2956 program->increaseLinkCount();
2959 } 2957 }
2960 2958
2961 void WebGLRenderingContextBase::pixelStorei(GLenum pname, GLint param) 2959 void WebGLRenderingContextBase::pixelStorei(GLenum pname, GLint param)
2962 { 2960 {
2963 if (isContextLost()) 2961 if (isContextLost())
2964 return; 2962 return;
2965 switch (pname) { 2963 switch (pname) {
2966 case GC3D_UNPACK_FLIP_Y_WEBGL: 2964 case GC3D_UNPACK_FLIP_Y_WEBGL:
2967 m_unpackFlipY = param; 2965 m_unpackFlipY = param;
(...skipping 11 matching lines...) Expand all
2979 break; 2977 break;
2980 case GL_PACK_ALIGNMENT: 2978 case GL_PACK_ALIGNMENT:
2981 case GL_UNPACK_ALIGNMENT: 2979 case GL_UNPACK_ALIGNMENT:
2982 if (param == 1 || param == 2 || param == 4 || param == 8) { 2980 if (param == 1 || param == 2 || param == 4 || param == 8) {
2983 if (pname == GL_PACK_ALIGNMENT) { 2981 if (pname == GL_PACK_ALIGNMENT) {
2984 m_packAlignment = param; 2982 m_packAlignment = param;
2985 m_drawingBuffer->setPackAlignment(param); 2983 m_drawingBuffer->setPackAlignment(param);
2986 } else { // GL_UNPACK_ALIGNMENT: 2984 } else { // GL_UNPACK_ALIGNMENT:
2987 m_unpackAlignment = param; 2985 m_unpackAlignment = param;
2988 } 2986 }
2989 m_context->pixelStorei(pname, param); 2987 webContext()->pixelStorei(pname, param);
2990 } else { 2988 } else {
2991 synthesizeGLError(GL_INVALID_VALUE, "pixelStorei", "invalid paramete r for alignment"); 2989 synthesizeGLError(GL_INVALID_VALUE, "pixelStorei", "invalid paramete r for alignment");
2992 return; 2990 return;
2993 } 2991 }
2994 break; 2992 break;
2995 default: 2993 default:
2996 synthesizeGLError(GL_INVALID_ENUM, "pixelStorei", "invalid parameter nam e"); 2994 synthesizeGLError(GL_INVALID_ENUM, "pixelStorei", "invalid parameter nam e");
2997 return; 2995 return;
2998 } 2996 }
2999 } 2997 }
3000 2998
3001 void WebGLRenderingContextBase::polygonOffset(GLfloat factor, GLfloat units) 2999 void WebGLRenderingContextBase::polygonOffset(GLfloat factor, GLfloat units)
3002 { 3000 {
3003 if (isContextLost()) 3001 if (isContextLost())
3004 return; 3002 return;
3005 m_context->polygonOffset(factor, units); 3003 webContext()->polygonOffset(factor, units);
3006 } 3004 }
3007 3005
3008 void WebGLRenderingContextBase::readPixels(GLint x, GLint y, GLsizei width, GLsi zei height, GLenum format, GLenum type, ArrayBufferView* pixels) 3006 void WebGLRenderingContextBase::readPixels(GLint x, GLint y, GLsizei width, GLsi zei height, GLenum format, GLenum type, ArrayBufferView* pixels)
3009 { 3007 {
3010 if (isContextLost()) 3008 if (isContextLost())
3011 return; 3009 return;
3012 // Due to WebGL's same-origin restrictions, it is not possible to 3010 // Due to WebGL's same-origin restrictions, it is not possible to
3013 // taint the origin using the WebGL API. 3011 // taint the origin using the WebGL API.
3014 ASSERT(canvas()->originClean()); 3012 ASSERT(canvas()->originClean());
3015 // Validate input parameters. 3013 // Validate input parameters.
(...skipping 23 matching lines...) Expand all
3039 if (format != GL_RGBA || type != GL_UNSIGNED_BYTE) { 3037 if (format != GL_RGBA || type != GL_UNSIGNED_BYTE) {
3040 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "format not RGBA o r type not UNSIGNED_BYTE"); 3038 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "format not RGBA o r type not UNSIGNED_BYTE");
3041 return; 3039 return;
3042 } 3040 }
3043 // Validate array type against pixel type. 3041 // Validate array type against pixel type.
3044 if (pixels->type() != ArrayBufferView::TypeUint8) { 3042 if (pixels->type() != ArrayBufferView::TypeUint8) {
3045 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "ArrayBufferView n ot Uint8Array"); 3043 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "ArrayBufferView n ot Uint8Array");
3046 return; 3044 return;
3047 } 3045 }
3048 const char* reason = "framebuffer incomplete"; 3046 const char* reason = "framebuffer incomplete";
3049 if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context.get(), &reason)) { 3047 if (m_framebufferBinding && !m_framebufferBinding->onAccess(webContext(), &r eason)) {
3050 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "readPixels", reason ); 3048 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "readPixels", reason );
3051 return; 3049 return;
3052 } 3050 }
3053 // Calculate array size, taking into consideration of PACK_ALIGNMENT. 3051 // Calculate array size, taking into consideration of PACK_ALIGNMENT.
3054 unsigned totalBytesRequired = 0; 3052 unsigned totalBytesRequired = 0;
3055 unsigned padding = 0; 3053 unsigned padding = 0;
3056 GLenum error = WebGLImageConversion::computeImageSizeInBytes(format, type, w idth, height, m_packAlignment, &totalBytesRequired, &padding); 3054 GLenum error = WebGLImageConversion::computeImageSizeInBytes(format, type, w idth, height, m_packAlignment, &totalBytesRequired, &padding);
3057 if (error != GL_NO_ERROR) { 3055 if (error != GL_NO_ERROR) {
3058 synthesizeGLError(error, "readPixels", "invalid dimensions"); 3056 synthesizeGLError(error, "readPixels", "invalid dimensions");
3059 return; 3057 return;
3060 } 3058 }
3061 if (pixels->byteLength() < totalBytesRequired) { 3059 if (pixels->byteLength() < totalBytesRequired) {
3062 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "ArrayBufferView n ot large enough for dimensions"); 3060 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "ArrayBufferView n ot large enough for dimensions");
3063 return; 3061 return;
3064 } 3062 }
3065 3063
3066 clearIfComposited(); 3064 clearIfComposited();
3067 void* data = pixels->baseAddress(); 3065 void* data = pixels->baseAddress();
3068 3066
3069 { 3067 {
3070 ScopedDrawingBufferBinder binder(m_drawingBuffer.get(), m_framebufferBin ding.get()); 3068 ScopedDrawingBufferBinder binder(m_drawingBuffer.get(), m_framebufferBin ding.get());
3071 m_context->readPixels(x, y, width, height, format, type, data); 3069 webContext()->readPixels(x, y, width, height, format, type, data);
3072 } 3070 }
3073 3071
3074 #if OS(MACOSX) 3072 #if OS(MACOSX)
3075 // FIXME: remove this section when GL driver bug on Mac is fixed, i.e., 3073 // FIXME: remove this section when GL driver bug on Mac is fixed, i.e.,
3076 // when alpha is off, readPixels should set alpha to 255 instead of 0. 3074 // when alpha is off, readPixels should set alpha to 255 instead of 0.
3077 if (!m_framebufferBinding && !m_context->getContextAttributes().alpha) { 3075 if (!m_framebufferBinding && !webContext()->getContextAttributes().alpha) {
3078 unsigned char* pixels = reinterpret_cast<unsigned char*>(data); 3076 unsigned char* pixels = reinterpret_cast<unsigned char*>(data);
3079 for (GLsizei iy = 0; iy < height; ++iy) { 3077 for (GLsizei iy = 0; iy < height; ++iy) {
3080 for (GLsizei ix = 0; ix < width; ++ix) { 3078 for (GLsizei ix = 0; ix < width; ++ix) {
3081 pixels[3] = 255; 3079 pixels[3] = 255;
3082 pixels += 4; 3080 pixels += 4;
3083 } 3081 }
3084 pixels += padding; 3082 pixels += padding;
3085 } 3083 }
3086 } 3084 }
3087 #endif 3085 #endif
(...skipping 12 matching lines...) Expand all
3100 return; 3098 return;
3101 } 3099 }
3102 if (!validateSize("renderbufferStorage", width, height)) 3100 if (!validateSize("renderbufferStorage", width, height))
3103 return; 3101 return;
3104 switch (internalformat) { 3102 switch (internalformat) {
3105 case GL_DEPTH_COMPONENT16: 3103 case GL_DEPTH_COMPONENT16:
3106 case GL_RGBA4: 3104 case GL_RGBA4:
3107 case GL_RGB5_A1: 3105 case GL_RGB5_A1:
3108 case GL_RGB565: 3106 case GL_RGB565:
3109 case GL_STENCIL_INDEX8: 3107 case GL_STENCIL_INDEX8:
3110 m_context->renderbufferStorage(target, internalformat, width, height); 3108 webContext()->renderbufferStorage(target, internalformat, width, height) ;
3111 m_renderbufferBinding->setInternalFormat(internalformat); 3109 m_renderbufferBinding->setInternalFormat(internalformat);
3112 m_renderbufferBinding->setSize(width, height); 3110 m_renderbufferBinding->setSize(width, height);
3113 m_renderbufferBinding->deleteEmulatedStencilBuffer(m_context.get()); 3111 m_renderbufferBinding->deleteEmulatedStencilBuffer(webContext());
3114 break; 3112 break;
3115 case GL_DEPTH_STENCIL_OES: 3113 case GL_DEPTH_STENCIL_OES:
3116 if (isDepthStencilSupported()) { 3114 if (isDepthStencilSupported()) {
3117 m_context->renderbufferStorage(target, GL_DEPTH24_STENCIL8_OES, widt h, height); 3115 webContext()->renderbufferStorage(target, GL_DEPTH24_STENCIL8_OES, w idth, height);
3118 } else { 3116 } else {
3119 WebGLRenderbuffer* emulatedStencilBuffer = ensureEmulatedStencilBuff er(target, m_renderbufferBinding.get()); 3117 WebGLRenderbuffer* emulatedStencilBuffer = ensureEmulatedStencilBuff er(target, m_renderbufferBinding.get());
3120 if (!emulatedStencilBuffer) { 3118 if (!emulatedStencilBuffer) {
3121 synthesizeGLError(GL_OUT_OF_MEMORY, "renderbufferStorage", "out of memory"); 3119 synthesizeGLError(GL_OUT_OF_MEMORY, "renderbufferStorage", "out of memory");
3122 return; 3120 return;
3123 } 3121 }
3124 m_context->renderbufferStorage(target, GL_DEPTH_COMPONENT16, width, height); 3122 webContext()->renderbufferStorage(target, GL_DEPTH_COMPONENT16, widt h, height);
3125 m_context->bindRenderbuffer(target, objectOrZero(emulatedStencilBuff er)); 3123 webContext()->bindRenderbuffer(target, objectOrZero(emulatedStencilB uffer));
3126 m_context->renderbufferStorage(target, GL_STENCIL_INDEX8, width, hei ght); 3124 webContext()->renderbufferStorage(target, GL_STENCIL_INDEX8, width, height);
3127 m_context->bindRenderbuffer(target, objectOrZero(m_renderbufferBindi ng.get())); 3125 webContext()->bindRenderbuffer(target, objectOrZero(m_renderbufferBi nding.get()));
3128 emulatedStencilBuffer->setSize(width, height); 3126 emulatedStencilBuffer->setSize(width, height);
3129 emulatedStencilBuffer->setInternalFormat(GL_STENCIL_INDEX8); 3127 emulatedStencilBuffer->setInternalFormat(GL_STENCIL_INDEX8);
3130 } 3128 }
3131 m_renderbufferBinding->setSize(width, height); 3129 m_renderbufferBinding->setSize(width, height);
3132 m_renderbufferBinding->setInternalFormat(internalformat); 3130 m_renderbufferBinding->setInternalFormat(internalformat);
3133 break; 3131 break;
3134 default: 3132 default:
3135 synthesizeGLError(GL_INVALID_ENUM, "renderbufferStorage", "invalid inter nalformat"); 3133 synthesizeGLError(GL_INVALID_ENUM, "renderbufferStorage", "invalid inter nalformat");
3136 return; 3134 return;
3137 } 3135 }
3138 applyStencilTest(); 3136 applyStencilTest();
3139 } 3137 }
3140 3138
3141 void WebGLRenderingContextBase::sampleCoverage(GLfloat value, GLboolean invert) 3139 void WebGLRenderingContextBase::sampleCoverage(GLfloat value, GLboolean invert)
3142 { 3140 {
3143 if (isContextLost()) 3141 if (isContextLost())
3144 return; 3142 return;
3145 m_context->sampleCoverage(value, invert); 3143 webContext()->sampleCoverage(value, invert);
3146 } 3144 }
3147 3145
3148 void WebGLRenderingContextBase::scissor(GLint x, GLint y, GLsizei width, GLsizei height) 3146 void WebGLRenderingContextBase::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
3149 { 3147 {
3150 if (isContextLost()) 3148 if (isContextLost())
3151 return; 3149 return;
3152 if (!validateSize("scissor", width, height)) 3150 if (!validateSize("scissor", width, height))
3153 return; 3151 return;
3154 m_context->scissor(x, y, width, height); 3152 webContext()->scissor(x, y, width, height);
3155 } 3153 }
3156 3154
3157 void WebGLRenderingContextBase::shaderSource(WebGLShader* shader, const String& string) 3155 void WebGLRenderingContextBase::shaderSource(WebGLShader* shader, const String& string)
3158 { 3156 {
3159 if (isContextLost() || !validateWebGLObject("shaderSource", shader)) 3157 if (isContextLost() || !validateWebGLObject("shaderSource", shader))
3160 return; 3158 return;
3161 String stringWithoutComments = StripComments(string).result(); 3159 String stringWithoutComments = StripComments(string).result();
3162 if (!validateString("shaderSource", stringWithoutComments)) 3160 if (!validateString("shaderSource", stringWithoutComments))
3163 return; 3161 return;
3164 shader->setSource(string); 3162 shader->setSource(string);
3165 m_context->shaderSource(objectOrZero(shader), stringWithoutComments.utf8().d ata()); 3163 webContext()->shaderSource(objectOrZero(shader), stringWithoutComments.utf8( ).data());
3166 } 3164 }
3167 3165
3168 void WebGLRenderingContextBase::stencilFunc(GLenum func, GLint ref, GLuint mask) 3166 void WebGLRenderingContextBase::stencilFunc(GLenum func, GLint ref, GLuint mask)
3169 { 3167 {
3170 if (isContextLost()) 3168 if (isContextLost())
3171 return; 3169 return;
3172 if (!validateStencilOrDepthFunc("stencilFunc", func)) 3170 if (!validateStencilOrDepthFunc("stencilFunc", func))
3173 return; 3171 return;
3174 m_stencilFuncRef = ref; 3172 m_stencilFuncRef = ref;
3175 m_stencilFuncRefBack = ref; 3173 m_stencilFuncRefBack = ref;
3176 m_stencilFuncMask = mask; 3174 m_stencilFuncMask = mask;
3177 m_stencilFuncMaskBack = mask; 3175 m_stencilFuncMaskBack = mask;
3178 m_context->stencilFunc(func, ref, mask); 3176 webContext()->stencilFunc(func, ref, mask);
3179 } 3177 }
3180 3178
3181 void WebGLRenderingContextBase::stencilFuncSeparate(GLenum face, GLenum func, GL int ref, GLuint mask) 3179 void WebGLRenderingContextBase::stencilFuncSeparate(GLenum face, GLenum func, GL int ref, GLuint mask)
3182 { 3180 {
3183 if (isContextLost()) 3181 if (isContextLost())
3184 return; 3182 return;
3185 if (!validateStencilOrDepthFunc("stencilFuncSeparate", func)) 3183 if (!validateStencilOrDepthFunc("stencilFuncSeparate", func))
3186 return; 3184 return;
3187 switch (face) { 3185 switch (face) {
3188 case GL_FRONT_AND_BACK: 3186 case GL_FRONT_AND_BACK:
3189 m_stencilFuncRef = ref; 3187 m_stencilFuncRef = ref;
3190 m_stencilFuncRefBack = ref; 3188 m_stencilFuncRefBack = ref;
3191 m_stencilFuncMask = mask; 3189 m_stencilFuncMask = mask;
3192 m_stencilFuncMaskBack = mask; 3190 m_stencilFuncMaskBack = mask;
3193 break; 3191 break;
3194 case GL_FRONT: 3192 case GL_FRONT:
3195 m_stencilFuncRef = ref; 3193 m_stencilFuncRef = ref;
3196 m_stencilFuncMask = mask; 3194 m_stencilFuncMask = mask;
3197 break; 3195 break;
3198 case GL_BACK: 3196 case GL_BACK:
3199 m_stencilFuncRefBack = ref; 3197 m_stencilFuncRefBack = ref;
3200 m_stencilFuncMaskBack = mask; 3198 m_stencilFuncMaskBack = mask;
3201 break; 3199 break;
3202 default: 3200 default:
3203 synthesizeGLError(GL_INVALID_ENUM, "stencilFuncSeparate", "invalid face" ); 3201 synthesizeGLError(GL_INVALID_ENUM, "stencilFuncSeparate", "invalid face" );
3204 return; 3202 return;
3205 } 3203 }
3206 m_context->stencilFuncSeparate(face, func, ref, mask); 3204 webContext()->stencilFuncSeparate(face, func, ref, mask);
3207 } 3205 }
3208 3206
3209 void WebGLRenderingContextBase::stencilMask(GLuint mask) 3207 void WebGLRenderingContextBase::stencilMask(GLuint mask)
3210 { 3208 {
3211 if (isContextLost()) 3209 if (isContextLost())
3212 return; 3210 return;
3213 m_stencilMask = mask; 3211 m_stencilMask = mask;
3214 m_stencilMaskBack = mask; 3212 m_stencilMaskBack = mask;
3215 m_context->stencilMask(mask); 3213 webContext()->stencilMask(mask);
3216 } 3214 }
3217 3215
3218 void WebGLRenderingContextBase::stencilMaskSeparate(GLenum face, GLuint mask) 3216 void WebGLRenderingContextBase::stencilMaskSeparate(GLenum face, GLuint mask)
3219 { 3217 {
3220 if (isContextLost()) 3218 if (isContextLost())
3221 return; 3219 return;
3222 switch (face) { 3220 switch (face) {
3223 case GL_FRONT_AND_BACK: 3221 case GL_FRONT_AND_BACK:
3224 m_stencilMask = mask; 3222 m_stencilMask = mask;
3225 m_stencilMaskBack = mask; 3223 m_stencilMaskBack = mask;
3226 break; 3224 break;
3227 case GL_FRONT: 3225 case GL_FRONT:
3228 m_stencilMask = mask; 3226 m_stencilMask = mask;
3229 break; 3227 break;
3230 case GL_BACK: 3228 case GL_BACK:
3231 m_stencilMaskBack = mask; 3229 m_stencilMaskBack = mask;
3232 break; 3230 break;
3233 default: 3231 default:
3234 synthesizeGLError(GL_INVALID_ENUM, "stencilMaskSeparate", "invalid face" ); 3232 synthesizeGLError(GL_INVALID_ENUM, "stencilMaskSeparate", "invalid face" );
3235 return; 3233 return;
3236 } 3234 }
3237 m_context->stencilMaskSeparate(face, mask); 3235 webContext()->stencilMaskSeparate(face, mask);
3238 } 3236 }
3239 3237
3240 void WebGLRenderingContextBase::stencilOp(GLenum fail, GLenum zfail, GLenum zpas s) 3238 void WebGLRenderingContextBase::stencilOp(GLenum fail, GLenum zfail, GLenum zpas s)
3241 { 3239 {
3242 if (isContextLost()) 3240 if (isContextLost())
3243 return; 3241 return;
3244 m_context->stencilOp(fail, zfail, zpass); 3242 webContext()->stencilOp(fail, zfail, zpass);
3245 } 3243 }
3246 3244
3247 void WebGLRenderingContextBase::stencilOpSeparate(GLenum face, GLenum fail, GLen um zfail, GLenum zpass) 3245 void WebGLRenderingContextBase::stencilOpSeparate(GLenum face, GLenum fail, GLen um zfail, GLenum zpass)
3248 { 3246 {
3249 if (isContextLost()) 3247 if (isContextLost())
3250 return; 3248 return;
3251 m_context->stencilOpSeparate(face, fail, zfail, zpass); 3249 webContext()->stencilOpSeparate(face, fail, zfail, zpass);
3252 } 3250 }
3253 3251
3254 GLenum WebGLRenderingContextBase::convertTexInternalFormat(GLenum internalformat , GLenum type) 3252 GLenum WebGLRenderingContextBase::convertTexInternalFormat(GLenum internalformat , GLenum type)
3255 { 3253 {
3256 // Convert to sized internal formats that are renderable with GL_CHROMIUM_co lor_buffer_float_rgb(a). 3254 // Convert to sized internal formats that are renderable with GL_CHROMIUM_co lor_buffer_float_rgb(a).
3257 if (type == GL_FLOAT && internalformat == GL_RGBA 3255 if (type == GL_FLOAT && internalformat == GL_RGBA
3258 && extensionsUtil()->isExtensionEnabled("GL_CHROMIUM_color_buffer_float_ rgba")) 3256 && extensionsUtil()->isExtensionEnabled("GL_CHROMIUM_color_buffer_float_ rgba"))
3259 return GL_RGBA32F_EXT; 3257 return GL_RGBA32F_EXT;
3260 if (type == GL_FLOAT && internalformat == GL_RGB 3258 if (type == GL_FLOAT && internalformat == GL_RGB
3261 && extensionsUtil()->isExtensionEnabled("GL_CHROMIUM_color_buffer_float_ rgb")) 3259 && extensionsUtil()->isExtensionEnabled("GL_CHROMIUM_color_buffer_float_ rgb"))
3262 return GL_RGB32F_EXT; 3260 return GL_RGB32F_EXT;
3263 return internalformat; 3261 return internalformat;
3264 } 3262 }
3265 3263
3266 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) 3264 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)
3267 { 3265 {
3268 // All calling functions check isContextLost, so a duplicate check is not ne eded here. 3266 // All calling functions check isContextLost, so a duplicate check is not ne eded here.
3269 // FIXME: Handle errors. 3267 // FIXME: Handle errors.
3270 WebGLTexture* tex = validateTextureBinding("texImage2D", target, true); 3268 WebGLTexture* tex = validateTextureBinding("texImage2D", target, true);
3271 ASSERT(validateTexFuncParameters("texImage2D", NotTexSubImage2D, target, lev el, internalformat, width, height, border, format, type)); 3269 ASSERT(validateTexFuncParameters("texImage2D", NotTexSubImage2D, target, lev el, internalformat, width, height, border, format, type));
3272 ASSERT(tex); 3270 ASSERT(tex);
3273 ASSERT(!level || !WebGLTexture::isNPOT(width, height)); 3271 ASSERT(!level || !WebGLTexture::isNPOT(width, height));
3274 ASSERT(!pixels || validateSettableTexFormat("texImage2D", internalformat)); 3272 ASSERT(!pixels || validateSettableTexFormat("texImage2D", internalformat));
3275 m_context->texImage2D(target, level, convertTexInternalFormat(internalformat , type), width, height, border, format, type, pixels); 3273 webContext()->texImage2D(target, level, convertTexInternalFormat(internalfor mat, type), width, height, border, format, type, pixels);
3276 tex->setLevelInfo(target, level, internalformat, width, height, type); 3274 tex->setLevelInfo(target, level, internalformat, width, height, type);
3277 } 3275 }
3278 3276
3279 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) 3277 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)
3280 { 3278 {
3281 // All calling functions check isContextLost, so a duplicate check is not ne eded here. 3279 // All calling functions check isContextLost, so a duplicate check is not ne eded here.
3282 Vector<uint8_t> data; 3280 Vector<uint8_t> data;
3283 WebGLImageConversion::ImageExtractor imageExtractor(image, domSource, premul tiplyAlpha, m_unpackColorspaceConversion == GL_NONE); 3281 WebGLImageConversion::ImageExtractor imageExtractor(image, domSource, premul tiplyAlpha, m_unpackColorspaceConversion == GL_NONE);
3284 if (!imageExtractor.extractSucceeded()) { 3282 if (!imageExtractor.extractSucceeded()) {
3285 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "bad image data"); 3283 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "bad image data");
3286 return; 3284 return;
3287 } 3285 }
3288 WebGLImageConversion::DataFormat sourceDataFormat = imageExtractor.imageSour ceFormat(); 3286 WebGLImageConversion::DataFormat sourceDataFormat = imageExtractor.imageSour ceFormat();
3289 WebGLImageConversion::AlphaOp alphaOp = imageExtractor.imageAlphaOp(); 3287 WebGLImageConversion::AlphaOp alphaOp = imageExtractor.imageAlphaOp();
3290 const void* imagePixelData = imageExtractor.imagePixelData(); 3288 const void* imagePixelData = imageExtractor.imagePixelData();
3291 3289
3292 bool needConversion = true; 3290 bool needConversion = true;
3293 if (type == GL_UNSIGNED_BYTE && sourceDataFormat == WebGLImageConversion::Da taFormatRGBA8 && format == GL_RGBA && alphaOp == WebGLImageConversion::AlphaDoNo thing && !flipY) 3291 if (type == GL_UNSIGNED_BYTE && sourceDataFormat == WebGLImageConversion::Da taFormatRGBA8 && format == GL_RGBA && alphaOp == WebGLImageConversion::AlphaDoNo thing && !flipY)
3294 needConversion = false; 3292 needConversion = false;
3295 else { 3293 else {
3296 if (!WebGLImageConversion::packImageData(image, imagePixelData, format, type, flipY, alphaOp, sourceDataFormat, imageExtractor.imageWidth(), imageExtrac tor.imageHeight(), imageExtractor.imageSourceUnpackAlignment(), data)) { 3294 if (!WebGLImageConversion::packImageData(image, imagePixelData, format, type, flipY, alphaOp, sourceDataFormat, imageExtractor.imageWidth(), imageExtrac tor.imageHeight(), imageExtractor.imageSourceUnpackAlignment(), data)) {
3297 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "packImage error") ; 3295 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "packImage error") ;
3298 return; 3296 return;
3299 } 3297 }
3300 } 3298 }
3301 3299
3302 if (m_unpackAlignment != 1) 3300 if (m_unpackAlignment != 1)
3303 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, 1); 3301 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1);
3304 texImage2DBase(target, level, internalformat, imageExtractor.imageWidth(), i mageExtractor.imageHeight(), 0, format, type, needConversion ? data.data() : ima gePixelData, exceptionState); 3302 texImage2DBase(target, level, internalformat, imageExtractor.imageWidth(), i mageExtractor.imageHeight(), 0, format, type, needConversion ? data.data() : ima gePixelData, exceptionState);
3305 if (m_unpackAlignment != 1) 3303 if (m_unpackAlignment != 1)
3306 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); 3304 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
3307 } 3305 }
3308 3306
3309 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) 3307 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)
3310 { 3308 {
3311 if (!validateTexFuncParameters(functionName, functionType, target, level, in ternalformat, width, height, border, format, type)) 3309 if (!validateTexFuncParameters(functionName, functionType, target, level, in ternalformat, width, height, border, format, type))
3312 return false; 3310 return false;
3313 3311
3314 WebGLTexture* texture = validateTextureBinding(functionName, target, true); 3312 WebGLTexture* texture = validateTextureBinding(functionName, target, true);
3315 if (!texture) 3313 if (!texture)
3316 return false; 3314 return false;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
3374 void* data = pixels ? pixels->baseAddress() : 0; 3372 void* data = pixels ? pixels->baseAddress() : 0;
3375 Vector<uint8_t> tempData; 3373 Vector<uint8_t> tempData;
3376 bool changeUnpackAlignment = false; 3374 bool changeUnpackAlignment = false;
3377 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) { 3375 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) {
3378 if (!WebGLImageConversion::extractTextureData(width, height, format, typ e, m_unpackAlignment, m_unpackFlipY, m_unpackPremultiplyAlpha, data, tempData)) 3376 if (!WebGLImageConversion::extractTextureData(width, height, format, typ e, m_unpackAlignment, m_unpackFlipY, m_unpackPremultiplyAlpha, data, tempData))
3379 return; 3377 return;
3380 data = tempData.data(); 3378 data = tempData.data();
3381 changeUnpackAlignment = true; 3379 changeUnpackAlignment = true;
3382 } 3380 }
3383 if (changeUnpackAlignment) 3381 if (changeUnpackAlignment)
3384 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, 1); 3382 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1);
3385 texImage2DBase(target, level, internalformat, width, height, border, format, type, data, exceptionState); 3383 texImage2DBase(target, level, internalformat, width, height, border, format, type, data, exceptionState);
3386 if (changeUnpackAlignment) 3384 if (changeUnpackAlignment)
3387 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); 3385 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
3388 } 3386 }
3389 3387
3390 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat, 3388 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat,
3391 GLenum format, GLenum type, ImageData* pixels, ExceptionState& exceptionStat e) 3389 GLenum format, GLenum type, ImageData* pixels, ExceptionState& exceptionStat e)
3392 { 3390 {
3393 if (isContextLost() || !pixels || !validateTexFunc("texImage2D", NotTexSubIm age2D, SourceImageData, target, level, internalformat, pixels->width(), pixels-> height(), 0, format, type, 0, 0)) 3391 if (isContextLost() || !pixels || !validateTexFunc("texImage2D", NotTexSubIm age2D, SourceImageData, target, level, internalformat, pixels->width(), pixels-> height(), 0, format, type, 0, 0))
3394 return; 3392 return;
3395 Vector<uint8_t> data; 3393 Vector<uint8_t> data;
3396 bool needConversion = true; 3394 bool needConversion = true;
3397 // The data from ImageData is always of format RGBA8. 3395 // The data from ImageData is always of format RGBA8.
3398 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required. 3396 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required.
3399 if (!m_unpackFlipY && !m_unpackPremultiplyAlpha && format == GL_RGBA && type == GL_UNSIGNED_BYTE) 3397 if (!m_unpackFlipY && !m_unpackPremultiplyAlpha && format == GL_RGBA && type == GL_UNSIGNED_BYTE)
3400 needConversion = false; 3398 needConversion = false;
3401 else { 3399 else {
3402 if (!WebGLImageConversion::extractImageData(pixels->data()->data(), pixe ls->size(), format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) { 3400 if (!WebGLImageConversion::extractImageData(pixels->data()->data(), pixe ls->size(), format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) {
3403 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "bad image data"); 3401 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "bad image data");
3404 return; 3402 return;
3405 } 3403 }
3406 } 3404 }
3407 if (m_unpackAlignment != 1) 3405 if (m_unpackAlignment != 1)
3408 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, 1); 3406 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1);
3409 texImage2DBase(target, level, internalformat, pixels->width(), pixels->heigh t(), 0, format, type, needConversion ? data.data() : pixels->data()->data(), exc eptionState); 3407 texImage2DBase(target, level, internalformat, pixels->width(), pixels->heigh t(), 0, format, type, needConversion ? data.data() : pixels->data()->data(), exc eptionState);
3410 if (m_unpackAlignment != 1) 3408 if (m_unpackAlignment != 1)
3411 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); 3409 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
3412 } 3410 }
3413 3411
3414 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat, 3412 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in ternalformat,
3415 GLenum format, GLenum type, HTMLImageElement* image, ExceptionState& excepti onState) 3413 GLenum format, GLenum type, HTMLImageElement* image, ExceptionState& excepti onState)
3416 { 3414 {
3417 if (isContextLost() || !validateHTMLImageElement("texImage2D", image, except ionState)) 3415 if (isContextLost() || !validateHTMLImageElement("texImage2D", image, except ionState))
3418 return; 3416 return;
3419 3417
3420 RefPtr<Image> imageForRender = image->cachedImage()->imageForRenderer(image- >renderer()); 3418 RefPtr<Image> imageForRender = image->cachedImage()->imageForRenderer(image- >renderer());
3421 if (imageForRender->isSVGImage()) 3419 if (imageForRender->isSVGImage())
(...skipping 13 matching lines...) Expand all
3435 3433
3436 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true); 3434 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true);
3437 3435
3438 // If possible, copy from the canvas element directly to the texture 3436 // If possible, copy from the canvas element directly to the texture
3439 // via the GPU, without a read-back to system memory. 3437 // via the GPU, without a read-back to system memory.
3440 if (GL_TEXTURE_2D == target && texture) { 3438 if (GL_TEXTURE_2D == target && texture) {
3441 ScopedTexture2DRestorer restorer(this); 3439 ScopedTexture2DRestorer restorer(this);
3442 3440
3443 if (!canvas->is3D()) { 3441 if (!canvas->is3D()) {
3444 ImageBuffer* buffer = canvas->buffer(); 3442 ImageBuffer* buffer = canvas->buffer();
3445 if (buffer && buffer->copyToPlatformTexture(m_context.get(), texture ->object(), internalformat, type, 3443 if (buffer && buffer->copyToPlatformTexture(webContext(), texture->o bject(), internalformat, type,
3446 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) { 3444 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) {
3447 texture->setLevelInfo(target, level, internalformat, canvas->wid th(), canvas->height(), type); 3445 texture->setLevelInfo(target, level, internalformat, canvas->wid th(), canvas->height(), type);
3448 return; 3446 return;
3449 } 3447 }
3450 } else { 3448 } else {
3451 WebGLRenderingContextBase* gl = toWebGLRenderingContextBase(canvas-> renderingContext()); 3449 WebGLRenderingContextBase* gl = toWebGLRenderingContextBase(canvas-> renderingContext());
3452 ScopedTexture2DRestorer restorer(gl); 3450 ScopedTexture2DRestorer restorer(gl);
3453 if (gl && gl->m_drawingBuffer->copyToPlatformTexture(m_context.get() , texture->object(), internalformat, type, 3451 if (gl && gl->m_drawingBuffer->copyToPlatformTexture(webContext(), t exture->object(), internalformat, type,
3454 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) { 3452 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) {
3455 texture->setLevelInfo(target, level, internalformat, canvas->wid th(), canvas->height(), type); 3453 texture->setLevelInfo(target, level, internalformat, canvas->wid th(), canvas->height(), type);
3456 return; 3454 return;
3457 } 3455 }
3458 } 3456 }
3459 } 3457 }
3460 3458
3461 RefPtrWillBeRawPtr<ImageData> imageData = canvas->getImageData(); 3459 RefPtrWillBeRawPtr<ImageData> imageData = canvas->getImageData();
3462 if (imageData) 3460 if (imageData)
3463 texImage2D(target, level, internalformat, format, type, imageData.get(), exceptionState); 3461 texImage2D(target, level, internalformat, format, type, imageData.get(), exceptionState);
(...skipping 19 matching lines...) Expand all
3483 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState) 3481 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState)
3484 { 3482 {
3485 if (isContextLost() || !validateHTMLVideoElement("texImage2D", video, except ionState) 3483 if (isContextLost() || !validateHTMLVideoElement("texImage2D", video, except ionState)
3486 || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLVideoEleme nt, target, level, internalformat, video->videoWidth(), video->videoHeight(), 0, format, type, 0, 0)) 3484 || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLVideoEleme nt, target, level, internalformat, video->videoWidth(), video->videoHeight(), 0, format, type, 0, 0))
3487 return; 3485 return;
3488 3486
3489 // Go through the fast path doing a GPU-GPU textures copy without a readback to system memory if possible. 3487 // Go through the fast path doing a GPU-GPU textures copy without a readback to system memory if possible.
3490 // Otherwise, it will fall back to the normal SW path. 3488 // Otherwise, it will fall back to the normal SW path.
3491 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true); 3489 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true);
3492 if (GL_TEXTURE_2D == target && texture) { 3490 if (GL_TEXTURE_2D == target && texture) {
3493 if (video->copyVideoTextureToPlatformTexture(m_context.get(), texture->o bject(), level, type, internalformat, m_unpackPremultiplyAlpha, m_unpackFlipY)) { 3491 if (video->copyVideoTextureToPlatformTexture(webContext(), texture->obje ct(), level, type, internalformat, m_unpackPremultiplyAlpha, m_unpackFlipY)) {
3494 texture->setLevelInfo(target, level, internalformat, video->videoWid th(), video->videoHeight(), type); 3492 texture->setLevelInfo(target, level, internalformat, video->videoWid th(), video->videoHeight(), type);
3495 return; 3493 return;
3496 } 3494 }
3497 } 3495 }
3498 3496
3499 // Normal pure SW path. 3497 // Normal pure SW path.
3500 RefPtr<Image> image = videoFrameToImage(video, ImageBuffer::fastCopyImageMod e()); 3498 RefPtr<Image> image = videoFrameToImage(video, ImageBuffer::fastCopyImageMod e());
3501 if (!image) 3499 if (!image)
3502 return; 3500 return;
3503 texImage2DImpl(target, level, internalformat, format, type, image.get(), Web GLImageConversion::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha, except ionState); 3501 texImage2DImpl(target, level, internalformat, format, type, image.get(), Web GLImageConversion::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha, except ionState);
(...skipping 23 matching lines...) Expand all
3527 synthesizeGLError(GL_INVALID_ENUM, "texParameter", "invalid paramete r, EXT_texture_filter_anisotropic not enabled"); 3525 synthesizeGLError(GL_INVALID_ENUM, "texParameter", "invalid paramete r, EXT_texture_filter_anisotropic not enabled");
3528 return; 3526 return;
3529 } 3527 }
3530 break; 3528 break;
3531 default: 3529 default:
3532 synthesizeGLError(GL_INVALID_ENUM, "texParameter", "invalid parameter na me"); 3530 synthesizeGLError(GL_INVALID_ENUM, "texParameter", "invalid parameter na me");
3533 return; 3531 return;
3534 } 3532 }
3535 if (isFloat) { 3533 if (isFloat) {
3536 tex->setParameterf(pname, paramf); 3534 tex->setParameterf(pname, paramf);
3537 m_context->texParameterf(target, pname, paramf); 3535 webContext()->texParameterf(target, pname, paramf);
3538 } else { 3536 } else {
3539 tex->setParameteri(pname, parami); 3537 tex->setParameteri(pname, parami);
3540 m_context->texParameteri(target, pname, parami); 3538 webContext()->texParameteri(target, pname, parami);
3541 } 3539 }
3542 } 3540 }
3543 3541
3544 void WebGLRenderingContextBase::texParameterf(GLenum target, GLenum pname, GLflo at param) 3542 void WebGLRenderingContextBase::texParameterf(GLenum target, GLenum pname, GLflo at param)
3545 { 3543 {
3546 texParameter(target, pname, param, 0, true); 3544 texParameter(target, pname, param, 0, true);
3547 } 3545 }
3548 3546
3549 void WebGLRenderingContextBase::texParameteri(GLenum target, GLenum pname, GLint param) 3547 void WebGLRenderingContextBase::texParameteri(GLenum target, GLenum pname, GLint param)
3550 { 3548 {
(...skipping 11 matching lines...) Expand all
3562 if (!tex) { 3560 if (!tex) {
3563 ASSERT_NOT_REACHED(); 3561 ASSERT_NOT_REACHED();
3564 return; 3562 return;
3565 } 3563 }
3566 ASSERT((xoffset + width) >= 0); 3564 ASSERT((xoffset + width) >= 0);
3567 ASSERT((yoffset + height) >= 0); 3565 ASSERT((yoffset + height) >= 0);
3568 ASSERT(tex->getWidth(target, level) >= (xoffset + width)); 3566 ASSERT(tex->getWidth(target, level) >= (xoffset + width));
3569 ASSERT(tex->getHeight(target, level) >= (yoffset + height)); 3567 ASSERT(tex->getHeight(target, level) >= (yoffset + height));
3570 ASSERT(tex->getInternalFormat(target, level) == format); 3568 ASSERT(tex->getInternalFormat(target, level) == format);
3571 ASSERT(tex->getType(target, level) == type); 3569 ASSERT(tex->getType(target, level) == type);
3572 m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, for mat, type, pixels); 3570 webContext()->texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
3573 } 3571 }
3574 3572
3575 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) 3573 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)
3576 { 3574 {
3577 // All calling functions check isContextLost, so a duplicate check is not ne eded here. 3575 // All calling functions check isContextLost, so a duplicate check is not ne eded here.
3578 Vector<uint8_t> data; 3576 Vector<uint8_t> data;
3579 WebGLImageConversion::ImageExtractor imageExtractor(image, domSource, premul tiplyAlpha, m_unpackColorspaceConversion == GL_NONE); 3577 WebGLImageConversion::ImageExtractor imageExtractor(image, domSource, premul tiplyAlpha, m_unpackColorspaceConversion == GL_NONE);
3580 if (!imageExtractor.extractSucceeded()) { 3578 if (!imageExtractor.extractSucceeded()) {
3581 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "bad image"); 3579 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "bad image");
3582 return; 3580 return;
3583 } 3581 }
3584 WebGLImageConversion::DataFormat sourceDataFormat = imageExtractor.imageSour ceFormat(); 3582 WebGLImageConversion::DataFormat sourceDataFormat = imageExtractor.imageSour ceFormat();
3585 WebGLImageConversion::AlphaOp alphaOp = imageExtractor.imageAlphaOp(); 3583 WebGLImageConversion::AlphaOp alphaOp = imageExtractor.imageAlphaOp();
3586 const void* imagePixelData = imageExtractor.imagePixelData(); 3584 const void* imagePixelData = imageExtractor.imagePixelData();
3587 3585
3588 bool needConversion = true; 3586 bool needConversion = true;
3589 if (type == GL_UNSIGNED_BYTE && sourceDataFormat == WebGLImageConversion::Da taFormatRGBA8 && format == GL_RGBA && alphaOp == WebGLImageConversion::AlphaDoNo thing && !flipY) 3587 if (type == GL_UNSIGNED_BYTE && sourceDataFormat == WebGLImageConversion::Da taFormatRGBA8 && format == GL_RGBA && alphaOp == WebGLImageConversion::AlphaDoNo thing && !flipY)
3590 needConversion = false; 3588 needConversion = false;
3591 else { 3589 else {
3592 if (!WebGLImageConversion::packImageData(image, imagePixelData, format, type, flipY, alphaOp, sourceDataFormat, imageExtractor.imageWidth(), imageExtrac tor.imageHeight(), imageExtractor.imageSourceUnpackAlignment(), data)) { 3590 if (!WebGLImageConversion::packImageData(image, imagePixelData, format, type, flipY, alphaOp, sourceDataFormat, imageExtractor.imageWidth(), imageExtrac tor.imageHeight(), imageExtractor.imageSourceUnpackAlignment(), data)) {
3593 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "bad image data "); 3591 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "bad image data ");
3594 return; 3592 return;
3595 } 3593 }
3596 } 3594 }
3597 3595
3598 if (m_unpackAlignment != 1) 3596 if (m_unpackAlignment != 1)
3599 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, 1); 3597 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1);
3600 texSubImage2DBase(target, level, xoffset, yoffset, imageExtractor.imageWidth (), imageExtractor.imageHeight(), format, type, needConversion ? data.data() : imagePixelData, exceptionState); 3598 texSubImage2DBase(target, level, xoffset, yoffset, imageExtractor.imageWidth (), imageExtractor.imageHeight(), format, type, needConversion ? data.data() : imagePixelData, exceptionState);
3601 if (m_unpackAlignment != 1) 3599 if (m_unpackAlignment != 1)
3602 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); 3600 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
3603 } 3601 }
3604 3602
3605 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, 3603 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
3606 GLsizei width, GLsizei height, 3604 GLsizei width, GLsizei height,
3607 GLenum format, GLenum type, ArrayBufferView* pixels, ExceptionState& excepti onState) 3605 GLenum format, GLenum type, ArrayBufferView* pixels, ExceptionState& excepti onState)
3608 { 3606 {
3609 if (isContextLost() || !validateTexFuncData("texSubImage2D", level, width, h eight, format, type, pixels, NullNotAllowed) 3607 if (isContextLost() || !validateTexFuncData("texSubImage2D", level, width, h eight, format, type, pixels, NullNotAllowed)
3610 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceArrayBufferVie w, target, level, format, width, height, 0, format, type, xoffset, yoffset)) 3608 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceArrayBufferVie w, target, level, format, width, height, 0, format, type, xoffset, yoffset))
3611 return; 3609 return;
3612 void* data = pixels->baseAddress(); 3610 void* data = pixels->baseAddress();
3613 Vector<uint8_t> tempData; 3611 Vector<uint8_t> tempData;
3614 bool changeUnpackAlignment = false; 3612 bool changeUnpackAlignment = false;
3615 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) { 3613 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) {
3616 if (!WebGLImageConversion::extractTextureData(width, height, format, typ e, 3614 if (!WebGLImageConversion::extractTextureData(width, height, format, typ e,
3617 m_unpackAlignment, 3615 m_unpackAlignment,
3618 m_unpackFlipY, m_unpackPremultiplyAlp ha, 3616 m_unpackFlipY, m_unpackPremultiplyAlp ha,
3619 data, 3617 data,
3620 tempData)) 3618 tempData))
3621 return; 3619 return;
3622 data = tempData.data(); 3620 data = tempData.data();
3623 changeUnpackAlignment = true; 3621 changeUnpackAlignment = true;
3624 } 3622 }
3625 if (changeUnpackAlignment) 3623 if (changeUnpackAlignment)
3626 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, 1); 3624 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1);
3627 texSubImage2DBase(target, level, xoffset, yoffset, width, height, format, ty pe, data, exceptionState); 3625 texSubImage2DBase(target, level, xoffset, yoffset, width, height, format, ty pe, data, exceptionState);
3628 if (changeUnpackAlignment) 3626 if (changeUnpackAlignment)
3629 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); 3627 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
3630 } 3628 }
3631 3629
3632 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, 3630 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
3633 GLenum format, GLenum type, ImageData* pixels, ExceptionState& exceptionStat e) 3631 GLenum format, GLenum type, ImageData* pixels, ExceptionState& exceptionStat e)
3634 { 3632 {
3635 if (isContextLost() || !pixels || !validateTexFunc("texSubImage2D", TexSubIm age2D, SourceImageData, target, level, format, pixels->width(), pixels->height( ), 0, format, type, xoffset, yoffset)) 3633 if (isContextLost() || !pixels || !validateTexFunc("texSubImage2D", TexSubIm age2D, SourceImageData, target, level, format, pixels->width(), pixels->height( ), 0, format, type, xoffset, yoffset))
3636 return; 3634 return;
3637 3635
3638 Vector<uint8_t> data; 3636 Vector<uint8_t> data;
3639 bool needConversion = true; 3637 bool needConversion = true;
3640 // The data from ImageData is always of format RGBA8. 3638 // The data from ImageData is always of format RGBA8.
3641 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required. 3639 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required.
3642 if (format == GL_RGBA && type == GL_UNSIGNED_BYTE && !m_unpackFlipY && !m_un packPremultiplyAlpha) 3640 if (format == GL_RGBA && type == GL_UNSIGNED_BYTE && !m_unpackFlipY && !m_un packPremultiplyAlpha)
3643 needConversion = false; 3641 needConversion = false;
3644 else { 3642 else {
3645 if (!WebGLImageConversion::extractImageData(pixels->data()->data(), pixe ls->size(), format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) { 3643 if (!WebGLImageConversion::extractImageData(pixels->data()->data(), pixe ls->size(), format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) {
3646 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "bad image data "); 3644 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "bad image data ");
3647 return; 3645 return;
3648 } 3646 }
3649 } 3647 }
3650 if (m_unpackAlignment != 1) 3648 if (m_unpackAlignment != 1)
3651 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, 1); 3649 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1);
3652 texSubImage2DBase(target, level, xoffset, yoffset, pixels->width(), pixels-> height(), format, type, needConversion ? data.data() : pixels->data()->data(), e xceptionState); 3650 texSubImage2DBase(target, level, xoffset, yoffset, pixels->width(), pixels-> height(), format, type, needConversion ? data.data() : pixels->data()->data(), e xceptionState);
3653 if (m_unpackAlignment != 1) 3651 if (m_unpackAlignment != 1)
3654 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); 3652 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
3655 } 3653 }
3656 3654
3657 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, 3655 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
3658 GLenum format, GLenum type, HTMLImageElement* image, ExceptionState& excepti onState) 3656 GLenum format, GLenum type, HTMLImageElement* image, ExceptionState& excepti onState)
3659 { 3657 {
3660 if (isContextLost() || !validateHTMLImageElement("texSubImage2D", image, exc eptionState)) 3658 if (isContextLost() || !validateHTMLImageElement("texSubImage2D", image, exc eptionState))
3661 return; 3659 return;
3662 3660
3663 RefPtr<Image> imageForRender = image->cachedImage()->imageForRenderer(image- >renderer()); 3661 RefPtr<Image> imageForRender = image->cachedImage()->imageForRenderer(image- >renderer());
3664 if (imageForRender->isSVGImage()) 3662 if (imageForRender->isSVGImage())
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3700 void WebGLRenderingContextBase::uniform1f(const WebGLUniformLocation* location, GLfloat x) 3698 void WebGLRenderingContextBase::uniform1f(const WebGLUniformLocation* location, GLfloat x)
3701 { 3699 {
3702 if (isContextLost() || !location) 3700 if (isContextLost() || !location)
3703 return; 3701 return;
3704 3702
3705 if (location->program() != m_currentProgram) { 3703 if (location->program() != m_currentProgram) {
3706 synthesizeGLError(GL_INVALID_OPERATION, "uniform1f", "location not for c urrent program"); 3704 synthesizeGLError(GL_INVALID_OPERATION, "uniform1f", "location not for c urrent program");
3707 return; 3705 return;
3708 } 3706 }
3709 3707
3710 m_context->uniform1f(location->location(), x); 3708 webContext()->uniform1f(location->location(), x);
3711 } 3709 }
3712 3710
3713 void WebGLRenderingContextBase::uniform1fv(const WebGLUniformLocation* location, Float32Array* v) 3711 void WebGLRenderingContextBase::uniform1fv(const WebGLUniformLocation* location, Float32Array* v)
3714 { 3712 {
3715 if (isContextLost() || !validateUniformParameters("uniform1fv", location, v, 1)) 3713 if (isContextLost() || !validateUniformParameters("uniform1fv", location, v, 1))
3716 return; 3714 return;
3717 3715
3718 m_context->uniform1fv(location->location(), v->length(), v->data()); 3716 webContext()->uniform1fv(location->location(), v->length(), v->data());
3719 } 3717 }
3720 3718
3721 void WebGLRenderingContextBase::uniform1fv(const WebGLUniformLocation* location, GLfloat* v, GLsizei size) 3719 void WebGLRenderingContextBase::uniform1fv(const WebGLUniformLocation* location, GLfloat* v, GLsizei size)
3722 { 3720 {
3723 if (isContextLost() || !validateUniformParameters("uniform1fv", location, v, size, 1)) 3721 if (isContextLost() || !validateUniformParameters("uniform1fv", location, v, size, 1))
3724 return; 3722 return;
3725 3723
3726 m_context->uniform1fv(location->location(), size, v); 3724 webContext()->uniform1fv(location->location(), size, v);
3727 } 3725 }
3728 3726
3729 void WebGLRenderingContextBase::uniform1i(const WebGLUniformLocation* location, GLint x) 3727 void WebGLRenderingContextBase::uniform1i(const WebGLUniformLocation* location, GLint x)
3730 { 3728 {
3731 if (isContextLost() || !location) 3729 if (isContextLost() || !location)
3732 return; 3730 return;
3733 3731
3734 if (location->program() != m_currentProgram) { 3732 if (location->program() != m_currentProgram) {
3735 synthesizeGLError(GL_INVALID_OPERATION, "uniform1i", "location not for c urrent program"); 3733 synthesizeGLError(GL_INVALID_OPERATION, "uniform1i", "location not for c urrent program");
3736 return; 3734 return;
3737 } 3735 }
3738 3736
3739 m_context->uniform1i(location->location(), x); 3737 webContext()->uniform1i(location->location(), x);
3740 } 3738 }
3741 3739
3742 void WebGLRenderingContextBase::uniform1iv(const WebGLUniformLocation* location, Int32Array* v) 3740 void WebGLRenderingContextBase::uniform1iv(const WebGLUniformLocation* location, Int32Array* v)
3743 { 3741 {
3744 if (isContextLost() || !validateUniformParameters("uniform1iv", location, v, 1)) 3742 if (isContextLost() || !validateUniformParameters("uniform1iv", location, v, 1))
3745 return; 3743 return;
3746 3744
3747 m_context->uniform1iv(location->location(), v->length(), v->data()); 3745 webContext()->uniform1iv(location->location(), v->length(), v->data());
3748 } 3746 }
3749 3747
3750 void WebGLRenderingContextBase::uniform1iv(const WebGLUniformLocation* location, GLint* v, GLsizei size) 3748 void WebGLRenderingContextBase::uniform1iv(const WebGLUniformLocation* location, GLint* v, GLsizei size)
3751 { 3749 {
3752 if (isContextLost() || !validateUniformParameters("uniform1iv", location, v, size, 1)) 3750 if (isContextLost() || !validateUniformParameters("uniform1iv", location, v, size, 1))
3753 return; 3751 return;
3754 3752
3755 m_context->uniform1iv(location->location(), size, v); 3753 webContext()->uniform1iv(location->location(), size, v);
3756 } 3754 }
3757 3755
3758 void WebGLRenderingContextBase::uniform2f(const WebGLUniformLocation* location, GLfloat x, GLfloat y) 3756 void WebGLRenderingContextBase::uniform2f(const WebGLUniformLocation* location, GLfloat x, GLfloat y)
3759 { 3757 {
3760 if (isContextLost() || !location) 3758 if (isContextLost() || !location)
3761 return; 3759 return;
3762 3760
3763 if (location->program() != m_currentProgram) { 3761 if (location->program() != m_currentProgram) {
3764 synthesizeGLError(GL_INVALID_OPERATION, "uniform2f", "location not for c urrent program"); 3762 synthesizeGLError(GL_INVALID_OPERATION, "uniform2f", "location not for c urrent program");
3765 return; 3763 return;
3766 } 3764 }
3767 3765
3768 m_context->uniform2f(location->location(), x, y); 3766 webContext()->uniform2f(location->location(), x, y);
3769 } 3767 }
3770 3768
3771 void WebGLRenderingContextBase::uniform2fv(const WebGLUniformLocation* location, Float32Array* v) 3769 void WebGLRenderingContextBase::uniform2fv(const WebGLUniformLocation* location, Float32Array* v)
3772 { 3770 {
3773 if (isContextLost() || !validateUniformParameters("uniform2fv", location, v, 2)) 3771 if (isContextLost() || !validateUniformParameters("uniform2fv", location, v, 2))
3774 return; 3772 return;
3775 3773
3776 m_context->uniform2fv(location->location(), v->length() / 2, v->data()); 3774 webContext()->uniform2fv(location->location(), v->length() / 2, v->data());
3777 } 3775 }
3778 3776
3779 void WebGLRenderingContextBase::uniform2fv(const WebGLUniformLocation* location, GLfloat* v, GLsizei size) 3777 void WebGLRenderingContextBase::uniform2fv(const WebGLUniformLocation* location, GLfloat* v, GLsizei size)
3780 { 3778 {
3781 if (isContextLost() || !validateUniformParameters("uniform2fv", location, v, size, 2)) 3779 if (isContextLost() || !validateUniformParameters("uniform2fv", location, v, size, 2))
3782 return; 3780 return;
3783 3781
3784 m_context->uniform2fv(location->location(), size / 2, v); 3782 webContext()->uniform2fv(location->location(), size / 2, v);
3785 } 3783 }
3786 3784
3787 void WebGLRenderingContextBase::uniform2i(const WebGLUniformLocation* location, GLint x, GLint y) 3785 void WebGLRenderingContextBase::uniform2i(const WebGLUniformLocation* location, GLint x, GLint y)
3788 { 3786 {
3789 if (isContextLost() || !location) 3787 if (isContextLost() || !location)
3790 return; 3788 return;
3791 3789
3792 if (location->program() != m_currentProgram) { 3790 if (location->program() != m_currentProgram) {
3793 synthesizeGLError(GL_INVALID_OPERATION, "uniform2i", "location not for c urrent program"); 3791 synthesizeGLError(GL_INVALID_OPERATION, "uniform2i", "location not for c urrent program");
3794 return; 3792 return;
3795 } 3793 }
3796 3794
3797 m_context->uniform2i(location->location(), x, y); 3795 webContext()->uniform2i(location->location(), x, y);
3798 } 3796 }
3799 3797
3800 void WebGLRenderingContextBase::uniform2iv(const WebGLUniformLocation* location, Int32Array* v) 3798 void WebGLRenderingContextBase::uniform2iv(const WebGLUniformLocation* location, Int32Array* v)
3801 { 3799 {
3802 if (isContextLost() || !validateUniformParameters("uniform2iv", location, v, 2)) 3800 if (isContextLost() || !validateUniformParameters("uniform2iv", location, v, 2))
3803 return; 3801 return;
3804 3802
3805 m_context->uniform2iv(location->location(), v->length() / 2, v->data()); 3803 webContext()->uniform2iv(location->location(), v->length() / 2, v->data());
3806 } 3804 }
3807 3805
3808 void WebGLRenderingContextBase::uniform2iv(const WebGLUniformLocation* location, GLint* v, GLsizei size) 3806 void WebGLRenderingContextBase::uniform2iv(const WebGLUniformLocation* location, GLint* v, GLsizei size)
3809 { 3807 {
3810 if (isContextLost() || !validateUniformParameters("uniform2iv", location, v, size, 2)) 3808 if (isContextLost() || !validateUniformParameters("uniform2iv", location, v, size, 2))
3811 return; 3809 return;
3812 3810
3813 m_context->uniform2iv(location->location(), size / 2, v); 3811 webContext()->uniform2iv(location->location(), size / 2, v);
3814 } 3812 }
3815 3813
3816 void WebGLRenderingContextBase::uniform3f(const WebGLUniformLocation* location, GLfloat x, GLfloat y, GLfloat z) 3814 void WebGLRenderingContextBase::uniform3f(const WebGLUniformLocation* location, GLfloat x, GLfloat y, GLfloat z)
3817 { 3815 {
3818 if (isContextLost() || !location) 3816 if (isContextLost() || !location)
3819 return; 3817 return;
3820 3818
3821 if (location->program() != m_currentProgram) { 3819 if (location->program() != m_currentProgram) {
3822 synthesizeGLError(GL_INVALID_OPERATION, "uniform3f", "location not for c urrent program"); 3820 synthesizeGLError(GL_INVALID_OPERATION, "uniform3f", "location not for c urrent program");
3823 return; 3821 return;
3824 } 3822 }
3825 3823
3826 m_context->uniform3f(location->location(), x, y, z); 3824 webContext()->uniform3f(location->location(), x, y, z);
3827 } 3825 }
3828 3826
3829 void WebGLRenderingContextBase::uniform3fv(const WebGLUniformLocation* location, Float32Array* v) 3827 void WebGLRenderingContextBase::uniform3fv(const WebGLUniformLocation* location, Float32Array* v)
3830 { 3828 {
3831 if (isContextLost() || !validateUniformParameters("uniform3fv", location, v, 3)) 3829 if (isContextLost() || !validateUniformParameters("uniform3fv", location, v, 3))
3832 return; 3830 return;
3833 3831
3834 m_context->uniform3fv(location->location(), v->length() / 3, v->data()); 3832 webContext()->uniform3fv(location->location(), v->length() / 3, v->data());
3835 } 3833 }
3836 3834
3837 void WebGLRenderingContextBase::uniform3fv(const WebGLUniformLocation* location, GLfloat* v, GLsizei size) 3835 void WebGLRenderingContextBase::uniform3fv(const WebGLUniformLocation* location, GLfloat* v, GLsizei size)
3838 { 3836 {
3839 if (isContextLost() || !validateUniformParameters("uniform3fv", location, v, size, 3)) 3837 if (isContextLost() || !validateUniformParameters("uniform3fv", location, v, size, 3))
3840 return; 3838 return;
3841 3839
3842 m_context->uniform3fv(location->location(), size / 3, v); 3840 webContext()->uniform3fv(location->location(), size / 3, v);
3843 } 3841 }
3844 3842
3845 void WebGLRenderingContextBase::uniform3i(const WebGLUniformLocation* location, GLint x, GLint y, GLint z) 3843 void WebGLRenderingContextBase::uniform3i(const WebGLUniformLocation* location, GLint x, GLint y, GLint z)
3846 { 3844 {
3847 if (isContextLost() || !location) 3845 if (isContextLost() || !location)
3848 return; 3846 return;
3849 3847
3850 if (location->program() != m_currentProgram) { 3848 if (location->program() != m_currentProgram) {
3851 synthesizeGLError(GL_INVALID_OPERATION, "uniform3i", "location not for c urrent program"); 3849 synthesizeGLError(GL_INVALID_OPERATION, "uniform3i", "location not for c urrent program");
3852 return; 3850 return;
3853 } 3851 }
3854 3852
3855 m_context->uniform3i(location->location(), x, y, z); 3853 webContext()->uniform3i(location->location(), x, y, z);
3856 } 3854 }
3857 3855
3858 void WebGLRenderingContextBase::uniform3iv(const WebGLUniformLocation* location, Int32Array* v) 3856 void WebGLRenderingContextBase::uniform3iv(const WebGLUniformLocation* location, Int32Array* v)
3859 { 3857 {
3860 if (isContextLost() || !validateUniformParameters("uniform3iv", location, v, 3)) 3858 if (isContextLost() || !validateUniformParameters("uniform3iv", location, v, 3))
3861 return; 3859 return;
3862 3860
3863 m_context->uniform3iv(location->location(), v->length() / 3, v->data()); 3861 webContext()->uniform3iv(location->location(), v->length() / 3, v->data());
3864 } 3862 }
3865 3863
3866 void WebGLRenderingContextBase::uniform3iv(const WebGLUniformLocation* location, GLint* v, GLsizei size) 3864 void WebGLRenderingContextBase::uniform3iv(const WebGLUniformLocation* location, GLint* v, GLsizei size)
3867 { 3865 {
3868 if (isContextLost() || !validateUniformParameters("uniform3iv", location, v, size, 3)) 3866 if (isContextLost() || !validateUniformParameters("uniform3iv", location, v, size, 3))
3869 return; 3867 return;
3870 3868
3871 m_context->uniform3iv(location->location(), size / 3, v); 3869 webContext()->uniform3iv(location->location(), size / 3, v);
3872 } 3870 }
3873 3871
3874 void WebGLRenderingContextBase::uniform4f(const WebGLUniformLocation* location, GLfloat x, GLfloat y, GLfloat z, GLfloat w) 3872 void WebGLRenderingContextBase::uniform4f(const WebGLUniformLocation* location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
3875 { 3873 {
3876 if (isContextLost() || !location) 3874 if (isContextLost() || !location)
3877 return; 3875 return;
3878 3876
3879 if (location->program() != m_currentProgram) { 3877 if (location->program() != m_currentProgram) {
3880 synthesizeGLError(GL_INVALID_OPERATION, "uniform4f", "location not for c urrent program"); 3878 synthesizeGLError(GL_INVALID_OPERATION, "uniform4f", "location not for c urrent program");
3881 return; 3879 return;
3882 } 3880 }
3883 3881
3884 m_context->uniform4f(location->location(), x, y, z, w); 3882 webContext()->uniform4f(location->location(), x, y, z, w);
3885 } 3883 }
3886 3884
3887 void WebGLRenderingContextBase::uniform4fv(const WebGLUniformLocation* location, Float32Array* v) 3885 void WebGLRenderingContextBase::uniform4fv(const WebGLUniformLocation* location, Float32Array* v)
3888 { 3886 {
3889 if (isContextLost() || !validateUniformParameters("uniform4fv", location, v, 4)) 3887 if (isContextLost() || !validateUniformParameters("uniform4fv", location, v, 4))
3890 return; 3888 return;
3891 3889
3892 m_context->uniform4fv(location->location(), v->length() / 4, v->data()); 3890 webContext()->uniform4fv(location->location(), v->length() / 4, v->data());
3893 } 3891 }
3894 3892
3895 void WebGLRenderingContextBase::uniform4fv(const WebGLUniformLocation* location, GLfloat* v, GLsizei size) 3893 void WebGLRenderingContextBase::uniform4fv(const WebGLUniformLocation* location, GLfloat* v, GLsizei size)
3896 { 3894 {
3897 if (isContextLost() || !validateUniformParameters("uniform4fv", location, v, size, 4)) 3895 if (isContextLost() || !validateUniformParameters("uniform4fv", location, v, size, 4))
3898 return; 3896 return;
3899 3897
3900 m_context->uniform4fv(location->location(), size / 4, v); 3898 webContext()->uniform4fv(location->location(), size / 4, v);
3901 } 3899 }
3902 3900
3903 void WebGLRenderingContextBase::uniform4i(const WebGLUniformLocation* location, GLint x, GLint y, GLint z, GLint w) 3901 void WebGLRenderingContextBase::uniform4i(const WebGLUniformLocation* location, GLint x, GLint y, GLint z, GLint w)
3904 { 3902 {
3905 if (isContextLost() || !location) 3903 if (isContextLost() || !location)
3906 return; 3904 return;
3907 3905
3908 if (location->program() != m_currentProgram) { 3906 if (location->program() != m_currentProgram) {
3909 synthesizeGLError(GL_INVALID_OPERATION, "uniform4i", "location not for c urrent program"); 3907 synthesizeGLError(GL_INVALID_OPERATION, "uniform4i", "location not for c urrent program");
3910 return; 3908 return;
3911 } 3909 }
3912 3910
3913 m_context->uniform4i(location->location(), x, y, z, w); 3911 webContext()->uniform4i(location->location(), x, y, z, w);
3914 } 3912 }
3915 3913
3916 void WebGLRenderingContextBase::uniform4iv(const WebGLUniformLocation* location, Int32Array* v) 3914 void WebGLRenderingContextBase::uniform4iv(const WebGLUniformLocation* location, Int32Array* v)
3917 { 3915 {
3918 if (isContextLost() || !validateUniformParameters("uniform4iv", location, v, 4)) 3916 if (isContextLost() || !validateUniformParameters("uniform4iv", location, v, 4))
3919 return; 3917 return;
3920 3918
3921 m_context->uniform4iv(location->location(), v->length() / 4, v->data()); 3919 webContext()->uniform4iv(location->location(), v->length() / 4, v->data());
3922 } 3920 }
3923 3921
3924 void WebGLRenderingContextBase::uniform4iv(const WebGLUniformLocation* location, GLint* v, GLsizei size) 3922 void WebGLRenderingContextBase::uniform4iv(const WebGLUniformLocation* location, GLint* v, GLsizei size)
3925 { 3923 {
3926 if (isContextLost() || !validateUniformParameters("uniform4iv", location, v, size, 4)) 3924 if (isContextLost() || !validateUniformParameters("uniform4iv", location, v, size, 4))
3927 return; 3925 return;
3928 3926
3929 m_context->uniform4iv(location->location(), size / 4, v); 3927 webContext()->uniform4iv(location->location(), size / 4, v);
3930 } 3928 }
3931 3929
3932 void WebGLRenderingContextBase::uniformMatrix2fv(const WebGLUniformLocation* loc ation, GLboolean transpose, Float32Array* v) 3930 void WebGLRenderingContextBase::uniformMatrix2fv(const WebGLUniformLocation* loc ation, GLboolean transpose, Float32Array* v)
3933 { 3931 {
3934 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix2fv", location, transpose, v, 4)) 3932 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix2fv", location, transpose, v, 4))
3935 return; 3933 return;
3936 m_context->uniformMatrix2fv(location->location(), v->length() / 4, transpose , v->data()); 3934 webContext()->uniformMatrix2fv(location->location(), v->length() / 4, transp ose, v->data());
3937 } 3935 }
3938 3936
3939 void WebGLRenderingContextBase::uniformMatrix2fv(const WebGLUniformLocation* loc ation, GLboolean transpose, GLfloat* v, GLsizei size) 3937 void WebGLRenderingContextBase::uniformMatrix2fv(const WebGLUniformLocation* loc ation, GLboolean transpose, GLfloat* v, GLsizei size)
3940 { 3938 {
3941 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix2fv", location, transpose, v, size, 4)) 3939 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix2fv", location, transpose, v, size, 4))
3942 return; 3940 return;
3943 m_context->uniformMatrix2fv(location->location(), size / 4, transpose, v); 3941 webContext()->uniformMatrix2fv(location->location(), size / 4, transpose, v) ;
3944 } 3942 }
3945 3943
3946 void WebGLRenderingContextBase::uniformMatrix3fv(const WebGLUniformLocation* loc ation, GLboolean transpose, Float32Array* v) 3944 void WebGLRenderingContextBase::uniformMatrix3fv(const WebGLUniformLocation* loc ation, GLboolean transpose, Float32Array* v)
3947 { 3945 {
3948 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix3fv", location, transpose, v, 9)) 3946 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix3fv", location, transpose, v, 9))
3949 return; 3947 return;
3950 m_context->uniformMatrix3fv(location->location(), v->length() / 9, transpose , v->data()); 3948 webContext()->uniformMatrix3fv(location->location(), v->length() / 9, transp ose, v->data());
3951 } 3949 }
3952 3950
3953 void WebGLRenderingContextBase::uniformMatrix3fv(const WebGLUniformLocation* loc ation, GLboolean transpose, GLfloat* v, GLsizei size) 3951 void WebGLRenderingContextBase::uniformMatrix3fv(const WebGLUniformLocation* loc ation, GLboolean transpose, GLfloat* v, GLsizei size)
3954 { 3952 {
3955 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix3fv", location, transpose, v, size, 9)) 3953 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix3fv", location, transpose, v, size, 9))
3956 return; 3954 return;
3957 m_context->uniformMatrix3fv(location->location(), size / 9, transpose, v); 3955 webContext()->uniformMatrix3fv(location->location(), size / 9, transpose, v) ;
3958 } 3956 }
3959 3957
3960 void WebGLRenderingContextBase::uniformMatrix4fv(const WebGLUniformLocation* loc ation, GLboolean transpose, Float32Array* v) 3958 void WebGLRenderingContextBase::uniformMatrix4fv(const WebGLUniformLocation* loc ation, GLboolean transpose, Float32Array* v)
3961 { 3959 {
3962 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix4fv", location, transpose, v, 16)) 3960 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix4fv", location, transpose, v, 16))
3963 return; 3961 return;
3964 m_context->uniformMatrix4fv(location->location(), v->length() / 16, transpos e, v->data()); 3962 webContext()->uniformMatrix4fv(location->location(), v->length() / 16, trans pose, v->data());
3965 } 3963 }
3966 3964
3967 void WebGLRenderingContextBase::uniformMatrix4fv(const WebGLUniformLocation* loc ation, GLboolean transpose, GLfloat* v, GLsizei size) 3965 void WebGLRenderingContextBase::uniformMatrix4fv(const WebGLUniformLocation* loc ation, GLboolean transpose, GLfloat* v, GLsizei size)
3968 { 3966 {
3969 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix4fv", location, transpose, v, size, 16)) 3967 if (isContextLost() || !validateUniformMatrixParameters("uniformMatrix4fv", location, transpose, v, size, 16))
3970 return; 3968 return;
3971 m_context->uniformMatrix4fv(location->location(), size / 16, transpose, v); 3969 webContext()->uniformMatrix4fv(location->location(), size / 16, transpose, v );
3972 } 3970 }
3973 3971
3974 void WebGLRenderingContextBase::useProgram(WebGLProgram* program) 3972 void WebGLRenderingContextBase::useProgram(WebGLProgram* program)
3975 { 3973 {
3976 bool deleted; 3974 bool deleted;
3977 if (!checkObjectToBeBound("useProgram", program, deleted)) 3975 if (!checkObjectToBeBound("useProgram", program, deleted))
3978 return; 3976 return;
3979 if (deleted) 3977 if (deleted)
3980 program = 0; 3978 program = 0;
3981 if (program && !program->linkStatus()) { 3979 if (program && !program->linkStatus()) {
3982 synthesizeGLError(GL_INVALID_OPERATION, "useProgram", "program not valid "); 3980 synthesizeGLError(GL_INVALID_OPERATION, "useProgram", "program not valid ");
3983 return; 3981 return;
3984 } 3982 }
3985 if (m_currentProgram != program) { 3983 if (m_currentProgram != program) {
3986 if (m_currentProgram) 3984 if (m_currentProgram)
3987 m_currentProgram->onDetached(m_context.get()); 3985 m_currentProgram->onDetached(webContext());
3988 m_currentProgram = program; 3986 m_currentProgram = program;
3989 m_context->useProgram(objectOrZero(program)); 3987 webContext()->useProgram(objectOrZero(program));
3990 if (program) 3988 if (program)
3991 program->onAttached(); 3989 program->onAttached();
3992 } 3990 }
3993 } 3991 }
3994 3992
3995 void WebGLRenderingContextBase::validateProgram(WebGLProgram* program) 3993 void WebGLRenderingContextBase::validateProgram(WebGLProgram* program)
3996 { 3994 {
3997 if (isContextLost() || !validateWebGLObject("validateProgram", program)) 3995 if (isContextLost() || !validateWebGLObject("validateProgram", program))
3998 return; 3996 return;
3999 m_context->validateProgram(objectOrZero(program)); 3997 webContext()->validateProgram(objectOrZero(program));
4000 } 3998 }
4001 3999
4002 void WebGLRenderingContextBase::vertexAttrib1f(GLuint index, GLfloat v0) 4000 void WebGLRenderingContextBase::vertexAttrib1f(GLuint index, GLfloat v0)
4003 { 4001 {
4004 vertexAttribfImpl("vertexAttrib1f", index, 1, v0, 0.0f, 0.0f, 1.0f); 4002 vertexAttribfImpl("vertexAttrib1f", index, 1, v0, 0.0f, 0.0f, 1.0f);
4005 } 4003 }
4006 4004
4007 void WebGLRenderingContextBase::vertexAttrib1fv(GLuint index, Float32Array* v) 4005 void WebGLRenderingContextBase::vertexAttrib1fv(GLuint index, Float32Array* v)
4008 { 4006 {
4009 vertexAttribfvImpl("vertexAttrib1fv", index, v, 1); 4007 vertexAttribfvImpl("vertexAttrib1fv", index, v, 1);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
4092 synthesizeGLError(GL_INVALID_ENUM, "vertexAttribPointer", "invalid type" ); 4090 synthesizeGLError(GL_INVALID_ENUM, "vertexAttribPointer", "invalid type" );
4093 return; 4091 return;
4094 } 4092 }
4095 if ((stride % typeSize) || (static_cast<GLintptr>(offset) % typeSize)) { 4093 if ((stride % typeSize) || (static_cast<GLintptr>(offset) % typeSize)) {
4096 synthesizeGLError(GL_INVALID_OPERATION, "vertexAttribPointer", "stride o r offset not valid for type"); 4094 synthesizeGLError(GL_INVALID_OPERATION, "vertexAttribPointer", "stride o r offset not valid for type");
4097 return; 4095 return;
4098 } 4096 }
4099 GLsizei bytesPerElement = size * typeSize; 4097 GLsizei bytesPerElement = size * typeSize;
4100 4098
4101 m_boundVertexArrayObject->setVertexAttribState(index, bytesPerElement, size, type, normalized, stride, static_cast<GLintptr>(offset), m_boundArrayBuffer); 4099 m_boundVertexArrayObject->setVertexAttribState(index, bytesPerElement, size, type, normalized, stride, static_cast<GLintptr>(offset), m_boundArrayBuffer);
4102 m_context->vertexAttribPointer(index, size, type, normalized, stride, static _cast<GLintptr>(offset)); 4100 webContext()->vertexAttribPointer(index, size, type, normalized, stride, sta tic_cast<GLintptr>(offset));
4103 } 4101 }
4104 4102
4105 void WebGLRenderingContextBase::vertexAttribDivisorANGLE(GLuint index, GLuint di visor) 4103 void WebGLRenderingContextBase::vertexAttribDivisorANGLE(GLuint index, GLuint di visor)
4106 { 4104 {
4107 if (isContextLost()) 4105 if (isContextLost())
4108 return; 4106 return;
4109 4107
4110 if (index >= m_maxVertexAttribs) { 4108 if (index >= m_maxVertexAttribs) {
4111 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribDivisorANGLE", "index o ut of range"); 4109 synthesizeGLError(GL_INVALID_VALUE, "vertexAttribDivisorANGLE", "index o ut of range");
4112 return; 4110 return;
4113 } 4111 }
4114 4112
4115 m_boundVertexArrayObject->setVertexAttribDivisor(index, divisor); 4113 m_boundVertexArrayObject->setVertexAttribDivisor(index, divisor);
4116 m_context->vertexAttribDivisorANGLE(index, divisor); 4114 webContext()->vertexAttribDivisorANGLE(index, divisor);
4117 } 4115 }
4118 4116
4119 void WebGLRenderingContextBase::viewport(GLint x, GLint y, GLsizei width, GLsize i height) 4117 void WebGLRenderingContextBase::viewport(GLint x, GLint y, GLsizei width, GLsize i height)
4120 { 4118 {
4121 if (isContextLost()) 4119 if (isContextLost())
4122 return; 4120 return;
4123 if (!validateSize("viewport", width, height)) 4121 if (!validateSize("viewport", width, height))
4124 return; 4122 return;
4125 m_context->viewport(x, y, width, height); 4123 webContext()->viewport(x, y, width, height);
4126 } 4124 }
4127 4125
4128 void WebGLRenderingContextBase::forceLostContext(WebGLRenderingContextBase::Lost ContextMode mode) 4126 void WebGLRenderingContextBase::forceLostContext(WebGLRenderingContextBase::Lost ContextMode mode)
4129 { 4127 {
4130 if (isContextLost()) { 4128 if (isContextLost()) {
4131 synthesizeGLError(GL_INVALID_OPERATION, "loseContext", "context already lost"); 4129 synthesizeGLError(GL_INVALID_OPERATION, "loseContext", "context already lost");
4132 return; 4130 return;
4133 } 4131 }
4134 4132
4135 m_contextGroup->loseContextGroup(mode); 4133 m_contextGroup->loseContextGroup(mode);
4136 } 4134 }
4137 4135
4138 void WebGLRenderingContextBase::loseContextImpl(WebGLRenderingContextBase::LostC ontextMode mode) 4136 void WebGLRenderingContextBase::loseContextImpl(WebGLRenderingContextBase::LostC ontextMode mode)
4139 { 4137 {
4140 if (isContextLost()) 4138 if (isContextLost())
4141 return; 4139 return;
4142 4140
4143 m_contextLost = true; 4141 m_contextLost = true;
4144 m_contextLostMode = mode; 4142 m_contextLostMode = mode;
4145 4143
4146 if (mode == RealLostContext) { 4144 if (mode == RealLostContext) {
4147 // Inform the embedder that a lost context was received. In response, th e embedder might 4145 // Inform the embedder that a lost context was received. In response, th e embedder might
4148 // decide to take action such as asking the user for permission to use W ebGL again. 4146 // decide to take action such as asking the user for permission to use W ebGL again.
4149 if (LocalFrame* frame = canvas()->document().frame()) 4147 if (LocalFrame* frame = canvas()->document().frame())
4150 frame->loader().client()->didLoseWebGLContext(m_context->getGraphics ResetStatusARB()); 4148 frame->loader().client()->didLoseWebGLContext(webContext()->getGraph icsResetStatusARB());
4151 } 4149 }
4152 4150
4153 // Make absolutely sure we do not refer to an already-deleted texture or fra mebuffer. 4151 // Make absolutely sure we do not refer to an already-deleted texture or fra mebuffer.
4154 m_drawingBuffer->setTexture2DBinding(0); 4152 m_drawingBuffer->setTexture2DBinding(0);
4155 m_drawingBuffer->setFramebufferBinding(0); 4153 m_drawingBuffer->setFramebufferBinding(0);
4156 4154
4157 detachAndRemoveAllObjects(); 4155 detachAndRemoveAllObjects();
4158 4156
4159 // Lose all the extensions. 4157 // Lose all the extensions.
4160 for (size_t i = 0; i < m_extensions.size(); ++i) { 4158 for (size_t i = 0; i < m_extensions.size(); ++i) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
4194 synthesizeGLError(GL_INVALID_OPERATION, "restoreContext", "context r estoration not allowed"); 4192 synthesizeGLError(GL_INVALID_OPERATION, "restoreContext", "context r estoration not allowed");
4195 return; 4193 return;
4196 } 4194 }
4197 4195
4198 if (!m_restoreTimer.isActive()) 4196 if (!m_restoreTimer.isActive())
4199 m_restoreTimer.startOneShot(0, FROM_HERE); 4197 m_restoreTimer.startOneShot(0, FROM_HERE);
4200 } 4198 }
4201 4199
4202 blink::WebLayer* WebGLRenderingContextBase::platformLayer() const 4200 blink::WebLayer* WebGLRenderingContextBase::platformLayer() const
4203 { 4201 {
4204 return m_drawingBuffer->platformLayer(); 4202 return isContextLost() ? 0 : m_drawingBuffer->platformLayer();
4205 } 4203 }
4206 4204
4207 Extensions3DUtil* WebGLRenderingContextBase::extensionsUtil() 4205 Extensions3DUtil* WebGLRenderingContextBase::extensionsUtil()
4208 { 4206 {
4207 ASSERT(!isContextLost());
4209 if (!m_extensionsUtil) 4208 if (!m_extensionsUtil)
4210 m_extensionsUtil = adoptPtr(new Extensions3DUtil(m_context.get())); 4209 m_extensionsUtil = adoptPtr(new Extensions3DUtil(webContext()));
4211 return m_extensionsUtil.get(); 4210 return m_extensionsUtil.get();
4212 } 4211 }
4213 4212
4214 void WebGLRenderingContextBase::removeSharedObject(WebGLSharedObject* object) 4213 void WebGLRenderingContextBase::removeSharedObject(WebGLSharedObject* object)
4215 { 4214 {
4216 m_contextGroup->removeObject(object); 4215 m_contextGroup->removeObject(object);
4217 } 4216 }
4218 4217
4219 void WebGLRenderingContextBase::addSharedObject(WebGLSharedObject* object) 4218 void WebGLRenderingContextBase::addSharedObject(WebGLSharedObject* object)
4220 { 4219 {
(...skipping 30 matching lines...) Expand all
4251 if (!isContextLost()) { 4250 if (!isContextLost()) {
4252 forceLostContext(SyntheticLostContext); 4251 forceLostContext(SyntheticLostContext);
4253 destroyContext(); 4252 destroyContext();
4254 } 4253 }
4255 } 4254 }
4256 4255
4257 WebGLGetInfo WebGLRenderingContextBase::getBooleanParameter(GLenum pname) 4256 WebGLGetInfo WebGLRenderingContextBase::getBooleanParameter(GLenum pname)
4258 { 4257 {
4259 GLboolean value = 0; 4258 GLboolean value = 0;
4260 if (!isContextLost()) 4259 if (!isContextLost())
4261 m_context->getBooleanv(pname, &value); 4260 webContext()->getBooleanv(pname, &value);
4262 return WebGLGetInfo(static_cast<bool>(value)); 4261 return WebGLGetInfo(static_cast<bool>(value));
4263 } 4262 }
4264 4263
4265 WebGLGetInfo WebGLRenderingContextBase::getBooleanArrayParameter(GLenum pname) 4264 WebGLGetInfo WebGLRenderingContextBase::getBooleanArrayParameter(GLenum pname)
4266 { 4265 {
4267 if (pname != GL_COLOR_WRITEMASK) { 4266 if (pname != GL_COLOR_WRITEMASK) {
4268 notImplemented(); 4267 notImplemented();
4269 return WebGLGetInfo(0, 0); 4268 return WebGLGetInfo(0, 0);
4270 } 4269 }
4271 GLboolean value[4] = {0}; 4270 GLboolean value[4] = {0};
4272 if (!isContextLost()) 4271 if (!isContextLost())
4273 m_context->getBooleanv(pname, value); 4272 webContext()->getBooleanv(pname, value);
4274 bool boolValue[4]; 4273 bool boolValue[4];
4275 for (int ii = 0; ii < 4; ++ii) 4274 for (int ii = 0; ii < 4; ++ii)
4276 boolValue[ii] = static_cast<bool>(value[ii]); 4275 boolValue[ii] = static_cast<bool>(value[ii]);
4277 return WebGLGetInfo(boolValue, 4); 4276 return WebGLGetInfo(boolValue, 4);
4278 } 4277 }
4279 4278
4280 WebGLGetInfo WebGLRenderingContextBase::getFloatParameter(GLenum pname) 4279 WebGLGetInfo WebGLRenderingContextBase::getFloatParameter(GLenum pname)
4281 { 4280 {
4282 GLfloat value = 0; 4281 GLfloat value = 0;
4283 if (!isContextLost()) 4282 if (!isContextLost())
4284 m_context->getFloatv(pname, &value); 4283 webContext()->getFloatv(pname, &value);
4285 return WebGLGetInfo(value); 4284 return WebGLGetInfo(value);
4286 } 4285 }
4287 4286
4288 WebGLGetInfo WebGLRenderingContextBase::getIntParameter(GLenum pname) 4287 WebGLGetInfo WebGLRenderingContextBase::getIntParameter(GLenum pname)
4289 { 4288 {
4290 GLint value = 0; 4289 GLint value = 0;
4291 if (!isContextLost()) 4290 if (!isContextLost())
4292 m_context->getIntegerv(pname, &value); 4291 webContext()->getIntegerv(pname, &value);
4293 return WebGLGetInfo(value); 4292 return WebGLGetInfo(value);
4294 } 4293 }
4295 4294
4296 WebGLGetInfo WebGLRenderingContextBase::getUnsignedIntParameter(GLenum pname) 4295 WebGLGetInfo WebGLRenderingContextBase::getUnsignedIntParameter(GLenum pname)
4297 { 4296 {
4298 GLint value = 0; 4297 GLint value = 0;
4299 if (!isContextLost()) 4298 if (!isContextLost())
4300 m_context->getIntegerv(pname, &value); 4299 webContext()->getIntegerv(pname, &value);
4301 return WebGLGetInfo(static_cast<unsigned>(value)); 4300 return WebGLGetInfo(static_cast<unsigned>(value));
4302 } 4301 }
4303 4302
4304 WebGLGetInfo WebGLRenderingContextBase::getWebGLFloatArrayParameter(GLenum pname ) 4303 WebGLGetInfo WebGLRenderingContextBase::getWebGLFloatArrayParameter(GLenum pname )
4305 { 4304 {
4306 GLfloat value[4] = {0}; 4305 GLfloat value[4] = {0};
4307 if (!isContextLost()) 4306 if (!isContextLost())
4308 m_context->getFloatv(pname, value); 4307 webContext()->getFloatv(pname, value);
4309 unsigned length = 0; 4308 unsigned length = 0;
4310 switch (pname) { 4309 switch (pname) {
4311 case GL_ALIASED_POINT_SIZE_RANGE: 4310 case GL_ALIASED_POINT_SIZE_RANGE:
4312 case GL_ALIASED_LINE_WIDTH_RANGE: 4311 case GL_ALIASED_LINE_WIDTH_RANGE:
4313 case GL_DEPTH_RANGE: 4312 case GL_DEPTH_RANGE:
4314 length = 2; 4313 length = 2;
4315 break; 4314 break;
4316 case GL_BLEND_COLOR: 4315 case GL_BLEND_COLOR:
4317 case GL_COLOR_CLEAR_VALUE: 4316 case GL_COLOR_CLEAR_VALUE:
4318 length = 4; 4317 length = 4;
4319 break; 4318 break;
4320 default: 4319 default:
4321 notImplemented(); 4320 notImplemented();
4322 } 4321 }
4323 return WebGLGetInfo(Float32Array::create(value, length)); 4322 return WebGLGetInfo(Float32Array::create(value, length));
4324 } 4323 }
4325 4324
4326 WebGLGetInfo WebGLRenderingContextBase::getWebGLIntArrayParameter(GLenum pname) 4325 WebGLGetInfo WebGLRenderingContextBase::getWebGLIntArrayParameter(GLenum pname)
4327 { 4326 {
4328 GLint value[4] = {0}; 4327 GLint value[4] = {0};
4329 if (!isContextLost()) 4328 if (!isContextLost())
4330 m_context->getIntegerv(pname, value); 4329 webContext()->getIntegerv(pname, value);
4331 unsigned length = 0; 4330 unsigned length = 0;
4332 switch (pname) { 4331 switch (pname) {
4333 case GL_MAX_VIEWPORT_DIMS: 4332 case GL_MAX_VIEWPORT_DIMS:
4334 length = 2; 4333 length = 2;
4335 break; 4334 break;
4336 case GL_SCISSOR_BOX: 4335 case GL_SCISSOR_BOX:
4337 case GL_VIEWPORT: 4336 case GL_VIEWPORT:
4338 length = 4; 4337 length = 4;
4339 break; 4338 break;
4340 default: 4339 default:
4341 notImplemented(); 4340 notImplemented();
4342 } 4341 }
4343 return WebGLGetInfo(Int32Array::create(value, length)); 4342 return WebGLGetInfo(Int32Array::create(value, length));
4344 } 4343 }
4345 4344
4346 void WebGLRenderingContextBase::handleTextureCompleteness(const char* functionNa me, bool prepareToDraw) 4345 void WebGLRenderingContextBase::handleTextureCompleteness(const char* functionNa me, bool prepareToDraw)
4347 { 4346 {
4348 // All calling functions check isContextLost, so a duplicate check is not ne eded here. 4347 // All calling functions check isContextLost, so a duplicate check is not ne eded here.
4349 bool resetActiveUnit = false; 4348 bool resetActiveUnit = false;
4350 WebGLTexture::TextureExtensionFlag flag = static_cast<WebGLTexture::TextureE xtensionFlag>((extensionEnabled(OESTextureFloatLinearName) ? WebGLTexture::Textu reFloatLinearExtensionEnabled : 0) 4349 WebGLTexture::TextureExtensionFlag flag = static_cast<WebGLTexture::TextureE xtensionFlag>((extensionEnabled(OESTextureFloatLinearName) ? WebGLTexture::Textu reFloatLinearExtensionEnabled : 0)
4351 | (extensionEnabled(OESTextureHalfFloatLinearName) ? WebGLTexture::Textu reHalfFloatLinearExtensionEnabled : 0)); 4350 | (extensionEnabled(OESTextureHalfFloatLinearName) ? WebGLTexture::Textu reHalfFloatLinearExtensionEnabled : 0));
4352 for (unsigned ii = 0; ii < m_onePlusMaxNonDefaultTextureUnit; ++ii) { 4351 for (unsigned ii = 0; ii < m_onePlusMaxNonDefaultTextureUnit; ++ii) {
4353 if ((m_textureUnits[ii].m_texture2DBinding.get() && m_textureUnits[ii].m _texture2DBinding->needToUseBlackTexture(flag)) 4352 if ((m_textureUnits[ii].m_texture2DBinding.get() && m_textureUnits[ii].m _texture2DBinding->needToUseBlackTexture(flag))
4354 || (m_textureUnits[ii].m_textureCubeMapBinding.get() && m_textureUni ts[ii].m_textureCubeMapBinding->needToUseBlackTexture(flag))) { 4353 || (m_textureUnits[ii].m_textureCubeMapBinding.get() && m_textureUni ts[ii].m_textureCubeMapBinding->needToUseBlackTexture(flag))) {
4355 if (ii != m_activeTextureUnit) { 4354 if (ii != m_activeTextureUnit) {
4356 m_context->activeTexture(ii); 4355 webContext()->activeTexture(ii);
4357 resetActiveUnit = true; 4356 resetActiveUnit = true;
4358 } else if (resetActiveUnit) { 4357 } else if (resetActiveUnit) {
4359 m_context->activeTexture(ii); 4358 webContext()->activeTexture(ii);
4360 resetActiveUnit = false; 4359 resetActiveUnit = false;
4361 } 4360 }
4362 WebGLTexture* tex2D; 4361 WebGLTexture* tex2D;
4363 WebGLTexture* texCubeMap; 4362 WebGLTexture* texCubeMap;
4364 if (prepareToDraw) { 4363 if (prepareToDraw) {
4365 String msg(String("texture bound to texture unit ") + String::nu mber(ii) 4364 String msg(String("texture bound to texture unit ") + String::nu mber(ii)
4366 + " is not renderable. It maybe non-power-of-2 and have inco mpatible texture filtering or is not 'texture complete'." 4365 + " is not renderable. It maybe non-power-of-2 and have inco mpatible texture filtering or is not 'texture complete'."
4367 + " Or the texture is Float or Half Float type with linear f iltering while OES_float_linear or OES_half_float_linear extension is not enable d."); 4366 + " Or the texture is Float or Half Float type with linear f iltering while OES_float_linear or OES_half_float_linear extension is not enable d.");
4368 emitGLWarning(functionName, msg.utf8().data()); 4367 emitGLWarning(functionName, msg.utf8().data());
4369 tex2D = m_blackTexture2D.get(); 4368 tex2D = m_blackTexture2D.get();
4370 texCubeMap = m_blackTextureCubeMap.get(); 4369 texCubeMap = m_blackTextureCubeMap.get();
4371 } else { 4370 } else {
4372 tex2D = m_textureUnits[ii].m_texture2DBinding.get(); 4371 tex2D = m_textureUnits[ii].m_texture2DBinding.get();
4373 texCubeMap = m_textureUnits[ii].m_textureCubeMapBinding.get(); 4372 texCubeMap = m_textureUnits[ii].m_textureCubeMapBinding.get();
4374 } 4373 }
4375 if (m_textureUnits[ii].m_texture2DBinding && m_textureUnits[ii].m_te xture2DBinding->needToUseBlackTexture(flag)) 4374 if (m_textureUnits[ii].m_texture2DBinding && m_textureUnits[ii].m_te xture2DBinding->needToUseBlackTexture(flag))
4376 m_context->bindTexture(GL_TEXTURE_2D, objectOrZero(tex2D)); 4375 webContext()->bindTexture(GL_TEXTURE_2D, objectOrZero(tex2D));
4377 if (m_textureUnits[ii].m_textureCubeMapBinding && m_textureUnits[ii] .m_textureCubeMapBinding->needToUseBlackTexture(flag)) 4376 if (m_textureUnits[ii].m_textureCubeMapBinding && m_textureUnits[ii] .m_textureCubeMapBinding->needToUseBlackTexture(flag))
4378 m_context->bindTexture(GL_TEXTURE_CUBE_MAP, objectOrZero(texCube Map)); 4377 webContext()->bindTexture(GL_TEXTURE_CUBE_MAP, objectOrZero(texC ubeMap));
4379 } 4378 }
4380 } 4379 }
4381 if (resetActiveUnit) 4380 if (resetActiveUnit)
4382 m_context->activeTexture(m_activeTextureUnit); 4381 webContext()->activeTexture(m_activeTextureUnit);
4383 } 4382 }
4384 4383
4385 void WebGLRenderingContextBase::createFallbackBlackTextures1x1() 4384 void WebGLRenderingContextBase::createFallbackBlackTextures1x1()
4386 { 4385 {
4387 // All calling functions check isContextLost, so a duplicate check is not ne eded here. 4386 // All calling functions check isContextLost, so a duplicate check is not ne eded here.
4388 unsigned char black[] = {0, 0, 0, 255}; 4387 unsigned char black[] = {0, 0, 0, 255};
4389 m_blackTexture2D = createTexture(); 4388 m_blackTexture2D = createTexture();
4390 m_context->bindTexture(GL_TEXTURE_2D, m_blackTexture2D->object()); 4389 webContext()->bindTexture(GL_TEXTURE_2D, m_blackTexture2D->object());
4391 m_context->texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 4390 webContext()->texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1,
4392 0, GL_RGBA, GL_UNSIGNED_BYTE, black); 4391 0, GL_RGBA, GL_UNSIGNED_BYTE, black);
4393 m_context->bindTexture(GL_TEXTURE_2D, 0); 4392 webContext()->bindTexture(GL_TEXTURE_2D, 0);
4394 m_blackTextureCubeMap = createTexture(); 4393 m_blackTextureCubeMap = createTexture();
4395 m_context->bindTexture(GL_TEXTURE_CUBE_MAP, m_blackTextureCubeMap->object()) ; 4394 webContext()->bindTexture(GL_TEXTURE_CUBE_MAP, m_blackTextureCubeMap->object ());
4396 m_context->texImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 1, 1, 4395 webContext()->texImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 1, 1,
4397 0, GL_RGBA, GL_UNSIGNED_BYTE, black); 4396 0, GL_RGBA, GL_UNSIGNED_BYTE, black);
4398 m_context->texImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 1, 1, 4397 webContext()->texImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 1, 1,
4399 0, GL_RGBA, GL_UNSIGNED_BYTE, black); 4398 0, GL_RGBA, GL_UNSIGNED_BYTE, black);
4400 m_context->texImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 1, 1, 4399 webContext()->texImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 1, 1,
4401 0, GL_RGBA, GL_UNSIGNED_BYTE, black); 4400 0, GL_RGBA, GL_UNSIGNED_BYTE, black);
4402 m_context->texImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 1, 1, 4401 webContext()->texImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 1, 1,
4403 0, GL_RGBA, GL_UNSIGNED_BYTE, black); 4402 0, GL_RGBA, GL_UNSIGNED_BYTE, black);
4404 m_context->texImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 1, 1, 4403 webContext()->texImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 1, 1,
4405 0, GL_RGBA, GL_UNSIGNED_BYTE, black); 4404 0, GL_RGBA, GL_UNSIGNED_BYTE, black);
4406 m_context->texImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 1, 1, 4405 webContext()->texImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 1, 1,
4407 0, GL_RGBA, GL_UNSIGNED_BYTE, black); 4406 0, GL_RGBA, GL_UNSIGNED_BYTE, black);
4408 m_context->bindTexture(GL_TEXTURE_CUBE_MAP, 0); 4407 webContext()->bindTexture(GL_TEXTURE_CUBE_MAP, 0);
4409 } 4408 }
4410 4409
4411 bool WebGLRenderingContextBase::isTexInternalFormatColorBufferCombinationValid(G Lenum texInternalFormat, GLenum colorBufferFormat) 4410 bool WebGLRenderingContextBase::isTexInternalFormatColorBufferCombinationValid(G Lenum texInternalFormat, GLenum colorBufferFormat)
4412 { 4411 {
4413 unsigned need = WebGLImageConversion::getChannelBitsByFormat(texInternalForm at); 4412 unsigned need = WebGLImageConversion::getChannelBitsByFormat(texInternalForm at);
4414 unsigned have = WebGLImageConversion::getChannelBitsByFormat(colorBufferForm at); 4413 unsigned have = WebGLImageConversion::getChannelBitsByFormat(colorBufferForm at);
4415 return (need & have) == need; 4414 return (need & have) == need;
4416 } 4415 }
4417 4416
4418 GLenum WebGLRenderingContextBase::boundFramebufferColorFormat() 4417 GLenum WebGLRenderingContextBase::boundFramebufferColorFormat()
(...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after
5175 if (!count) { 5174 if (!count) {
5176 markContextChanged(CanvasChanged); 5175 markContextChanged(CanvasChanged);
5177 return false; 5176 return false;
5178 } 5177 }
5179 5178
5180 if (!validateRenderingState(functionName)) { 5179 if (!validateRenderingState(functionName)) {
5181 return false; 5180 return false;
5182 } 5181 }
5183 5182
5184 const char* reason = "framebuffer incomplete"; 5183 const char* reason = "framebuffer incomplete";
5185 if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context.get(), &reason)) { 5184 if (m_framebufferBinding && !m_framebufferBinding->onAccess(webContext(), &r eason)) {
5186 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, functionName, reason ); 5185 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, functionName, reason );
5187 return false; 5186 return false;
5188 } 5187 }
5189 5188
5190 return true; 5189 return true;
5191 } 5190 }
5192 5191
5193 bool WebGLRenderingContextBase::validateDrawElements(const char* functionName, G Lenum mode, GLsizei count, GLenum type, long long offset) 5192 bool WebGLRenderingContextBase::validateDrawElements(const char* functionName, G Lenum mode, GLsizei count, GLenum type, long long offset)
5194 { 5193 {
5195 if (isContextLost() || !validateDrawMode(functionName, mode)) 5194 if (isContextLost() || !validateDrawMode(functionName, mode))
(...skipping 29 matching lines...) Expand all
5225 if (!m_boundVertexArrayObject->boundElementArrayBuffer()) { 5224 if (!m_boundVertexArrayObject->boundElementArrayBuffer()) {
5226 synthesizeGLError(GL_INVALID_OPERATION, functionName, "no ELEMENT_ARRAY_ BUFFER bound"); 5225 synthesizeGLError(GL_INVALID_OPERATION, functionName, "no ELEMENT_ARRAY_ BUFFER bound");
5227 return false; 5226 return false;
5228 } 5227 }
5229 5228
5230 if (!validateRenderingState(functionName)) { 5229 if (!validateRenderingState(functionName)) {
5231 return false; 5230 return false;
5232 } 5231 }
5233 5232
5234 const char* reason = "framebuffer incomplete"; 5233 const char* reason = "framebuffer incomplete";
5235 if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context.get(), &reason)) { 5234 if (m_framebufferBinding && !m_framebufferBinding->onAccess(webContext(), &r eason)) {
5236 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, functionName, reason ); 5235 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, functionName, reason );
5237 return false; 5236 return false;
5238 } 5237 }
5239 5238
5240 return true; 5239 return true;
5241 } 5240 }
5242 5241
5243 // Helper function to validate draw*Instanced calls 5242 // Helper function to validate draw*Instanced calls
5244 bool WebGLRenderingContextBase::validateDrawInstanced(const char* functionName, GLsizei primcount) 5243 bool WebGLRenderingContextBase::validateDrawInstanced(const char* functionName, GLsizei primcount)
5245 { 5244 {
(...skipping 17 matching lines...) Expand all
5263 { 5262 {
5264 if (isContextLost()) 5263 if (isContextLost())
5265 return; 5264 return;
5266 if (index >= m_maxVertexAttribs) { 5265 if (index >= m_maxVertexAttribs) {
5267 synthesizeGLError(GL_INVALID_VALUE, functionName, "index out of range"); 5266 synthesizeGLError(GL_INVALID_VALUE, functionName, "index out of range");
5268 return; 5267 return;
5269 } 5268 }
5270 // In GL, we skip setting vertexAttrib0 values. 5269 // In GL, we skip setting vertexAttrib0 values.
5271 switch (expectedSize) { 5270 switch (expectedSize) {
5272 case 1: 5271 case 1:
5273 m_context->vertexAttrib1f(index, v0); 5272 webContext()->vertexAttrib1f(index, v0);
5274 break; 5273 break;
5275 case 2: 5274 case 2:
5276 m_context->vertexAttrib2f(index, v0, v1); 5275 webContext()->vertexAttrib2f(index, v0, v1);
5277 break; 5276 break;
5278 case 3: 5277 case 3:
5279 m_context->vertexAttrib3f(index, v0, v1, v2); 5278 webContext()->vertexAttrib3f(index, v0, v1, v2);
5280 break; 5279 break;
5281 case 4: 5280 case 4:
5282 m_context->vertexAttrib4f(index, v0, v1, v2, v3); 5281 webContext()->vertexAttrib4f(index, v0, v1, v2, v3);
5283 break; 5282 break;
5284 } 5283 }
5285 VertexAttribValue& attribValue = m_vertexAttribValue[index]; 5284 VertexAttribValue& attribValue = m_vertexAttribValue[index];
5286 attribValue.value[0] = v0; 5285 attribValue.value[0] = v0;
5287 attribValue.value[1] = v1; 5286 attribValue.value[1] = v1;
5288 attribValue.value[2] = v2; 5287 attribValue.value[2] = v2;
5289 attribValue.value[3] = v3; 5288 attribValue.value[3] = v3;
5290 } 5289 }
5291 5290
5292 void WebGLRenderingContextBase::vertexAttribfvImpl(const char* functionName, GLu int index, Float32Array* v, GLsizei expectedSize) 5291 void WebGLRenderingContextBase::vertexAttribfvImpl(const char* functionName, GLu int index, Float32Array* v, GLsizei expectedSize)
(...skipping 19 matching lines...) Expand all
5312 synthesizeGLError(GL_INVALID_VALUE, functionName, "invalid size"); 5311 synthesizeGLError(GL_INVALID_VALUE, functionName, "invalid size");
5313 return; 5312 return;
5314 } 5313 }
5315 if (index >= m_maxVertexAttribs) { 5314 if (index >= m_maxVertexAttribs) {
5316 synthesizeGLError(GL_INVALID_VALUE, functionName, "index out of range"); 5315 synthesizeGLError(GL_INVALID_VALUE, functionName, "index out of range");
5317 return; 5316 return;
5318 } 5317 }
5319 // In GL, we skip setting vertexAttrib0 values. 5318 // In GL, we skip setting vertexAttrib0 values.
5320 switch (expectedSize) { 5319 switch (expectedSize) {
5321 case 1: 5320 case 1:
5322 m_context->vertexAttrib1fv(index, v); 5321 webContext()->vertexAttrib1fv(index, v);
5323 break; 5322 break;
5324 case 2: 5323 case 2:
5325 m_context->vertexAttrib2fv(index, v); 5324 webContext()->vertexAttrib2fv(index, v);
5326 break; 5325 break;
5327 case 3: 5326 case 3:
5328 m_context->vertexAttrib3fv(index, v); 5327 webContext()->vertexAttrib3fv(index, v);
5329 break; 5328 break;
5330 case 4: 5329 case 4:
5331 m_context->vertexAttrib4fv(index, v); 5330 webContext()->vertexAttrib4fv(index, v);
5332 break; 5331 break;
5333 } 5332 }
5334 VertexAttribValue& attribValue = m_vertexAttribValue[index]; 5333 VertexAttribValue& attribValue = m_vertexAttribValue[index];
5335 attribValue.initValue(); 5334 attribValue.initValue();
5336 for (int ii = 0; ii < expectedSize; ++ii) 5335 for (int ii = 0; ii < expectedSize; ++ii)
5337 attribValue.value[ii] = v[ii]; 5336 attribValue.value[ii] = v[ii];
5338 } 5337 }
5339 5338
5340 void WebGLRenderingContextBase::dispatchContextLostEvent(Timer<WebGLRenderingCon textBase>*) 5339 void WebGLRenderingContextBase::dispatchContextLostEvent(Timer<WebGLRenderingCon textBase>*)
5341 { 5340 {
(...skipping 20 matching lines...) Expand all
5362 5361
5363 LocalFrame* frame = canvas()->document().frame(); 5362 LocalFrame* frame = canvas()->document().frame();
5364 if (!frame) 5363 if (!frame)
5365 return; 5364 return;
5366 5365
5367 Settings* settings = frame->settings(); 5366 Settings* settings = frame->settings();
5368 5367
5369 if (!frame->loader().client()->allowWebGL(settings && settings->webGLEnabled ())) 5368 if (!frame->loader().client()->allowWebGL(settings && settings->webGLEnabled ()))
5370 return; 5369 return;
5371 5370
5371 // If the context was lost due to RealLostContext, we need to destruct the o ld DrawingBuffer before creating new DrawingBuffer to ensure resource budget eno ugh.
Ken Russell (switch to Gerrit) 2014/04/06 06:07:24 destruct -> destroy
5372 m_drawingBuffer.clear();
5373
5372 blink::WebGraphicsContext3D::Attributes attributes = m_requestedAttributes-> attributes(canvas()->document().topDocument().url().string(), settings); 5374 blink::WebGraphicsContext3D::Attributes attributes = m_requestedAttributes-> attributes(canvas()->document().topDocument().url().string(), settings);
5373 OwnPtr<blink::WebGraphicsContext3D> context = adoptPtr(blink::Platform::curr ent()->createOffscreenGraphicsContext3D(attributes, 0)); 5375 OwnPtr<blink::WebGraphicsContext3D> context = adoptPtr(blink::Platform::curr ent()->createOffscreenGraphicsContext3D(attributes, 0));
5374 RefPtr<DrawingBuffer> drawingBuffer; 5376 RefPtr<DrawingBuffer> drawingBuffer;
5375 if (context) { 5377 if (context) {
5376 // If the context was lost due to RealLostContext, we need to release FB Os before creating new DrawingBuffer to ensure resource budget enough.
5377 m_drawingBuffer->releaseResources();
5378 RefPtr<WebGLRenderingContextEvictionManager> contextEvictionManager = ad optRef(new WebGLRenderingContextEvictionManager()); 5378 RefPtr<WebGLRenderingContextEvictionManager> contextEvictionManager = ad optRef(new WebGLRenderingContextEvictionManager());
5379 5379
5380 // Construct a new drawing buffer with the new WebGraphicsContext3D. 5380 // Construct a new drawing buffer with the new WebGraphicsContext3D.
5381 DrawingBuffer::PreserveDrawingBuffer preserve = m_requestedAttributes->p reserveDrawingBuffer() ? DrawingBuffer::Preserve : DrawingBuffer::Discard; 5381 DrawingBuffer::PreserveDrawingBuffer preserve = m_requestedAttributes->p reserveDrawingBuffer() ? DrawingBuffer::Preserve : DrawingBuffer::Discard;
5382 drawingBuffer = DrawingBuffer::create(context.get(), clampedCanvasSize() , preserve, contextEvictionManager.release()); 5382 drawingBuffer = DrawingBuffer::create(context.release(), clampedCanvasSi ze(), preserve, contextEvictionManager.release());
5383 5383 // If DrawingBuffer::create() fails to allocate a fbo, |drawingBuffer| i s set to null.
5384 if (drawingBuffer->isZeroSized()) {
5385 drawingBuffer.clear();
5386 context.clear();
5387 }
5388 } 5384 }
5389 if (!context) { 5385 if (!drawingBuffer) {
5390 if (m_contextLostMode == RealLostContext) { 5386 if (m_contextLostMode == RealLostContext) {
5391 m_restoreTimer.startOneShot(secondsBetweenRestoreAttempts, FROM_HERE ); 5387 m_restoreTimer.startOneShot(secondsBetweenRestoreAttempts, FROM_HERE );
5392 } else { 5388 } else {
5393 // This likely shouldn't happen but is the best way to report it to the WebGL app. 5389 // This likely shouldn't happen but is the best way to report it to the WebGL app.
5394 synthesizeGLError(GL_INVALID_OPERATION, "", "error restoring context "); 5390 synthesizeGLError(GL_INVALID_OPERATION, "", "error restoring context ");
5395 } 5391 }
5396 return; 5392 return;
5397 } 5393 }
5398 5394
5399 m_drawingBuffer = drawingBuffer.release(); 5395 m_drawingBuffer = drawingBuffer.release();
5400 m_drawingBuffer->bind(); 5396 m_drawingBuffer->bind();
5401
5402 m_lostContextErrors.clear(); 5397 m_lostContextErrors.clear();
5403
5404 m_context = context.release();
5405 m_contextLost = false; 5398 m_contextLost = false;
5406 5399
5407 setupFlags(); 5400 setupFlags();
5408 initializeNewContext(); 5401 initializeNewContext();
5409 markContextChanged(CanvasContextChanged); 5402 markContextChanged(CanvasContextChanged);
5410 canvas()->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglconte xtrestored, false, true, "")); 5403 canvas()->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglconte xtrestored, false, true, ""));
5411 } 5404 }
5412 5405
5413 String WebGLRenderingContextBase::ensureNotNull(const String& text) const 5406 String WebGLRenderingContextBase::ensureNotNull(const String& text) const
5414 { 5407 {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
5478 } // namespace anonymous 5471 } // namespace anonymous
5479 5472
5480 void WebGLRenderingContextBase::synthesizeGLError(GLenum error, const char* func tionName, const char* description, ConsoleDisplayPreference display) 5473 void WebGLRenderingContextBase::synthesizeGLError(GLenum error, const char* func tionName, const char* description, ConsoleDisplayPreference display)
5481 { 5474 {
5482 String errorType = GetErrorString(error); 5475 String errorType = GetErrorString(error);
5483 if (m_synthesizedErrorsToConsole && display == DisplayInConsole) { 5476 if (m_synthesizedErrorsToConsole && display == DisplayInConsole) {
5484 String message = String("WebGL: ") + errorType + ": " + String(function Name) + ": " + String(description); 5477 String message = String("WebGL: ") + errorType + ": " + String(function Name) + ": " + String(description);
5485 printGLErrorToConsole(message); 5478 printGLErrorToConsole(message);
5486 } 5479 }
5487 if (!isContextLost()) 5480 if (!isContextLost())
5488 m_context->synthesizeGLError(error); 5481 webContext()->synthesizeGLError(error);
5489 else { 5482 else {
5490 if (m_lostContextErrors.find(error) == WTF::kNotFound) 5483 if (m_lostContextErrors.find(error) == WTF::kNotFound)
5491 m_lostContextErrors.append(error); 5484 m_lostContextErrors.append(error);
5492 } 5485 }
5493 InspectorInstrumentation::didFireWebGLError(canvas(), errorType); 5486 InspectorInstrumentation::didFireWebGLError(canvas(), errorType);
5494 } 5487 }
5495 5488
5496 void WebGLRenderingContextBase::emitGLWarning(const char* functionName, const ch ar* description) 5489 void WebGLRenderingContextBase::emitGLWarning(const char* functionName, const ch ar* description)
5497 { 5490 {
5498 if (m_synthesizedErrorsToConsole) { 5491 if (m_synthesizedErrorsToConsole) {
(...skipping 15 matching lines...) Expand all
5514 } 5507 }
5515 enableOrDisable(GL_STENCIL_TEST, 5508 enableOrDisable(GL_STENCIL_TEST,
5516 m_stencilEnabled && haveStencilBuffer); 5509 m_stencilEnabled && haveStencilBuffer);
5517 } 5510 }
5518 5511
5519 void WebGLRenderingContextBase::enableOrDisable(GLenum capability, bool enable) 5512 void WebGLRenderingContextBase::enableOrDisable(GLenum capability, bool enable)
5520 { 5513 {
5521 if (isContextLost()) 5514 if (isContextLost())
5522 return; 5515 return;
5523 if (enable) 5516 if (enable)
5524 m_context->enable(capability); 5517 webContext()->enable(capability);
5525 else 5518 else
5526 m_context->disable(capability); 5519 webContext()->disable(capability);
5527 } 5520 }
5528 5521
5529 IntSize WebGLRenderingContextBase::clampedCanvasSize() 5522 IntSize WebGLRenderingContextBase::clampedCanvasSize()
5530 { 5523 {
5531 return IntSize(clamp(canvas()->width(), 1, m_maxViewportDims[0]), 5524 return IntSize(clamp(canvas()->width(), 1, m_maxViewportDims[0]),
5532 clamp(canvas()->height(), 1, m_maxViewportDims[1])); 5525 clamp(canvas()->height(), 1, m_maxViewportDims[1]));
5533 } 5526 }
5534 5527
5535 GLint WebGLRenderingContextBase::maxDrawBuffers() 5528 GLint WebGLRenderingContextBase::maxDrawBuffers()
5536 { 5529 {
5537 if (isContextLost() || !extensionEnabled(WebGLDrawBuffersName)) 5530 if (isContextLost() || !extensionEnabled(WebGLDrawBuffersName))
5538 return 0; 5531 return 0;
5539 if (!m_maxDrawBuffers) 5532 if (!m_maxDrawBuffers)
5540 m_context->getIntegerv(GL_MAX_DRAW_BUFFERS_EXT, &m_maxDrawBuffers); 5533 webContext()->getIntegerv(GL_MAX_DRAW_BUFFERS_EXT, &m_maxDrawBuffers);
5541 if (!m_maxColorAttachments) 5534 if (!m_maxColorAttachments)
5542 m_context->getIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &m_maxColorAttachme nts); 5535 webContext()->getIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &m_maxColorAttac hments);
5543 // WEBGL_draw_buffers requires MAX_COLOR_ATTACHMENTS >= MAX_DRAW_BUFFERS. 5536 // WEBGL_draw_buffers requires MAX_COLOR_ATTACHMENTS >= MAX_DRAW_BUFFERS.
5544 return std::min(m_maxDrawBuffers, m_maxColorAttachments); 5537 return std::min(m_maxDrawBuffers, m_maxColorAttachments);
5545 } 5538 }
5546 5539
5547 GLint WebGLRenderingContextBase::maxColorAttachments() 5540 GLint WebGLRenderingContextBase::maxColorAttachments()
5548 { 5541 {
5549 if (isContextLost() || !extensionEnabled(WebGLDrawBuffersName)) 5542 if (isContextLost() || !extensionEnabled(WebGLDrawBuffersName))
5550 return 0; 5543 return 0;
5551 if (!m_maxColorAttachments) 5544 if (!m_maxColorAttachments)
5552 m_context->getIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &m_maxColorAttachme nts); 5545 webContext()->getIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &m_maxColorAttac hments);
5553 return m_maxColorAttachments; 5546 return m_maxColorAttachments;
5554 } 5547 }
5555 5548
5556 void WebGLRenderingContextBase::setBackDrawBuffer(GLenum buf) 5549 void WebGLRenderingContextBase::setBackDrawBuffer(GLenum buf)
5557 { 5550 {
5558 m_backDrawBuffer = buf; 5551 m_backDrawBuffer = buf;
5559 } 5552 }
5560 5553
5561 void WebGLRenderingContextBase::restoreCurrentFramebuffer() 5554 void WebGLRenderingContextBase::restoreCurrentFramebuffer()
5562 { 5555 {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
5597 if (m_textureUnits[i].m_texture2DBinding 5590 if (m_textureUnits[i].m_texture2DBinding
5598 || m_textureUnits[i].m_textureCubeMapBinding) { 5591 || m_textureUnits[i].m_textureCubeMapBinding) {
5599 m_onePlusMaxNonDefaultTextureUnit = i + 1; 5592 m_onePlusMaxNonDefaultTextureUnit = i + 1;
5600 return; 5593 return;
5601 } 5594 }
5602 } 5595 }
5603 m_onePlusMaxNonDefaultTextureUnit = 0; 5596 m_onePlusMaxNonDefaultTextureUnit = 0;
5604 } 5597 }
5605 5598
5606 } // namespace WebCore 5599 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/html/canvas/WebGLRenderingContextBase.h ('k') | Source/core/html/canvas/WebGLShader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698