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: third_party/WebKit/Source/modules/webgl/WebGLRenderingContext.cpp

Issue 1881563003: Implement OffscreenCanvas.getContext('webgl') (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase and remove static_cast Created 4 years, 7 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 #include "modules/webgl/WebGLDepthTexture.h" 58 #include "modules/webgl/WebGLDepthTexture.h"
59 #include "modules/webgl/WebGLDrawBuffers.h" 59 #include "modules/webgl/WebGLDrawBuffers.h"
60 #include "modules/webgl/WebGLLoseContext.h" 60 #include "modules/webgl/WebGLLoseContext.h"
61 #include "platform/CheckedInt.h" 61 #include "platform/CheckedInt.h"
62 #include "platform/graphics/gpu/DrawingBuffer.h" 62 #include "platform/graphics/gpu/DrawingBuffer.h"
63 #include "public/platform/Platform.h" 63 #include "public/platform/Platform.h"
64 #include "public/platform/WebGraphicsContext3DProvider.h" 64 #include "public/platform/WebGraphicsContext3DProvider.h"
65 65
66 namespace blink { 66 namespace blink {
67 67
68 // An helper function for the two create() methods. The return value is an
69 // indicate of whether the create() should return nullptr or not.
70 static bool shouldCreateContext(WebGraphicsContext3DProvider* contextProvider)
71 {
72 if (!contextProvider)
73 return false;
74 gpu::gles2::GLES2Interface* gl = contextProvider->contextGL();
75 OwnPtr<Extensions3DUtil> extensionsUtil = Extensions3DUtil::create(gl);
76 if (!extensionsUtil)
77 return false;
78 if (extensionsUtil->supportsExtension("GL_EXT_debug_marker")) {
79 String contextLabel(String::format("WebGLRenderingContext-%p", contextPr ovider));
80 gl->PushGroupMarkerEXT(0, contextLabel.ascii().data());
81 }
82 return true;
83 }
84
85 CanvasRenderingContext* WebGLRenderingContext::Factory::create(ScriptState* scri ptState, OffscreenCanvas* offscreenCanvas, const CanvasContextCreationAttributes & attrs)
86 {
87 WebGLContextAttributes attributes = toWebGLContextAttributes(attrs);
88 OwnPtr<WebGraphicsContext3DProvider> contextProvider(createWebGraphicsContex t3DProvider(scriptState, attributes, 1));
89 if (!shouldCreateContext(contextProvider.get()))
90 return nullptr;
91
92 WebGLRenderingContext* renderingContext = new WebGLRenderingContext(offscree nCanvas, contextProvider.release(), attributes);
93 if (!renderingContext->drawingBuffer())
94 return nullptr;
95 renderingContext->initializeNewContext();
96 renderingContext->registerContextExtensions();
97
98 return renderingContext;
99 }
100
68 CanvasRenderingContext* WebGLRenderingContext::Factory::create(HTMLCanvasElement * canvas, const CanvasContextCreationAttributes& attrs, Document&) 101 CanvasRenderingContext* WebGLRenderingContext::Factory::create(HTMLCanvasElement * canvas, const CanvasContextCreationAttributes& attrs, Document&)
69 { 102 {
70 WebGLContextAttributes attributes = toWebGLContextAttributes(attrs); 103 WebGLContextAttributes attributes = toWebGLContextAttributes(attrs);
71 OwnPtr<WebGraphicsContext3DProvider> contextProvider(createWebGraphicsContex t3DProvider(canvas, attributes, 1)); 104 OwnPtr<WebGraphicsContext3DProvider> contextProvider(createWebGraphicsContex t3DProvider(canvas, attributes, 1));
72 if (!contextProvider) 105 if (!shouldCreateContext(contextProvider.get()))
73 return nullptr; 106 return nullptr;
74 gpu::gles2::GLES2Interface* gl = contextProvider->contextGL();
75 OwnPtr<Extensions3DUtil> extensionsUtil = Extensions3DUtil::create(gl);
76 if (!extensionsUtil)
77 return nullptr;
78 if (extensionsUtil->supportsExtension("GL_EXT_debug_marker")) {
79 String contextLabel(String::format("WebGLRenderingContext-%p", contextPr ovider.get()));
80 gl->PushGroupMarkerEXT(0, contextLabel.ascii().data());
81 }
82 107
83 WebGLRenderingContext* renderingContext = new WebGLRenderingContext(canvas, contextProvider.release(), attributes); 108 WebGLRenderingContext* renderingContext = new WebGLRenderingContext(canvas, contextProvider.release(), attributes);
84
85 if (!renderingContext->drawingBuffer()) { 109 if (!renderingContext->drawingBuffer()) {
86 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Could not create a WebGL context.")); 110 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Could not create a WebGL context."));
87 return nullptr; 111 return nullptr;
88 } 112 }
89
90 renderingContext->initializeNewContext(); 113 renderingContext->initializeNewContext();
91 renderingContext->registerContextExtensions(); 114 renderingContext->registerContextExtensions();
92 115
93 return renderingContext; 116 return renderingContext;
94 } 117 }
95 118
96 void WebGLRenderingContext::Factory::onError(HTMLCanvasElement* canvas, const St ring& error) 119 void WebGLRenderingContext::Factory::onError(HTMLCanvasElement* canvas, const St ring& error)
97 { 120 {
98 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcontext creationerror, false, true, error)); 121 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcontext creationerror, false, true, error));
99 } 122 }
100 123
101 WebGLRenderingContext::WebGLRenderingContext(HTMLCanvasElement* passedCanvas, Pa ssOwnPtr<WebGraphicsContext3DProvider> contextProvider, const WebGLContextAttrib utes& requestedAttributes) 124 WebGLRenderingContext::WebGLRenderingContext(HTMLCanvasElement* passedCanvas, Pa ssOwnPtr<WebGraphicsContext3DProvider> contextProvider, const WebGLContextAttrib utes& requestedAttributes)
102 : WebGLRenderingContextBase(passedCanvas, std::move(contextProvider), reques tedAttributes) 125 : WebGLRenderingContextBase(passedCanvas, std::move(contextProvider), reques tedAttributes)
103 { 126 {
104 } 127 }
105 128
129 WebGLRenderingContext::WebGLRenderingContext(OffscreenCanvas* passedOffscreenCan vas, PassOwnPtr<WebGraphicsContext3DProvider> contextProvider, const WebGLContex tAttributes& requestedAttributes)
130 : WebGLRenderingContextBase(passedOffscreenCanvas, std::move(contextProvider ), requestedAttributes)
131 {
132 }
133
106 WebGLRenderingContext::~WebGLRenderingContext() 134 WebGLRenderingContext::~WebGLRenderingContext()
107 { 135 {
108 } 136 }
109 137
110 void WebGLRenderingContext::setCanvasGetContextResult(RenderingContext& result) 138 void WebGLRenderingContext::setCanvasGetContextResult(RenderingContext& result)
111 { 139 {
112 result.setWebGLRenderingContext(this); 140 result.setWebGLRenderingContext(this);
113 } 141 }
114 142
143 void WebGLRenderingContext::setOffscreenCanvasGetContextResult(OffscreenRenderin gContext& result)
144 {
145 result.setWebGLRenderingContext(this);
146 }
147
148 ImageBitmap* WebGLRenderingContext::transferToImageBitmap(ExceptionState& except ionState)
149 {
150 NOTIMPLEMENTED();
151 return nullptr;
152 }
153
115 void WebGLRenderingContext::registerContextExtensions() 154 void WebGLRenderingContext::registerContextExtensions()
116 { 155 {
117 // Register extensions. 156 // Register extensions.
118 static const char* const bothPrefixes[] = { "", "WEBKIT_", 0, }; 157 static const char* const bothPrefixes[] = { "", "WEBKIT_", 0, };
119 158
120 registerExtension<ANGLEInstancedArrays>(m_angleInstancedArrays); 159 registerExtension<ANGLEInstancedArrays>(m_angleInstancedArrays);
121 registerExtension<EXTBlendMinMax>(m_extBlendMinMax); 160 registerExtension<EXTBlendMinMax>(m_extBlendMinMax);
122 registerExtension<EXTDisjointTimerQuery>(m_extDisjointTimerQuery); 161 registerExtension<EXTDisjointTimerQuery>(m_extDisjointTimerQuery);
123 registerExtension<EXTFragDepth>(m_extFragDepth); 162 registerExtension<EXTFragDepth>(m_extFragDepth);
124 registerExtension<EXTShaderTextureLOD>(m_extShaderTextureLOD); 163 registerExtension<EXTShaderTextureLOD>(m_extShaderTextureLOD);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 visitor->trace(m_webglCompressedTextureASTC); 205 visitor->trace(m_webglCompressedTextureASTC);
167 visitor->trace(m_webglCompressedTextureATC); 206 visitor->trace(m_webglCompressedTextureATC);
168 visitor->trace(m_webglCompressedTextureETC1); 207 visitor->trace(m_webglCompressedTextureETC1);
169 visitor->trace(m_webglCompressedTexturePVRTC); 208 visitor->trace(m_webglCompressedTexturePVRTC);
170 visitor->trace(m_webglCompressedTextureS3TC); 209 visitor->trace(m_webglCompressedTextureS3TC);
171 visitor->trace(m_webglDepthTexture); 210 visitor->trace(m_webglDepthTexture);
172 WebGLRenderingContextBase::trace(visitor); 211 WebGLRenderingContextBase::trace(visitor);
173 } 212 }
174 213
175 } // namespace blink 214 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698