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

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

Issue 2820373003: WebGL: Tidy up buffer allocation logic (Closed)
Patch Set: WebGL: tidy buffer allocation logic Created 3 years, 8 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
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/gpu/DrawingBuffer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 525
526 DrawingBuffer::ColorBufferParameters 526 DrawingBuffer::ColorBufferParameters
527 DrawingBuffer::GpuMemoryBufferColorBufferParameters() { 527 DrawingBuffer::GpuMemoryBufferColorBufferParameters() {
528 #if OS(MACOSX) 528 #if OS(MACOSX)
529 // A CHROMIUM_image backed texture requires a specialized set of parameters 529 // A CHROMIUM_image backed texture requires a specialized set of parameters
530 // on OSX. 530 // on OSX.
531 ColorBufferParameters parameters; 531 ColorBufferParameters parameters;
532 parameters.target = GC3D_TEXTURE_RECTANGLE_ARB; 532 parameters.target = GC3D_TEXTURE_RECTANGLE_ARB;
533 533
534 if (want_alpha_channel_) { 534 if (want_alpha_channel_) {
535 parameters.creation_internal_color_format = GL_RGBA; 535 parameters.allocate_alpha_channel = true;
536 parameters.internal_color_format = GL_RGBA;
537 } else if (ContextProvider() 536 } else if (ContextProvider()
538 ->GetCapabilities() 537 ->GetCapabilities()
539 .chromium_image_rgb_emulation) { 538 .chromium_image_rgb_emulation) {
540 parameters.creation_internal_color_format = GL_RGB; 539 parameters.allocate_alpha_channel = true;
541 parameters.internal_color_format = GL_RGBA;
542 } else { 540 } else {
543 GLenum format = 541 parameters.allocate_alpha_channel =
544 DefaultBufferRequiresAlphaChannelToBePreserved() ? GL_RGBA : GL_RGB; 542 DefaultBufferRequiresAlphaChannelToBePreserved();
545 parameters.creation_internal_color_format = format;
546 parameters.internal_color_format = format;
547 } 543 }
548
549 // Unused when CHROMIUM_image is being used.
550 parameters.color_format = 0;
551 return parameters; 544 return parameters;
552 #else 545 #else
553 return TextureColorBufferParameters(); 546 return TextureColorBufferParameters();
554 #endif 547 #endif
555 } 548 }
556 549
557 DrawingBuffer::ColorBufferParameters 550 DrawingBuffer::ColorBufferParameters
558 DrawingBuffer::TextureColorBufferParameters() { 551 DrawingBuffer::TextureColorBufferParameters() {
559 ColorBufferParameters parameters; 552 ColorBufferParameters parameters;
560 parameters.target = GL_TEXTURE_2D; 553 parameters.target = GL_TEXTURE_2D;
561 if (want_alpha_channel_) { 554 if (want_alpha_channel_) {
562 parameters.internal_color_format = GL_RGBA; 555 parameters.allocate_alpha_channel = true();
563 parameters.creation_internal_color_format = GL_RGBA;
564 parameters.color_format = GL_RGBA;
565 } else if (ContextProvider() 556 } else if (ContextProvider()
566 ->GetCapabilities() 557 ->GetCapabilities()
567 .emulate_rgb_buffer_with_rgba) { 558 .emulate_rgb_buffer_with_rgba) {
568 parameters.internal_color_format = GL_RGBA; 559 parameters.allocate_alpha_channel = true();
569 parameters.creation_internal_color_format = GL_RGBA;
570 parameters.color_format = GL_RGBA;
571 } else { 560 } else {
572 GLenum format = 561 parameters.allocate_alpha_channel =
573 DefaultBufferRequiresAlphaChannelToBePreserved() ? GL_RGBA : GL_RGB; 562 DefaultBufferRequiresAlphaChannelToBePreserved();
574 parameters.creation_internal_color_format = format;
575 parameters.internal_color_format = format;
576 parameters.color_format = format;
577 } 563 }
578 return parameters; 564 return parameters;
579 } 565 }
580 566
581 PassRefPtr<DrawingBuffer::ColorBuffer> 567 PassRefPtr<DrawingBuffer::ColorBuffer>
582 DrawingBuffer::CreateOrRecycleColorBuffer() { 568 DrawingBuffer::CreateOrRecycleColorBuffer() {
583 DCHECK(state_restorer_); 569 DCHECK(state_restorer_);
584 if (!recycled_color_buffer_queue_.IsEmpty()) { 570 if (!recycled_color_buffer_queue_.IsEmpty()) {
585 RefPtr<ColorBuffer> recycled = recycled_color_buffer_queue_.TakeLast(); 571 RefPtr<ColorBuffer> recycled = recycled_color_buffer_queue_.TakeLast();
586 if (recycled->receive_sync_token.HasData()) 572 if (recycled->receive_sync_token.HasData())
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 1135
1150 // Select the Parameters for the texture object. Allocate the backing 1136 // Select the Parameters for the texture object. Allocate the backing
1151 // GpuMemoryBuffer and GLImage, if one is going to be used. 1137 // GpuMemoryBuffer and GLImage, if one is going to be used.
1152 ColorBufferParameters parameters; 1138 ColorBufferParameters parameters;
1153 GLuint image_id = 0; 1139 GLuint image_id = 0;
1154 std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer; 1140 std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer;
1155 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager = 1141 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager =
1156 Platform::Current()->GetGpuMemoryBufferManager(); 1142 Platform::Current()->GetGpuMemoryBufferManager();
1157 if (ShouldUseChromiumImage() && gpu_memory_buffer_manager) { 1143 if (ShouldUseChromiumImage() && gpu_memory_buffer_manager) {
1158 parameters = GpuMemoryBufferColorBufferParameters(); 1144 parameters = GpuMemoryBufferColorBufferParameters();
1159 gfx::BufferFormat buffer_format = gpu::DefaultBufferFormatForImageFormat( 1145 gfx::BufferFormat buffer_format;
1160 parameters.creation_internal_color_format); 1146 GLenum gl_format = GL_NONE;
1147 if (parameters.allocate_alpha_channel) {
1148 buffer_format = gfx::BufferFormat::gfx::BufferFormat::RGBA_8888;
1149 gl_format = GL_RGBA;
1150 } else {
1151 buffer_format = gfx::BufferFormat::gfx::BufferFormat::BGRX_8888;
1152 gl_format = GL_RGB;
1153 }
1161 gpu_memory_buffer = gpu_memory_buffer_manager->CreateGpuMemoryBuffer( 1154 gpu_memory_buffer = gpu_memory_buffer_manager->CreateGpuMemoryBuffer(
1162 gfx::Size(size), buffer_format, gfx::BufferUsage::SCANOUT, 1155 gfx::Size(size), buffer_format, gfx::BufferUsage::SCANOUT,
1163 gpu::kNullSurfaceHandle); 1156 gpu::kNullSurfaceHandle);
1164 if (gpu_memory_buffer) { 1157 if (gpu_memory_buffer) {
1165 if (RuntimeEnabledFeatures::colorCorrectRenderingEnabled()) 1158 if (RuntimeEnabledFeatures::colorCorrectRenderingEnabled())
1166 gpu_memory_buffer->SetColorSpaceForScanout(color_space_); 1159 gpu_memory_buffer->SetColorSpaceForScanout(color_space_);
1167 image_id = gl_->CreateImageCHROMIUM( 1160 image_id =
1168 gpu_memory_buffer->AsClientBuffer(), size.Width(), size.Height(), 1161 gl_->CreateImageCHROMIUM(gpu_memory_buffer->AsClientBuffer(),
1169 parameters.creation_internal_color_format); 1162 size.Width(), size.Height(), gl_format);
1170 if (!image_id) 1163 if (!image_id)
1171 gpu_memory_buffer.reset(); 1164 gpu_memory_buffer.reset();
1172 } 1165 }
1173 } else { 1166 }
ccameron 2017/04/19 06:09:03 This line here is the only logic change -- if we f
1167 if (!image_id)
1174 parameters = TextureColorBufferParameters(); 1168 parameters = TextureColorBufferParameters();
1175 }
1176 1169
1177 // Allocate the texture for this object. 1170 // Allocate the texture for this object.
1178 GLuint texture_id = 0; 1171 GLuint texture_id = 0;
1179 { 1172 {
1180 gl_->GenTextures(1, &texture_id); 1173 gl_->GenTextures(1, &texture_id);
1181 gl_->BindTexture(parameters.target, texture_id); 1174 gl_->BindTexture(parameters.target, texture_id);
1182 gl_->TexParameteri(parameters.target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 1175 gl_->TexParameteri(parameters.target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1183 gl_->TexParameteri(parameters.target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 1176 gl_->TexParameteri(parameters.target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1184 gl_->TexParameteri(parameters.target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 1177 gl_->TexParameteri(parameters.target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1185 gl_->TexParameteri(parameters.target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 1178 gl_->TexParameteri(parameters.target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1186 } 1179 }
1187 1180
1188 // If this is GpuMemoryBuffer-backed, then bind the texture to the 1181 // If this is GpuMemoryBuffer-backed, then bind the texture to the
1189 // GpuMemoryBuffer's GLImage. Otherwise, allocate ordinary texture storage. 1182 // GpuMemoryBuffer's GLImage. Otherwise, allocate ordinary texture storage.
1190 if (image_id) { 1183 if (image_id) {
1191 gl_->BindTexImage2DCHROMIUM(parameters.target, image_id); 1184 gl_->BindTexImage2DCHROMIUM(parameters.target, image_id);
1192 } else { 1185 } else {
1193 if (storage_texture_supported_) { 1186 if (storage_texture_supported_) {
1194 GLenum internal_storage_format = GL_NONE; 1187 GLenum internal_storage_format = GL_NONE;
1195 if (parameters.creation_internal_color_format == GL_RGB) { 1188 if (parameters.allocate_alpha_channel)
1189 internal_storage_format = GL_RGBA8;
1190 else
1196 internal_storage_format = GL_RGB8; 1191 internal_storage_format = GL_RGB8;
1197 } else if (parameters.creation_internal_color_format == GL_RGBA) {
1198 internal_storage_format = GL_RGBA8;
1199 } else {
1200 NOTREACHED();
1201 }
1202 gl_->TexStorage2DEXT(GL_TEXTURE_2D, 1, internal_storage_format, 1192 gl_->TexStorage2DEXT(GL_TEXTURE_2D, 1, internal_storage_format,
1203 size.Width(), size.Height()); 1193 size.Width(), size.Height());
1204 } else { 1194 } else {
1205 gl_->TexImage2D(parameters.target, 0, 1195 GLenum gl_format = GL_NONE;
1206 parameters.creation_internal_color_format, size.Width(), 1196 if (parameters.allocate_alpha_channel)
1207 size.Height(), 0, parameters.color_format, 1197 gl_format = GL_RGBA;
1208 GL_UNSIGNED_BYTE, 0); 1198 else
1199 gl_format = GL_RGB;
1200 gl_->TexImage2D(parameters.target, 0, gl_format, size.Width(),
1201 size.Height(), 0, gl_format, GL_UNSIGNED_BYTE, 0);
1209 } 1202 }
1210 } 1203 }
1211 1204
1212 // Clear the alpha channel if this is RGB emulated. 1205 // Clear the alpha channel if this is RGB emulated.
1213 if (image_id && !want_alpha_channel_ && 1206 if (image_id && !want_alpha_channel_ &&
1214 ContextProvider()->GetCapabilities().chromium_image_rgb_emulation) { 1207 ContextProvider()->GetCapabilities().chromium_image_rgb_emulation) {
1215 GLuint fbo = 0; 1208 GLuint fbo = 0;
1216 1209
1217 state_restorer_->SetClearStateDirty(); 1210 state_restorer_->SetClearStateDirty();
1218 gl_->GenFramebuffers(1, &fbo); 1211 gl_->GenFramebuffers(1, &fbo);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1303 if (pixel_unpack_buffer_binding_dirty_) 1296 if (pixel_unpack_buffer_binding_dirty_)
1304 client->DrawingBufferClientRestorePixelUnpackBufferBinding(); 1297 client->DrawingBufferClientRestorePixelUnpackBufferBinding();
1305 } 1298 }
1306 1299
1307 bool DrawingBuffer::ShouldUseChromiumImage() { 1300 bool DrawingBuffer::ShouldUseChromiumImage() {
1308 return RuntimeEnabledFeatures::webGLImageChromiumEnabled() && 1301 return RuntimeEnabledFeatures::webGLImageChromiumEnabled() &&
1309 chromium_image_usage_ == kAllowChromiumImage; 1302 chromium_image_usage_ == kAllowChromiumImage;
1310 } 1303 }
1311 1304
1312 } // namespace blink 1305 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/gpu/DrawingBuffer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698