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

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

Issue 1154053002: gpu: Use a rectangle to keep track of the cleared area of each texture level. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: restore scissor state in GLES2DecoderImpl::ClearLevel and update GLES2DecoderManualInitTest.DrawCle… Created 5 years, 6 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 // 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 <stdio.h> 7 #include <stdio.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <cmath> 10 #include <cmath>
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 } 184 }
185 185
186 struct Vec4f { 186 struct Vec4f {
187 explicit Vec4f(const Vec4& data) { 187 explicit Vec4f(const Vec4& data) {
188 data.GetValues(v); 188 data.GetValues(v);
189 } 189 }
190 190
191 GLfloat v[4]; 191 GLfloat v[4];
192 }; 192 };
193 193
194 // Returns the union of |rect1| and |rect2| if one of the rectangles is empty,
195 // contains the other rectangle or shares an edge with the other rectangle.
196 bool CombineAdjacentRects(const gfx::Rect& rect1,
197 const gfx::Rect& rect2,
198 gfx::Rect* result) {
199 // Return |rect2| if |rect1| is empty or |rect2| contains |rect1|.
200 if (rect1.IsEmpty() || rect2.Contains(rect1)) {
201 *result = rect2;
202 return true;
203 }
204
205 // Return |rect1| if |rect2| is empty or |rect1| contains |rect2|.
206 if (rect2.IsEmpty() || rect1.Contains(rect2)) {
207 *result = rect1;
208 return true;
209 }
210
211 // Return the union of |rect1| and |rect2| if they share an edge.
212 if (rect1.SharesEdgeWith(rect2)) {
213 *result = gfx::UnionRects(rect1, rect2);
214 return true;
215 }
216
217 // Return false if it's not possible to combine |rect1| and |rect2|.
218 return false;
219 }
220
194 } // namespace 221 } // namespace
195 222
196 class GLES2DecoderImpl; 223 class GLES2DecoderImpl;
197 224
198 // Local versions of the SET_GL_ERROR macros 225 // Local versions of the SET_GL_ERROR macros
199 #define LOCAL_SET_GL_ERROR(error, function_name, msg) \ 226 #define LOCAL_SET_GL_ERROR(error, function_name, msg) \
200 ERRORSTATE_SET_GL_ERROR(state_.GetErrorState(), error, function_name, msg) 227 ERRORSTATE_SET_GL_ERROR(state_.GetErrorState(), error, function_name, msg)
201 #define LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, value, label) \ 228 #define LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, value, label) \
202 ERRORSTATE_SET_GL_ERROR_INVALID_ENUM(state_.GetErrorState(), \ 229 ERRORSTATE_SET_GL_ERROR_INVALID_ENUM(state_.GetErrorState(), \
203 function_name, value, label) 230 function_name, value, label)
(...skipping 1060 matching lines...) Expand 10 before | Expand all | Expand 10 after
1264 bool ClearUnclearedTextures(); 1291 bool ClearUnclearedTextures();
1265 1292
1266 // Clears any uncleared attachments attached to the given frame buffer. 1293 // Clears any uncleared attachments attached to the given frame buffer.
1267 // Returns false if there was a generated GL error. 1294 // Returns false if there was a generated GL error.
1268 void ClearUnclearedAttachments(GLenum target, Framebuffer* framebuffer); 1295 void ClearUnclearedAttachments(GLenum target, Framebuffer* framebuffer);
1269 1296
1270 // overridden from GLES2Decoder 1297 // overridden from GLES2Decoder
1271 bool ClearLevel(Texture* texture, 1298 bool ClearLevel(Texture* texture,
1272 unsigned target, 1299 unsigned target,
1273 int level, 1300 int level,
1274 unsigned internal_format,
1275 unsigned format, 1301 unsigned format,
1276 unsigned type, 1302 unsigned type,
1303 int xoffset,
1304 int yoffset,
1277 int width, 1305 int width,
1278 int height, 1306 int height) override;
1279 bool is_texture_immutable) override;
1280 1307
1281 // Restore all GL state that affects clearing. 1308 // Restore all GL state that affects clearing.
1282 void RestoreClearState(); 1309 void RestoreClearState();
1283 1310
1284 // Remembers the state of some capabilities. 1311 // Remembers the state of some capabilities.
1285 // Returns: true if glEnable/glDisable should actually be called. 1312 // Returns: true if glEnable/glDisable should actually be called.
1286 bool SetCapabilityState(GLenum cap, bool enabled); 1313 bool SetCapabilityState(GLenum cap, bool enabled);
1287 1314
1288 // Check that the currently bound framebuffers are valid. 1315 // Check that the currently bound framebuffers are valid.
1289 // Generates GL error if not. 1316 // Generates GL error if not.
(...skipping 2394 matching lines...) Expand 10 before | Expand all | Expand 10 after
3684 return back_buffer_color_format_; 3711 return back_buffer_color_format_;
3685 } 3712 }
3686 } 3713 }
3687 3714
3688 void GLES2DecoderImpl::UpdateParentTextureInfo() { 3715 void GLES2DecoderImpl::UpdateParentTextureInfo() {
3689 if (!offscreen_saved_color_texture_info_.get()) 3716 if (!offscreen_saved_color_texture_info_.get())
3690 return; 3717 return;
3691 GLenum target = offscreen_saved_color_texture_info_->texture()->target(); 3718 GLenum target = offscreen_saved_color_texture_info_->texture()->target();
3692 glBindTexture(target, offscreen_saved_color_texture_info_->service_id()); 3719 glBindTexture(target, offscreen_saved_color_texture_info_->service_id());
3693 texture_manager()->SetLevelInfo( 3720 texture_manager()->SetLevelInfo(
3694 offscreen_saved_color_texture_info_.get(), 3721 offscreen_saved_color_texture_info_.get(), GL_TEXTURE_2D,
3695 GL_TEXTURE_2D,
3696 0, // level 3722 0, // level
3697 GL_RGBA, 3723 GL_RGBA, offscreen_size_.width(), offscreen_size_.height(),
3698 offscreen_size_.width(),
3699 offscreen_size_.height(),
3700 1, // depth 3724 1, // depth
3701 0, // border 3725 0, // border
3702 GL_RGBA, 3726 GL_RGBA, GL_UNSIGNED_BYTE, gfx::Rect(offscreen_size_));
3703 GL_UNSIGNED_BYTE,
3704 true);
3705 texture_manager()->SetParameteri( 3727 texture_manager()->SetParameteri(
3706 "UpdateParentTextureInfo", 3728 "UpdateParentTextureInfo",
3707 GetErrorState(), 3729 GetErrorState(),
3708 offscreen_saved_color_texture_info_.get(), 3730 offscreen_saved_color_texture_info_.get(),
3709 GL_TEXTURE_MAG_FILTER, 3731 GL_TEXTURE_MAG_FILTER,
3710 GL_LINEAR); 3732 GL_LINEAR);
3711 texture_manager()->SetParameteri( 3733 texture_manager()->SetParameteri(
3712 "UpdateParentTextureInfo", 3734 "UpdateParentTextureInfo",
3713 GetErrorState(), 3735 GetErrorState(),
3714 offscreen_saved_color_texture_info_.get(), 3736 offscreen_saved_color_texture_info_.get(),
(...skipping 5153 matching lines...) Expand 10 before | Expand all | Expand 10 after
8868 return error::kNoError; 8890 return error::kNoError;
8869 } 8891 }
8870 8892
8871 void GLES2DecoderImpl::DoBufferSubData( 8893 void GLES2DecoderImpl::DoBufferSubData(
8872 GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data) { 8894 GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data) {
8873 // Just delegate it. Some validation is actually done before this. 8895 // Just delegate it. Some validation is actually done before this.
8874 buffer_manager()->ValidateAndDoBufferSubData( 8896 buffer_manager()->ValidateAndDoBufferSubData(
8875 &state_, target, offset, size, data); 8897 &state_, target, offset, size, data);
8876 } 8898 }
8877 8899
8878 bool GLES2DecoderImpl::ClearLevel( 8900 bool GLES2DecoderImpl::ClearLevel(Texture* texture,
8879 Texture* texture, 8901 unsigned target,
8880 unsigned target, 8902 int level,
8881 int level, 8903 unsigned format,
8882 unsigned internal_format, 8904 unsigned type,
8883 unsigned format, 8905 int xoffset,
8884 unsigned type, 8906 int yoffset,
8885 int width, 8907 int width,
8886 int height, 8908 int height) {
8887 bool is_texture_immutable) {
8888 uint32 channels = GLES2Util::GetChannelsForFormat(format); 8909 uint32 channels = GLES2Util::GetChannelsForFormat(format);
8889 if (feature_info_->feature_flags().angle_depth_texture && 8910 if (feature_info_->feature_flags().angle_depth_texture &&
8890 (channels & GLES2Util::kDepth) != 0) { 8911 (channels & GLES2Util::kDepth) != 0) {
8891 // It's a depth format and ANGLE doesn't allow texImage2D or texSubImage2D 8912 // It's a depth format and ANGLE doesn't allow texImage2D or texSubImage2D
8892 // on depth formats. 8913 // on depth formats.
8893 GLuint fb = 0; 8914 GLuint fb = 0;
8894 glGenFramebuffersEXT(1, &fb); 8915 glGenFramebuffersEXT(1, &fb);
8895 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fb); 8916 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fb);
8896 8917
8897 bool have_stencil = (channels & GLES2Util::kStencil) != 0; 8918 bool have_stencil = (channels & GLES2Util::kStencil) != 0;
8898 GLenum attachment = have_stencil ? GL_DEPTH_STENCIL_ATTACHMENT : 8919 GLenum attachment = have_stencil ? GL_DEPTH_STENCIL_ATTACHMENT :
8899 GL_DEPTH_ATTACHMENT; 8920 GL_DEPTH_ATTACHMENT;
8900 8921
8901 glFramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER_EXT, attachment, target, 8922 glFramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER_EXT, attachment, target,
8902 texture->service_id(), level); 8923 texture->service_id(), level);
8903 // ANGLE promises a depth only attachment ok. 8924 // ANGLE promises a depth only attachment ok.
8904 if (glCheckFramebufferStatusEXT(GL_DRAW_FRAMEBUFFER_EXT) != 8925 if (glCheckFramebufferStatusEXT(GL_DRAW_FRAMEBUFFER_EXT) !=
8905 GL_FRAMEBUFFER_COMPLETE) { 8926 GL_FRAMEBUFFER_COMPLETE) {
8906 return false; 8927 return false;
8907 } 8928 }
8908 glClearStencil(0); 8929 glClearStencil(0);
8909 state_.SetDeviceStencilMaskSeparate(GL_FRONT, kDefaultStencilMask); 8930 state_.SetDeviceStencilMaskSeparate(GL_FRONT, kDefaultStencilMask);
8910 state_.SetDeviceStencilMaskSeparate(GL_BACK, kDefaultStencilMask); 8931 state_.SetDeviceStencilMaskSeparate(GL_BACK, kDefaultStencilMask);
8911 glClearDepth(1.0f); 8932 glClearDepth(1.0f);
8912 state_.SetDeviceDepthMask(GL_TRUE); 8933 state_.SetDeviceDepthMask(GL_TRUE);
8913 state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); 8934 state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, true);
8935 glScissor(xoffset, yoffset, width, height);
Ken Russell (switch to Gerrit) 2015/06/06 00:33:05 Can this end up changing the user's scissor rectan
piman 2015/06/06 00:48:13 Good point, we should restore the rectangle, eithe
8914 glClear(GL_DEPTH_BUFFER_BIT | (have_stencil ? GL_STENCIL_BUFFER_BIT : 0)); 8936 glClear(GL_DEPTH_BUFFER_BIT | (have_stencil ? GL_STENCIL_BUFFER_BIT : 0));
8915 8937
8938 state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false);
8916 RestoreClearState(); 8939 RestoreClearState();
8917 8940
8918 glDeleteFramebuffersEXT(1, &fb); 8941 glDeleteFramebuffersEXT(1, &fb);
8919 Framebuffer* framebuffer = 8942 Framebuffer* framebuffer =
8920 GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); 8943 GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT);
8921 GLuint fb_service_id = 8944 GLuint fb_service_id =
8922 framebuffer ? framebuffer->service_id() : GetBackbufferServiceId(); 8945 framebuffer ? framebuffer->service_id() : GetBackbufferServiceId();
8923 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fb_service_id); 8946 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fb_service_id);
8924 return true; 8947 return true;
8925 } 8948 }
(...skipping 27 matching lines...) Expand all
8953 } 8976 }
8954 } else { 8977 } else {
8955 tile_height = height; 8978 tile_height = height;
8956 } 8979 }
8957 8980
8958 // Assumes the size has already been checked. 8981 // Assumes the size has already been checked.
8959 scoped_ptr<char[]> zero(new char[size]); 8982 scoped_ptr<char[]> zero(new char[size]);
8960 memset(zero.get(), 0, size); 8983 memset(zero.get(), 0, size);
8961 glBindTexture(texture->target(), texture->service_id()); 8984 glBindTexture(texture->target(), texture->service_id());
8962 8985
8963 bool has_images = texture->HasImages();
8964 GLint y = 0; 8986 GLint y = 0;
8965 while (y < height) { 8987 while (y < height) {
8966 GLint h = y + tile_height > height ? height - y : tile_height; 8988 GLint h = y + tile_height > height ? height - y : tile_height;
8967 if (is_texture_immutable || h != height || has_images) { 8989 glTexSubImage2D(target, level, xoffset, yoffset + y, width, h, format, type,
8968 glTexSubImage2D(target, level, 0, y, width, h, format, type, zero.get()); 8990 zero.get());
8969 } else {
8970 glTexImage2D(
8971 target, level, internal_format, width, h, 0, format, type,
8972 zero.get());
8973 }
8974 y += tile_height; 8991 y += tile_height;
8975 } 8992 }
8976 TextureRef* bound_texture = 8993 TextureRef* bound_texture =
8977 texture_manager()->GetTextureInfoForTarget(&state_, texture->target()); 8994 texture_manager()->GetTextureInfoForTarget(&state_, texture->target());
8978 glBindTexture(texture->target(), 8995 glBindTexture(texture->target(),
8979 bound_texture ? bound_texture->service_id() : 0); 8996 bound_texture ? bound_texture->service_id() : 0);
8980 return true; 8997 return true;
8981 } 8998 }
8982 8999
8983 namespace { 9000 namespace {
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
9324 if (!data) { 9341 if (!data) {
9325 zero.reset(new int8[image_size]); 9342 zero.reset(new int8[image_size]);
9326 memset(zero.get(), 0, image_size); 9343 memset(zero.get(), 0, image_size);
9327 data = zero.get(); 9344 data = zero.get();
9328 } 9345 }
9329 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCompressedTexImage2D"); 9346 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCompressedTexImage2D");
9330 glCompressedTexImage2D( 9347 glCompressedTexImage2D(
9331 target, level, internal_format, width, height, border, image_size, data); 9348 target, level, internal_format, width, height, border, image_size, data);
9332 GLenum error = LOCAL_PEEK_GL_ERROR("glCompressedTexImage2D"); 9349 GLenum error = LOCAL_PEEK_GL_ERROR("glCompressedTexImage2D");
9333 if (error == GL_NO_ERROR) { 9350 if (error == GL_NO_ERROR) {
9334 texture_manager()->SetLevelInfo( 9351 texture_manager()->SetLevelInfo(texture_ref, target, level, internal_format,
9335 texture_ref, target, level, internal_format, 9352 width, height, 1, border, 0, 0,
9336 width, height, 1, border, 0, 0, true); 9353 gfx::Rect(width, height));
9337 } 9354 }
9338 9355
9339 // This may be a slow command. Exit command processing to allow for 9356 // This may be a slow command. Exit command processing to allow for
9340 // context preemption and GPU watchdog checks. 9357 // context preemption and GPU watchdog checks.
9341 ExitCommandProcessingEarly(); 9358 ExitCommandProcessingEarly();
9342 return error::kNoError; 9359 return error::kNoError;
9343 } 9360 }
9344 9361
9345 error::Error GLES2DecoderImpl::HandleCompressedTexImage2D( 9362 error::Error GLES2DecoderImpl::HandleCompressedTexImage2D(
9346 uint32 immediate_data_size, 9363 uint32 immediate_data_size,
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
9511 if (!data) { 9528 if (!data) {
9512 zero.reset(new int8[image_size]); 9529 zero.reset(new int8[image_size]);
9513 memset(zero.get(), 0, image_size); 9530 memset(zero.get(), 0, image_size);
9514 data = zero.get(); 9531 data = zero.get();
9515 } 9532 }
9516 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCompressedTexImage3D"); 9533 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCompressedTexImage3D");
9517 glCompressedTexImage3D(target, level, internal_format, width, height, depth, 9534 glCompressedTexImage3D(target, level, internal_format, width, height, depth,
9518 border, image_size, data); 9535 border, image_size, data);
9519 GLenum error = LOCAL_PEEK_GL_ERROR("glCompressedTexImage3D"); 9536 GLenum error = LOCAL_PEEK_GL_ERROR("glCompressedTexImage3D");
9520 if (error == GL_NO_ERROR) { 9537 if (error == GL_NO_ERROR) {
9521 texture_manager()->SetLevelInfo( 9538 texture_manager()->SetLevelInfo(texture_ref, target, level, internal_format,
9522 texture_ref, target, level, internal_format, 9539 width, height, depth, border, 0, 0,
9523 width, height, depth, border, 0, 0, true); 9540 gfx::Rect(width, height));
9524 } 9541 }
9525 9542
9526 // This may be a slow command. Exit command processing to allow for 9543 // This may be a slow command. Exit command processing to allow for
9527 // context preemption and GPU watchdog checks. 9544 // context preemption and GPU watchdog checks.
9528 ExitCommandProcessingEarly(); 9545 ExitCommandProcessingEarly();
9529 return error::kNoError; 9546 return error::kNoError;
9530 } 9547 }
9531 9548
9532 error::Error GLES2DecoderImpl::HandleCompressedTexImage3D( 9549 error::Error GLES2DecoderImpl::HandleCompressedTexImage3D(
9533 uint32 immediate_data_size, const void* cmd_data) { 9550 uint32 immediate_data_size, const void* cmd_data) {
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
9977 GLint copyY = 0; 9994 GLint copyY = 0;
9978 GLint copyWidth = 0; 9995 GLint copyWidth = 0;
9979 GLint copyHeight = 0; 9996 GLint copyHeight = 0;
9980 Clip(x, width, size.width(), &copyX, &copyWidth); 9997 Clip(x, width, size.width(), &copyX, &copyWidth);
9981 Clip(y, height, size.height(), &copyY, &copyHeight); 9998 Clip(y, height, size.height(), &copyY, &copyHeight);
9982 9999
9983 if (copyX != x || 10000 if (copyX != x ||
9984 copyY != y || 10001 copyY != y ||
9985 copyWidth != width || 10002 copyWidth != width ||
9986 copyHeight != height) { 10003 copyHeight != height) {
9987 // some part was clipped so clear the texture. 10004 // some part was clipped so clear the rect.
9988 if (!ClearLevel(texture, target, level, internal_format, internal_format, 10005 uint32 pixels_size = 0;
9989 GL_UNSIGNED_BYTE, width, height, texture->IsImmutable())) { 10006 if (!GLES2Util::ComputeImageDataSizes(
10007 width, height, 1, internal_format, GL_UNSIGNED_BYTE,
10008 state_.unpack_alignment, &pixels_size, NULL, NULL)) {
9990 LOCAL_SET_GL_ERROR( 10009 LOCAL_SET_GL_ERROR(
9991 GL_OUT_OF_MEMORY, "glCopyTexImage2D", "dimensions too big"); 10010 GL_OUT_OF_MEMORY, "glCopyTexImage2D", "dimensions too big");
9992 return; 10011 return;
9993 } 10012 }
10013 scoped_ptr<char[]> zero(new char[pixels_size]);
10014 memset(zero.get(), 0, pixels_size);
10015 ScopedModifyPixels modify(texture_ref);
10016 glTexImage2D(target, level, internal_format, width, height, border,
10017 internal_format, GL_UNSIGNED_BYTE, zero.get());
9994 if (copyHeight > 0 && copyWidth > 0) { 10018 if (copyHeight > 0 && copyWidth > 0) {
9995 GLint dx = copyX - x; 10019 GLint dx = copyX - x;
9996 GLint dy = copyY - y; 10020 GLint dy = copyY - y;
9997 GLint destX = dx; 10021 GLint destX = dx;
9998 GLint destY = dy; 10022 GLint destY = dy;
9999 ScopedModifyPixels modify(texture_ref);
10000 glCopyTexSubImage2D(target, level, 10023 glCopyTexSubImage2D(target, level,
10001 destX, destY, copyX, copyY, 10024 destX, destY, copyX, copyY,
10002 copyWidth, copyHeight); 10025 copyWidth, copyHeight);
10003 } 10026 }
10004 } else { 10027 } else {
10005 ScopedModifyPixels modify(texture_ref); 10028 ScopedModifyPixels modify(texture_ref);
10006 glCopyTexImage2D(target, level, internal_format, 10029 glCopyTexImage2D(target, level, internal_format,
10007 copyX, copyY, copyWidth, copyHeight, border); 10030 copyX, copyY, copyWidth, copyHeight, border);
10008 } 10031 }
10009 GLenum error = LOCAL_PEEK_GL_ERROR("glCopyTexImage2D"); 10032 GLenum error = LOCAL_PEEK_GL_ERROR("glCopyTexImage2D");
10010 if (error == GL_NO_ERROR) { 10033 if (error == GL_NO_ERROR) {
10011 texture_manager()->SetLevelInfo( 10034 texture_manager()->SetLevelInfo(texture_ref, target, level, internal_format,
10012 texture_ref, target, level, internal_format, width, height, 1, 10035 width, height, 1, border, internal_format,
10013 border, internal_format, GL_UNSIGNED_BYTE, true); 10036 GL_UNSIGNED_BYTE, gfx::Rect(width, height));
10014 } 10037 }
10015 10038
10016 // This may be a slow command. Exit command processing to allow for 10039 // This may be a slow command. Exit command processing to allow for
10017 // context preemption and GPU watchdog checks. 10040 // context preemption and GPU watchdog checks.
10018 ExitCommandProcessingEarly(); 10041 ExitCommandProcessingEarly();
10019 } 10042 }
10020 10043
10021 void GLES2DecoderImpl::DoCopyTexSubImage2D( 10044 void GLES2DecoderImpl::DoCopyTexSubImage2D(
10022 GLenum target, 10045 GLenum target,
10023 GLint level, 10046 GLint level,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
10091 gfx::Size size = GetBoundReadFrameBufferSize(); 10114 gfx::Size size = GetBoundReadFrameBufferSize();
10092 GLint copyX = 0; 10115 GLint copyX = 0;
10093 GLint copyY = 0; 10116 GLint copyY = 0;
10094 GLint copyWidth = 0; 10117 GLint copyWidth = 0;
10095 GLint copyHeight = 0; 10118 GLint copyHeight = 0;
10096 Clip(x, width, size.width(), &copyX, &copyWidth); 10119 Clip(x, width, size.width(), &copyX, &copyWidth);
10097 Clip(y, height, size.height(), &copyY, &copyHeight); 10120 Clip(y, height, size.height(), &copyY, &copyHeight);
10098 10121
10099 if (xoffset != 0 || yoffset != 0 || width != size.width() || 10122 if (xoffset != 0 || yoffset != 0 || width != size.width() ||
10100 height != size.height()) { 10123 height != size.height()) {
10101 if (!texture_manager()->ClearTextureLevel(this, texture_ref, target, 10124 gfx::Rect cleared_rect;
10102 level)) { 10125 if (CombineAdjacentRects(texture->GetLevelClearedRect(target, level),
10103 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glCopyTexSubImage2D", 10126 gfx::Rect(xoffset, yoffset, width, height),
10104 "dimensions too big"); 10127 &cleared_rect)) {
10105 return; 10128 DCHECK_GE(cleared_rect.size().GetArea(),
10129 texture->GetLevelClearedRect(target, level).size().GetArea());
10130 texture_manager()->SetLevelClearedRect(texture_ref, target, level,
10131 cleared_rect);
10132 } else {
10133 // Otherwise clear part of texture level that is not already cleared.
10134 if (!texture_manager()->ClearTextureLevel(this, texture_ref, target,
10135 level)) {
10136 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glCopyTexSubImage2D",
10137 "dimensions too big");
10138 return;
10139 }
10106 } 10140 }
10107 } else { 10141 } else {
10108 // Write all pixels in below. 10142 // Write all pixels in below.
10109 texture_manager()->SetLevelCleared(texture_ref, target, level, true); 10143 texture_manager()->SetLevelCleared(texture_ref, target, level, true);
10110 } 10144 }
10111 10145
10112 if (copyX != x || 10146 if (copyX != x ||
10113 copyY != y || 10147 copyY != y ||
10114 copyWidth != width || 10148 copyWidth != width ||
10115 copyHeight != height) { 10149 copyHeight != height) {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
10240 TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( 10274 TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget(
10241 &state_, target); 10275 &state_, target);
10242 Texture* texture = texture_ref->texture(); 10276 Texture* texture = texture_ref->texture();
10243 GLsizei tex_width = 0; 10277 GLsizei tex_width = 0;
10244 GLsizei tex_height = 0; 10278 GLsizei tex_height = 0;
10245 bool ok = texture->GetLevelSize( 10279 bool ok = texture->GetLevelSize(
10246 target, level, &tex_width, &tex_height, nullptr); 10280 target, level, &tex_width, &tex_height, nullptr);
10247 DCHECK(ok); 10281 DCHECK(ok);
10248 if (xoffset != 0 || yoffset != 0 || 10282 if (xoffset != 0 || yoffset != 0 ||
10249 width != tex_width || height != tex_height) { 10283 width != tex_width || height != tex_height) {
10250 if (!texture_manager()->ClearTextureLevel(this, texture_ref, 10284 gfx::Rect cleared_rect;
10251 target, level)) { 10285 if (CombineAdjacentRects(texture->GetLevelClearedRect(target, level),
10252 LOCAL_SET_GL_ERROR( 10286 gfx::Rect(xoffset, yoffset, width, height),
10253 GL_OUT_OF_MEMORY, "glTexSubImage2D", "dimensions too big"); 10287 &cleared_rect)) {
10254 return error::kNoError; 10288 DCHECK_GE(cleared_rect.size().GetArea(),
10289 texture->GetLevelClearedRect(target, level).size().GetArea());
10290 texture_manager()->SetLevelClearedRect(texture_ref, target, level,
10291 cleared_rect);
10292 } else {
10293 // Otherwise clear part of texture level that is not already cleared.
10294 if (!texture_manager()->ClearTextureLevel(this, texture_ref, target,
10295 level)) {
10296 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glTexSubImage2D",
10297 "dimensions too big");
10298 return error::kNoError;
10299 }
10255 } 10300 }
10256 ScopedTextureUploadTimer timer(&texture_state_); 10301 ScopedTextureUploadTimer timer(&texture_state_);
10257 glTexSubImage2D( 10302 glTexSubImage2D(
10258 target, level, xoffset, yoffset, width, height, format, type, data); 10303 target, level, xoffset, yoffset, width, height, format, type, data);
10259 return error::kNoError; 10304 return error::kNoError;
10260 } 10305 }
10261 10306
10262 if (!texture_state_.texsubimage_faster_than_teximage && 10307 if (!texture_state_.texsubimage_faster_than_teximage &&
10263 !texture->IsImmutable() && 10308 !texture->IsImmutable() &&
10264 !texture->HasImages()) { 10309 !texture->HasImages()) {
(...skipping 1494 matching lines...) Expand 10 before | Expand all | Expand 10 after
11759 plane); 11804 plane);
11760 11805
11761 if (err != kCGLNoError) { 11806 if (err != kCGLNoError) {
11762 LOCAL_SET_GL_ERROR( 11807 LOCAL_SET_GL_ERROR(
11763 GL_INVALID_OPERATION, 11808 GL_INVALID_OPERATION,
11764 "glTexImageIOSurface2DCHROMIUM", "error in CGLTexImageIOSurface2D"); 11809 "glTexImageIOSurface2DCHROMIUM", "error in CGLTexImageIOSurface2D");
11765 return; 11810 return;
11766 } 11811 }
11767 11812
11768 texture_manager()->SetLevelInfo( 11813 texture_manager()->SetLevelInfo(
11769 texture_ref, target, 0, GL_RGBA, width, height, 1, 0, 11814 texture_ref, target, 0, GL_RGBA, width, height, 1, 0, GL_BGRA,
11770 GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, true); 11815 GL_UNSIGNED_INT_8_8_8_8_REV, gfx::Rect(width, height));
11771 11816
11772 #else 11817 #else
11773 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, 11818 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION,
11774 "glTexImageIOSurface2DCHROMIUM", "not supported."); 11819 "glTexImageIOSurface2DCHROMIUM", "not supported.");
11775 #endif 11820 #endif
11776 } 11821 }
11777 11822
11778 static GLenum ExtractFormatFromStorageFormat(GLenum internalformat) { 11823 static GLenum ExtractFormatFromStorageFormat(GLenum internalformat) {
11779 switch (internalformat) { 11824 switch (internalformat) {
11780 case GL_RGB565: 11825 case GL_RGB565:
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
11983 glTexImage2D(GL_TEXTURE_2D, 0, internal_format, source_width, source_height, 12028 glTexImage2D(GL_TEXTURE_2D, 0, internal_format, source_width, source_height,
11984 0, internal_format, dest_type, NULL); 12029 0, internal_format, dest_type, NULL);
11985 GLenum error = LOCAL_PEEK_GL_ERROR("glCopyTextureCHROMIUM"); 12030 GLenum error = LOCAL_PEEK_GL_ERROR("glCopyTextureCHROMIUM");
11986 if (error != GL_NO_ERROR) { 12031 if (error != GL_NO_ERROR) {
11987 RestoreCurrentTextureBindings(&state_, GL_TEXTURE_2D); 12032 RestoreCurrentTextureBindings(&state_, GL_TEXTURE_2D);
11988 return; 12033 return;
11989 } 12034 }
11990 12035
11991 texture_manager()->SetLevelInfo( 12036 texture_manager()->SetLevelInfo(
11992 dest_texture_ref, GL_TEXTURE_2D, 0, internal_format, source_width, 12037 dest_texture_ref, GL_TEXTURE_2D, 0, internal_format, source_width,
11993 source_height, 1, 0, internal_format, dest_type, true); 12038 source_height, 1, 0, internal_format, dest_type,
12039 gfx::Rect(source_width, source_height));
11994 } else { 12040 } else {
11995 texture_manager()->SetLevelCleared(dest_texture_ref, GL_TEXTURE_2D, 0, 12041 texture_manager()->SetLevelCleared(dest_texture_ref, GL_TEXTURE_2D, 0,
11996 true); 12042 true);
11997 } 12043 }
11998 12044
11999 ScopedModifyPixels modify(dest_texture_ref); 12045 ScopedModifyPixels modify(dest_texture_ref);
12000 12046
12001 // Try using GLImage::CopyTexSubImage when possible. 12047 // Try using GLImage::CopyTexSubImage when possible.
12002 bool unpack_premultiply_alpha_change = 12048 bool unpack_premultiply_alpha_change =
12003 unpack_premultiply_alpha_ ^ unpack_unpremultiply_alpha_; 12049 unpack_premultiply_alpha_ ^ unpack_unpremultiply_alpha_;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
12129 return; 12175 return;
12130 } 12176 }
12131 12177
12132 int dest_width = 0; 12178 int dest_width = 0;
12133 int dest_height = 0; 12179 int dest_height = 0;
12134 bool ok = dest_texture->GetLevelSize( 12180 bool ok = dest_texture->GetLevelSize(
12135 GL_TEXTURE_2D, 0, &dest_width, &dest_height, nullptr); 12181 GL_TEXTURE_2D, 0, &dest_width, &dest_height, nullptr);
12136 DCHECK(ok); 12182 DCHECK(ok);
12137 if (xoffset != 0 || yoffset != 0 || width != dest_width || 12183 if (xoffset != 0 || yoffset != 0 || width != dest_width ||
12138 height != dest_height) { 12184 height != dest_height) {
12139 if (!texture_manager()->ClearTextureLevel(this, dest_texture_ref, target, 12185 gfx::Rect cleared_rect;
12140 0)) { 12186 if (CombineAdjacentRects(dest_texture->GetLevelClearedRect(target, 0),
12141 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glCopySubTextureCHROMIUM", 12187 gfx::Rect(xoffset, yoffset, width, height),
12142 "destination texture dimensions too big"); 12188 &cleared_rect)) {
12143 return; 12189 DCHECK_GE(cleared_rect.size().GetArea(),
12190 dest_texture->GetLevelClearedRect(target, 0).size().GetArea());
12191 texture_manager()->SetLevelClearedRect(dest_texture_ref, target, 0,
12192 cleared_rect);
12193 } else {
12194 // Otherwise clear part of texture level that is not already cleared.
12195 if (!texture_manager()->ClearTextureLevel(this, dest_texture_ref, target,
12196 0)) {
12197 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glCopySubTextureCHROMIUM",
12198 "destination texture dimensions too big");
12199 return;
12200 }
12144 } 12201 }
12145 } else { 12202 } else {
12146 texture_manager()->SetLevelCleared(dest_texture_ref, GL_TEXTURE_2D, 0, 12203 texture_manager()->SetLevelCleared(dest_texture_ref, GL_TEXTURE_2D, 0,
12147 true); 12204 true);
12148 } 12205 }
12149 12206
12150 ScopedModifyPixels modify(dest_texture_ref); 12207 ScopedModifyPixels modify(dest_texture_ref);
12151 12208
12152 // Try using GLImage::CopyTexSubImage when possible. 12209 // Try using GLImage::CopyTexSubImage when possible.
12153 bool unpack_premultiply_alpha_change = 12210 bool unpack_premultiply_alpha_change =
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
12279 } 12336 }
12280 } 12337 }
12281 12338
12282 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glTexStorage2DEXT"); 12339 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glTexStorage2DEXT");
12283 glTexStorage2DEXT(target, levels, internal_format, width, height); 12340 glTexStorage2DEXT(target, levels, internal_format, width, height);
12284 GLenum error = LOCAL_PEEK_GL_ERROR("glTexStorage2DEXT"); 12341 GLenum error = LOCAL_PEEK_GL_ERROR("glTexStorage2DEXT");
12285 if (error == GL_NO_ERROR) { 12342 if (error == GL_NO_ERROR) {
12286 GLsizei level_width = width; 12343 GLsizei level_width = width;
12287 GLsizei level_height = height; 12344 GLsizei level_height = height;
12288 for (int ii = 0; ii < levels; ++ii) { 12345 for (int ii = 0; ii < levels; ++ii) {
12289 texture_manager()->SetLevelInfo( 12346 texture_manager()->SetLevelInfo(texture_ref, target, ii, format,
12290 texture_ref, target, ii, format, 12347 level_width, level_height, 1, 0, format,
12291 level_width, level_height, 1, 0, format, type, false); 12348 type, gfx::Rect());
12292 level_width = std::max(1, level_width >> 1); 12349 level_width = std::max(1, level_width >> 1);
12293 level_height = std::max(1, level_height >> 1); 12350 level_height = std::max(1, level_height >> 1);
12294 } 12351 }
12295 texture->SetImmutable(true); 12352 texture->SetImmutable(true);
12296 } 12353 }
12297 } 12354 }
12298 12355
12299 error::Error GLES2DecoderImpl::HandleGenMailboxCHROMIUM( 12356 error::Error GLES2DecoderImpl::HandleGenMailboxCHROMIUM(
12300 uint32 immediate_data_size, 12357 uint32 immediate_data_size,
12301 const void* cmd_data) { 12358 const void* cmd_data) {
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
12631 if (!gl_image->BindTexImage(target)) { 12688 if (!gl_image->BindTexImage(target)) {
12632 LOCAL_SET_GL_ERROR( 12689 LOCAL_SET_GL_ERROR(
12633 GL_INVALID_OPERATION, 12690 GL_INVALID_OPERATION,
12634 "glBindTexImage2DCHROMIUM", "fail to bind image with the given ID"); 12691 "glBindTexImage2DCHROMIUM", "fail to bind image with the given ID");
12635 return; 12692 return;
12636 } 12693 }
12637 } 12694 }
12638 12695
12639 gfx::Size size = gl_image->GetSize(); 12696 gfx::Size size = gl_image->GetSize();
12640 texture_manager()->SetLevelInfo( 12697 texture_manager()->SetLevelInfo(
12641 texture_ref, target, 0, gl_image->GetInternalFormat(), 12698 texture_ref, target, 0, gl_image->GetInternalFormat(), size.width(),
12642 size.width(), size.height(), 1, 0, 12699 size.height(), 1, 0, gl_image->GetInternalFormat(), GL_UNSIGNED_BYTE,
12643 gl_image->GetInternalFormat(), GL_UNSIGNED_BYTE, true); 12700 gfx::Rect(size));
12644 texture_manager()->SetLevelImage(texture_ref, target, 0, gl_image); 12701 texture_manager()->SetLevelImage(texture_ref, target, 0, gl_image);
12645 } 12702 }
12646 12703
12647 void GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM( 12704 void GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM(
12648 GLenum target, GLint image_id) { 12705 GLenum target, GLint image_id) {
12649 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM"); 12706 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM");
12650 12707
12651 // Default target might be conceptually valid, but disallow it to avoid 12708 // Default target might be conceptually valid, but disallow it to avoid
12652 // accidents. 12709 // accidents.
12653 TextureRef* texture_ref = 12710 TextureRef* texture_ref =
(...skipping 18 matching lines...) Expand all
12672 return; 12729 return;
12673 12730
12674 { 12731 {
12675 ScopedGLErrorSuppressor suppressor( 12732 ScopedGLErrorSuppressor suppressor(
12676 "GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM", GetErrorState()); 12733 "GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM", GetErrorState());
12677 gl_image->ReleaseTexImage(target); 12734 gl_image->ReleaseTexImage(target);
12678 } 12735 }
12679 12736
12680 texture_manager()->SetLevelInfo( 12737 texture_manager()->SetLevelInfo(
12681 texture_ref, target, 0, gl_image->GetInternalFormat(), 0, 0, 1, 0, 12738 texture_ref, target, 0, gl_image->GetInternalFormat(), 0, 0, 1, 0,
12682 gl_image->GetInternalFormat(), GL_UNSIGNED_BYTE, false); 12739 gl_image->GetInternalFormat(), GL_UNSIGNED_BYTE, gfx::Rect());
12683 } 12740 }
12684 12741
12685 error::Error GLES2DecoderImpl::HandleTraceBeginCHROMIUM( 12742 error::Error GLES2DecoderImpl::HandleTraceBeginCHROMIUM(
12686 uint32 immediate_data_size, 12743 uint32 immediate_data_size,
12687 const void* cmd_data) { 12744 const void* cmd_data) {
12688 const gles2::cmds::TraceBeginCHROMIUM& c = 12745 const gles2::cmds::TraceBeginCHROMIUM& c =
12689 *static_cast<const gles2::cmds::TraceBeginCHROMIUM*>(cmd_data); 12746 *static_cast<const gles2::cmds::TraceBeginCHROMIUM*>(cmd_data);
12690 Bucket* category_bucket = GetBucket(c.category_bucket_id); 12747 Bucket* category_bucket = GetBucket(c.category_bucket_id);
12691 Bucket* name_bucket = GetBucket(c.name_bucket_id); 12748 Bucket* name_bucket = GetBucket(c.name_bucket_id);
12692 if (!category_bucket || category_bucket->size() == 0 || 12749 if (!category_bucket || category_bucket->size() == 0 ||
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after
13319 } 13376 }
13320 } 13377 }
13321 13378
13322 // Include the auto-generated part of this file. We split this because it means 13379 // Include the auto-generated part of this file. We split this because it means
13323 // we can easily edit the non-auto generated parts right here in this file 13380 // we can easily edit the non-auto generated parts right here in this file
13324 // instead of having to edit some template or the code generator. 13381 // instead of having to edit some template or the code generator.
13325 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 13382 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
13326 13383
13327 } // namespace gles2 13384 } // namespace gles2
13328 } // namespace gpu 13385 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/gles2_cmd_decoder.h ('k') | gpu/command_buffer/service/gles2_cmd_decoder_mock.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698