OLD | NEW |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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_passthrough.h" | 5 #include "gpu/command_buffer/service/gles2_cmd_decoder_passthrough.h" |
6 | 6 |
7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
8 #include "ui/gl/gl_version_info.h" | 8 #include "ui/gl/gl_version_info.h" |
9 | 9 |
10 namespace gpu { | 10 namespace gpu { |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 } | 186 } |
187 | 187 |
188 void AppendStringToBuffer(std::vector<uint8_t>* data, | 188 void AppendStringToBuffer(std::vector<uint8_t>* data, |
189 const char* str, | 189 const char* str, |
190 size_t len) { | 190 size_t len) { |
191 const base::CheckedNumeric<size_t> old_size = data->size(); | 191 const base::CheckedNumeric<size_t> old_size = data->size(); |
192 data->resize((old_size + len).ValueOrDie()); | 192 data->resize((old_size + len).ValueOrDie()); |
193 memcpy(data->data() + old_size.ValueOrDie(), str, len); | 193 memcpy(data->data() + old_size.ValueOrDie(), str, len); |
194 } | 194 } |
195 | 195 |
| 196 // In order to minimize the amount of data copied, the command buffer client |
| 197 // unpack pixels before sending the glTex[Sub]Image[2|3]D calls. The only |
| 198 // parameter it doesn't handle is the alignment. Resetting the unpack state is |
| 199 // not needed when uploading from a PBO and for compressed formats which the |
| 200 // client sends untouched. This class handles resetting and restoring the unpack |
| 201 // state. |
| 202 // TODO(cwallez@chromium.org) it would be nicer to handle the resetting / |
| 203 // restoring on the client side. |
| 204 class ScopedUnpackStateButAlignmentReset { |
| 205 public: |
| 206 ScopedUnpackStateButAlignmentReset(bool enable, bool is_3d) { |
| 207 if (!enable) { |
| 208 return; |
| 209 } |
| 210 |
| 211 glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &skip_pixels_); |
| 212 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); |
| 213 glGetIntegerv(GL_UNPACK_SKIP_ROWS, &skip_rows_); |
| 214 glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); |
| 215 glGetIntegerv(GL_UNPACK_ROW_LENGTH, &row_length_); |
| 216 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); |
| 217 |
| 218 if (is_3d) { |
| 219 glGetIntegerv(GL_UNPACK_SKIP_IMAGES, &skip_images_); |
| 220 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 0); |
| 221 glGetIntegerv(GL_UNPACK_IMAGE_HEIGHT, &image_height_); |
| 222 glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, 0); |
| 223 } |
| 224 } |
| 225 |
| 226 ~ScopedUnpackStateButAlignmentReset() { |
| 227 if (skip_pixels_ != 0) { |
| 228 glPixelStorei(GL_UNPACK_SKIP_PIXELS, skip_pixels_); |
| 229 } |
| 230 if (skip_rows_ != 0) { |
| 231 glPixelStorei(GL_UNPACK_SKIP_ROWS, skip_rows_); |
| 232 } |
| 233 if (skip_images_ != 0) { |
| 234 glPixelStorei(GL_UNPACK_SKIP_IMAGES, skip_images_); |
| 235 } |
| 236 if (row_length_ != 0) { |
| 237 glPixelStorei(GL_UNPACK_ROW_LENGTH, row_length_); |
| 238 } |
| 239 if (image_height_ != 0) { |
| 240 glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, image_height_); |
| 241 } |
| 242 } |
| 243 |
| 244 private: |
| 245 GLint skip_pixels_ = 0; |
| 246 GLint skip_rows_ = 0; |
| 247 GLint skip_images_ = 0; |
| 248 GLint row_length_ = 0; |
| 249 GLint image_height_ = 0; |
| 250 }; |
| 251 |
196 } // anonymous namespace | 252 } // anonymous namespace |
197 | 253 |
198 // Implementations of commands | 254 // Implementations of commands |
199 error::Error GLES2DecoderPassthroughImpl::DoActiveTexture(GLenum texture) { | 255 error::Error GLES2DecoderPassthroughImpl::DoActiveTexture(GLenum texture) { |
200 FlushErrors(); | 256 FlushErrors(); |
201 glActiveTexture(texture); | 257 glActiveTexture(texture); |
202 if (FlushErrors()) { | 258 if (FlushErrors()) { |
203 return error::kNoError; | 259 return error::kNoError; |
204 } | 260 } |
205 | 261 |
(...skipping 1632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1838 } | 1894 } |
1839 | 1895 |
1840 error::Error GLES2DecoderPassthroughImpl::DoTexImage2D(GLenum target, | 1896 error::Error GLES2DecoderPassthroughImpl::DoTexImage2D(GLenum target, |
1841 GLint level, | 1897 GLint level, |
1842 GLint internalformat, | 1898 GLint internalformat, |
1843 GLsizei width, | 1899 GLsizei width, |
1844 GLsizei height, | 1900 GLsizei height, |
1845 GLint border, | 1901 GLint border, |
1846 GLenum format, | 1902 GLenum format, |
1847 GLenum type, | 1903 GLenum type, |
1848 GLsizei imagesize, | 1904 GLsizei image_size, |
1849 const void* pixels) { | 1905 const void* pixels) { |
| 1906 ScopedUnpackStateButAlignmentReset reset_unpack( |
| 1907 image_size != 0 && feature_info_->gl_version_info().is_es3, false); |
1850 glTexImage2DRobustANGLE(target, level, internalformat, width, height, border, | 1908 glTexImage2DRobustANGLE(target, level, internalformat, width, height, border, |
1851 format, type, imagesize, pixels); | 1909 format, type, image_size, pixels); |
1852 return error::kNoError; | 1910 return error::kNoError; |
1853 } | 1911 } |
1854 | 1912 |
1855 error::Error GLES2DecoderPassthroughImpl::DoTexImage3D(GLenum target, | 1913 error::Error GLES2DecoderPassthroughImpl::DoTexImage3D(GLenum target, |
1856 GLint level, | 1914 GLint level, |
1857 GLint internalformat, | 1915 GLint internalformat, |
1858 GLsizei width, | 1916 GLsizei width, |
1859 GLsizei height, | 1917 GLsizei height, |
1860 GLsizei depth, | 1918 GLsizei depth, |
1861 GLint border, | 1919 GLint border, |
1862 GLenum format, | 1920 GLenum format, |
1863 GLenum type, | 1921 GLenum type, |
1864 GLsizei imagesize, | 1922 GLsizei image_size, |
1865 const void* pixels) { | 1923 const void* pixels) { |
| 1924 ScopedUnpackStateButAlignmentReset reset_unpack( |
| 1925 image_size != 0 && feature_info_->gl_version_info().is_es3, true); |
1866 glTexImage3DRobustANGLE(target, level, internalformat, width, height, depth, | 1926 glTexImage3DRobustANGLE(target, level, internalformat, width, height, depth, |
1867 border, format, type, imagesize, pixels); | 1927 border, format, type, image_size, pixels); |
1868 return error::kNoError; | 1928 return error::kNoError; |
1869 } | 1929 } |
1870 | 1930 |
1871 error::Error GLES2DecoderPassthroughImpl::DoTexParameterf(GLenum target, | 1931 error::Error GLES2DecoderPassthroughImpl::DoTexParameterf(GLenum target, |
1872 GLenum pname, | 1932 GLenum pname, |
1873 GLfloat param) { | 1933 GLfloat param) { |
1874 glTexParameterf(target, pname, param); | 1934 glTexParameterf(target, pname, param); |
1875 return error::kNoError; | 1935 return error::kNoError; |
1876 } | 1936 } |
1877 | 1937 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1915 } | 1975 } |
1916 | 1976 |
1917 error::Error GLES2DecoderPassthroughImpl::DoTexSubImage2D(GLenum target, | 1977 error::Error GLES2DecoderPassthroughImpl::DoTexSubImage2D(GLenum target, |
1918 GLint level, | 1978 GLint level, |
1919 GLint xoffset, | 1979 GLint xoffset, |
1920 GLint yoffset, | 1980 GLint yoffset, |
1921 GLsizei width, | 1981 GLsizei width, |
1922 GLsizei height, | 1982 GLsizei height, |
1923 GLenum format, | 1983 GLenum format, |
1924 GLenum type, | 1984 GLenum type, |
1925 GLsizei imagesize, | 1985 GLsizei image_size, |
1926 const void* pixels) { | 1986 const void* pixels) { |
| 1987 ScopedUnpackStateButAlignmentReset reset_unpack( |
| 1988 image_size != 0 && feature_info_->gl_version_info().is_es3, false); |
1927 glTexSubImage2DRobustANGLE(target, level, xoffset, yoffset, width, height, | 1989 glTexSubImage2DRobustANGLE(target, level, xoffset, yoffset, width, height, |
1928 format, type, imagesize, pixels); | 1990 format, type, image_size, pixels); |
1929 return error::kNoError; | 1991 return error::kNoError; |
1930 } | 1992 } |
1931 | 1993 |
1932 error::Error GLES2DecoderPassthroughImpl::DoTexSubImage3D(GLenum target, | 1994 error::Error GLES2DecoderPassthroughImpl::DoTexSubImage3D(GLenum target, |
1933 GLint level, | 1995 GLint level, |
1934 GLint xoffset, | 1996 GLint xoffset, |
1935 GLint yoffset, | 1997 GLint yoffset, |
1936 GLint zoffset, | 1998 GLint zoffset, |
1937 GLsizei width, | 1999 GLsizei width, |
1938 GLsizei height, | 2000 GLsizei height, |
1939 GLsizei depth, | 2001 GLsizei depth, |
1940 GLenum format, | 2002 GLenum format, |
1941 GLenum type, | 2003 GLenum type, |
1942 GLsizei imagesize, | 2004 GLsizei image_size, |
1943 const void* pixels) { | 2005 const void* pixels) { |
| 2006 ScopedUnpackStateButAlignmentReset reset_unpack( |
| 2007 image_size != 0 && feature_info_->gl_version_info().is_es3, true); |
1944 glTexSubImage3DRobustANGLE(target, level, xoffset, yoffset, zoffset, width, | 2008 glTexSubImage3DRobustANGLE(target, level, xoffset, yoffset, zoffset, width, |
1945 height, depth, format, type, imagesize, pixels); | 2009 height, depth, format, type, image_size, pixels); |
1946 return error::kNoError; | 2010 return error::kNoError; |
1947 } | 2011 } |
1948 | 2012 |
1949 error::Error GLES2DecoderPassthroughImpl::DoTransformFeedbackVaryings( | 2013 error::Error GLES2DecoderPassthroughImpl::DoTransformFeedbackVaryings( |
1950 GLuint program, | 2014 GLuint program, |
1951 GLsizei count, | 2015 GLsizei count, |
1952 const char** varyings, | 2016 const char** varyings, |
1953 GLenum buffermode) { | 2017 GLenum buffermode) { |
1954 glTransformFeedbackVaryings(GetProgramServiceID(program, resources_), count, | 2018 glTransformFeedbackVaryings(GetProgramServiceID(program, resources_), count, |
1955 varyings, buffermode); | 2019 varyings, buffermode); |
(...skipping 2017 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3973 } | 4037 } |
3974 | 4038 |
3975 error::Error GLES2DecoderPassthroughImpl::DoSetEnableDCLayersCHROMIUM( | 4039 error::Error GLES2DecoderPassthroughImpl::DoSetEnableDCLayersCHROMIUM( |
3976 GLboolean enable) { | 4040 GLboolean enable) { |
3977 NOTIMPLEMENTED(); | 4041 NOTIMPLEMENTED(); |
3978 return error::kNoError; | 4042 return error::kNoError; |
3979 } | 4043 } |
3980 | 4044 |
3981 } // namespace gles2 | 4045 } // namespace gles2 |
3982 } // namespace gpu | 4046 } // namespace gpu |
OLD | NEW |