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

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

Issue 2490553004: Reduce unique_ptr scope to save memory (Closed)
Patch Set: fix code comments Created 4 years, 1 month 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 2619 matching lines...) Expand 10 before | Expand all | Expand 10 after
2630 if (!memory_tracker_.EnsureGPUMemoryAvailable(image_size)) { 2630 if (!memory_tracker_.EnsureGPUMemoryAvailable(image_size)) {
2631 return false; 2631 return false;
2632 } 2632 }
2633 2633
2634 bool success = false; 2634 bool success = false;
2635 size_ = size; 2635 size_ = size;
2636 if (decoder_->should_use_native_gmb_for_backbuffer_) { 2636 if (decoder_->should_use_native_gmb_for_backbuffer_) {
2637 DestroyNativeGpuMemoryBuffer(true); 2637 DestroyNativeGpuMemoryBuffer(true);
2638 success = AllocateNativeGpuMemoryBuffer(size, format, zero); 2638 success = AllocateNativeGpuMemoryBuffer(size, format, zero);
2639 } else { 2639 } else {
2640 std::unique_ptr<char[]> zero_data; 2640 {
2641 if (zero) { 2641 // Add extra scope to destroy zero_data and the object it owns right
2642 zero_data.reset(new char[image_size]); 2642 // after its usage.
2643 memset(zero_data.get(), 0, image_size); 2643 std::unique_ptr<char[]> zero_data;
2644 if (zero) {
2645 zero_data.reset(new char[image_size]);
2646 memset(zero_data.get(), 0, image_size);
2647 }
2648
2649 glTexImage2D(Target(),
2650 0, // mip level
2651 format, size.width(), size.height(),
2652 0, // border
2653 format, GL_UNSIGNED_BYTE, zero_data.get());
2644 } 2654 }
2645 2655
2646 glTexImage2D(Target(),
2647 0, // mip level
2648 format, size.width(), size.height(),
2649 0, // border
2650 format, GL_UNSIGNED_BYTE, zero_data.get());
2651 decoder_->texture_manager()->SetLevelInfo( 2656 decoder_->texture_manager()->SetLevelInfo(
2652 texture_ref_.get(), Target(), 2657 texture_ref_.get(), Target(),
2653 0, // level 2658 0, // level
2654 GL_RGBA, size.width(), size.height(), 2659 GL_RGBA, size.width(), size.height(),
2655 1, // depth 2660 1, // depth
2656 0, // border 2661 0, // border
2657 GL_RGBA, GL_UNSIGNED_BYTE, gfx::Rect(size)); 2662 GL_RGBA, GL_UNSIGNED_BYTE, gfx::Rect(size));
2658 success = glGetError() == GL_NO_ERROR; 2663 success = glGetError() == GL_NO_ERROR;
2659 } 2664 }
2660 2665
(...skipping 9590 matching lines...) Expand 10 before | Expand all | Expand 10 after
12251 tile_height = kMaxZeroSize / padded_row_size; 12256 tile_height = kMaxZeroSize / padded_row_size;
12252 if (!GLES2Util::ComputeImageDataSizes( 12257 if (!GLES2Util::ComputeImageDataSizes(
12253 width, tile_height, 1, format, type, state_.unpack_alignment, &size, 12258 width, tile_height, 1, format, type, state_.unpack_alignment, &size,
12254 NULL, NULL)) { 12259 NULL, NULL)) {
12255 return false; 12260 return false;
12256 } 12261 }
12257 } else { 12262 } else {
12258 tile_height = height; 12263 tile_height = height;
12259 } 12264 }
12260 12265
12261 // Assumes the size has already been checked. 12266 {
12262 std::unique_ptr<char[]> zero(new char[size]); 12267 // Add extra scope to destroy zero and the object it owns right
12263 memset(zero.get(), 0, size); 12268 // after its usage.
12264 glBindTexture(texture->target(), texture->service_id()); 12269 // Assumes the size has already been checked.
12270 std::unique_ptr<char[]> zero(new char[size]);
12271 memset(zero.get(), 0, size);
12272 glBindTexture(texture->target(), texture->service_id());
12265 12273
12266 GLint y = 0; 12274 GLint y = 0;
12267 while (y < height) { 12275 while (y < height) {
12268 GLint h = y + tile_height > height ? height - y : tile_height; 12276 GLint h = y + tile_height > height ? height - y : tile_height;
12269 glTexSubImage2D( 12277 glTexSubImage2D(
12270 target, level, xoffset, yoffset + y, width, h, 12278 target, level, xoffset, yoffset + y, width, h,
12271 TextureManager::AdjustTexFormat(feature_info_.get(), format), 12279 TextureManager::AdjustTexFormat(feature_info_.get(), format),
12272 type, 12280 type,
12273 zero.get()); 12281 zero.get());
12274 y += tile_height; 12282 y += tile_height;
12283 }
12275 } 12284 }
12276 TextureRef* bound_texture = 12285 TextureRef* bound_texture =
12277 texture_manager()->GetTextureInfoForTarget(&state_, texture->target()); 12286 texture_manager()->GetTextureInfoForTarget(&state_, texture->target());
12278 glBindTexture(texture->target(), 12287 glBindTexture(texture->target(),
12279 bound_texture ? bound_texture->service_id() : 0); 12288 bound_texture ? bound_texture->service_id() : 0);
12280 return true; 12289 return true;
12281 } 12290 }
12282 12291
12283 bool GLES2DecoderImpl::ClearCompressedTextureLevel(Texture* texture, 12292 bool GLES2DecoderImpl::ClearCompressedTextureLevel(Texture* texture,
12284 unsigned target, 12293 unsigned target,
(...skipping 12 matching lines...) Expand all
12297 if (!GetCompressedTexSizeInBytes( 12306 if (!GetCompressedTexSizeInBytes(
12298 "ClearCompressedTextureLevel", width, height, 1, format, 12307 "ClearCompressedTextureLevel", width, height, 1, format,
12299 &bytes_required)) { 12308 &bytes_required)) {
12300 return false; 12309 return false;
12301 } 12310 }
12302 12311
12303 TRACE_EVENT1("gpu", "GLES2DecoderImpl::ClearCompressedTextureLevel", 12312 TRACE_EVENT1("gpu", "GLES2DecoderImpl::ClearCompressedTextureLevel",
12304 "bytes_required", bytes_required); 12313 "bytes_required", bytes_required);
12305 12314
12306 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); 12315 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
12307 std::unique_ptr<char[]> zero(new char[bytes_required]); 12316 {
12308 memset(zero.get(), 0, bytes_required); 12317 // Add extra scope to destroy zero and the object it owns right
12309 glBindTexture(texture->target(), texture->service_id()); 12318 // after its usage.
12310 glCompressedTexSubImage2D( 12319 std::unique_ptr<char[]> zero(new char[bytes_required]);
12320 memset(zero.get(), 0, bytes_required);
12321 glBindTexture(texture->target(), texture->service_id());
12322 glCompressedTexSubImage2D(
12311 target, level, 0, 0, width, height, format, bytes_required, zero.get()); 12323 target, level, 0, 0, width, height, format, bytes_required, zero.get());
12324 }
12312 TextureRef* bound_texture = 12325 TextureRef* bound_texture =
12313 texture_manager()->GetTextureInfoForTarget(&state_, texture->target()); 12326 texture_manager()->GetTextureInfoForTarget(&state_, texture->target());
12314 glBindTexture(texture->target(), 12327 glBindTexture(texture->target(),
12315 bound_texture ? bound_texture->service_id() : 0); 12328 bound_texture ? bound_texture->service_id() : 0);
12316 Buffer* bound_buffer = buffer_manager()->GetBufferInfoForTarget( 12329 Buffer* bound_buffer = buffer_manager()->GetBufferInfoForTarget(
12317 &state_, GL_PIXEL_UNPACK_BUFFER); 12330 &state_, GL_PIXEL_UNPACK_BUFFER);
12318 if (bound_buffer) { 12331 if (bound_buffer) {
12319 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, bound_buffer->service_id()); 12332 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, bound_buffer->service_id());
12320 } 12333 }
12321 return true; 12334 return true;
(...skipping 1541 matching lines...) Expand 10 before | Expand all | Expand 10 after
13863 return; 13876 return;
13864 } 13877 }
13865 13878
13866 // Clip to size to source dimensions 13879 // Clip to size to source dimensions
13867 gfx::Rect src(x, y, width, height); 13880 gfx::Rect src(x, y, width, height);
13868 const gfx::Rect dst(0, 0, size.width(), size.height()); 13881 const gfx::Rect dst(0, 0, size.width(), size.height());
13869 src.Intersect(dst); 13882 src.Intersect(dst);
13870 13883
13871 if (src.x() != x || src.y() != y || 13884 if (src.x() != x || src.y() != y ||
13872 src.width() != width || src.height() != height) { 13885 src.width() != width || src.height() != height) {
13873 // some part was clipped so clear the rect. 13886 {
13874 std::unique_ptr<char[]> zero(new char[pixels_size]); 13887 // Add extra scope to destroy zero and the object it owns right
13875 memset(zero.get(), 0, pixels_size); 13888 // after its usage.
13876 glTexImage2D(target, level, TextureManager::AdjustTexInternalFormat( 13889 // some part was clipped so clear the rect.
13877 feature_info_.get(), internal_format), 13890
13878 width, height, border, format, type, zero.get()); 13891 std::unique_ptr<char[]> zero(new char[pixels_size]);
13892 memset(zero.get(), 0, pixels_size);
13893 glTexImage2D(target, level, TextureManager::AdjustTexInternalFormat(
13894 feature_info_.get(), internal_format),
13895 width, height, border, format, type, zero.get());
stanisc 2016/11/09 22:33:03 You could consider something like replacing zero.g
chengx 2016/11/10 22:43:46 Thanks for your suggestion. I will the current ver
13896 }
13897
13879 if (!src.IsEmpty()) { 13898 if (!src.IsEmpty()) {
13880 GLint destX = src.x() - x; 13899 GLint destX = src.x() - x;
13881 GLint destY = src.y() - y; 13900 GLint destY = src.y() - y;
13882 if (requires_luma_blit) { 13901 if (requires_luma_blit) {
13883 copy_tex_image_blit_->DoCopyTexSubImageToLUMACompatibilityTexture( 13902 copy_tex_image_blit_->DoCopyTexSubImageToLUMACompatibilityTexture(
13884 this, texture->service_id(), texture->target(), target, format, 13903 this, texture->service_id(), texture->target(), target, format,
13885 type, level, destX, destY, 0, 13904 type, level, destX, destY, 0,
13886 src.x(), src.y(), src.width(), src.height(), 13905 src.x(), src.y(), src.width(), src.height(),
13887 GetBoundReadFramebufferServiceId(), 13906 GetBoundReadFramebufferServiceId(),
13888 GetBoundReadFramebufferInternalFormat()); 13907 GetBoundReadFramebufferInternalFormat());
(...skipping 4907 matching lines...) Expand 10 before | Expand all | Expand 10 after
18796 } 18815 }
18797 18816
18798 // Include the auto-generated part of this file. We split this because it means 18817 // Include the auto-generated part of this file. We split this because it means
18799 // we can easily edit the non-auto generated parts right here in this file 18818 // we can easily edit the non-auto generated parts right here in this file
18800 // instead of having to edit some template or the code generator. 18819 // instead of having to edit some template or the code generator.
18801 #include "base/macros.h" 18820 #include "base/macros.h"
18802 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 18821 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
18803 18822
18804 } // namespace gles2 18823 } // namespace gles2
18805 } // namespace gpu 18824 } // 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