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

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

Issue 127493002: Removed most calls to GraphicsContext3D from DrawingBuffer (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Moved texImage2DSafe to DrawingBuffer, it's only caller. Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2009 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 119
120 size_t WebGLRenderingContext::oldestContextIndex() 120 size_t WebGLRenderingContext::oldestContextIndex()
121 { 121 {
122 if (!activeContexts().size()) 122 if (!activeContexts().size())
123 return maxGLActiveContexts; 123 return maxGLActiveContexts;
124 124
125 WebGLRenderingContext* candidate = activeContexts().first(); 125 WebGLRenderingContext* candidate = activeContexts().first();
126 size_t candidateID = 0; 126 size_t candidateID = 0;
127 for (size_t ii = 1; ii < activeContexts().size(); ++ii) { 127 for (size_t ii = 1; ii < activeContexts().size(); ++ii) {
128 WebGLRenderingContext* context = activeContexts()[ii]; 128 WebGLRenderingContext* context = activeContexts()[ii];
129 if (context->graphicsContext3D() && candidate->graphicsContext3D() && co ntext->graphicsContext3D()->lastFlushID() < candidate->graphicsContext3D()->last FlushID()) { 129 if (context->webGraphicsContext3D() && candidate->webGraphicsContext3D() && context->webGraphicsContext3D()->lastFlushID() < candidate->webGraphicsConte xt3D()->lastFlushID()) {
130 candidate = context; 130 candidate = context;
131 candidateID = ii; 131 candidateID = ii;
132 } 132 }
133 } 133 }
134 134
135 return candidateID; 135 return candidateID;
136 } 136 }
137 137
138 IntSize WebGLRenderingContext::oldestContextSize() 138 IntSize WebGLRenderingContext::oldestContextSize()
139 { 139 {
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 } 522 }
523 523
524 RefPtr<GraphicsContext3D> contextSupport(GraphicsContext3D::createContextSup port(context.get())); 524 RefPtr<GraphicsContext3D> contextSupport(GraphicsContext3D::createContextSup port(context.get()));
525 525
526 if (!contextSupport) { 526 if (!contextSupport) {
527 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Could not create a WebGL context.")); 527 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Could not create a WebGL context."));
528 return nullptr; 528 return nullptr;
529 } 529 }
530 530
531 if (contextSupport->supportsExtension("GL_EXT_debug_marker")) 531 if (contextSupport->supportsExtension("GL_EXT_debug_marker"))
532 contextSupport->webContext()->pushGroupMarkerEXT("WebGLRenderingContext" ); 532 context->pushGroupMarkerEXT("WebGLRenderingContext");
533 533
534 OwnPtr<WebGLRenderingContext> renderingContext = adoptPtr(new WebGLRendering Context(canvas, context.release(), contextSupport, attributes, requestedAttribut es, preserveDrawingBuffer)); 534 OwnPtr<WebGLRenderingContext> renderingContext = adoptPtr(new WebGLRendering Context(canvas, context.release(), contextSupport, attributes, requestedAttribut es, preserveDrawingBuffer));
535 renderingContext->suspendIfNeeded(); 535 renderingContext->suspendIfNeeded();
536 536
537 if (renderingContext->m_drawingBuffer->isZeroSized()) { 537 if (renderingContext->m_drawingBuffer->isZeroSized()) {
538 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Could not create a WebGL context.")); 538 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Could not create a WebGL context."));
539 return nullptr; 539 return nullptr;
540 } 540 }
541 541
542 return renderingContext.release(); 542 return renderingContext.release();
(...skipping 27 matching lines...) Expand all
570 m_contextGroup = WebGLContextGroup::create(); 570 m_contextGroup = WebGLContextGroup::create();
571 m_contextGroup->addContext(this); 571 m_contextGroup->addContext(this);
572 572
573 m_maxViewportDims[0] = m_maxViewportDims[1] = 0; 573 m_maxViewportDims[0] = m_maxViewportDims[1] = 0;
574 m_context->getIntegerv(GL_MAX_VIEWPORT_DIMS, m_maxViewportDims); 574 m_context->getIntegerv(GL_MAX_VIEWPORT_DIMS, m_maxViewportDims);
575 575
576 RefPtr<WebGLRenderingContextEvictionManager> contextEvictionManager = adoptR ef(new WebGLRenderingContextEvictionManager()); 576 RefPtr<WebGLRenderingContextEvictionManager> contextEvictionManager = adoptR ef(new WebGLRenderingContextEvictionManager());
577 577
578 // Create the DrawingBuffer and initialize the platform layer. 578 // Create the DrawingBuffer and initialize the platform layer.
579 DrawingBuffer::PreserveDrawingBuffer preserve = preserveDrawingBuffer ? Draw ingBuffer::Preserve : DrawingBuffer::Discard; 579 DrawingBuffer::PreserveDrawingBuffer preserve = preserveDrawingBuffer ? Draw ingBuffer::Preserve : DrawingBuffer::Discard;
580 m_drawingBuffer = DrawingBuffer::create(m_contextSupport.get(), clampedCanva sSize(), preserve, contextEvictionManager.release()); 580 m_drawingBuffer = DrawingBuffer::create(m_context.get(), clampedCanvasSize() , preserve, contextEvictionManager.release());
581 581
582 if (!m_drawingBuffer->isZeroSized()) { 582 if (!m_drawingBuffer->isZeroSized()) {
583 m_drawingBuffer->bind(); 583 m_drawingBuffer->bind();
584 setupFlags(); 584 setupFlags();
585 initializeNewContext(); 585 initializeNewContext();
586 } 586 }
587 587
588 // Register extensions. 588 // Register extensions.
589 static const char* const webkitPrefix[] = { "WEBKIT_", 0, }; 589 static const char* const webkitPrefix[] = { "WEBKIT_", 0, };
590 static const char* const bothPrefixes[] = { "", "WEBKIT_", 0, }; 590 static const char* const bothPrefixes[] = { "", "WEBKIT_", 0, };
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 m_context->setErrorMessageCallback(0); 796 m_context->setErrorMessageCallback(0);
797 m_context.clear(); 797 m_context.clear();
798 } 798 }
799 } 799 }
800 800
801 void WebGLRenderingContext::markContextChanged() 801 void WebGLRenderingContext::markContextChanged()
802 { 802 {
803 if (m_framebufferBinding || isContextLost()) 803 if (m_framebufferBinding || isContextLost())
804 return; 804 return;
805 805
806 m_contextSupport->markContextChanged();
807 m_drawingBuffer->markContentsChanged(); 806 m_drawingBuffer->markContentsChanged();
808 807
809 m_layerCleared = false; 808 m_layerCleared = false;
810 RenderBox* renderBox = canvas()->renderBox(); 809 RenderBox* renderBox = canvas()->renderBox();
811 if (renderBox && renderBox->hasAcceleratedCompositing()) { 810 if (renderBox && renderBox->hasAcceleratedCompositing()) {
812 m_markedCanvasDirty = true; 811 m_markedCanvasDirty = true;
813 canvas()->clearCopiedImage(); 812 canvas()->clearCopiedImage();
814 renderBox->contentChanged(CanvasChanged); 813 renderBox->contentChanged(CanvasChanged);
815 } else { 814 } else {
816 if (!m_markedCanvasDirty) { 815 if (!m_markedCanvasDirty) {
817 m_markedCanvasDirty = true; 816 m_markedCanvasDirty = true;
818 canvas()->didDraw(FloatRect(FloatPoint(0, 0), clampedCanvasSize())); 817 canvas()->didDraw(FloatRect(FloatPoint(0, 0), clampedCanvasSize()));
819 } 818 }
820 } 819 }
821 } 820 }
822 821
823 bool WebGLRenderingContext::clearIfComposited(GLbitfield mask) 822 bool WebGLRenderingContext::clearIfComposited(GLbitfield mask)
824 { 823 {
825 if (isContextLost()) 824 if (isContextLost())
826 return false; 825 return false;
827 826
828 if (!m_contextSupport->layerComposited() || m_layerCleared 827 if (!m_drawingBuffer->layerComposited() || m_layerCleared
829 || m_preserveDrawingBuffer || (mask && m_framebufferBinding)) 828 || m_preserveDrawingBuffer || (mask && m_framebufferBinding))
830 return false; 829 return false;
831 830
832 RefPtr<WebGLContextAttributes> contextAttributes = getContextAttributes(); 831 RefPtr<WebGLContextAttributes> contextAttributes = getContextAttributes();
833 832
834 // Determine if it's possible to combine the clear the user asked for and th is clear. 833 // Determine if it's possible to combine the clear the user asked for and th is clear.
835 bool combinedClear = mask && !m_scissorEnabled; 834 bool combinedClear = mask && !m_scissorEnabled;
836 835
837 m_context->disable(GL_SCISSOR_TEST); 836 m_context->disable(GL_SCISSOR_TEST);
838 if (combinedClear && (mask & GL_COLOR_BUFFER_BIT)) 837 if (combinedClear && (mask & GL_COLOR_BUFFER_BIT))
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 m_colorMask[2], m_colorMask[3]); 882 m_colorMask[2], m_colorMask[3]);
884 m_context->clearDepth(m_clearDepth); 883 m_context->clearDepth(m_clearDepth);
885 m_context->clearStencil(m_clearStencil); 884 m_context->clearStencil(m_clearStencil);
886 m_context->stencilMaskSeparate(GL_FRONT, m_stencilMask); 885 m_context->stencilMaskSeparate(GL_FRONT, m_stencilMask);
887 m_context->depthMask(m_depthMask); 886 m_context->depthMask(m_depthMask);
888 } 887 }
889 888
890 void WebGLRenderingContext::markLayerComposited() 889 void WebGLRenderingContext::markLayerComposited()
891 { 890 {
892 if (!isContextLost()) 891 if (!isContextLost())
893 m_contextSupport->markLayerComposited(); 892 m_drawingBuffer->markLayerComposited();
894 } 893 }
895 894
896 void WebGLRenderingContext::paintRenderingResultsToCanvas() 895 void WebGLRenderingContext::paintRenderingResultsToCanvas()
897 { 896 {
898 if (isContextLost()) { 897 if (isContextLost()) {
899 canvas()->clearPresentationCopy(); 898 canvas()->clearPresentationCopy();
900 return; 899 return;
901 } 900 }
902 901
903 if (canvas()->document().printing()) 902 if (canvas()->document().printing())
904 canvas()->clearPresentationCopy(); 903 canvas()->clearPresentationCopy();
905 904
906 // Until the canvas is written to by the application, the clear that 905 // Until the canvas is written to by the application, the clear that
907 // happened after it was composited should be ignored by the compositor. 906 // happened after it was composited should be ignored by the compositor.
908 if (m_contextSupport->layerComposited() && !m_preserveDrawingBuffer) { 907 if (m_drawingBuffer->layerComposited() && !m_preserveDrawingBuffer) {
909 m_drawingBuffer->paintCompositedResultsToCanvas(canvas()->buffer()); 908 m_drawingBuffer->paintCompositedResultsToCanvas(canvas()->buffer());
910 909
911 canvas()->makePresentationCopy(); 910 canvas()->makePresentationCopy();
912 } else 911 } else
913 canvas()->clearPresentationCopy(); 912 canvas()->clearPresentationCopy();
914 clearIfComposited(); 913 clearIfComposited();
915 914
916 if (!m_markedCanvasDirty && !m_layerCleared) 915 if (!m_markedCanvasDirty && !m_layerCleared)
917 return; 916 return;
918 917
919 canvas()->clearCopiedImage(); 918 canvas()->clearCopiedImage();
920 m_markedCanvasDirty = false; 919 m_markedCanvasDirty = false;
921 920
922 m_drawingBuffer->commit(); 921 m_drawingBuffer->commit();
923 if (!(canvas()->buffer())->copyRenderingResultsFromDrawingBuffer(m_drawingBu ffer.get())) 922 if (!(canvas()->buffer())->copyRenderingResultsFromDrawingBuffer(m_drawingBu ffer.get()))
924 m_contextSupport->paintRenderingResultsToCanvas(canvas()->buffer(), m_dr awingBuffer.get()); 923 m_drawingBuffer->paintRenderingResultsToCanvas(canvas()->buffer());
925 924
926 if (m_framebufferBinding) 925 if (m_framebufferBinding)
927 m_context->bindFramebuffer(GL_FRAMEBUFFER, objectOrZero(m_framebufferBin ding.get())); 926 m_context->bindFramebuffer(GL_FRAMEBUFFER, objectOrZero(m_framebufferBin ding.get()));
928 else 927 else
929 m_drawingBuffer->bind(); 928 m_drawingBuffer->bind();
930 } 929 }
931 930
932 PassRefPtr<ImageData> WebGLRenderingContext::paintRenderingResultsToImageData() 931 PassRefPtr<ImageData> WebGLRenderingContext::paintRenderingResultsToImageData()
933 { 932 {
934 if (isContextLost()) 933 if (isContextLost())
935 return 0; 934 return 0;
936 935
937 clearIfComposited(); 936 clearIfComposited();
938 m_drawingBuffer->commit(); 937 m_drawingBuffer->commit();
939 int width, height; 938 int width, height;
940 RefPtr<Uint8ClampedArray> imageDataPixels = m_contextSupport->paintRendering ResultsToImageData(m_drawingBuffer.get(), width, height); 939 RefPtr<Uint8ClampedArray> imageDataPixels = m_drawingBuffer->paintRenderingR esultsToImageData(width, height);
941 if (!imageDataPixels) 940 if (!imageDataPixels)
942 return 0; 941 return 0;
943 942
944 if (m_framebufferBinding) 943 if (m_framebufferBinding)
945 m_context->bindFramebuffer(GL_FRAMEBUFFER, objectOrZero(m_framebufferBin ding.get())); 944 m_context->bindFramebuffer(GL_FRAMEBUFFER, objectOrZero(m_framebufferBin ding.get()));
946 else 945 else
947 m_drawingBuffer->bind(); 946 m_drawingBuffer->bind();
948 947
949 return ImageData::create(IntSize(width, height), imageDataPixels); 948 return ImageData::create(IntSize(width, height), imageDataPixels);
950 } 949 }
(...skipping 2073 matching lines...) Expand 10 before | Expand all | Expand 10 after
3024 } else { 3023 } else {
3025 synthesizeGLError(GL_INVALID_VALUE, "pixelStorei", "invalid paramete r for UNPACK_COLORSPACE_CONVERSION_WEBGL"); 3024 synthesizeGLError(GL_INVALID_VALUE, "pixelStorei", "invalid paramete r for UNPACK_COLORSPACE_CONVERSION_WEBGL");
3026 return; 3025 return;
3027 } 3026 }
3028 break; 3027 break;
3029 case GL_PACK_ALIGNMENT: 3028 case GL_PACK_ALIGNMENT:
3030 case GL_UNPACK_ALIGNMENT: 3029 case GL_UNPACK_ALIGNMENT:
3031 if (param == 1 || param == 2 || param == 4 || param == 8) { 3030 if (param == 1 || param == 2 || param == 4 || param == 8) {
3032 if (pname == GL_PACK_ALIGNMENT) { 3031 if (pname == GL_PACK_ALIGNMENT) {
3033 m_packAlignment = param; 3032 m_packAlignment = param;
3034 m_contextSupport->setPackAlignment(param); 3033 m_drawingBuffer->setPackAlignment(param);
3035 } else { // GL_UNPACK_ALIGNMENT: 3034 } else { // GL_UNPACK_ALIGNMENT:
3036 m_unpackAlignment = param; 3035 m_unpackAlignment = param;
3037 } 3036 }
3038 m_context->pixelStorei(pname, param); 3037 m_context->pixelStorei(pname, param);
3039 } else { 3038 } else {
3040 synthesizeGLError(GL_INVALID_VALUE, "pixelStorei", "invalid paramete r for alignment"); 3039 synthesizeGLError(GL_INVALID_VALUE, "pixelStorei", "invalid paramete r for alignment");
3041 return; 3040 return;
3042 } 3041 }
3043 break; 3042 break;
3044 default: 3043 default:
(...skipping 2382 matching lines...) Expand 10 before | Expand all | Expand 10 after
5427 synthesizeGLError(GL_INVALID_OPERATION, "", "error restoring context "); 5426 synthesizeGLError(GL_INVALID_OPERATION, "", "error restoring context ");
5428 } 5427 }
5429 return; 5428 return;
5430 } 5429 }
5431 5430
5432 RefPtr<WebGLRenderingContextEvictionManager> contextEvictionManager = adoptR ef(new WebGLRenderingContextEvictionManager()); 5431 RefPtr<WebGLRenderingContextEvictionManager> contextEvictionManager = adoptR ef(new WebGLRenderingContextEvictionManager());
5433 5432
5434 // Construct a new drawing buffer with the new GraphicsContext3D. 5433 // Construct a new drawing buffer with the new GraphicsContext3D.
5435 m_drawingBuffer->releaseResources(); 5434 m_drawingBuffer->releaseResources();
5436 DrawingBuffer::PreserveDrawingBuffer preserve = m_preserveDrawingBuffer ? Dr awingBuffer::Preserve : DrawingBuffer::Discard; 5435 DrawingBuffer::PreserveDrawingBuffer preserve = m_preserveDrawingBuffer ? Dr awingBuffer::Preserve : DrawingBuffer::Discard;
5437 m_drawingBuffer = DrawingBuffer::create(contextSupport.get(), clampedCanvasS ize(), preserve, contextEvictionManager.release()); 5436 m_drawingBuffer = DrawingBuffer::create(context.get(), clampedCanvasSize(), preserve, contextEvictionManager.release());
5438 5437
5439 if (m_drawingBuffer->isZeroSized()) 5438 if (m_drawingBuffer->isZeroSized())
5440 return; 5439 return;
5441 5440
5442 m_drawingBuffer->bind(); 5441 m_drawingBuffer->bind();
5443 5442
5444 m_lostContextErrors.clear(); 5443 m_lostContextErrors.clear();
5445 5444
5446 m_contextSupport = contextSupport; 5445 m_contextSupport = contextSupport;
5447 m_context = context.release(); 5446 m_context = context.release();
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
5639 if (m_textureUnits[i].m_texture2DBinding 5638 if (m_textureUnits[i].m_texture2DBinding
5640 || m_textureUnits[i].m_textureCubeMapBinding) { 5639 || m_textureUnits[i].m_textureCubeMapBinding) {
5641 m_onePlusMaxNonDefaultTextureUnit = i + 1; 5640 m_onePlusMaxNonDefaultTextureUnit = i + 1;
5642 return; 5641 return;
5643 } 5642 }
5644 } 5643 }
5645 m_onePlusMaxNonDefaultTextureUnit = 0; 5644 m_onePlusMaxNonDefaultTextureUnit = 0;
5646 } 5645 }
5647 5646
5648 } // namespace WebCore 5647 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/html/canvas/WebGLRenderingContext.h ('k') | Source/platform/graphics/GraphicsContext3D.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698