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

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

Issue 1403483002: Update CopyTexImage2D to do internal format validation in ES3 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix comments#4 and #5 Created 5 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
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 1549 matching lines...) Expand 10 before | Expand all | Expand 10 after
1560 bool SetCapabilityState(GLenum cap, bool enabled); 1560 bool SetCapabilityState(GLenum cap, bool enabled);
1561 1561
1562 // Check that the currently bound framebuffers are valid. 1562 // Check that the currently bound framebuffers are valid.
1563 // Generates GL error if not. 1563 // Generates GL error if not.
1564 bool CheckBoundFramebuffersValid(const char* func_name); 1564 bool CheckBoundFramebuffersValid(const char* func_name);
1565 1565
1566 // Check that the currently bound read framebuffer has a color image 1566 // Check that the currently bound read framebuffer has a color image
1567 // attached. Generates GL error if not. 1567 // attached. Generates GL error if not.
1568 bool CheckBoundReadFramebufferColorAttachment(const char* func_name); 1568 bool CheckBoundReadFramebufferColorAttachment(const char* func_name);
1569 1569
1570 // Infer color encoding from internalformat
1571 GLint GetColorEncodingFromInternalFormat(GLenum internalformat);
Zhenyao Mo 2015/10/13 17:00:23 Make it static.
qiankun 2015/10/13 23:54:07 Done.
1572
1573 // Get the value of GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the
1574 // framebuffer attachment corresponding to the read buffer.
1575 GLint GetReadFramebufferAttachmentColorEncoding();
1576
1570 // Check that the currently bound read framebuffer's color image 1577 // Check that the currently bound read framebuffer's color image
1571 // isn't the target texture of the glCopyTex{Sub}Image2D. 1578 // isn't the target texture of the glCopyTex{Sub}Image2D.
1572 bool FormsTextureCopyingFeedbackLoop(TextureRef* texture, GLint level); 1579 bool FormsTextureCopyingFeedbackLoop(TextureRef* texture, GLint level);
1573 1580
1574 // Check if a framebuffer meets our requirements. 1581 // Check if a framebuffer meets our requirements.
1575 bool CheckFramebufferValid( 1582 bool CheckFramebufferValid(
1576 Framebuffer* framebuffer, 1583 Framebuffer* framebuffer,
1577 GLenum target, 1584 GLenum target,
1578 const char* func_name); 1585 const char* func_name);
1579 1586
(...skipping 2432 matching lines...) Expand 10 before | Expand all | Expand 10 after
4012 if (!framebuffer) 4019 if (!framebuffer)
4013 return true; 4020 return true;
4014 if (framebuffer->GetAttachment(GL_COLOR_ATTACHMENT0) == NULL) { 4021 if (framebuffer->GetAttachment(GL_COLOR_ATTACHMENT0) == NULL) {
4015 LOCAL_SET_GL_ERROR( 4022 LOCAL_SET_GL_ERROR(
4016 GL_INVALID_OPERATION, func_name, "no color image attached"); 4023 GL_INVALID_OPERATION, func_name, "no color image attached");
4017 return false; 4024 return false;
4018 } 4025 }
4019 return true; 4026 return true;
4020 } 4027 }
4021 4028
4029 GLint GLES2DecoderImpl::GetColorEncodingFromInternalFormat(
4030 GLenum internalformat) {
4031 switch (internalformat) {
4032 case GL_SRGB_EXT:
4033 case GL_SRGB_ALPHA_EXT:
4034 case GL_SRGB8:
4035 case GL_SRGB8_ALPHA8:
4036 return GL_SRGB;
4037 default:
4038 return GL_LINEAR;
4039 }
4040 }
4041
4042 GLint GLES2DecoderImpl::GetReadFramebufferAttachmentColorEncoding() {
4043 GLenum target = features().chromium_framebuffer_multisample ?
4044 GL_READ_FRAMEBUFFER_EXT : GL_FRAMEBUFFER_EXT;
4045 GLint v = GL_NONE;
4046 glGetFramebufferAttachmentParameterivEXT(
4047 target, GL_COLOR_ATTACHMENT0,
4048 GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING, &v);
4049 return v;
4050 }
4051
4022 bool GLES2DecoderImpl::FormsTextureCopyingFeedbackLoop( 4052 bool GLES2DecoderImpl::FormsTextureCopyingFeedbackLoop(
4023 TextureRef* texture, GLint level) { 4053 TextureRef* texture, GLint level) {
4024 Framebuffer* framebuffer = features().chromium_framebuffer_multisample ? 4054 Framebuffer* framebuffer = features().chromium_framebuffer_multisample ?
4025 framebuffer_state_.bound_read_framebuffer.get() : 4055 framebuffer_state_.bound_read_framebuffer.get() :
4026 framebuffer_state_.bound_draw_framebuffer.get(); 4056 framebuffer_state_.bound_draw_framebuffer.get();
4027 if (!framebuffer) 4057 if (!framebuffer)
4028 return false; 4058 return false;
4029 const Framebuffer::Attachment* attachment = framebuffer->GetAttachment( 4059 const Framebuffer::Attachment* attachment = framebuffer->GetAttachment(
4030 GL_COLOR_ATTACHMENT0); 4060 GL_COLOR_ATTACHMENT0);
4031 if (!attachment) 4061 if (!attachment)
(...skipping 6964 matching lines...) Expand 10 before | Expand all | Expand 10 after
10996 GLenum read_format = GetBoundReadFrameBufferInternalFormat(); 11026 GLenum read_format = GetBoundReadFrameBufferInternalFormat();
10997 uint32 channels_exist = GLES2Util::GetChannelsForFormat(read_format); 11027 uint32 channels_exist = GLES2Util::GetChannelsForFormat(read_format);
10998 uint32 channels_needed = GLES2Util::GetChannelsForFormat(internal_format); 11028 uint32 channels_needed = GLES2Util::GetChannelsForFormat(internal_format);
10999 11029
11000 if ((channels_needed & channels_exist) != channels_needed) { 11030 if ((channels_needed & channels_exist) != channels_needed) {
11001 LOCAL_SET_GL_ERROR( 11031 LOCAL_SET_GL_ERROR(
11002 GL_INVALID_OPERATION, "glCopyTexImage2D", "incompatible format"); 11032 GL_INVALID_OPERATION, "glCopyTexImage2D", "incompatible format");
11003 return; 11033 return;
11004 } 11034 }
11005 11035
11036 if (feature_info_->IsES3Enabled()) {
11037 GLint color_encoding = GetReadFramebufferAttachmentColorEncoding();
Zhenyao Mo 2015/10/13 17:00:24 Here you don't need the GetReadFramebufferAttachme
qiankun 2015/10/13 23:54:07 Done.
Zhenyao Mo 2015/10/14 18:39:20 Then please get rid of the GetReadFramebufferAttac
11038 if (color_encoding != GetColorEncodingFromInternalFormat(internal_format) ||
11039 GLES2Util::IsFloatFormat(internal_format) ||
11040 (GLES2Util::IsSignedIntegerFormat(internal_format) !=
11041 GLES2Util::IsSignedIntegerFormat(read_format)) ||
11042 (GLES2Util::IsUnsignedIntegerFormat(internal_format) !=
11043 GLES2Util::IsUnsignedIntegerFormat(read_format))) {
11044 LOCAL_SET_GL_ERROR(
11045 GL_INVALID_OPERATION, "glCopyTexImage2D", "incompatible format");
11046 return;
11047 }
11048 }
11049
11006 if ((channels_needed & (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) { 11050 if ((channels_needed & (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) {
11007 LOCAL_SET_GL_ERROR( 11051 LOCAL_SET_GL_ERROR(
11008 GL_INVALID_OPERATION, 11052 GL_INVALID_OPERATION,
11009 "glCopyTexImage2D", "can not be used with depth or stencil textures"); 11053 "glCopyTexImage2D", "can not be used with depth or stencil textures");
11010 return; 11054 return;
11011 } 11055 }
11012 11056
11013 uint32 pixels_size = 0; 11057 uint32 pixels_size = 0;
11014 GLenum format = ExtractFormatFromStorageFormat(internal_format); 11058 GLenum format = ExtractFormatFromStorageFormat(internal_format);
11015 GLenum type = ExtractTypeFromStorageFormat(internal_format); 11059 GLenum type = ExtractTypeFromStorageFormat(internal_format);
(...skipping 4050 matching lines...) Expand 10 before | Expand all | Expand 10 after
15066 return error::kNoError; 15110 return error::kNoError;
15067 } 15111 }
15068 15112
15069 // Include the auto-generated part of this file. We split this because it means 15113 // Include the auto-generated part of this file. We split this because it means
15070 // we can easily edit the non-auto generated parts right here in this file 15114 // we can easily edit the non-auto generated parts right here in this file
15071 // instead of having to edit some template or the code generator. 15115 // instead of having to edit some template or the code generator.
15072 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 15116 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
15073 15117
15074 } // namespace gles2 15118 } // namespace gles2
15075 } // namespace gpu 15119 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/common/gles2_cmd_utils.cc ('k') | gpu/command_buffer/service/gles2_cmd_decoder_unittest_framebuffers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698