| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2010, Google Inc. All rights reserved. | 2 * Copyright (c) 2010, Google 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 GLuint m_oldTextureUnitZeroId; | 83 GLuint m_oldTextureUnitZeroId; |
| 84 }; | 84 }; |
| 85 | 85 |
| 86 static bool shouldFailDrawingBufferCreationForTesting = false; | 86 static bool shouldFailDrawingBufferCreationForTesting = false; |
| 87 | 87 |
| 88 } // namespace | 88 } // namespace |
| 89 | 89 |
| 90 PassRefPtr<DrawingBuffer> DrawingBuffer::create(std::unique_ptr<WebGraphicsConte
xt3DProvider> contextProvider, | 90 PassRefPtr<DrawingBuffer> DrawingBuffer::create(std::unique_ptr<WebGraphicsConte
xt3DProvider> contextProvider, |
| 91 const IntSize& size, bool premultipliedAlpha, bool wantAlphaChannel, | 91 const IntSize& size, bool premultipliedAlpha, bool wantAlphaChannel, |
| 92 bool wantDepthBuffer, bool wantStencilBuffer, bool wantAntialiasing, | 92 bool wantDepthBuffer, bool wantStencilBuffer, bool wantAntialiasing, |
| 93 PreserveDrawingBuffer preserve, WebGLVersion webGLVersion) | 93 PreserveDrawingBuffer preserve, WebGLVersion webGLVersion, |
| 94 ChromiumImageUsage chromiumImageUsage) |
| 94 { | 95 { |
| 95 ASSERT(contextProvider); | 96 ASSERT(contextProvider); |
| 96 | 97 |
| 97 if (shouldFailDrawingBufferCreationForTesting) { | 98 if (shouldFailDrawingBufferCreationForTesting) { |
| 98 shouldFailDrawingBufferCreationForTesting = false; | 99 shouldFailDrawingBufferCreationForTesting = false; |
| 99 return nullptr; | 100 return nullptr; |
| 100 } | 101 } |
| 101 | 102 |
| 102 std::unique_ptr<Extensions3DUtil> extensionsUtil = Extensions3DUtil::create(
contextProvider->contextGL()); | 103 std::unique_ptr<Extensions3DUtil> extensionsUtil = Extensions3DUtil::create(
contextProvider->contextGL()); |
| 103 if (!extensionsUtil->isValid()) { | 104 if (!extensionsUtil->isValid()) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 116 extensionsUtil->ensureExtensionEnabled("GL_CHROMIUM_framebuffer_mult
isample"); | 117 extensionsUtil->ensureExtensionEnabled("GL_CHROMIUM_framebuffer_mult
isample"); |
| 117 else | 118 else |
| 118 extensionsUtil->ensureExtensionEnabled("GL_EXT_multisampled_render_t
o_texture"); | 119 extensionsUtil->ensureExtensionEnabled("GL_EXT_multisampled_render_t
o_texture"); |
| 119 } | 120 } |
| 120 bool discardFramebufferSupported = extensionsUtil->supportsExtension("GL_EXT
_discard_framebuffer"); | 121 bool discardFramebufferSupported = extensionsUtil->supportsExtension("GL_EXT
_discard_framebuffer"); |
| 121 if (discardFramebufferSupported) | 122 if (discardFramebufferSupported) |
| 122 extensionsUtil->ensureExtensionEnabled("GL_EXT_discard_framebuffer"); | 123 extensionsUtil->ensureExtensionEnabled("GL_EXT_discard_framebuffer"); |
| 123 | 124 |
| 124 RefPtr<DrawingBuffer> drawingBuffer = adoptRef(new DrawingBuffer(std::move(c
ontextProvider), std::move(extensionsUtil), | 125 RefPtr<DrawingBuffer> drawingBuffer = adoptRef(new DrawingBuffer(std::move(c
ontextProvider), std::move(extensionsUtil), |
| 125 discardFramebufferSupported, wantAlphaChannel, premultipliedAlpha, | 126 discardFramebufferSupported, wantAlphaChannel, premultipliedAlpha, |
| 126 preserve, webGLVersion, wantDepthBuffer, wantStencilBuffer)); | 127 preserve, webGLVersion, wantDepthBuffer, wantStencilBuffer, chromiumImag
eUsage)); |
| 127 if (!drawingBuffer->initialize(size, multisampleSupported)) { | 128 if (!drawingBuffer->initialize(size, multisampleSupported)) { |
| 128 drawingBuffer->beginDestruction(); | 129 drawingBuffer->beginDestruction(); |
| 129 return PassRefPtr<DrawingBuffer>(); | 130 return PassRefPtr<DrawingBuffer>(); |
| 130 } | 131 } |
| 131 return drawingBuffer.release(); | 132 return drawingBuffer.release(); |
| 132 } | 133 } |
| 133 | 134 |
| 134 void DrawingBuffer::forceNextDrawingBufferCreationToFail() | 135 void DrawingBuffer::forceNextDrawingBufferCreationToFail() |
| 135 { | 136 { |
| 136 shouldFailDrawingBufferCreationForTesting = true; | 137 shouldFailDrawingBufferCreationForTesting = true; |
| 137 } | 138 } |
| 138 | 139 |
| 139 DrawingBuffer::DrawingBuffer( | 140 DrawingBuffer::DrawingBuffer( |
| 140 std::unique_ptr<WebGraphicsContext3DProvider> contextProvider, | 141 std::unique_ptr<WebGraphicsContext3DProvider> contextProvider, |
| 141 std::unique_ptr<Extensions3DUtil> extensionsUtil, | 142 std::unique_ptr<Extensions3DUtil> extensionsUtil, |
| 142 bool discardFramebufferSupported, | 143 bool discardFramebufferSupported, |
| 143 bool wantAlphaChannel, | 144 bool wantAlphaChannel, |
| 144 bool premultipliedAlpha, | 145 bool premultipliedAlpha, |
| 145 PreserveDrawingBuffer preserve, | 146 PreserveDrawingBuffer preserve, |
| 146 WebGLVersion webGLVersion, | 147 WebGLVersion webGLVersion, |
| 147 bool wantDepth, | 148 bool wantDepth, |
| 148 bool wantStencil) | 149 bool wantStencil, |
| 150 ChromiumImageUsage chromiumImageUsage) |
| 149 : m_preserveDrawingBuffer(preserve) | 151 : m_preserveDrawingBuffer(preserve) |
| 150 , m_webGLVersion(webGLVersion) | 152 , m_webGLVersion(webGLVersion) |
| 151 , m_contextProvider(std::move(contextProvider)) | 153 , m_contextProvider(std::move(contextProvider)) |
| 152 , m_gl(m_contextProvider->contextGL()) | 154 , m_gl(m_contextProvider->contextGL()) |
| 153 , m_extensionsUtil(std::move(extensionsUtil)) | 155 , m_extensionsUtil(std::move(extensionsUtil)) |
| 154 , m_discardFramebufferSupported(discardFramebufferSupported) | 156 , m_discardFramebufferSupported(discardFramebufferSupported) |
| 155 , m_wantAlphaChannel(wantAlphaChannel) | 157 , m_wantAlphaChannel(wantAlphaChannel) |
| 156 , m_premultipliedAlpha(premultipliedAlpha) | 158 , m_premultipliedAlpha(premultipliedAlpha) |
| 157 , m_softwareRendering(m_contextProvider->isSoftwareRendering()) | 159 , m_softwareRendering(m_contextProvider->isSoftwareRendering()) |
| 158 , m_wantDepth(wantDepth) | 160 , m_wantDepth(wantDepth) |
| 159 , m_wantStencil(wantStencil) | 161 , m_wantStencil(wantStencil) |
| 162 , m_chromiumImageUsage(chromiumImageUsage) |
| 160 { | 163 { |
| 161 memset(m_colorMask, 0, 4 * sizeof(GLboolean)); | 164 memset(m_colorMask, 0, 4 * sizeof(GLboolean)); |
| 162 memset(m_clearColor, 0, 4 * sizeof(GLfloat)); | 165 memset(m_clearColor, 0, 4 * sizeof(GLfloat)); |
| 163 // Used by browser tests to detect the use of a DrawingBuffer. | 166 // Used by browser tests to detect the use of a DrawingBuffer. |
| 164 TRACE_EVENT_INSTANT0("test_gpu", "DrawingBufferCreation", TRACE_EVENT_SCOPE_
GLOBAL); | 167 TRACE_EVENT_INSTANT0("test_gpu", "DrawingBufferCreation", TRACE_EVENT_SCOPE_
GLOBAL); |
| 165 } | 168 } |
| 166 | 169 |
| 167 DrawingBuffer::~DrawingBuffer() | 170 DrawingBuffer::~DrawingBuffer() |
| 168 { | 171 { |
| 169 ASSERT(m_destructionInProgress); | 172 ASSERT(m_destructionInProgress); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 return !m_drawFramebufferBinding && defaultBufferRequiresAlphaChannelToBePre
served(); | 228 return !m_drawFramebufferBinding && defaultBufferRequiresAlphaChannelToBePre
served(); |
| 226 } | 229 } |
| 227 | 230 |
| 228 bool DrawingBuffer::defaultBufferRequiresAlphaChannelToBePreserved() | 231 bool DrawingBuffer::defaultBufferRequiresAlphaChannelToBePreserved() |
| 229 { | 232 { |
| 230 if (wantExplicitResolve()) { | 233 if (wantExplicitResolve()) { |
| 231 return !m_wantAlphaChannel && getMultisampledRenderbufferFormat() == GL_
RGBA8_OES; | 234 return !m_wantAlphaChannel && getMultisampledRenderbufferFormat() == GL_
RGBA8_OES; |
| 232 } | 235 } |
| 233 | 236 |
| 234 bool rgbEmulation = contextProvider()->getCapabilities().emulate_rgb_buffer_
with_rgba | 237 bool rgbEmulation = contextProvider()->getCapabilities().emulate_rgb_buffer_
with_rgba |
| 235 || (RuntimeEnabledFeatures::webGLImageChromiumEnabled() && contextProvid
er()->getCapabilities().chromium_image_rgb_emulation); | 238 || (shouldUseChromiumImage() && contextProvider()->getCapabilities().chr
omium_image_rgb_emulation); |
| 236 return !m_wantAlphaChannel && rgbEmulation; | 239 return !m_wantAlphaChannel && rgbEmulation; |
| 237 } | 240 } |
| 238 | 241 |
| 239 void DrawingBuffer::freeRecycledMailboxes() | 242 void DrawingBuffer::freeRecycledMailboxes() |
| 240 { | 243 { |
| 241 while (!m_recycledMailboxQueue.isEmpty()) { | 244 while (!m_recycledMailboxQueue.isEmpty()) { |
| 242 RefPtr<RecycledMailbox> recycled = m_recycledMailboxQueue.takeLast(); | 245 RefPtr<RecycledMailbox> recycled = m_recycledMailboxQueue.takeLast(); |
| 243 deleteMailbox(recycled->mailbox, recycled->syncToken); | 246 deleteMailbox(recycled->mailbox, recycled->syncToken); |
| 244 } | 247 } |
| 245 } | 248 } |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 } | 532 } |
| 530 | 533 |
| 531 PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::takeRecycledMailbox() | 534 PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::takeRecycledMailbox() |
| 532 { | 535 { |
| 533 if (m_recycledMailboxQueue.isEmpty()) | 536 if (m_recycledMailboxQueue.isEmpty()) |
| 534 return nullptr; | 537 return nullptr; |
| 535 | 538 |
| 536 // Creation of image backed mailboxes is very expensive, so be less | 539 // Creation of image backed mailboxes is very expensive, so be less |
| 537 // aggressive about pruning them. | 540 // aggressive about pruning them. |
| 538 size_t cacheLimit = 1; | 541 size_t cacheLimit = 1; |
| 539 if (RuntimeEnabledFeatures::webGLImageChromiumEnabled()) | 542 if (shouldUseChromiumImage()) |
| 540 cacheLimit = 4; | 543 cacheLimit = 4; |
| 541 | 544 |
| 542 RefPtr<RecycledMailbox> recycled; | 545 RefPtr<RecycledMailbox> recycled; |
| 543 while (m_recycledMailboxQueue.size() > cacheLimit) { | 546 while (m_recycledMailboxQueue.size() > cacheLimit) { |
| 544 recycled = m_recycledMailboxQueue.takeLast(); | 547 recycled = m_recycledMailboxQueue.takeLast(); |
| 545 deleteMailbox(recycled->mailbox, recycled->syncToken); | 548 deleteMailbox(recycled->mailbox, recycled->syncToken); |
| 546 } | 549 } |
| 547 recycled = m_recycledMailboxQueue.takeLast(); | 550 recycled = m_recycledMailboxQueue.takeLast(); |
| 548 | 551 |
| 549 if (recycled->syncToken.HasData()) | 552 if (recycled->syncToken.HasData()) |
| (...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1131 m_gl->Clear(GL_COLOR_BUFFER_BIT); | 1134 m_gl->Clear(GL_COLOR_BUFFER_BIT); |
| 1132 m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, info.parame
ters.target, 0, 0); | 1135 m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, info.parame
ters.target, 0, 0); |
| 1133 m_gl->DeleteFramebuffers(1, &fbo); | 1136 m_gl->DeleteFramebuffers(1, &fbo); |
| 1134 restoreFramebufferBindings(); | 1137 restoreFramebufferBindings(); |
| 1135 m_gl->ClearColor(m_clearColor[0], m_clearColor[1], m_clearColor[2], m_clearC
olor[3]); | 1138 m_gl->ClearColor(m_clearColor[0], m_clearColor[1], m_clearColor[2], m_clearC
olor[3]); |
| 1136 m_gl->ColorMask(m_colorMask[0], m_colorMask[1], m_colorMask[2], m_colorMask[
3]); | 1139 m_gl->ColorMask(m_colorMask[0], m_colorMask[1], m_colorMask[2], m_colorMask[
3]); |
| 1137 } | 1140 } |
| 1138 | 1141 |
| 1139 DrawingBuffer::TextureInfo DrawingBuffer::createTextureAndAllocateMemory(const I
ntSize& size) | 1142 DrawingBuffer::TextureInfo DrawingBuffer::createTextureAndAllocateMemory(const I
ntSize& size) |
| 1140 { | 1143 { |
| 1141 if (!RuntimeEnabledFeatures::webGLImageChromiumEnabled()) | 1144 if (!shouldUseChromiumImage()) |
| 1142 return createDefaultTextureAndAllocateMemory(size); | 1145 return createDefaultTextureAndAllocateMemory(size); |
| 1143 | 1146 |
| 1144 TextureParameters parameters = chromiumImageTextureParameters(); | 1147 TextureParameters parameters = chromiumImageTextureParameters(); |
| 1145 GLuint imageId = m_gl->CreateGpuMemoryBufferImageCHROMIUM(size.width(), size
.height(), parameters.creationInternalColorFormat, GC3D_SCANOUT_CHROMIUM); | 1148 GLuint imageId = m_gl->CreateGpuMemoryBufferImageCHROMIUM(size.width(), size
.height(), parameters.creationInternalColorFormat, GC3D_SCANOUT_CHROMIUM); |
| 1146 GLuint textureId = createColorTexture(parameters); | 1149 GLuint textureId = createColorTexture(parameters); |
| 1147 if (imageId) { | 1150 if (imageId) { |
| 1148 m_gl->BindTexImage2DCHROMIUM(parameters.target, imageId); | 1151 m_gl->BindTexImage2DCHROMIUM(parameters.target, imageId); |
| 1149 } | 1152 } |
| 1150 | 1153 |
| 1151 TextureInfo info; | 1154 TextureInfo info; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1164 info.textureId = createColorTexture(parameters); | 1167 info.textureId = createColorTexture(parameters); |
| 1165 allocateConditionallyImmutableTexture(parameters.target, parameters.creation
InternalColorFormat, | 1168 allocateConditionallyImmutableTexture(parameters.target, parameters.creation
InternalColorFormat, |
| 1166 size.width(), size.height(), 0, parameters.colorFormat, GL_UNSIGNED_BYTE
); | 1169 size.width(), size.height(), 0, parameters.colorFormat, GL_UNSIGNED_BYTE
); |
| 1167 info.immutable = m_storageTextureSupported; | 1170 info.immutable = m_storageTextureSupported; |
| 1168 return info; | 1171 return info; |
| 1169 } | 1172 } |
| 1170 | 1173 |
| 1171 void DrawingBuffer::resizeTextureMemory(TextureInfo* info, const IntSize& size) | 1174 void DrawingBuffer::resizeTextureMemory(TextureInfo* info, const IntSize& size) |
| 1172 { | 1175 { |
| 1173 ASSERT(info->textureId); | 1176 ASSERT(info->textureId); |
| 1174 if (!RuntimeEnabledFeatures::webGLImageChromiumEnabled()) { | 1177 if (!shouldUseChromiumImage()) { |
| 1175 if (info->immutable) { | 1178 if (info->immutable) { |
| 1176 DCHECK(m_storageTextureSupported); | 1179 DCHECK(m_storageTextureSupported); |
| 1177 m_gl->DeleteTextures(1, &info->textureId); | 1180 m_gl->DeleteTextures(1, &info->textureId); |
| 1178 info->textureId = createColorTexture(info->parameters); | 1181 info->textureId = createColorTexture(info->parameters); |
| 1179 } | 1182 } |
| 1180 m_gl->BindTexture(info->parameters.target, info->textureId); | 1183 m_gl->BindTexture(info->parameters.target, info->textureId); |
| 1181 allocateConditionallyImmutableTexture(info->parameters.target, info->par
ameters.creationInternalColorFormat, | 1184 allocateConditionallyImmutableTexture(info->parameters.target, info->par
ameters.creationInternalColorFormat, |
| 1182 size.width(), size.height(), 0, info->parameters.colorFormat, GL_UNS
IGNED_BYTE); | 1185 size.width(), size.height(), 0, info->parameters.colorFormat, GL_UNS
IGNED_BYTE); |
| 1183 info->immutable = m_storageTextureSupported; | 1186 info->immutable = m_storageTextureSupported; |
| 1184 return; | 1187 return; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1224 bool DrawingBuffer::wantDepthOrStencil() | 1227 bool DrawingBuffer::wantDepthOrStencil() |
| 1225 { | 1228 { |
| 1226 return m_wantDepth || m_wantStencil; | 1229 return m_wantDepth || m_wantStencil; |
| 1227 } | 1230 } |
| 1228 | 1231 |
| 1229 GLenum DrawingBuffer::getMultisampledRenderbufferFormat() | 1232 GLenum DrawingBuffer::getMultisampledRenderbufferFormat() |
| 1230 { | 1233 { |
| 1231 DCHECK(wantExplicitResolve()); | 1234 DCHECK(wantExplicitResolve()); |
| 1232 if (m_wantAlphaChannel) | 1235 if (m_wantAlphaChannel) |
| 1233 return GL_RGBA8_OES; | 1236 return GL_RGBA8_OES; |
| 1234 if (RuntimeEnabledFeatures::webGLImageChromiumEnabled() && contextProvider()
->getCapabilities().chromium_image_rgb_emulation) | 1237 if (shouldUseChromiumImage() && contextProvider()->getCapabilities().chromiu
m_image_rgb_emulation) |
| 1235 return GL_RGBA8_OES; | 1238 return GL_RGBA8_OES; |
| 1236 if (contextProvider()->getCapabilities().disable_webgl_rgb_multisampling_usa
ge) | 1239 if (contextProvider()->getCapabilities().disable_webgl_rgb_multisampling_usa
ge) |
| 1237 return GL_RGBA8_OES; | 1240 return GL_RGBA8_OES; |
| 1238 return GL_RGB8_OES; | 1241 return GL_RGB8_OES; |
| 1239 } | 1242 } |
| 1240 | 1243 |
| 1241 void DrawingBuffer::restoreTextureBindings() | 1244 void DrawingBuffer::restoreTextureBindings() |
| 1242 { | 1245 { |
| 1243 // This class potentially modifies the bindings for GL_TEXTURE_2D and | 1246 // This class potentially modifies the bindings for GL_TEXTURE_2D and |
| 1244 // GL_TEXTURE_RECTANGLE. Only GL_TEXTURE_2D needs to be restored since | 1247 // GL_TEXTURE_RECTANGLE. Only GL_TEXTURE_2D needs to be restored since |
| 1245 // the public interface for WebGL does not support GL_TEXTURE_RECTANGLE. | 1248 // the public interface for WebGL does not support GL_TEXTURE_RECTANGLE. |
| 1246 m_gl->BindTexture(GL_TEXTURE_2D, m_texture2DBinding); | 1249 m_gl->BindTexture(GL_TEXTURE_2D, m_texture2DBinding); |
| 1247 } | 1250 } |
| 1248 | 1251 |
| 1252 bool DrawingBuffer::shouldUseChromiumImage() |
| 1253 { |
| 1254 return RuntimeEnabledFeatures::webGLImageChromiumEnabled() && m_chromiumImag
eUsage == AllowChromiumImage; |
| 1255 } |
| 1256 |
| 1249 } // namespace blink | 1257 } // namespace blink |
| OLD | NEW |