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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gpu/command_buffer/service/gles2_cmd_decoder.cc
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc
index c480b71567dca3814c19aeca0b4f7185bc338e42..1a998c796c0233fa70d81126153aaeb224f44718 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder.cc
+++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc
@@ -2637,17 +2637,22 @@ bool BackTexture::AllocateStorage(
DestroyNativeGpuMemoryBuffer(true);
success = AllocateNativeGpuMemoryBuffer(size, format, zero);
} else {
- std::unique_ptr<char[]> zero_data;
- if (zero) {
- zero_data.reset(new char[image_size]);
- memset(zero_data.get(), 0, image_size);
+ {
+ // Add extra scope to destroy zero_data and the object it owns right
+ // after its usage.
+ std::unique_ptr<char[]> zero_data;
+ if (zero) {
+ zero_data.reset(new char[image_size]);
+ memset(zero_data.get(), 0, image_size);
+ }
+
+ glTexImage2D(Target(),
+ 0, // mip level
+ format, size.width(), size.height(),
+ 0, // border
+ format, GL_UNSIGNED_BYTE, zero_data.get());
}
- glTexImage2D(Target(),
- 0, // mip level
- format, size.width(), size.height(),
- 0, // border
- format, GL_UNSIGNED_BYTE, zero_data.get());
decoder_->texture_manager()->SetLevelInfo(
texture_ref_.get(), Target(),
0, // level
@@ -12258,20 +12263,24 @@ bool GLES2DecoderImpl::ClearLevel(Texture* texture,
tile_height = height;
}
- // Assumes the size has already been checked.
- std::unique_ptr<char[]> zero(new char[size]);
- memset(zero.get(), 0, size);
- glBindTexture(texture->target(), texture->service_id());
-
- GLint y = 0;
- while (y < height) {
- GLint h = y + tile_height > height ? height - y : tile_height;
- glTexSubImage2D(
+ {
+ // Add extra scope to destroy zero and the object it owns right
+ // after its usage.
+ // Assumes the size has already been checked.
+ std::unique_ptr<char[]> zero(new char[size]);
+ memset(zero.get(), 0, size);
+ glBindTexture(texture->target(), texture->service_id());
+
+ GLint y = 0;
+ while (y < height) {
+ GLint h = y + tile_height > height ? height - y : tile_height;
+ glTexSubImage2D(
target, level, xoffset, yoffset + y, width, h,
TextureManager::AdjustTexFormat(feature_info_.get(), format),
type,
zero.get());
- y += tile_height;
+ y += tile_height;
+ }
}
TextureRef* bound_texture =
texture_manager()->GetTextureInfoForTarget(&state_, texture->target());
@@ -12304,11 +12313,15 @@ bool GLES2DecoderImpl::ClearCompressedTextureLevel(Texture* texture,
"bytes_required", bytes_required);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
- std::unique_ptr<char[]> zero(new char[bytes_required]);
- memset(zero.get(), 0, bytes_required);
- glBindTexture(texture->target(), texture->service_id());
- glCompressedTexSubImage2D(
+ {
+ // Add extra scope to destroy zero and the object it owns right
+ // after its usage.
+ std::unique_ptr<char[]> zero(new char[bytes_required]);
+ memset(zero.get(), 0, bytes_required);
+ glBindTexture(texture->target(), texture->service_id());
+ glCompressedTexSubImage2D(
target, level, 0, 0, width, height, format, bytes_required, zero.get());
+ }
TextureRef* bound_texture =
texture_manager()->GetTextureInfoForTarget(&state_, texture->target());
glBindTexture(texture->target(),
@@ -13870,12 +13883,18 @@ void GLES2DecoderImpl::DoCopyTexImage2D(
if (src.x() != x || src.y() != y ||
src.width() != width || src.height() != height) {
- // some part was clipped so clear the rect.
- std::unique_ptr<char[]> zero(new char[pixels_size]);
- memset(zero.get(), 0, pixels_size);
- glTexImage2D(target, level, TextureManager::AdjustTexInternalFormat(
- feature_info_.get(), internal_format),
- width, height, border, format, type, zero.get());
+ {
+ // Add extra scope to destroy zero and the object it owns right
+ // after its usage.
+ // some part was clipped so clear the rect.
+
+ std::unique_ptr<char[]> zero(new char[pixels_size]);
+ memset(zero.get(), 0, pixels_size);
+ glTexImage2D(target, level, TextureManager::AdjustTexInternalFormat(
+ feature_info_.get(), internal_format),
+ 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
+ }
+
if (!src.IsEmpty()) {
GLint destX = src.x() - x;
GLint destY = src.y() - y;
« 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