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

Side by Side Diff: gpu/command_buffer/service/gles2_cmd_decoder.cc

Issue 2442073003: Fix initialization of offscreen resources for command buffer. (Closed)
Patch Set: Comments from piman. Created 4 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
« no previous file with comments | « no previous file | 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 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" 5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 #include <stdio.h> 10 #include <stdio.h>
(...skipping 3275 matching lines...) Expand 10 before | Expand all | Expand 10 after
3286 offscreen_target_stencil_format_ = attrib_helper.stencil_size > 0 ? 3286 offscreen_target_stencil_format_ = attrib_helper.stencil_size > 0 ?
3287 GL_STENCIL_INDEX : 0; 3287 GL_STENCIL_INDEX : 0;
3288 } 3288 }
3289 } 3289 }
3290 3290
3291 offscreen_saved_color_format_ = offscreen_buffer_texture_needs_alpha || 3291 offscreen_saved_color_format_ = offscreen_buffer_texture_needs_alpha ||
3292 workarounds().disable_gl_rgb_format 3292 workarounds().disable_gl_rgb_format
3293 ? GL_RGBA 3293 ? GL_RGBA
3294 : GL_RGB; 3294 : GL_RGB;
3295 3295
3296 // Create the target frame buffer. This is the one that the client renders
3297 // directly to.
3298 offscreen_target_frame_buffer_.reset(new BackFramebuffer(this));
3299 offscreen_target_frame_buffer_->Create();
3300 // Due to GLES2 format limitations, either the color texture (for
3301 // non-multisampling) or the color render buffer (for multisampling) will be
3302 // attached to the offscreen frame buffer. The render buffer has more
3303 // limited formats available to it, but the texture can't do multisampling.
3304 if (IsOffscreenBufferMultisampled()) {
3305 offscreen_target_color_render_buffer_.reset(new BackRenderbuffer(this));
3306 offscreen_target_color_render_buffer_->Create();
3307 } else {
3308 offscreen_target_color_texture_.reset(new BackTexture(this));
3309 offscreen_target_color_texture_->Create();
3310 }
3311 offscreen_target_depth_render_buffer_.reset(new BackRenderbuffer(this));
3312 offscreen_target_depth_render_buffer_->Create();
3313 offscreen_target_stencil_render_buffer_.reset(new BackRenderbuffer(this));
3314 offscreen_target_stencil_render_buffer_->Create();
3315
3316 // Create the saved offscreen texture. The target frame buffer is copied
3317 // here when SwapBuffers is called.
3318 offscreen_saved_frame_buffer_.reset(new BackFramebuffer(this));
3319 offscreen_saved_frame_buffer_->Create();
3320 //
3321 offscreen_saved_color_texture_.reset(new BackTexture(this));
3322 offscreen_saved_color_texture_->Create();
3323
3324 gfx::Size initial_size = attrib_helper.offscreen_framebuffer_size; 3296 gfx::Size initial_size = attrib_helper.offscreen_framebuffer_size;
3325 if (initial_size.IsEmpty()) { 3297 if (initial_size.IsEmpty()) {
3326 // If we're an offscreen surface with zero width and/or height, set to a 3298 // If we're an offscreen surface with zero width and/or height, set to a
3327 // non-zero size so that we have a complete framebuffer for operations 3299 // non-zero size so that we have a complete framebuffer for operations
3328 // like glClear. 3300 // like glClear.
3329 // TODO(piman): allow empty framebuffers, similar to 3301 // TODO(piman): allow empty framebuffers, similar to
3330 // EGL_KHR_surfaceless_context / GL_OES_surfaceless_context. 3302 // EGL_KHR_surfaceless_context / GL_OES_surfaceless_context.
3331 initial_size = gfx::Size(1, 1); 3303 initial_size = gfx::Size(1, 1);
3332 } 3304 }
3333 3305
3334 // Allocate the render buffers at their initial size and check the status
3335 // of the frame buffers is okay.
3336 if (!ResizeOffscreenFramebuffer(initial_size)) {
3337 LOG(ERROR) << "Could not allocate offscreen buffer storage.";
3338 Destroy(true);
3339 return false;
3340 }
3341
3342 state_.viewport_width = initial_size.width(); 3306 state_.viewport_width = initial_size.width();
3343 state_.viewport_height = initial_size.height(); 3307 state_.viewport_height = initial_size.height();
3344
3345 // Allocate the offscreen saved color texture.
3346 DCHECK(offscreen_saved_color_format_);
3347 offscreen_saved_color_texture_->AllocateStorage(
3348 gfx::Size(1, 1), offscreen_saved_color_format_, true);
3349
3350 offscreen_saved_frame_buffer_->AttachRenderTexture(
3351 offscreen_saved_color_texture_.get());
3352 if (offscreen_saved_frame_buffer_->CheckStatus() !=
3353 GL_FRAMEBUFFER_COMPLETE) {
3354 LOG(ERROR) << "Offscreen saved FBO was incomplete.";
3355 Destroy(true);
3356 return false;
3357 }
3358
3359 // Bind to the new default frame buffer (the offscreen target frame buffer).
3360 // This should now be associated with ID zero.
3361 DoBindFramebuffer(GL_FRAMEBUFFER, 0);
3362 } else { 3308 } else {
3363 glBindFramebufferEXT(GL_FRAMEBUFFER, GetBackbufferServiceId()); 3309 glBindFramebufferEXT(GL_FRAMEBUFFER, GetBackbufferServiceId());
3364 // These are NOT if the back buffer has these proprorties. They are 3310 // These are NOT if the back buffer has these proprorties. They are
3365 // if we want the command buffer to enforce them regardless of what 3311 // if we want the command buffer to enforce them regardless of what
3366 // the real backbuffer is assuming the real back buffer gives us more than 3312 // the real backbuffer is assuming the real back buffer gives us more than
3367 // we ask for. In other words, if we ask for RGB and we get RGBA then we'll 3313 // we ask for. In other words, if we ask for RGB and we get RGBA then we'll
3368 // make it appear RGB. If on the other hand we ask for RGBA nd get RGB we 3314 // make it appear RGB. If on the other hand we ask for RGBA nd get RGB we
3369 // can't do anything about that. 3315 // can't do anything about that.
3370 3316
3371 if (!surfaceless_) { 3317 if (!surfaceless_) {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
3447 viewport_max_height_ = viewport_params[1]; 3393 viewport_max_height_ = viewport_params[1];
3448 3394
3449 glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, line_width_range_); 3395 glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, line_width_range_);
3450 3396
3451 state_.scissor_width = state_.viewport_width; 3397 state_.scissor_width = state_.viewport_width;
3452 state_.scissor_height = state_.viewport_height; 3398 state_.scissor_height = state_.viewport_height;
3453 3399
3454 // Set all the default state because some GL drivers get it wrong. 3400 // Set all the default state because some GL drivers get it wrong.
3455 state_.InitCapabilities(NULL); 3401 state_.InitCapabilities(NULL);
3456 state_.InitState(NULL); 3402 state_.InitState(NULL);
3403
3404 // Default state must be set before offscreen resources can be created.
3405 if (offscreen) {
3406 // Create the target frame buffer. This is the one that the client renders
3407 // directly to.
3408 offscreen_target_frame_buffer_.reset(new BackFramebuffer(this));
3409 offscreen_target_frame_buffer_->Create();
3410 // Due to GLES2 format limitations, either the color texture (for
3411 // non-multisampling) or the color render buffer (for multisampling) will be
3412 // attached to the offscreen frame buffer. The render buffer has more
3413 // limited formats available to it, but the texture can't do multisampling.
3414 if (IsOffscreenBufferMultisampled()) {
3415 offscreen_target_color_render_buffer_.reset(new BackRenderbuffer(this));
3416 offscreen_target_color_render_buffer_->Create();
3417 } else {
3418 offscreen_target_color_texture_.reset(new BackTexture(this));
3419 offscreen_target_color_texture_->Create();
3420 }
3421 offscreen_target_depth_render_buffer_.reset(new BackRenderbuffer(this));
3422 offscreen_target_depth_render_buffer_->Create();
3423 offscreen_target_stencil_render_buffer_.reset(new BackRenderbuffer(this));
3424 offscreen_target_stencil_render_buffer_->Create();
3425
3426 // Create the saved offscreen texture. The target frame buffer is copied
3427 // here when SwapBuffers is called.
3428 offscreen_saved_frame_buffer_.reset(new BackFramebuffer(this));
3429 offscreen_saved_frame_buffer_->Create();
3430 //
3431 offscreen_saved_color_texture_.reset(new BackTexture(this));
3432 offscreen_saved_color_texture_->Create();
3433
3434 // Allocate the render buffers at their initial size and check the status
3435 // of the frame buffers is okay.
3436 if (!ResizeOffscreenFramebuffer(
3437 gfx::Size(state_.viewport_width, state_.viewport_height))) {
3438 LOG(ERROR) << "Could not allocate offscreen buffer storage.";
3439 Destroy(true);
3440 return false;
3441 }
3442 // Allocate the offscreen saved color texture.
3443 DCHECK(offscreen_saved_color_format_);
3444 offscreen_saved_color_texture_->AllocateStorage(
3445 gfx::Size(1, 1), offscreen_saved_color_format_, true);
3446
3447 offscreen_saved_frame_buffer_->AttachRenderTexture(
3448 offscreen_saved_color_texture_.get());
3449 if (offscreen_saved_frame_buffer_->CheckStatus() !=
3450 GL_FRAMEBUFFER_COMPLETE) {
3451 LOG(ERROR) << "Offscreen saved FBO was incomplete.";
3452 Destroy(true);
3453 return false;
3454 }
3455 }
3456
3457 glActiveTexture(GL_TEXTURE0 + state_.active_texture_unit); 3457 glActiveTexture(GL_TEXTURE0 + state_.active_texture_unit);
3458 3458
3459 DoBindBuffer(GL_ARRAY_BUFFER, 0); 3459 DoBindBuffer(GL_ARRAY_BUFFER, 0);
3460 DoBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); 3460 DoBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
3461 DoBindFramebuffer(GL_FRAMEBUFFER, 0); 3461 DoBindFramebuffer(GL_FRAMEBUFFER, 0);
3462 DoBindRenderbuffer(GL_RENDERBUFFER, 0); 3462 DoBindRenderbuffer(GL_RENDERBUFFER, 0);
3463 3463
3464 bool call_gl_clear = !surfaceless_ && !offscreen; 3464 bool call_gl_clear = !surfaceless_ && !offscreen;
3465 #if defined(OS_ANDROID) 3465 #if defined(OS_ANDROID)
3466 // Temporary workaround for Android WebView because this clear ignores the 3466 // Temporary workaround for Android WebView because this clear ignores the
(...skipping 15050 matching lines...) Expand 10 before | Expand all | Expand 10 after
18517 } 18517 }
18518 18518
18519 // Include the auto-generated part of this file. We split this because it means 18519 // Include the auto-generated part of this file. We split this because it means
18520 // we can easily edit the non-auto generated parts right here in this file 18520 // we can easily edit the non-auto generated parts right here in this file
18521 // instead of having to edit some template or the code generator. 18521 // instead of having to edit some template or the code generator.
18522 #include "base/macros.h" 18522 #include "base/macros.h"
18523 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 18523 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
18524 18524
18525 } // namespace gles2 18525 } // namespace gles2
18526 } // namespace gpu 18526 } // namespace gpu
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698