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