OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <list> | 10 #include <list> |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 }; | 119 }; |
120 | 120 |
121 static bool IsAngle() { | 121 static bool IsAngle() { |
122 #if defined(OS_WIN) | 122 #if defined(OS_WIN) |
123 return gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2; | 123 return gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2; |
124 #else | 124 #else |
125 return false; | 125 return false; |
126 #endif | 126 #endif |
127 } | 127 } |
128 | 128 |
129 void WrappedTexImage2D( | 129 static void WrappedTexImage2D( |
130 GLenum target, | 130 GLenum target, |
131 GLint level, | 131 GLint level, |
132 GLenum internal_format, | 132 GLenum internal_format, |
133 GLsizei width, | 133 GLsizei width, |
134 GLsizei height, | 134 GLsizei height, |
135 GLint border, | 135 GLint border, |
136 GLenum format, | 136 GLenum format, |
137 GLenum type, | 137 GLenum type, |
138 const void* pixels) { | 138 const void* pixels) { |
139 GLenum gl_internal_format = internal_format; | 139 GLenum gl_internal_format = internal_format; |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 virtual void SetSwapBuffersCallback(Callback0::Type* callback); | 728 virtual void SetSwapBuffersCallback(Callback0::Type* callback); |
729 virtual void SetLatchCallback(const base::Callback<void(bool)>& callback);; | 729 virtual void SetLatchCallback(const base::Callback<void(bool)>& callback);; |
730 virtual bool GetServiceTextureId(uint32 client_texture_id, | 730 virtual bool GetServiceTextureId(uint32 client_texture_id, |
731 uint32* service_texture_id); | 731 uint32* service_texture_id); |
732 | 732 |
733 // Restores the current state to the user's settings. | 733 // Restores the current state to the user's settings. |
734 void RestoreCurrentFramebufferBindings(); | 734 void RestoreCurrentFramebufferBindings(); |
735 void RestoreCurrentRenderbufferBindings(); | 735 void RestoreCurrentRenderbufferBindings(); |
736 void RestoreCurrentTexture2DBindings(); | 736 void RestoreCurrentTexture2DBindings(); |
737 | 737 |
| 738 // Sets DEPTH_TEST, STENCIL_TEST and color mask for the current framebuffer. |
| 739 void ApplyDirtyState(); |
| 740 |
| 741 // These check the state of the currently bound framebuffer or the |
| 742 // backbuffer if no framebuffer is bound. |
| 743 bool BoundFramebufferHasColorAttachmentWithAlpha(); |
| 744 bool BoundFramebufferHasDepthAttachment(); |
| 745 bool BoundFramebufferHasStencilAttachment(); |
| 746 |
738 private: | 747 private: |
739 friend class ScopedGLErrorSuppressor; | 748 friend class ScopedGLErrorSuppressor; |
740 friend class ScopedResolvedFrameBufferBinder; | 749 friend class ScopedResolvedFrameBufferBinder; |
741 friend class RenderBuffer; | 750 friend class RenderBuffer; |
742 friend class FrameBuffer; | 751 friend class FrameBuffer; |
743 | 752 |
744 // State associated with each texture unit. | 753 // State associated with each texture unit. |
745 struct TextureUnit { | 754 struct TextureUnit { |
746 TextureUnit() : bind_target(GL_TEXTURE_2D) { } | 755 TextureUnit() : bind_target(GL_TEXTURE_2D) { } |
747 | 756 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 texture_manager()->RemoveTextureInfo(feature_info_, client_id); | 826 texture_manager()->RemoveTextureInfo(feature_info_, client_id); |
818 } | 827 } |
819 | 828 |
820 // Get the size (in pixels) of the currently bound frame buffer (either FBO | 829 // Get the size (in pixels) of the currently bound frame buffer (either FBO |
821 // or regular back buffer). | 830 // or regular back buffer). |
822 gfx::Size GetBoundReadFrameBufferSize(); | 831 gfx::Size GetBoundReadFrameBufferSize(); |
823 | 832 |
824 // Get the format of the currently bound frame buffer (either FBO or regular | 833 // Get the format of the currently bound frame buffer (either FBO or regular |
825 // back buffer) | 834 // back buffer) |
826 GLenum GetBoundReadFrameBufferInternalFormat(); | 835 GLenum GetBoundReadFrameBufferInternalFormat(); |
| 836 GLenum GetBoundDrawFrameBufferInternalFormat(); |
827 | 837 |
828 // Wrapper for CompressedTexImage2D commands. | 838 // Wrapper for CompressedTexImage2D commands. |
829 error::Error DoCompressedTexImage2D( | 839 error::Error DoCompressedTexImage2D( |
830 GLenum target, | 840 GLenum target, |
831 GLint level, | 841 GLint level, |
832 GLenum internal_format, | 842 GLenum internal_format, |
833 GLsizei width, | 843 GLsizei width, |
834 GLsizei height, | 844 GLsizei height, |
835 GLint border, | 845 GLint border, |
836 GLsizei image_size, | 846 GLsizei image_size, |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1252 void DoVertexAttrib2fv(GLuint index, const GLfloat *v); | 1262 void DoVertexAttrib2fv(GLuint index, const GLfloat *v); |
1253 void DoVertexAttrib3fv(GLuint index, const GLfloat *v); | 1263 void DoVertexAttrib3fv(GLuint index, const GLfloat *v); |
1254 void DoVertexAttrib4fv(GLuint index, const GLfloat *v); | 1264 void DoVertexAttrib4fv(GLuint index, const GLfloat *v); |
1255 | 1265 |
1256 // Wrapper for glUseProgram | 1266 // Wrapper for glUseProgram |
1257 void DoUseProgram(GLuint program); | 1267 void DoUseProgram(GLuint program); |
1258 | 1268 |
1259 // Wrapper for glValidateProgram. | 1269 // Wrapper for glValidateProgram. |
1260 void DoValidateProgram(GLuint program_client_id); | 1270 void DoValidateProgram(GLuint program_client_id); |
1261 | 1271 |
1262 void DoCopyTextureToParentTextureCHROMIUM(GLuint client_texture_id, | 1272 void DoCopyTextureToParentTextureCHROMIUM( |
1263 GLuint parent_client_texture_id); | 1273 GLuint client_texture_id, GLuint parent_client_texture_id); |
1264 | 1274 |
1265 void DoResizeCHROMIUM(GLuint width, GLuint height); | 1275 void DoResizeCHROMIUM(GLuint width, GLuint height); |
1266 | 1276 |
1267 void DoSetSurfaceCHROMIUM(GLint surface_id); | 1277 void DoSetSurfaceCHROMIUM(GLint surface_id); |
1268 | 1278 |
1269 // Gets the number of values that will be returned by glGetXXX. Returns | 1279 // Gets the number of values that will be returned by glGetXXX. Returns |
1270 // false if pname is unknown. | 1280 // false if pname is unknown. |
1271 bool GetNumValuesReturnedForGLGet(GLenum pname, GLsizei* num_values); | 1281 bool GetNumValuesReturnedForGLGet(GLenum pname, GLsizei* num_values); |
1272 | 1282 |
1273 // Gets the GLError through our wrapper. | 1283 // Gets the GLError through our wrapper. |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1455 GLboolean mask_red_; | 1465 GLboolean mask_red_; |
1456 GLboolean mask_green_; | 1466 GLboolean mask_green_; |
1457 GLboolean mask_blue_; | 1467 GLboolean mask_blue_; |
1458 GLboolean mask_alpha_; | 1468 GLboolean mask_alpha_; |
1459 GLint clear_stencil_; | 1469 GLint clear_stencil_; |
1460 GLuint mask_stencil_front_; | 1470 GLuint mask_stencil_front_; |
1461 GLuint mask_stencil_back_; | 1471 GLuint mask_stencil_back_; |
1462 GLclampf clear_depth_; | 1472 GLclampf clear_depth_; |
1463 GLboolean mask_depth_; | 1473 GLboolean mask_depth_; |
1464 bool enable_scissor_test_; | 1474 bool enable_scissor_test_; |
| 1475 bool state_dirty_; |
1465 | 1476 |
1466 // The program in use by glUseProgram | 1477 // The program in use by glUseProgram |
1467 ProgramManager::ProgramInfo::Ref current_program_; | 1478 ProgramManager::ProgramInfo::Ref current_program_; |
1468 | 1479 |
1469 // The currently bound framebuffers | 1480 // The currently bound framebuffers |
1470 FramebufferManager::FramebufferInfo::Ref bound_read_framebuffer_; | 1481 FramebufferManager::FramebufferInfo::Ref bound_read_framebuffer_; |
1471 FramebufferManager::FramebufferInfo::Ref bound_draw_framebuffer_; | 1482 FramebufferManager::FramebufferInfo::Ref bound_draw_framebuffer_; |
1472 | 1483 |
1473 // The currently bound renderbuffer | 1484 // The currently bound renderbuffer |
1474 RenderbufferManager::RenderbufferInfo::Ref bound_renderbuffer_; | 1485 RenderbufferManager::RenderbufferInfo::Ref bound_renderbuffer_; |
(...skipping 19 matching lines...) Expand all Loading... |
1494 scoped_ptr<FrameBuffer> offscreen_saved_frame_buffer_; | 1505 scoped_ptr<FrameBuffer> offscreen_saved_frame_buffer_; |
1495 scoped_ptr<Texture> offscreen_saved_color_texture_; | 1506 scoped_ptr<Texture> offscreen_saved_color_texture_; |
1496 GLenum offscreen_saved_color_format_; | 1507 GLenum offscreen_saved_color_format_; |
1497 | 1508 |
1498 scoped_ptr<Callback1<gfx::Size>::Type> resize_callback_; | 1509 scoped_ptr<Callback1<gfx::Size>::Type> resize_callback_; |
1499 scoped_ptr<Callback0::Type> swap_buffers_callback_; | 1510 scoped_ptr<Callback0::Type> swap_buffers_callback_; |
1500 base::Callback<void(bool)> latch_callback_; | 1511 base::Callback<void(bool)> latch_callback_; |
1501 | 1512 |
1502 // The format of the back buffer_ | 1513 // The format of the back buffer_ |
1503 GLenum back_buffer_color_format_; | 1514 GLenum back_buffer_color_format_; |
| 1515 bool back_buffer_has_depth_; |
| 1516 bool back_buffer_has_stencil_; |
1504 | 1517 |
1505 bool teximage2d_faster_than_texsubimage2d_; | 1518 bool teximage2d_faster_than_texsubimage2d_; |
1506 bool bufferdata_faster_than_buffersubdata_; | 1519 bool bufferdata_faster_than_buffersubdata_; |
1507 | 1520 |
1508 // The last error message set. | 1521 // The last error message set. |
1509 std::string last_error_; | 1522 std::string last_error_; |
1510 | 1523 |
1511 // The current decoder error. | 1524 // The current decoder error. |
1512 error::Error current_decoder_error_; | 1525 error::Error current_decoder_error_; |
1513 | 1526 |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1837 mask_red_(true), | 1850 mask_red_(true), |
1838 mask_green_(true), | 1851 mask_green_(true), |
1839 mask_blue_(true), | 1852 mask_blue_(true), |
1840 mask_alpha_(true), | 1853 mask_alpha_(true), |
1841 clear_stencil_(0), | 1854 clear_stencil_(0), |
1842 mask_stencil_front_(-1), | 1855 mask_stencil_front_(-1), |
1843 mask_stencil_back_(-1), | 1856 mask_stencil_back_(-1), |
1844 clear_depth_(1.0f), | 1857 clear_depth_(1.0f), |
1845 mask_depth_(true), | 1858 mask_depth_(true), |
1846 enable_scissor_test_(false), | 1859 enable_scissor_test_(false), |
| 1860 state_dirty_(true), |
1847 offscreen_target_color_format_(0), | 1861 offscreen_target_color_format_(0), |
1848 offscreen_target_depth_format_(0), | 1862 offscreen_target_depth_format_(0), |
1849 offscreen_target_stencil_format_(0), | 1863 offscreen_target_stencil_format_(0), |
1850 offscreen_target_samples_(0), | 1864 offscreen_target_samples_(0), |
1851 copy_texture_to_parent_texture_fb_(0), | 1865 copy_texture_to_parent_texture_fb_(0), |
1852 offscreen_saved_color_format_(0), | 1866 offscreen_saved_color_format_(0), |
1853 back_buffer_color_format_(0), | 1867 back_buffer_color_format_(0), |
| 1868 back_buffer_has_depth_(false), |
| 1869 back_buffer_has_stencil_(false), |
1854 teximage2d_faster_than_texsubimage2d_(true), | 1870 teximage2d_faster_than_texsubimage2d_(true), |
1855 bufferdata_faster_than_buffersubdata_(true), | 1871 bufferdata_faster_than_buffersubdata_(true), |
1856 current_decoder_error_(error::kNoError), | 1872 current_decoder_error_(error::kNoError), |
1857 use_shader_translator_(true), | 1873 use_shader_translator_(true), |
1858 validators_(group_->feature_info()->validators()), | 1874 validators_(group_->feature_info()->validators()), |
1859 feature_info_(group_->feature_info()), | 1875 feature_info_(group_->feature_info()), |
1860 tex_image_2d_failed_(false), | 1876 tex_image_2d_failed_(false), |
1861 frame_number_(0) { | 1877 frame_number_(0) { |
1862 attrib_0_value_.v[0] = 0.0f; | 1878 attrib_0_value_.v[0] = 0.0f; |
1863 attrib_0_value_.v[1] = 0.0f; | 1879 attrib_0_value_.v[1] = 0.0f; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1923 << "failed to initialize."; | 1939 << "failed to initialize."; |
1924 Destroy(); | 1940 Destroy(); |
1925 return false; | 1941 return false; |
1926 } | 1942 } |
1927 | 1943 |
1928 CHECK_GL_ERROR(); | 1944 CHECK_GL_ERROR(); |
1929 disallowed_extensions_ = disallowed_extensions; | 1945 disallowed_extensions_ = disallowed_extensions; |
1930 | 1946 |
1931 vertex_attrib_manager_.Initialize(group_->max_vertex_attribs()); | 1947 vertex_attrib_manager_.Initialize(group_->max_vertex_attribs()); |
1932 | 1948 |
1933 GLint v = 0; | |
1934 glGetIntegerv(GL_ALPHA_BITS, &v); | |
1935 back_buffer_color_format_ = v ? GL_RGBA : GL_RGB; | |
1936 | |
1937 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { | 1949 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { |
1938 // We have to enable vertex array 0 on OpenGL or it won't render. Note that | 1950 // We have to enable vertex array 0 on OpenGL or it won't render. Note that |
1939 // OpenGL ES 2.0 does not have this issue. | 1951 // OpenGL ES 2.0 does not have this issue. |
1940 glEnableVertexAttribArray(0); | 1952 glEnableVertexAttribArray(0); |
1941 } | 1953 } |
1942 glGenBuffersARB(1, &attrib_0_buffer_id_); | 1954 glGenBuffersARB(1, &attrib_0_buffer_id_); |
1943 glBindBuffer(GL_ARRAY_BUFFER, attrib_0_buffer_id_); | 1955 glBindBuffer(GL_ARRAY_BUFFER, attrib_0_buffer_id_); |
1944 glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, NULL); | 1956 glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, NULL); |
1945 glBindBuffer(GL_ARRAY_BUFFER, 0); | 1957 glBindBuffer(GL_ARRAY_BUFFER, 0); |
1946 glGenBuffersARB(1, &fixed_attrib_buffer_id_); | 1958 glGenBuffersARB(1, &fixed_attrib_buffer_id_); |
1947 | 1959 |
1948 texture_units_.reset( | 1960 texture_units_.reset( |
1949 new TextureUnit[group_->max_texture_units()]); | 1961 new TextureUnit[group_->max_texture_units()]); |
1950 for (uint32 tt = 0; tt < group_->max_texture_units(); ++tt) { | 1962 for (uint32 tt = 0; tt < group_->max_texture_units(); ++tt) { |
1951 glActiveTexture(GL_TEXTURE0 + tt); | 1963 glActiveTexture(GL_TEXTURE0 + tt); |
1952 // Do cube map first because we want the last bind to be 2D. | 1964 // Do cube map first because we want the last bind to be 2D. |
1953 TextureManager::TextureInfo* info = | 1965 TextureManager::TextureInfo* info = |
1954 texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_CUBE_MAP); | 1966 texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_CUBE_MAP); |
1955 texture_units_[tt].bound_texture_cube_map = info; | 1967 texture_units_[tt].bound_texture_cube_map = info; |
1956 glBindTexture(GL_TEXTURE_CUBE_MAP, info->service_id()); | 1968 glBindTexture(GL_TEXTURE_CUBE_MAP, info->service_id()); |
1957 info = texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_2D); | 1969 info = texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_2D); |
1958 texture_units_[tt].bound_texture_2d = info; | 1970 texture_units_[tt].bound_texture_2d = info; |
1959 glBindTexture(GL_TEXTURE_2D, info->service_id()); | 1971 glBindTexture(GL_TEXTURE_2D, info->service_id()); |
1960 } | 1972 } |
1961 glActiveTexture(GL_TEXTURE0); | 1973 glActiveTexture(GL_TEXTURE0); |
1962 CHECK_GL_ERROR(); | 1974 CHECK_GL_ERROR(); |
1963 | 1975 |
| 1976 ContextCreationAttribParser attrib_parser; |
| 1977 if (!attrib_parser.Parse(attribs)) |
| 1978 return false; |
| 1979 |
| 1980 // These are NOT if the back buffer has these proprorties. They are |
| 1981 // if we want the command buffer to enforce them regardless of what |
| 1982 // the real backbuffer is assuming the real back buffer gives us more than |
| 1983 // we ask for. In other words, if we ask for RGB and we get RGBA then we'll |
| 1984 // make it appear RGB. If on the other hand we ask for RGBA nd get RGB we |
| 1985 // can't do anything about that. |
| 1986 |
| 1987 GLint v = 0; |
| 1988 glGetIntegerv(GL_ALPHA_BITS, &v); |
| 1989 // This checks if the user requested RGBA and we have RGBA then RGBA. If the |
| 1990 // user requested RGB then RGB. If the user did not specify a preference than |
| 1991 // use whatever we were given. Same for DEPTH and STENCIL. |
| 1992 back_buffer_color_format_ = |
| 1993 (attrib_parser.alpha_size_ != 0 && v > 0) ? GL_RGBA : GL_RGB; |
| 1994 glGetIntegerv(GL_DEPTH_BITS, &v); |
| 1995 back_buffer_has_depth_ = attrib_parser.depth_size_ != 0 && v > 0; |
| 1996 glGetIntegerv(GL_STENCIL_BITS, &v); |
| 1997 back_buffer_has_stencil_ = attrib_parser.stencil_size_ != 0 && v > 0; |
| 1998 |
1964 if (surface_->IsOffscreen()) { | 1999 if (surface_->IsOffscreen()) { |
1965 ContextCreationAttribParser attrib_parser; | |
1966 if (!attrib_parser.Parse(attribs)) | |
1967 return false; | |
1968 | |
1969 if (attrib_parser.samples_ > 0 && attrib_parser.sample_buffers_ > 0 && | 2000 if (attrib_parser.samples_ > 0 && attrib_parser.sample_buffers_ > 0 && |
1970 (context_->HasExtension("GL_EXT_framebuffer_multisample") || | 2001 (context_->HasExtension("GL_EXT_framebuffer_multisample") || |
1971 context_->HasExtension("GL_ANGLE_framebuffer_multisample"))) { | 2002 context_->HasExtension("GL_ANGLE_framebuffer_multisample"))) { |
1972 // Per ext_framebuffer_multisample spec, need max bound on sample count. | 2003 // Per ext_framebuffer_multisample spec, need max bound on sample count. |
1973 // max_sample_count must be initialized to a sane value. If | 2004 // max_sample_count must be initialized to a sane value. If |
1974 // glGetIntegerv() throws a GL error, it leaves its argument unchanged. | 2005 // glGetIntegerv() throws a GL error, it leaves its argument unchanged. |
1975 GLint max_sample_count = 1; | 2006 GLint max_sample_count = 1; |
1976 glGetIntegerv(GL_MAX_SAMPLES_EXT, &max_sample_count); | 2007 glGetIntegerv(GL_MAX_SAMPLES_EXT, &max_sample_count); |
1977 offscreen_target_samples_ = std::min(attrib_parser.samples_, | 2008 offscreen_target_samples_ = std::min(attrib_parser.samples_, |
1978 max_sample_count); | 2009 max_sample_count); |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2227 } | 2258 } |
2228 } | 2259 } |
2229 } | 2260 } |
2230 | 2261 |
2231 void GLES2DecoderImpl::DeleteFramebuffersHelper( | 2262 void GLES2DecoderImpl::DeleteFramebuffersHelper( |
2232 GLsizei n, const GLuint* client_ids) { | 2263 GLsizei n, const GLuint* client_ids) { |
2233 for (GLsizei ii = 0; ii < n; ++ii) { | 2264 for (GLsizei ii = 0; ii < n; ++ii) { |
2234 FramebufferManager::FramebufferInfo* info = | 2265 FramebufferManager::FramebufferInfo* info = |
2235 GetFramebufferInfo(client_ids[ii]); | 2266 GetFramebufferInfo(client_ids[ii]); |
2236 if (info) { | 2267 if (info) { |
| 2268 if (info == bound_draw_framebuffer_) { |
| 2269 bound_draw_framebuffer_ = NULL; |
| 2270 state_dirty_ = true; |
| 2271 } |
2237 GLuint service_id = info->service_id(); | 2272 GLuint service_id = info->service_id(); |
2238 glDeleteFramebuffersEXT(1, &service_id); | 2273 glDeleteFramebuffersEXT(1, &service_id); |
2239 RemoveFramebufferInfo(client_ids[ii]); | 2274 RemoveFramebufferInfo(client_ids[ii]); |
2240 } | 2275 } |
2241 } | 2276 } |
2242 } | 2277 } |
2243 | 2278 |
2244 void GLES2DecoderImpl::DeleteRenderbuffersHelper( | 2279 void GLES2DecoderImpl::DeleteRenderbuffersHelper( |
2245 GLsizei n, const GLuint* client_ids) { | 2280 GLsizei n, const GLuint* client_ids) { |
2246 for (GLsizei ii = 0; ii < n; ++ii) { | 2281 for (GLsizei ii = 0; ii < n; ++ii) { |
2247 RenderbufferManager::RenderbufferInfo* info = | 2282 RenderbufferManager::RenderbufferInfo* info = |
2248 GetRenderbufferInfo(client_ids[ii]); | 2283 GetRenderbufferInfo(client_ids[ii]); |
2249 if (info) { | 2284 if (info) { |
| 2285 state_dirty_ = true; |
2250 GLuint service_id = info->service_id(); | 2286 GLuint service_id = info->service_id(); |
2251 glDeleteRenderbuffersEXT(1, &service_id); | 2287 glDeleteRenderbuffersEXT(1, &service_id); |
2252 RemoveRenderbufferInfo(client_ids[ii]); | 2288 RemoveRenderbufferInfo(client_ids[ii]); |
2253 } | 2289 } |
2254 } | 2290 } |
2255 } | 2291 } |
2256 | 2292 |
2257 void GLES2DecoderImpl::DeleteTexturesHelper( | 2293 void GLES2DecoderImpl::DeleteTexturesHelper( |
2258 GLsizei n, const GLuint* client_ids) { | 2294 GLsizei n, const GLuint* client_ids) { |
2259 for (GLsizei ii = 0; ii < n; ++ii) { | 2295 for (GLsizei ii = 0; ii < n; ++ii) { |
2260 TextureManager::TextureInfo* info = GetTextureInfo(client_ids[ii]); | 2296 TextureManager::TextureInfo* info = GetTextureInfo(client_ids[ii]); |
2261 if (info) { | 2297 if (info) { |
| 2298 if (info->IsAttachedToFramebuffer()) { |
| 2299 state_dirty_ = true; |
| 2300 } |
2262 GLuint service_id = info->service_id(); | 2301 GLuint service_id = info->service_id(); |
2263 glDeleteTextures(1, &service_id); | 2302 glDeleteTextures(1, &service_id); |
2264 RemoveTextureInfo(client_ids[ii]); | 2303 RemoveTextureInfo(client_ids[ii]); |
2265 } | 2304 } |
2266 } | 2305 } |
2267 } | 2306 } |
2268 | 2307 |
2269 // } // anonymous namespace | 2308 // } // anonymous namespace |
2270 | 2309 |
2271 bool GLES2DecoderImpl::MakeCurrent() { | 2310 bool GLES2DecoderImpl::MakeCurrent() { |
2272 return context_.get() ? context_->MakeCurrent(surface_.get()) : false; | 2311 return context_.get() ? context_->MakeCurrent(surface_.get()) : false; |
2273 } | 2312 } |
2274 | 2313 |
2275 void GLES2DecoderImpl::RestoreCurrentRenderbufferBindings() { | 2314 void GLES2DecoderImpl::RestoreCurrentRenderbufferBindings() { |
2276 glBindRenderbufferEXT( | 2315 glBindRenderbufferEXT( |
2277 GL_RENDERBUFFER, | 2316 GL_RENDERBUFFER, |
2278 bound_renderbuffer_ ? bound_renderbuffer_->service_id() : 0); | 2317 bound_renderbuffer_ ? bound_renderbuffer_->service_id() : 0); |
2279 } | 2318 } |
2280 | 2319 |
2281 static void RebindCurrentFramebuffer( | 2320 static void RebindCurrentFramebuffer( |
2282 GLenum target, | 2321 GLenum target, |
2283 FramebufferManager::FramebufferInfo* info, | 2322 FramebufferManager::FramebufferInfo* info, |
2284 FrameBuffer* offscreen_frame_buffer) { | 2323 FrameBuffer* offscreen_frame_buffer) { |
2285 GLuint framebuffer_id = info ? info->service_id() : 0; | 2324 GLuint framebuffer_id = info ? info->service_id() : 0; |
| 2325 |
2286 if (framebuffer_id == 0 && offscreen_frame_buffer) { | 2326 if (framebuffer_id == 0 && offscreen_frame_buffer) { |
2287 framebuffer_id = offscreen_frame_buffer->id(); | 2327 framebuffer_id = offscreen_frame_buffer->id(); |
2288 } | 2328 } |
| 2329 |
2289 glBindFramebufferEXT(target, framebuffer_id); | 2330 glBindFramebufferEXT(target, framebuffer_id); |
2290 } | 2331 } |
2291 | 2332 |
2292 void GLES2DecoderImpl::RestoreCurrentFramebufferBindings() { | 2333 void GLES2DecoderImpl::RestoreCurrentFramebufferBindings() { |
| 2334 state_dirty_ = true; |
| 2335 |
2293 if (!feature_info_->feature_flags().chromium_framebuffer_multisample) { | 2336 if (!feature_info_->feature_flags().chromium_framebuffer_multisample) { |
2294 RebindCurrentFramebuffer( | 2337 RebindCurrentFramebuffer( |
2295 GL_FRAMEBUFFER, | 2338 GL_FRAMEBUFFER, |
2296 bound_draw_framebuffer_.get(), | 2339 bound_draw_framebuffer_.get(), |
2297 offscreen_target_frame_buffer_.get()); | 2340 offscreen_target_frame_buffer_.get()); |
2298 } else { | 2341 } else { |
2299 RebindCurrentFramebuffer( | 2342 RebindCurrentFramebuffer( |
2300 GL_READ_FRAMEBUFFER_EXT, | 2343 GL_READ_FRAMEBUFFER_EXT, |
2301 bound_read_framebuffer_.get(), | 2344 bound_read_framebuffer_.get(), |
2302 offscreen_target_frame_buffer_.get()); | 2345 offscreen_target_frame_buffer_.get()); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2339 return gfx::Size(0, 0); | 2382 return gfx::Size(0, 0); |
2340 } else if (offscreen_target_frame_buffer_.get()) { | 2383 } else if (offscreen_target_frame_buffer_.get()) { |
2341 return offscreen_size_; | 2384 return offscreen_size_; |
2342 } else { | 2385 } else { |
2343 return surface_->GetSize(); | 2386 return surface_->GetSize(); |
2344 } | 2387 } |
2345 } | 2388 } |
2346 | 2389 |
2347 GLenum GLES2DecoderImpl::GetBoundReadFrameBufferInternalFormat() { | 2390 GLenum GLES2DecoderImpl::GetBoundReadFrameBufferInternalFormat() { |
2348 if (bound_read_framebuffer_ != 0) { | 2391 if (bound_read_framebuffer_ != 0) { |
2349 const FramebufferManager::FramebufferInfo::Attachment* attachment = | 2392 return bound_read_framebuffer_->GetColorAttachmentFormat(); |
2350 bound_read_framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT0); | |
2351 if (attachment) { | |
2352 return attachment->internal_format(); | |
2353 } | |
2354 return 0; | |
2355 } else if (offscreen_target_frame_buffer_.get()) { | 2393 } else if (offscreen_target_frame_buffer_.get()) { |
2356 return offscreen_target_color_format_; | 2394 return offscreen_target_color_format_; |
2357 } else { | 2395 } else { |
| 2396 return back_buffer_color_format_; |
| 2397 } |
| 2398 } |
| 2399 |
| 2400 GLenum GLES2DecoderImpl::GetBoundDrawFrameBufferInternalFormat() { |
| 2401 if (bound_draw_framebuffer_ != 0) { |
| 2402 return bound_draw_framebuffer_->GetColorAttachmentFormat(); |
| 2403 } else if (offscreen_target_frame_buffer_.get()) { |
| 2404 return offscreen_target_color_format_; |
| 2405 } else { |
2358 return back_buffer_color_format_; | 2406 return back_buffer_color_format_; |
2359 } | 2407 } |
2360 } | 2408 } |
2361 | 2409 |
2362 bool GLES2DecoderImpl::UpdateOffscreenFrameBufferSize() { | 2410 bool GLES2DecoderImpl::UpdateOffscreenFrameBufferSize() { |
2363 if (offscreen_size_ == pending_offscreen_size_) | 2411 if (offscreen_size_ == pending_offscreen_size_) |
2364 return true; | 2412 return true; |
2365 | 2413 |
2366 offscreen_size_ = pending_offscreen_size_; | 2414 offscreen_size_ = pending_offscreen_size_; |
2367 int w = offscreen_size_.width(); | 2415 int w = offscreen_size_.width(); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2436 if (offscreen_target_frame_buffer_->CheckStatus() != | 2484 if (offscreen_target_frame_buffer_->CheckStatus() != |
2437 GL_FRAMEBUFFER_COMPLETE) { | 2485 GL_FRAMEBUFFER_COMPLETE) { |
2438 LOG(ERROR) << "GLES2DecoderImpl::UpdateOffscreenFrameBufferSize failed " | 2486 LOG(ERROR) << "GLES2DecoderImpl::UpdateOffscreenFrameBufferSize failed " |
2439 << "because offscreen FBO was incomplete."; | 2487 << "because offscreen FBO was incomplete."; |
2440 return false; | 2488 return false; |
2441 } | 2489 } |
2442 | 2490 |
2443 // Clear the target frame buffer. | 2491 // Clear the target frame buffer. |
2444 { | 2492 { |
2445 ScopedFrameBufferBinder binder(this, offscreen_target_frame_buffer_->id()); | 2493 ScopedFrameBufferBinder binder(this, offscreen_target_frame_buffer_->id()); |
2446 glClearColor(0, 0, 0, 0); | 2494 glClearColor(0, 0, 0, offscreen_target_color_format_ == GL_RGB); |
2447 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); | 2495 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
2448 glClearStencil(0); | 2496 glClearStencil(0); |
2449 glStencilMaskSeparate(GL_FRONT, GL_TRUE); | 2497 glStencilMaskSeparate(GL_FRONT, GL_TRUE); |
2450 glStencilMaskSeparate(GL_BACK, GL_TRUE); | 2498 glStencilMaskSeparate(GL_BACK, GL_TRUE); |
2451 glClearDepth(0); | 2499 glClearDepth(0); |
2452 glDepthMask(GL_TRUE); | 2500 glDepthMask(GL_TRUE); |
2453 glDisable(GL_SCISSOR_TEST); | 2501 glDisable(GL_SCISSOR_TEST); |
2454 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); | 2502 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
2455 RestoreClearState(); | 2503 RestoreClearState(); |
2456 } | 2504 } |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2817 case GL_ELEMENT_ARRAY_BUFFER: | 2865 case GL_ELEMENT_ARRAY_BUFFER: |
2818 bound_element_array_buffer_ = info; | 2866 bound_element_array_buffer_ = info; |
2819 break; | 2867 break; |
2820 default: | 2868 default: |
2821 NOTREACHED(); // Validation should prevent us getting here. | 2869 NOTREACHED(); // Validation should prevent us getting here. |
2822 break; | 2870 break; |
2823 } | 2871 } |
2824 glBindBuffer(target, service_id); | 2872 glBindBuffer(target, service_id); |
2825 } | 2873 } |
2826 | 2874 |
| 2875 bool GLES2DecoderImpl::BoundFramebufferHasColorAttachmentWithAlpha() { |
| 2876 return (GLES2Util::GetChannelsForFormat( |
| 2877 GetBoundDrawFrameBufferInternalFormat()) & 0x0008) != 0; |
| 2878 } |
| 2879 |
| 2880 bool GLES2DecoderImpl::BoundFramebufferHasDepthAttachment() { |
| 2881 if (bound_draw_framebuffer_) { |
| 2882 return bound_draw_framebuffer_->HasDepthAttachment(); |
| 2883 } |
| 2884 if (offscreen_target_frame_buffer_.get()) { |
| 2885 return offscreen_target_depth_format_ != 0; |
| 2886 } |
| 2887 return back_buffer_has_depth_; |
| 2888 } |
| 2889 |
| 2890 bool GLES2DecoderImpl::BoundFramebufferHasStencilAttachment() { |
| 2891 if (bound_draw_framebuffer_) { |
| 2892 return bound_draw_framebuffer_->HasStencilAttachment(); |
| 2893 } |
| 2894 if (offscreen_target_frame_buffer_.get()) { |
| 2895 return offscreen_target_stencil_format_ != 0; |
| 2896 } |
| 2897 return back_buffer_has_stencil_; |
| 2898 } |
| 2899 |
| 2900 void GLES2DecoderImpl::ApplyDirtyState() { |
| 2901 if (state_dirty_) { |
| 2902 glColorMask( |
| 2903 mask_red_, mask_green_, mask_blue_, |
| 2904 mask_alpha_ && BoundFramebufferHasColorAttachmentWithAlpha()); |
| 2905 glDepthMask(mask_depth_ && BoundFramebufferHasDepthAttachment()); |
| 2906 glStencilMaskSeparate( |
| 2907 GL_FRONT, |
| 2908 BoundFramebufferHasStencilAttachment() ? mask_stencil_front_ : 0); |
| 2909 glStencilMaskSeparate( |
| 2910 GL_BACK, |
| 2911 BoundFramebufferHasStencilAttachment() ? mask_stencil_back_ : 0); |
| 2912 state_dirty_ = false; |
| 2913 } |
| 2914 } |
| 2915 |
2827 void GLES2DecoderImpl::DoBindFramebuffer(GLenum target, GLuint client_id) { | 2916 void GLES2DecoderImpl::DoBindFramebuffer(GLenum target, GLuint client_id) { |
2828 FramebufferManager::FramebufferInfo* info = NULL; | 2917 FramebufferManager::FramebufferInfo* info = NULL; |
2829 GLuint service_id = 0; | 2918 GLuint service_id = 0; |
2830 if (client_id != 0) { | 2919 if (client_id != 0) { |
2831 info = GetFramebufferInfo(client_id); | 2920 info = GetFramebufferInfo(client_id); |
2832 if (!info) { | 2921 if (!info) { |
2833 // It's a new id so make a framebuffer info for it. | 2922 // It's a new id so make a framebuffer info for it. |
2834 glGenFramebuffersEXT(1, &service_id); | 2923 glGenFramebuffersEXT(1, &service_id); |
2835 CreateFramebufferInfo(client_id, service_id); | 2924 CreateFramebufferInfo(client_id, service_id); |
2836 info = GetFramebufferInfo(client_id); | 2925 info = GetFramebufferInfo(client_id); |
2837 IdAllocator* id_allocator = | 2926 IdAllocator* id_allocator = |
2838 group_->GetIdAllocator(id_namespaces::kFramebuffers); | 2927 group_->GetIdAllocator(id_namespaces::kFramebuffers); |
2839 id_allocator->MarkAsUsed(client_id); | 2928 id_allocator->MarkAsUsed(client_id); |
2840 } else { | 2929 } else { |
2841 service_id = info->service_id(); | 2930 service_id = info->service_id(); |
2842 } | 2931 } |
2843 info->MarkAsValid(); | 2932 info->MarkAsValid(); |
2844 } else { | 2933 } else { |
2845 service_id = 0; | 2934 service_id = 0; |
2846 } | 2935 } |
2847 | 2936 |
2848 if (target == GL_FRAMEBUFFER || target == GL_DRAW_FRAMEBUFFER_EXT) { | 2937 if (target == GL_FRAMEBUFFER || target == GL_DRAW_FRAMEBUFFER_EXT) { |
2849 bound_draw_framebuffer_ = info; | 2938 bound_draw_framebuffer_ = info; |
2850 } | 2939 } |
2851 if (target == GL_FRAMEBUFFER || target == GL_READ_FRAMEBUFFER_EXT) { | 2940 if (target == GL_FRAMEBUFFER || target == GL_READ_FRAMEBUFFER_EXT) { |
2852 bound_read_framebuffer_ = info; | 2941 bound_read_framebuffer_ = info; |
2853 } | 2942 } |
2854 | 2943 |
| 2944 state_dirty_ = true; |
| 2945 |
2855 // When rendering to an offscreen frame buffer, instead of unbinding from | 2946 // When rendering to an offscreen frame buffer, instead of unbinding from |
2856 // the current frame buffer, bind to the offscreen target frame buffer. | 2947 // the current frame buffer, bind to the offscreen target frame buffer. |
2857 if (info == NULL && offscreen_target_frame_buffer_.get()) | 2948 if (info == NULL && offscreen_target_frame_buffer_.get()) { |
2858 service_id = offscreen_target_frame_buffer_->id(); | 2949 service_id = offscreen_target_frame_buffer_->id(); |
| 2950 } |
2859 | 2951 |
2860 glBindFramebufferEXT(target, service_id); | 2952 glBindFramebufferEXT(target, service_id); |
2861 } | 2953 } |
2862 | 2954 |
2863 void GLES2DecoderImpl::DoBindRenderbuffer(GLenum target, GLuint client_id) { | 2955 void GLES2DecoderImpl::DoBindRenderbuffer(GLenum target, GLuint client_id) { |
2864 RenderbufferManager::RenderbufferInfo* info = NULL; | 2956 RenderbufferManager::RenderbufferInfo* info = NULL; |
2865 GLuint service_id = 0; | 2957 GLuint service_id = 0; |
2866 if (client_id != 0) { | 2958 if (client_id != 0) { |
2867 info = GetRenderbufferInfo(client_id); | 2959 info = GetRenderbufferInfo(client_id); |
2868 if (!info) { | 2960 if (!info) { |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3002 *num_written = 2; | 3094 *num_written = 2; |
3003 if (params) { | 3095 if (params) { |
3004 params[0] = renderbuffer_manager()->max_renderbuffer_size(); | 3096 params[0] = renderbuffer_manager()->max_renderbuffer_size(); |
3005 params[1] = renderbuffer_manager()->max_renderbuffer_size(); | 3097 params[1] = renderbuffer_manager()->max_renderbuffer_size(); |
3006 } | 3098 } |
3007 return true; | 3099 return true; |
3008 } | 3100 } |
3009 } | 3101 } |
3010 } | 3102 } |
3011 switch (pname) { | 3103 switch (pname) { |
| 3104 case GL_COLOR_WRITEMASK: |
| 3105 *num_written = 4; |
| 3106 if (params) { |
| 3107 params[0] = mask_red_; |
| 3108 params[1] = mask_green_; |
| 3109 params[2] = mask_blue_; |
| 3110 params[3] = mask_alpha_; |
| 3111 } |
| 3112 return true; |
| 3113 case GL_DEPTH_WRITEMASK: |
| 3114 *num_written = 1; |
| 3115 if (params) { |
| 3116 params[0] = mask_depth_; |
| 3117 } |
| 3118 return true; |
| 3119 case GL_STENCIL_BACK_WRITEMASK: |
| 3120 *num_written = 1; |
| 3121 if (params) { |
| 3122 params[0] = mask_stencil_back_; |
| 3123 } |
| 3124 return true; |
| 3125 case GL_STENCIL_WRITEMASK: |
| 3126 *num_written = 1; |
| 3127 if (params) { |
| 3128 params[0] = mask_stencil_front_; |
| 3129 } |
| 3130 return true; |
| 3131 case GL_ALPHA_BITS: |
| 3132 *num_written = 1; |
| 3133 if (params) { |
| 3134 GLint v = 0; |
| 3135 glGetIntegerv(GL_ALPHA_BITS, &v); |
| 3136 params[0] = BoundFramebufferHasColorAttachmentWithAlpha() ? v : 0; |
| 3137 } |
| 3138 return true; |
| 3139 case GL_DEPTH_BITS: |
| 3140 *num_written = 1; |
| 3141 if (params) { |
| 3142 GLint v = 0; |
| 3143 glGetIntegerv(GL_DEPTH_BITS, &v); |
| 3144 params[0] = BoundFramebufferHasDepthAttachment() ? v : 0; |
| 3145 } |
| 3146 return true; |
| 3147 case GL_STENCIL_BITS: |
| 3148 *num_written = 1; |
| 3149 if (params) { |
| 3150 GLint v = 0; |
| 3151 glGetIntegerv(GL_STENCIL_BITS, &v); |
| 3152 params[0] = BoundFramebufferHasStencilAttachment() ? v : 0; |
| 3153 } |
| 3154 return true; |
3012 case GL_COMPRESSED_TEXTURE_FORMATS: | 3155 case GL_COMPRESSED_TEXTURE_FORMATS: |
3013 *num_written = 0; | 3156 *num_written = 0; |
3014 // We don't support compressed textures. | 3157 // We don't support compressed textures. |
3015 return true; | 3158 return true; |
3016 case GL_NUM_COMPRESSED_TEXTURE_FORMATS: | 3159 case GL_NUM_COMPRESSED_TEXTURE_FORMATS: |
3017 *num_written = 1; | 3160 *num_written = 1; |
3018 if (params) { | 3161 if (params) { |
3019 *params = 0; // We don't support compressed textures. | 3162 *params = 0; // We don't support compressed textures. |
3020 } | 3163 } |
3021 return true; | 3164 return true; |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3393 } | 3536 } |
3394 if (ids == NULL) { | 3537 if (ids == NULL) { |
3395 return error::kOutOfBounds; | 3538 return error::kOutOfBounds; |
3396 } | 3539 } |
3397 DoRegisterSharedIdsCHROMIUM(namespace_id, n, ids); | 3540 DoRegisterSharedIdsCHROMIUM(namespace_id, n, ids); |
3398 return error::kNoError; | 3541 return error::kNoError; |
3399 } | 3542 } |
3400 | 3543 |
3401 void GLES2DecoderImpl::DoClear(GLbitfield mask) { | 3544 void GLES2DecoderImpl::DoClear(GLbitfield mask) { |
3402 if (CheckFramebufferComplete("glClear")) { | 3545 if (CheckFramebufferComplete("glClear")) { |
| 3546 ApplyDirtyState(); |
3403 glClear(mask); | 3547 glClear(mask); |
3404 } | 3548 } |
3405 } | 3549 } |
3406 | 3550 |
3407 void GLES2DecoderImpl::DoDrawArrays( | 3551 void GLES2DecoderImpl::DoDrawArrays( |
3408 GLenum mode, GLint first, GLsizei count) { | 3552 GLenum mode, GLint first, GLsizei count) { |
3409 if (!CheckFramebufferComplete("glDrawArrays")) { | 3553 if (!CheckFramebufferComplete("glDrawArrays")) { |
3410 return; | 3554 return; |
3411 } | 3555 } |
3412 // We have to check this here because the prototype for glDrawArrays | 3556 // We have to check this here because the prototype for glDrawArrays |
3413 // is GLint not GLsizei. | 3557 // is GLint not GLsizei. |
3414 if (first < 0) { | 3558 if (first < 0) { |
3415 SetGLError(GL_INVALID_VALUE, "glDrawArrays: first < 0"); | 3559 SetGLError(GL_INVALID_VALUE, "glDrawArrays: first < 0"); |
3416 return; | 3560 return; |
3417 } | 3561 } |
3418 | 3562 |
3419 if (count == 0) { | 3563 if (count == 0) { |
3420 return; | 3564 return; |
3421 } | 3565 } |
3422 | 3566 |
3423 GLuint max_vertex_accessed = first + count - 1; | 3567 GLuint max_vertex_accessed = first + count - 1; |
3424 if (IsDrawValid(max_vertex_accessed)) { | 3568 if (IsDrawValid(max_vertex_accessed)) { |
3425 bool simulated_attrib_0 = SimulateAttrib0(max_vertex_accessed); | 3569 bool simulated_attrib_0 = SimulateAttrib0(max_vertex_accessed); |
3426 bool simulated_fixed_attribs = false; | 3570 bool simulated_fixed_attribs = false; |
3427 if (SimulateFixedAttribs(max_vertex_accessed, &simulated_fixed_attribs)) { | 3571 if (SimulateFixedAttribs(max_vertex_accessed, &simulated_fixed_attribs)) { |
3428 bool textures_set = SetBlackTextureForNonRenderableTextures(); | 3572 bool textures_set = SetBlackTextureForNonRenderableTextures(); |
| 3573 ApplyDirtyState(); |
3429 glDrawArrays(mode, first, count); | 3574 glDrawArrays(mode, first, count); |
3430 if (textures_set) { | 3575 if (textures_set) { |
3431 RestoreStateForNonRenderableTextures(); | 3576 RestoreStateForNonRenderableTextures(); |
3432 } | 3577 } |
3433 if (simulated_fixed_attribs) { | 3578 if (simulated_fixed_attribs) { |
3434 RestoreStateForSimulatedFixedAttribs(); | 3579 RestoreStateForSimulatedFixedAttribs(); |
3435 } | 3580 } |
3436 } | 3581 } |
3437 if (simulated_attrib_0) { | 3582 if (simulated_attrib_0) { |
3438 RestoreStateForSimulatedAttrib0(); | 3583 RestoreStateForSimulatedAttrib0(); |
(...skipping 28 matching lines...) Expand all Loading... |
3467 GLenum error = glGetError(); | 3612 GLenum error = glGetError(); |
3468 if (error == GL_NO_ERROR) { | 3613 if (error == GL_NO_ERROR) { |
3469 framebuffer_info->AttachRenderbuffer(attachment, info); | 3614 framebuffer_info->AttachRenderbuffer(attachment, info); |
3470 if (service_id == 0 || | 3615 if (service_id == 0 || |
3471 glCheckFramebufferStatusEXT(target) == GL_FRAMEBUFFER_COMPLETE) { | 3616 glCheckFramebufferStatusEXT(target) == GL_FRAMEBUFFER_COMPLETE) { |
3472 if (info) { | 3617 if (info) { |
3473 ClearUnclearedRenderbuffers(target, framebuffer_info); | 3618 ClearUnclearedRenderbuffers(target, framebuffer_info); |
3474 } | 3619 } |
3475 } | 3620 } |
3476 } | 3621 } |
| 3622 if (framebuffer_info == bound_draw_framebuffer_) { |
| 3623 state_dirty_ = true; |
| 3624 } |
3477 } | 3625 } |
3478 | 3626 |
3479 void GLES2DecoderImpl::SetCapabilityState(GLenum cap, bool enabled) { | 3627 void GLES2DecoderImpl::SetCapabilityState(GLenum cap, bool enabled) { |
3480 switch (cap) { | 3628 switch (cap) { |
3481 case GL_SCISSOR_TEST: | 3629 case GL_SCISSOR_TEST: |
3482 enable_scissor_test_ = enabled; | 3630 enable_scissor_test_ = enabled; |
3483 break; | 3631 break; |
3484 default: | 3632 default: |
3485 break; | 3633 break; |
3486 } | 3634 } |
(...skipping 27 matching lines...) Expand all Loading... |
3514 clear_stencil_ = s; | 3662 clear_stencil_ = s; |
3515 glClearStencil(s); | 3663 glClearStencil(s); |
3516 } | 3664 } |
3517 | 3665 |
3518 void GLES2DecoderImpl::DoColorMask( | 3666 void GLES2DecoderImpl::DoColorMask( |
3519 GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) { | 3667 GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) { |
3520 mask_red_ = red; | 3668 mask_red_ = red; |
3521 mask_green_ = green; | 3669 mask_green_ = green; |
3522 mask_blue_ = blue; | 3670 mask_blue_ = blue; |
3523 mask_alpha_ = alpha; | 3671 mask_alpha_ = alpha; |
3524 glColorMask(red, green, blue, alpha); | 3672 state_dirty_ = true; |
3525 } | 3673 } |
3526 | 3674 |
3527 void GLES2DecoderImpl::DoDepthMask(GLboolean depth) { | 3675 void GLES2DecoderImpl::DoDepthMask(GLboolean depth) { |
3528 mask_depth_ = depth; | 3676 mask_depth_ = depth; |
3529 glDepthMask(depth); | 3677 state_dirty_ = true; |
3530 } | 3678 } |
3531 | 3679 |
3532 void GLES2DecoderImpl::DoStencilMask(GLuint mask) { | 3680 void GLES2DecoderImpl::DoStencilMask(GLuint mask) { |
3533 mask_stencil_front_ = mask; | 3681 mask_stencil_front_ = mask; |
3534 mask_stencil_back_ = mask; | 3682 mask_stencil_back_ = mask; |
3535 glStencilMask(mask); | 3683 state_dirty_ = true; |
3536 } | 3684 } |
3537 | 3685 |
3538 void GLES2DecoderImpl::DoStencilMaskSeparate(GLenum face, GLuint mask) { | 3686 void GLES2DecoderImpl::DoStencilMaskSeparate(GLenum face, GLuint mask) { |
3539 if (face == GL_FRONT) { | 3687 if (face == GL_FRONT || face == GL_FRONT_AND_BACK) { |
3540 mask_stencil_front_ = mask; | 3688 mask_stencil_front_ = mask; |
3541 } else { | 3689 } |
| 3690 if (face == GL_BACK || face == GL_FRONT_AND_BACK) { |
3542 mask_stencil_back_ = mask; | 3691 mask_stencil_back_ = mask; |
3543 } | 3692 } |
3544 glStencilMaskSeparate(face, mask); | 3693 state_dirty_ = true; |
3545 } | 3694 } |
3546 | 3695 |
3547 // NOTE: There's an assumption here that Texture attachments | 3696 // NOTE: There's an assumption here that Texture attachments |
3548 // are cleared because they are textures so we only need to clear | 3697 // are cleared because they are textures so we only need to clear |
3549 // the renderbuffers. | 3698 // the renderbuffers. |
3550 void GLES2DecoderImpl::ClearUnclearedRenderbuffers( | 3699 void GLES2DecoderImpl::ClearUnclearedRenderbuffers( |
3551 GLenum target, FramebufferManager::FramebufferInfo* info) { | 3700 GLenum target, FramebufferManager::FramebufferInfo* info) { |
3552 if (target == GL_READ_FRAMEBUFFER_EXT) { | 3701 if (target == GL_READ_FRAMEBUFFER_EXT) { |
3553 // TODO(gman): bind this to the DRAW point, clear then bind back to READ | 3702 // TODO(gman): bind this to the DRAW point, clear then bind back to READ |
3554 } | 3703 } |
(...skipping 24 matching lines...) Expand all Loading... |
3579 info->MarkAttachedRenderbuffersAsCleared(); | 3728 info->MarkAttachedRenderbuffersAsCleared(); |
3580 | 3729 |
3581 RestoreClearState(); | 3730 RestoreClearState(); |
3582 | 3731 |
3583 if (target == GL_READ_FRAMEBUFFER_EXT) { | 3732 if (target == GL_READ_FRAMEBUFFER_EXT) { |
3584 // TODO(gman): rebind draw. | 3733 // TODO(gman): rebind draw. |
3585 } | 3734 } |
3586 } | 3735 } |
3587 | 3736 |
3588 void GLES2DecoderImpl::RestoreClearState() { | 3737 void GLES2DecoderImpl::RestoreClearState() { |
| 3738 state_dirty_ = true; |
3589 glClearColor(clear_red_, clear_green_, clear_blue_, clear_alpha_); | 3739 glClearColor(clear_red_, clear_green_, clear_blue_, clear_alpha_); |
3590 glColorMask(mask_red_, mask_green_, mask_blue_, mask_alpha_); | |
3591 glClearStencil(clear_stencil_); | 3740 glClearStencil(clear_stencil_); |
3592 glStencilMaskSeparate(GL_FRONT, mask_stencil_front_); | |
3593 glStencilMaskSeparate(GL_BACK, mask_stencil_back_); | |
3594 glClearDepth(clear_depth_); | 3741 glClearDepth(clear_depth_); |
3595 glDepthMask(mask_depth_); | |
3596 if (enable_scissor_test_) { | 3742 if (enable_scissor_test_) { |
3597 glEnable(GL_SCISSOR_TEST); | 3743 glEnable(GL_SCISSOR_TEST); |
3598 } | 3744 } |
3599 } | 3745 } |
3600 | 3746 |
3601 GLenum GLES2DecoderImpl::DoCheckFramebufferStatus(GLenum target) { | 3747 GLenum GLES2DecoderImpl::DoCheckFramebufferStatus(GLenum target) { |
3602 FramebufferManager::FramebufferInfo* info = | 3748 FramebufferManager::FramebufferInfo* info = |
3603 GetFramebufferInfoForTarget(target); | 3749 GetFramebufferInfoForTarget(target); |
3604 if (!info) { | 3750 if (!info) { |
3605 return GL_FRAMEBUFFER_COMPLETE; | 3751 return GL_FRAMEBUFFER_COMPLETE; |
(...skipping 25 matching lines...) Expand all Loading... |
3631 CopyRealGLErrorsToWrapper(); | 3777 CopyRealGLErrorsToWrapper(); |
3632 glFramebufferTexture2DEXT(target, attachment, textarget, service_id, level); | 3778 glFramebufferTexture2DEXT(target, attachment, textarget, service_id, level); |
3633 GLenum error = glGetError(); | 3779 GLenum error = glGetError(); |
3634 if (error == GL_NO_ERROR) { | 3780 if (error == GL_NO_ERROR) { |
3635 framebuffer_info->AttachTexture(attachment, info, textarget, level); | 3781 framebuffer_info->AttachTexture(attachment, info, textarget, level); |
3636 if (service_id != 0 && | 3782 if (service_id != 0 && |
3637 glCheckFramebufferStatusEXT(target) == GL_FRAMEBUFFER_COMPLETE) { | 3783 glCheckFramebufferStatusEXT(target) == GL_FRAMEBUFFER_COMPLETE) { |
3638 ClearUnclearedRenderbuffers(target, framebuffer_info); | 3784 ClearUnclearedRenderbuffers(target, framebuffer_info); |
3639 } | 3785 } |
3640 } | 3786 } |
| 3787 if (framebuffer_info == bound_draw_framebuffer_) { |
| 3788 state_dirty_ = true; |
| 3789 } |
3641 } | 3790 } |
3642 | 3791 |
3643 void GLES2DecoderImpl::DoGetFramebufferAttachmentParameteriv( | 3792 void GLES2DecoderImpl::DoGetFramebufferAttachmentParameteriv( |
3644 GLenum target, GLenum attachment, GLenum pname, GLint* params) { | 3793 GLenum target, GLenum attachment, GLenum pname, GLint* params) { |
3645 FramebufferManager::FramebufferInfo* framebuffer_info = | 3794 FramebufferManager::FramebufferInfo* framebuffer_info = |
3646 GetFramebufferInfoForTarget(target); | 3795 GetFramebufferInfoForTarget(target); |
3647 if (!framebuffer_info) { | 3796 if (!framebuffer_info) { |
3648 SetGLError(GL_INVALID_OPERATION, | 3797 SetGLError(GL_INVALID_OPERATION, |
3649 "glFramebufferAttachmentParameteriv: no framebuffer bound"); | 3798 "glFramebufferAttachmentParameteriv: no framebuffer bound"); |
3650 return; | 3799 return; |
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4426 SetGLError(GL_INVALID_OPERATION, | 4575 SetGLError(GL_INVALID_OPERATION, |
4427 "glDrawElements: range out of bounds for buffer"); | 4576 "glDrawElements: range out of bounds for buffer"); |
4428 return error::kNoError; | 4577 return error::kNoError; |
4429 } | 4578 } |
4430 | 4579 |
4431 if (IsDrawValid(max_vertex_accessed)) { | 4580 if (IsDrawValid(max_vertex_accessed)) { |
4432 bool simulated_attrib_0 = SimulateAttrib0(max_vertex_accessed); | 4581 bool simulated_attrib_0 = SimulateAttrib0(max_vertex_accessed); |
4433 bool simulated_fixed_attribs = false; | 4582 bool simulated_fixed_attribs = false; |
4434 if (SimulateFixedAttribs(max_vertex_accessed, &simulated_fixed_attribs)) { | 4583 if (SimulateFixedAttribs(max_vertex_accessed, &simulated_fixed_attribs)) { |
4435 bool textures_set = SetBlackTextureForNonRenderableTextures(); | 4584 bool textures_set = SetBlackTextureForNonRenderableTextures(); |
| 4585 ApplyDirtyState(); |
4436 const GLvoid* indices = reinterpret_cast<const GLvoid*>(offset); | 4586 const GLvoid* indices = reinterpret_cast<const GLvoid*>(offset); |
4437 glDrawElements(mode, count, type, indices); | 4587 glDrawElements(mode, count, type, indices); |
4438 if (textures_set) { | 4588 if (textures_set) { |
4439 RestoreStateForNonRenderableTextures(); | 4589 RestoreStateForNonRenderableTextures(); |
4440 } | 4590 } |
4441 if (simulated_fixed_attribs) { | 4591 if (simulated_fixed_attribs) { |
4442 RestoreStateForSimulatedFixedAttribs(); | 4592 RestoreStateForSimulatedFixedAttribs(); |
4443 } | 4593 } |
4444 } | 4594 } |
4445 if (simulated_attrib_0) { | 4595 if (simulated_attrib_0) { |
(...skipping 1195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5641 "glTexImage2D: unknown texture for target"); | 5791 "glTexImage2D: unknown texture for target"); |
5642 return error::kNoError; | 5792 return error::kNoError; |
5643 } | 5793 } |
5644 scoped_array<int8> zero; | 5794 scoped_array<int8> zero; |
5645 if (!pixels) { | 5795 if (!pixels) { |
5646 zero.reset(new int8[pixels_size]); | 5796 zero.reset(new int8[pixels_size]); |
5647 memset(zero.get(), 0, pixels_size); | 5797 memset(zero.get(), 0, pixels_size); |
5648 pixels = zero.get(); | 5798 pixels = zero.get(); |
5649 } | 5799 } |
5650 | 5800 |
| 5801 if (info->IsAttachedToFramebuffer()) { |
| 5802 state_dirty_ = true; |
| 5803 } |
| 5804 |
5651 if (!teximage2d_faster_than_texsubimage2d_) { | 5805 if (!teximage2d_faster_than_texsubimage2d_) { |
5652 GLsizei tex_width = 0; | 5806 GLsizei tex_width = 0; |
5653 GLsizei tex_height = 0; | 5807 GLsizei tex_height = 0; |
5654 GLenum tex_type = 0; | 5808 GLenum tex_type = 0; |
5655 GLenum tex_format = 0; | 5809 GLenum tex_format = 0; |
5656 if (info->GetLevelSize(target, level, &tex_width, &tex_height) && | 5810 if (info->GetLevelSize(target, level, &tex_width, &tex_height) && |
5657 info->GetLevelType(target, level, &tex_type, &tex_format) && | 5811 info->GetLevelType(target, level, &tex_type, &tex_format) && |
5658 width == tex_width && height == tex_height && | 5812 width == tex_width && height == tex_height && |
5659 type == tex_type && format == tex_format) { | 5813 type == tex_type && format == tex_format) { |
5660 glTexSubImage2D(target, level, 0, 0, width, height, format, type, pixels); | 5814 glTexSubImage2D(target, level, 0, 0, width, height, format, type, pixels); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5821 | 5975 |
5822 if ((channels_needed & channels_exist) != channels_needed) { | 5976 if ((channels_needed & channels_exist) != channels_needed) { |
5823 SetGLError(GL_INVALID_OPERATION, "glCopyTexImage2D: incompatible format"); | 5977 SetGLError(GL_INVALID_OPERATION, "glCopyTexImage2D: incompatible format"); |
5824 return; | 5978 return; |
5825 } | 5979 } |
5826 | 5980 |
5827 CopyRealGLErrorsToWrapper(); | 5981 CopyRealGLErrorsToWrapper(); |
5828 ScopedResolvedFrameBufferBinder binder(this, false); | 5982 ScopedResolvedFrameBufferBinder binder(this, false); |
5829 gfx::Size size = GetBoundReadFrameBufferSize(); | 5983 gfx::Size size = GetBoundReadFrameBufferSize(); |
5830 | 5984 |
| 5985 if (info->IsAttachedToFramebuffer()) { |
| 5986 state_dirty_ = true; |
| 5987 } |
| 5988 |
5831 // Clip to size to source dimensions | 5989 // Clip to size to source dimensions |
5832 GLint copyX = 0; | 5990 GLint copyX = 0; |
5833 GLint copyY = 0; | 5991 GLint copyY = 0; |
5834 GLint copyWidth = 0; | 5992 GLint copyWidth = 0; |
5835 GLint copyHeight = 0; | 5993 GLint copyHeight = 0; |
5836 Clip(x, width, size.width(), ©X, ©Width); | 5994 Clip(x, width, size.width(), ©X, ©Width); |
5837 Clip(y, height, size.height(), ©Y, ©Height); | 5995 Clip(y, height, size.height(), ©Y, ©Height); |
5838 | 5996 |
5839 if (copyX != x || | 5997 if (copyX != x || |
5840 copyY != y || | 5998 copyY != y || |
(...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6631 return error::kNoError; | 6789 return error::kNoError; |
6632 } | 6790 } |
6633 | 6791 |
6634 // Include the auto-generated part of this file. We split this because it means | 6792 // Include the auto-generated part of this file. We split this because it means |
6635 // we can easily edit the non-auto generated parts right here in this file | 6793 // we can easily edit the non-auto generated parts right here in this file |
6636 // instead of having to edit some template or the code generator. | 6794 // instead of having to edit some template or the code generator. |
6637 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 6795 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
6638 | 6796 |
6639 } // namespace gles2 | 6797 } // namespace gles2 |
6640 } // namespace gpu | 6798 } // namespace gpu |
OLD | NEW |