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

Side by Side Diff: Source/platform/graphics/gpu/DrawingBuffer.cpp

Issue 614883002: Use glDiscardFramebuffer to save memory bandwidth (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 2 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) 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 } 95 }
96 bool multisampleSupported = extensionsUtil->supportsExtension("GL_CHROMIUM_f ramebuffer_multisample") 96 bool multisampleSupported = extensionsUtil->supportsExtension("GL_CHROMIUM_f ramebuffer_multisample")
97 && extensionsUtil->supportsExtension("GL_OES_rgb8_rgba8"); 97 && extensionsUtil->supportsExtension("GL_OES_rgb8_rgba8");
98 if (multisampleSupported) { 98 if (multisampleSupported) {
99 extensionsUtil->ensureExtensionEnabled("GL_CHROMIUM_framebuffer_multisam ple"); 99 extensionsUtil->ensureExtensionEnabled("GL_CHROMIUM_framebuffer_multisam ple");
100 extensionsUtil->ensureExtensionEnabled("GL_OES_rgb8_rgba8"); 100 extensionsUtil->ensureExtensionEnabled("GL_OES_rgb8_rgba8");
101 } 101 }
102 bool packedDepthStencilSupported = extensionsUtil->supportsExtension("GL_OES _packed_depth_stencil"); 102 bool packedDepthStencilSupported = extensionsUtil->supportsExtension("GL_OES _packed_depth_stencil");
103 if (packedDepthStencilSupported) 103 if (packedDepthStencilSupported)
104 extensionsUtil->ensureExtensionEnabled("GL_OES_packed_depth_stencil"); 104 extensionsUtil->ensureExtensionEnabled("GL_OES_packed_depth_stencil");
105 bool discardFramebufferSupported = extensionsUtil->supportsExtension("GL_EXT _discard_framebuffer");
106 if (discardFramebufferSupported)
107 extensionsUtil->ensureExtensionEnabled("GL_EXT_discard_framebuffer");
105 108
106 RefPtr<DrawingBuffer> drawingBuffer = adoptRef(new DrawingBuffer(context, ex tensionsUtil.release(), multisampleSupported, packedDepthStencilSupported, prese rve, requestedAttributes, contextEvictionManager)); 109 RefPtr<DrawingBuffer> drawingBuffer = adoptRef(new DrawingBuffer(context, ex tensionsUtil.release(), multisampleSupported, packedDepthStencilSupported, disca rdFramebufferSupported, preserve, requestedAttributes, contextEvictionManager));
107 if (!drawingBuffer->initialize(size)) { 110 if (!drawingBuffer->initialize(size)) {
108 drawingBuffer->beginDestruction(); 111 drawingBuffer->beginDestruction();
109 return PassRefPtr<DrawingBuffer>(); 112 return PassRefPtr<DrawingBuffer>();
110 } 113 }
111 return drawingBuffer.release(); 114 return drawingBuffer.release();
112 } 115 }
113 116
114 DrawingBuffer::DrawingBuffer(PassOwnPtr<WebGraphicsContext3D> context, 117 DrawingBuffer::DrawingBuffer(PassOwnPtr<WebGraphicsContext3D> context,
115 PassOwnPtr<Extensions3DUtil> extensionsUtil, 118 PassOwnPtr<Extensions3DUtil> extensionsUtil,
116 bool multisampleExtensionSupported, 119 bool multisampleExtensionSupported,
117 bool packedDepthStencilExtensionSupported, 120 bool packedDepthStencilExtensionSupported,
121 bool discardFramebufferSupported,
118 PreserveDrawingBuffer preserve, 122 PreserveDrawingBuffer preserve,
119 WebGraphicsContext3D::Attributes requestedAttributes, 123 WebGraphicsContext3D::Attributes requestedAttributes,
120 PassRefPtr<ContextEvictionManager> contextEvictionManager) 124 PassRefPtr<ContextEvictionManager> contextEvictionManager)
121 : m_preserveDrawingBuffer(preserve) 125 : m_preserveDrawingBuffer(preserve)
122 , m_scissorEnabled(false) 126 , m_scissorEnabled(false)
123 , m_texture2DBinding(0) 127 , m_texture2DBinding(0)
124 , m_framebufferBinding(0) 128 , m_framebufferBinding(0)
125 , m_activeTextureUnit(GL_TEXTURE0) 129 , m_activeTextureUnit(GL_TEXTURE0)
126 , m_context(context) 130 , m_context(context)
127 , m_extensionsUtil(extensionsUtil) 131 , m_extensionsUtil(extensionsUtil)
128 , m_size(-1, -1) 132 , m_size(-1, -1)
129 , m_requestedAttributes(requestedAttributes) 133 , m_requestedAttributes(requestedAttributes)
130 , m_multisampleExtensionSupported(multisampleExtensionSupported) 134 , m_multisampleExtensionSupported(multisampleExtensionSupported)
131 , m_packedDepthStencilExtensionSupported(packedDepthStencilExtensionSupporte d) 135 , m_packedDepthStencilExtensionSupported(packedDepthStencilExtensionSupporte d)
136 , m_discardFramebufferSupported(discardFramebufferSupported)
132 , m_fbo(0) 137 , m_fbo(0)
133 , m_depthStencilBuffer(0) 138 , m_depthStencilBuffer(0)
134 , m_depthBuffer(0) 139 , m_depthBuffer(0)
135 , m_stencilBuffer(0) 140 , m_stencilBuffer(0)
136 , m_multisampleFBO(0) 141 , m_multisampleFBO(0)
137 , m_multisampleColorBuffer(0) 142 , m_multisampleColorBuffer(0)
138 , m_contentsChanged(true) 143 , m_contentsChanged(true)
139 , m_contentsChangeCommitted(false) 144 , m_contentsChangeCommitted(false)
140 , m_layerComposited(false) 145 , m_layerComposited(false)
141 , m_multisampleMode(None) 146 , m_multisampleMode(None)
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 std::swap(frontColorBufferMailbox->textureInfo, m_colorBuffer); 262 std::swap(frontColorBufferMailbox->textureInfo, m_colorBuffer);
258 // It appears safe to overwrite the context's framebuffer binding in the Discard case since there will always be a 263 // It appears safe to overwrite the context's framebuffer binding in the Discard case since there will always be a
259 // WebGLRenderingContext::clearIfComposited() call made before the next draw call which restores the framebuffer binding. 264 // WebGLRenderingContext::clearIfComposited() call made before the next draw call which restores the framebuffer binding.
260 // If this stops being true at some point, we should track the current f ramebuffer binding in the DrawingBuffer and restore 265 // If this stops being true at some point, we should track the current f ramebuffer binding in the DrawingBuffer and restore
261 // it after attaching the new back buffer here. 266 // it after attaching the new back buffer here.
262 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo); 267 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo);
263 if (m_multisampleMode == ImplicitResolve) 268 if (m_multisampleMode == ImplicitResolve)
264 m_context->framebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COL OR_ATTACHMENT0, GL_TEXTURE_2D, m_colorBuffer.textureId, 0, m_sampleCount); 269 m_context->framebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COL OR_ATTACHMENT0, GL_TEXTURE_2D, m_colorBuffer.textureId, 0, m_sampleCount);
265 else 270 else
266 m_context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 , GL_TEXTURE_2D, m_colorBuffer.textureId, 0); 271 m_context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 , GL_TEXTURE_2D, m_colorBuffer.textureId, 0);
272
273 if (m_discardFramebufferSupported) {
274 // Explicitly discard framebuffer to save GPU memory bandwidth for t ile-based GPU arch.
275 const WGC3Denum attachments[3] = { GL_COLOR_ATTACHMENT0, GL_DEPTH_AT TACHMENT, GL_STENCIL_ATTACHMENT};
276 m_context->discardFramebufferEXT(GL_FRAMEBUFFER, 3, attachments);
277 }
267 } else { 278 } else {
268 m_context->copyTextureCHROMIUM(GL_TEXTURE_2D, m_colorBuffer.textureId, f rontColorBufferMailbox->textureInfo.textureId, 0, GL_RGBA, GL_UNSIGNED_BYTE); 279 m_context->copyTextureCHROMIUM(GL_TEXTURE_2D, m_colorBuffer.textureId, f rontColorBufferMailbox->textureInfo.textureId, 0, GL_RGBA, GL_UNSIGNED_BYTE);
269 } 280 }
270 281
271 if (m_multisampleMode != None && !m_framebufferBinding) 282 if (m_multisampleMode != None && !m_framebufferBinding)
272 bind(); 283 bind();
273 else 284 else
274 restoreFramebufferBinding(); 285 restoreFramebufferBinding();
275 286
276 m_contentsChanged = false; 287 m_contentsChanged = false;
(...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after
1048 void DrawingBuffer::deleteChromiumImageForTexture(TextureInfo* info) 1059 void DrawingBuffer::deleteChromiumImageForTexture(TextureInfo* info)
1049 { 1060 {
1050 if (info->imageId) { 1061 if (info->imageId) {
1051 m_context->releaseTexImage2DCHROMIUM(GL_TEXTURE_2D, info->imageId); 1062 m_context->releaseTexImage2DCHROMIUM(GL_TEXTURE_2D, info->imageId);
1052 m_context->destroyImageCHROMIUM(info->imageId); 1063 m_context->destroyImageCHROMIUM(info->imageId);
1053 info->imageId = 0; 1064 info->imageId = 0;
1054 } 1065 }
1055 } 1066 }
1056 1067
1057 } // namespace blink 1068 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/graphics/gpu/DrawingBuffer.h ('k') | Source/platform/graphics/gpu/DrawingBufferTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698