Changeset 228084 in webkit
- Timestamp:
- Feb 4, 2018 11:33:44 PM (6 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r228052 r228084 1 2018-02-04 Zan Dobersek <zdobersek@igalia.com> 2 3 [Cairo] Split TexMap functionality out of GraphicsContext3DCairo 4 https://bugs.webkit.org/show_bug.cgi?id=182465 5 6 Reviewed by Michael Catanzaro. 7 8 Take the Non-Cairo GraphicsContext3D functionality that's stashed in 9 GraphicsContext3DCairo and move it into the GraphicsContext3DTextureMapper 10 file. 11 12 In GraphicsContext3DCairo.cpp, only the Cairo-specific GraphicsContext3D 13 functionality remains, specifically ImageExtractor and paintToCanvas(). 14 15 Everything else is moved into GraphicsContext3DTextureMapper.cpp. This 16 filename and its location under platform/graphics/texmap/ was chosen 17 since all the ports using this file (GTK, WPE, WinCairo) are also using 18 the TextureMapper module. Various #if-guards are simplified in the 19 moved-over code to reflect this. 20 21 GraphicsContext3DCairo.cpp now better reflects GraphicsContext3DCG.cpp, 22 with both implementing functionality specific to a 2D painting library, 23 whereas GraphicsContext3DTextureMapper.cpp reflects 24 GraphicsContext3DCocoa.cpp in covering functionality needed to integrate 25 the GraphicsContext3D output into the platform-specific composition 26 system. 27 28 No new tests -- no change in behavior. 29 30 * platform/TextureMapper.cmake: 31 * platform/graphics/cairo/GraphicsContext3DCairo.cpp: 32 (WebCore::activeContexts): Deleted. 33 (WebCore::GraphicsContext3D::create): Deleted. 34 (WebCore::GraphicsContext3D::GraphicsContext3D): Deleted. 35 (WebCore::GraphicsContext3D::~GraphicsContext3D): Deleted. 36 (WebCore::GraphicsContext3D::setContextLostCallback): Deleted. 37 (WebCore::GraphicsContext3D::setErrorMessageCallback): Deleted. 38 (WebCore::GraphicsContext3D::makeContextCurrent): Deleted. 39 (WebCore::GraphicsContext3D::checkGPUStatus): Deleted. 40 (WebCore::GraphicsContext3D::platformGraphicsContext3D): Deleted. 41 (WebCore::GraphicsContext3D::platformTexture const): Deleted. 42 (WebCore::GraphicsContext3D::isGLES2Compliant const): Deleted. 43 (WebCore::GraphicsContext3D::platformLayer const): Deleted. 44 (WebCore::GraphicsContext3D::getExtensions): Deleted. 45 * platform/graphics/texmap/GraphicsContext3DTextureMapper.cpp: Copied from Source/WebCore/platform/graphics/cairo/GraphicsContext3DCairo.cpp. 46 (WebCore::activeContexts): 47 (WebCore::GraphicsContext3D::create): 48 (WebCore::GraphicsContext3D::GraphicsContext3D): 49 (WebCore::GraphicsContext3D::~GraphicsContext3D): 50 (WebCore::GraphicsContext3D::setContextLostCallback): 51 (WebCore::GraphicsContext3D::setErrorMessageCallback): 52 (WebCore::GraphicsContext3D::makeContextCurrent): 53 (WebCore::GraphicsContext3D::checkGPUStatus): 54 (WebCore::GraphicsContext3D::platformGraphicsContext3D): 55 (WebCore::GraphicsContext3D::platformTexture const): 56 (WebCore::GraphicsContext3D::isGLES2Compliant const): 57 (WebCore::GraphicsContext3D::platformLayer const): 58 (WebCore::GraphicsContext3D::getExtensions): 59 1 60 2018-02-04 Zan Dobersek <zdobersek@igalia.com> 2 61 -
trunk/Source/WebCore/platform/TextureMapper.cmake
r225773 r228084 5 5 platform/graphics/texmap/BitmapTexture.cpp 6 6 platform/graphics/texmap/BitmapTexturePool.cpp 7 platform/graphics/texmap/GraphicsContext3DTextureMapper.cpp 7 8 platform/graphics/texmap/TextureMapper.cpp 8 9 platform/graphics/texmap/TextureMapperAnimation.cpp -
trunk/Source/WebCore/platform/graphics/cairo/GraphicsContext3DCairo.cpp
r228052 r228084 27 27 28 28 #include "config.h" 29 30 #if USE(CAIRO)31 32 #if ENABLE(GRAPHICS_CONTEXT_3D)33 29 #include "GraphicsContext3D.h" 34 30 31 #if ENABLE(GRAPHICS_CONTEXT_3D) && USE(CAIRO) 32 35 33 #include "CairoUtilities.h" 36 #include "GraphicsContext3DPrivate.h"37 34 #include "Image.h" 38 35 #include "ImageSource.h" 39 #include "NotImplemented.h"40 36 #include "PlatformContextCairo.h" 41 37 #include "RefPtrCairo.h" 42 38 #include <cairo.h> 43 #include <wtf/Deque.h>44 #include <wtf/NeverDestroyed.h>45 46 #if PLATFORM(WIN)47 #include <GLSLANG/ShaderLang.h>48 #else49 #include <ANGLE/ShaderLang.h>50 #endif51 52 #if USE(LIBEPOXY)53 #include <epoxy/gl.h>54 #elif !USE(OPENGL_ES_2)55 #include "OpenGLShims.h"56 #endif57 58 #if USE(OPENGL_ES_2)59 #include "Extensions3DOpenGLES.h"60 #else61 #include "Extensions3DOpenGL.h"62 #endif63 64 #if USE(TEXTURE_MAPPER)65 #include "TextureMapperGC3DPlatformLayer.h"66 #endif67 39 68 40 namespace WebCore { 69 41 70 static const size_t MaxActiveContexts = 16; 71 static Deque<GraphicsContext3D*, MaxActiveContexts>& activeContexts() 72 { 73 static NeverDestroyed<Deque<GraphicsContext3D*, MaxActiveContexts>> s_activeContexts; 74 return s_activeContexts; 75 } 76 77 RefPtr<GraphicsContext3D> GraphicsContext3D::create(GraphicsContext3DAttributes attributes, HostWindow* hostWindow, GraphicsContext3D::RenderStyle renderStyle) 78 { 79 // This implementation doesn't currently support rendering directly to the HostWindow. 80 if (renderStyle == RenderDirectlyToHostWindow) 81 return nullptr; 82 83 static bool initialized = false; 84 static bool success = true; 85 if (!initialized) { 86 #if !USE(OPENGL_ES_2) && !USE(LIBEPOXY) 87 success = initializeOpenGLShims(); 88 #endif 89 initialized = true; 90 } 91 if (!success) 92 return nullptr; 93 94 auto& contexts = activeContexts(); 95 if (contexts.size() >= MaxActiveContexts) 96 contexts.first()->recycleContext(); 97 98 // Calling recycleContext() above should have lead to the graphics context being 99 // destroyed and thus removed from the active contexts list. 100 if (contexts.size() >= MaxActiveContexts) 101 return nullptr; 102 103 // Create the GraphicsContext3D object first in order to establist a current context on this thread. 104 auto context = adoptRef(new GraphicsContext3D(attributes, hostWindow, renderStyle)); 105 106 #if USE(LIBEPOXY) && USE(OPENGL_ES_2) 107 // Bail if GLES3 was requested but cannot be provided. 108 if (attributes.useGLES3 && !epoxy_is_desktop_gl() && epoxy_gl_version() < 30) 109 return nullptr; 110 #endif 111 112 contexts.append(context.get()); 113 return context; 114 } 115 116 GraphicsContext3D::GraphicsContext3D(GraphicsContext3DAttributes attributes, HostWindow*, GraphicsContext3D::RenderStyle renderStyle, GraphicsContext3D* sharedContext) 117 : m_attrs(attributes) 118 { 119 ASSERT_UNUSED(sharedContext, !sharedContext); 120 #if USE(TEXTURE_MAPPER) 121 m_texmapLayer = std::make_unique<TextureMapperGC3DPlatformLayer>(*this, renderStyle); 122 #else 123 m_private = std::make_unique<GraphicsContext3DPrivate>(this, renderStyle); 124 #endif 125 126 makeContextCurrent(); 127 128 validateAttributes(); 129 130 if (renderStyle == RenderOffscreen) { 131 // Create a texture to render into. 132 ::glGenTextures(1, &m_texture); 133 ::glBindTexture(GL_TEXTURE_2D, m_texture); 134 ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 135 ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 136 ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 137 ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 138 ::glBindTexture(GL_TEXTURE_2D, 0); 139 140 // Create an FBO. 141 ::glGenFramebuffers(1, &m_fbo); 142 ::glBindFramebuffer(GL_FRAMEBUFFER, m_fbo); 143 144 #if USE(COORDINATED_GRAPHICS_THREADED) 145 ::glGenTextures(1, &m_compositorTexture); 146 ::glBindTexture(GL_TEXTURE_2D, m_compositorTexture); 147 ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 148 ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 149 ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 150 ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 151 152 ::glGenTextures(1, &m_intermediateTexture); 153 ::glBindTexture(GL_TEXTURE_2D, m_intermediateTexture); 154 ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 155 ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 156 ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 157 ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 158 159 ::glBindTexture(GL_TEXTURE_2D, 0); 160 #endif 161 162 163 // Create a multisample FBO. 164 if (m_attrs.antialias) { 165 ::glGenFramebuffers(1, &m_multisampleFBO); 166 ::glBindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO); 167 m_state.boundFBO = m_multisampleFBO; 168 ::glGenRenderbuffers(1, &m_multisampleColorBuffer); 169 if (m_attrs.stencil || m_attrs.depth) 170 ::glGenRenderbuffers(1, &m_multisampleDepthStencilBuffer); 171 } else { 172 // Bind canvas FBO. 173 glBindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo); 174 m_state.boundFBO = m_fbo; 175 #if USE(OPENGL_ES_2) 176 if (m_attrs.depth) 177 glGenRenderbuffers(1, &m_depthBuffer); 178 if (m_attrs.stencil) 179 glGenRenderbuffers(1, &m_stencilBuffer); 180 #endif 181 if (m_attrs.stencil || m_attrs.depth) 182 glGenRenderbuffers(1, &m_depthStencilBuffer); 183 } 184 } 185 186 #if !USE(OPENGL_ES_2) 187 ::glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); 188 189 if (GLContext::current()->version() >= 320) { 190 m_usingCoreProfile = true; 191 192 // From version 3.2 on we use the OpenGL Core profile, so request that ouput to the shader compiler. 193 // OpenGL version 3.2 uses GLSL version 1.50. 194 m_compiler = ANGLEWebKitBridge(SH_GLSL_150_CORE_OUTPUT); 195 196 // From version 3.2 on we use the OpenGL Core profile, and we need a VAO for rendering. 197 // A VAO could be created and bound by each component using GL rendering (TextureMapper, WebGL, etc). This is 198 // a simpler solution: the first GraphicsContext3D created on a GLContext will create and bind a VAO for that context. 199 GC3Dint currentVAO = 0; 200 getIntegerv(GraphicsContext3D::VERTEX_ARRAY_BINDING, ¤tVAO); 201 if (!currentVAO) { 202 m_vao = createVertexArray(); 203 bindVertexArray(m_vao); 204 } 205 } else { 206 // For lower versions request the compatibility output to the shader compiler. 207 m_compiler = ANGLEWebKitBridge(SH_GLSL_COMPATIBILITY_OUTPUT); 208 209 // GL_POINT_SPRITE is needed in lower versions. 210 ::glEnable(GL_POINT_SPRITE); 211 } 212 #else 213 // Adjust the shader specification depending on whether GLES3 (i.e. WebGL2 support) was requested. 214 m_compiler = ANGLEWebKitBridge(SH_ESSL_OUTPUT, m_attrs.useGLES3 ? SH_WEBGL2_SPEC : SH_WEBGL_SPEC); 215 #endif 216 217 // ANGLE initialization. 218 ShBuiltInResources ANGLEResources; 219 sh::InitBuiltInResources(&ANGLEResources); 220 221 getIntegerv(GraphicsContext3D::MAX_VERTEX_ATTRIBS, &ANGLEResources.MaxVertexAttribs); 222 getIntegerv(GraphicsContext3D::MAX_VERTEX_UNIFORM_VECTORS, &ANGLEResources.MaxVertexUniformVectors); 223 getIntegerv(GraphicsContext3D::MAX_VARYING_VECTORS, &ANGLEResources.MaxVaryingVectors); 224 getIntegerv(GraphicsContext3D::MAX_VERTEX_TEXTURE_IMAGE_UNITS, &ANGLEResources.MaxVertexTextureImageUnits); 225 getIntegerv(GraphicsContext3D::MAX_COMBINED_TEXTURE_IMAGE_UNITS, &ANGLEResources.MaxCombinedTextureImageUnits); 226 getIntegerv(GraphicsContext3D::MAX_TEXTURE_IMAGE_UNITS, &ANGLEResources.MaxTextureImageUnits); 227 getIntegerv(GraphicsContext3D::MAX_FRAGMENT_UNIFORM_VECTORS, &ANGLEResources.MaxFragmentUniformVectors); 228 229 // Always set to 1 for OpenGL ES. 230 ANGLEResources.MaxDrawBuffers = 1; 231 232 GC3Dint range[2], precision; 233 getShaderPrecisionFormat(GraphicsContext3D::FRAGMENT_SHADER, GraphicsContext3D::HIGH_FLOAT, range, &precision); 234 ANGLEResources.FragmentPrecisionHigh = (range[0] || range[1] || precision); 235 236 m_compiler.setResources(ANGLEResources); 237 238 ::glClearColor(0, 0, 0, 0); 239 } 240 241 GraphicsContext3D::~GraphicsContext3D() 242 { 243 makeContextCurrent(); 244 if (m_texture) 245 ::glDeleteTextures(1, &m_texture); 246 #if USE(COORDINATED_GRAPHICS_THREADED) 247 if (m_compositorTexture) 248 ::glDeleteTextures(1, &m_compositorTexture); 249 #endif 250 251 if (m_attrs.antialias) { 252 ::glDeleteRenderbuffers(1, &m_multisampleColorBuffer); 253 if (m_attrs.stencil || m_attrs.depth) 254 ::glDeleteRenderbuffers(1, &m_multisampleDepthStencilBuffer); 255 ::glDeleteFramebuffers(1, &m_multisampleFBO); 256 } else if (m_attrs.stencil || m_attrs.depth) { 257 #if USE(OPENGL_ES_2) 258 if (m_depthBuffer) 259 glDeleteRenderbuffers(1, &m_depthBuffer); 260 261 if (m_stencilBuffer) 262 glDeleteRenderbuffers(1, &m_stencilBuffer); 263 #endif 264 if (m_depthStencilBuffer) 265 ::glDeleteRenderbuffers(1, &m_depthStencilBuffer); 266 } 267 ::glDeleteFramebuffers(1, &m_fbo); 268 #if USE(COORDINATED_GRAPHICS_THREADED) 269 ::glDeleteTextures(1, &m_intermediateTexture); 270 #endif 271 272 if (m_vao) 273 deleteVertexArray(m_vao); 274 275 auto* activeContext = activeContexts().takeLast([this](auto* it) { return it == this; }); 276 ASSERT_UNUSED(activeContext, !!activeContext); 277 } 278 279 GraphicsContext3D::ImageExtractor::~ImageExtractor() 280 { 281 } 42 GraphicsContext3D::ImageExtractor::~ImageExtractor() = default; 282 43 283 44 bool GraphicsContext3D::ImageExtractor::extractImage(bool premultiplyAlpha, bool ignoreGammaAndColorProfile) … … 375 136 } 376 137 377 void GraphicsContext3D::setContextLostCallback(std::unique_ptr<ContextLostCallback>)378 {379 }380 381 void GraphicsContext3D::setErrorMessageCallback(std::unique_ptr<ErrorMessageCallback>)382 {383 }384 385 bool GraphicsContext3D::makeContextCurrent()386 {387 #if USE(TEXTURE_MAPPER)388 if (m_texmapLayer)389 return m_texmapLayer->makeContextCurrent();390 #else391 if (m_private)392 return m_private->makeContextCurrent();393 #endif394 return false;395 }396 397 void GraphicsContext3D::checkGPUStatus()398 {399 }400 401 PlatformGraphicsContext3D GraphicsContext3D::platformGraphicsContext3D()402 {403 #if USE(TEXTURE_MAPPER)404 return m_texmapLayer->platformContext();405 #else406 return m_private->platformContext();407 #endif408 }409 410 Platform3DObject GraphicsContext3D::platformTexture() const411 {412 return m_texture;413 }414 415 bool GraphicsContext3D::isGLES2Compliant() const416 {417 #if USE(OPENGL_ES_2)418 return true;419 #else420 return false;421 #endif422 }423 424 PlatformLayer* GraphicsContext3D::platformLayer() const425 {426 #if USE(TEXTURE_MAPPER)427 return m_texmapLayer.get();428 #else429 return m_private.get();430 #endif431 }432 433 #if PLATFORM(GTK)434 Extensions3D& GraphicsContext3D::getExtensions()435 {436 if (!m_extensions) {437 #if USE(OPENGL_ES_2)438 // glGetStringi is not available on GLES2.439 m_extensions = std::make_unique<Extensions3DOpenGLES>(this, false);440 #else441 // From OpenGL 3.2 on we use the Core profile, and there we must use glGetStringi.442 m_extensions = std::make_unique<Extensions3DOpenGL>(this, GLContext::current()->version() >= 320);443 #endif444 }445 return *m_extensions;446 }447 #endif448 449 138 } // namespace WebCore 450 139 451 #endif // ENABLE(GRAPHICS_CONTEXT_3D) 452 453 #endif // USE(CAIRO) 140 #endif // ENABLE(GRAPHICS_CONTEXT_3D) && USE(CAIRO)
Note: See TracChangeset
for help on using the changeset viewer.