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

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

Issue 148513004: Android: Always update SurfaceTexture when used for draw (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/common/gpu/stream_texture_android.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" 5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <list> 10 #include <list>
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 public: 292 public:
293 explicit ScopedGLErrorSuppressor( 293 explicit ScopedGLErrorSuppressor(
294 const char* function_name, ErrorState* error_state); 294 const char* function_name, ErrorState* error_state);
295 ~ScopedGLErrorSuppressor(); 295 ~ScopedGLErrorSuppressor();
296 private: 296 private:
297 const char* function_name_; 297 const char* function_name_;
298 ErrorState* error_state_; 298 ErrorState* error_state_;
299 DISALLOW_COPY_AND_ASSIGN(ScopedGLErrorSuppressor); 299 DISALLOW_COPY_AND_ASSIGN(ScopedGLErrorSuppressor);
300 }; 300 };
301 301
302 // Temporarily changes a decoder's bound 2D texture and restore it when this 302 // Temporarily changes a decoder's bound texture and restore it when this
303 // object goes out of scope. Also temporarily switches to using active texture 303 // object goes out of scope. Also temporarily switches to using active texture
304 // unit zero in case the client has changed that to something invalid. 304 // unit zero in case the client has changed that to something invalid.
305 class ScopedTexture2DBinder { 305 class ScopedTextureBinder {
306 public: 306 public:
307 ScopedTexture2DBinder(ContextState* state, GLuint id); 307 ScopedTextureBinder(ContextState* state, GLuint id, GLenum target);
308 ~ScopedTexture2DBinder(); 308 ~ScopedTextureBinder();
309 309
310 private: 310 private:
311 ContextState* state_; 311 ContextState* state_;
312 DISALLOW_COPY_AND_ASSIGN(ScopedTexture2DBinder); 312 GLenum target_;
313 DISALLOW_COPY_AND_ASSIGN(ScopedTextureBinder);
313 }; 314 };
314 315
315 // Temporarily changes a decoder's bound render buffer and restore it when this 316 // Temporarily changes a decoder's bound render buffer and restore it when this
316 // object goes out of scope. 317 // object goes out of scope.
317 class ScopedRenderBufferBinder { 318 class ScopedRenderBufferBinder {
318 public: 319 public:
319 ScopedRenderBufferBinder(ContextState* state, GLuint id); 320 ScopedRenderBufferBinder(ContextState* state, GLuint id);
320 ~ScopedRenderBufferBinder(); 321 ~ScopedRenderBufferBinder();
321 322
322 private: 323 private:
(...skipping 1387 matching lines...) Expand 10 before | Expand all | Expand 10 after
1710 const char* function_name, ErrorState* error_state) 1711 const char* function_name, ErrorState* error_state)
1711 : function_name_(function_name), 1712 : function_name_(function_name),
1712 error_state_(error_state) { 1713 error_state_(error_state) {
1713 ERRORSTATE_COPY_REAL_GL_ERRORS_TO_WRAPPER(error_state_, function_name_); 1714 ERRORSTATE_COPY_REAL_GL_ERRORS_TO_WRAPPER(error_state_, function_name_);
1714 } 1715 }
1715 1716
1716 ScopedGLErrorSuppressor::~ScopedGLErrorSuppressor() { 1717 ScopedGLErrorSuppressor::~ScopedGLErrorSuppressor() {
1717 ERRORSTATE_CLEAR_REAL_GL_ERRORS(error_state_, function_name_); 1718 ERRORSTATE_CLEAR_REAL_GL_ERRORS(error_state_, function_name_);
1718 } 1719 }
1719 1720
1720 static void RestoreCurrentTexture2DBindings(ContextState* state) { 1721 static void RestoreCurrentTextureBindings(ContextState* state, GLenum target) {
1721 TextureUnit& info = state->texture_units[0]; 1722 TextureUnit& info = state->texture_units[0];
1722 GLuint last_id; 1723 GLuint last_id;
1723 if (info.bound_texture_2d.get()) { 1724 scoped_refptr<TextureRef> texture_ref;
1724 last_id = info.bound_texture_2d->service_id(); 1725 switch (target) {
1726 case GL_TEXTURE_2D:
1727 texture_ref = info.bound_texture_2d;
1728 break;
1729 case GL_TEXTURE_CUBE_MAP:
1730 texture_ref = info.bound_texture_cube_map;
1731 break;
1732 case GL_TEXTURE_EXTERNAL_OES:
1733 texture_ref = info.bound_texture_external_oes;
1734 break;
1735 case GL_TEXTURE_RECTANGLE_ARB:
1736 texture_ref = info.bound_texture_rectangle_arb;
1737 break;
1738 default:
1739 NOTREACHED();
1740 break;
1741 }
1742 if (texture_ref.get()) {
1743 last_id = texture_ref->service_id();
1725 } else { 1744 } else {
1726 last_id = 0; 1745 last_id = 0;
1727 } 1746 }
1728 1747
1729 glBindTexture(GL_TEXTURE_2D, last_id); 1748 glBindTexture(target, last_id);
1730 glActiveTexture(GL_TEXTURE0 + state->active_texture_unit); 1749 glActiveTexture(GL_TEXTURE0 + state->active_texture_unit);
1731 } 1750 }
1732 1751
1733 ScopedTexture2DBinder::ScopedTexture2DBinder(ContextState* state, 1752 ScopedTextureBinder::ScopedTextureBinder(ContextState* state,
1734 GLuint id) 1753 GLuint id,
1735 : state_(state) { 1754 GLenum target)
1755 : state_(state),
1756 target_(target) {
1736 ScopedGLErrorSuppressor suppressor( 1757 ScopedGLErrorSuppressor suppressor(
1737 "ScopedTexture2DBinder::ctor", state_->GetErrorState()); 1758 "ScopedTextureBinder::ctor", state_->GetErrorState());
1738 1759
1739 // TODO(apatrick): Check if there are any other states that need to be reset 1760 // TODO(apatrick): Check if there are any other states that need to be reset
1740 // before binding a new texture. 1761 // before binding a new texture.
1741 glActiveTexture(GL_TEXTURE0); 1762 glActiveTexture(GL_TEXTURE0);
1742 glBindTexture(GL_TEXTURE_2D, id); 1763 glBindTexture(target, id);
1743 } 1764 }
1744 1765
1745 ScopedTexture2DBinder::~ScopedTexture2DBinder() { 1766 ScopedTextureBinder::~ScopedTextureBinder() {
1746 ScopedGLErrorSuppressor suppressor( 1767 ScopedGLErrorSuppressor suppressor(
1747 "ScopedTexture2DBinder::dtor", state_->GetErrorState()); 1768 "ScopedTextureBinder::dtor", state_->GetErrorState());
1748 RestoreCurrentTexture2DBindings(state_); 1769 RestoreCurrentTextureBindings(state_, target_);
1749 } 1770 }
1750 1771
1751 ScopedRenderBufferBinder::ScopedRenderBufferBinder(ContextState* state, 1772 ScopedRenderBufferBinder::ScopedRenderBufferBinder(ContextState* state,
1752 GLuint id) 1773 GLuint id)
1753 : state_(state) { 1774 : state_(state) {
1754 ScopedGLErrorSuppressor suppressor( 1775 ScopedGLErrorSuppressor suppressor(
1755 "ScopedRenderBufferBinder::ctor", state_->GetErrorState()); 1776 "ScopedRenderBufferBinder::ctor", state_->GetErrorState());
1756 glBindRenderbufferEXT(GL_RENDERBUFFER, id); 1777 glBindRenderbufferEXT(GL_RENDERBUFFER, id);
1757 } 1778 }
1758 1779
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1862 // the associated GL context was current. Just check that it was explicitly 1883 // the associated GL context was current. Just check that it was explicitly
1863 // destroyed. 1884 // destroyed.
1864 DCHECK_EQ(id_, 0u); 1885 DCHECK_EQ(id_, 0u);
1865 } 1886 }
1866 1887
1867 void BackTexture::Create() { 1888 void BackTexture::Create() {
1868 ScopedGLErrorSuppressor suppressor("BackTexture::Create", 1889 ScopedGLErrorSuppressor suppressor("BackTexture::Create",
1869 state_->GetErrorState()); 1890 state_->GetErrorState());
1870 Destroy(); 1891 Destroy();
1871 glGenTextures(1, &id_); 1892 glGenTextures(1, &id_);
1872 ScopedTexture2DBinder binder(state_, id_); 1893 ScopedTextureBinder binder(state_, id_, GL_TEXTURE_2D);
1873 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 1894 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1874 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 1895 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1875 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 1896 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1876 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 1897 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1877 1898
1878 // TODO(apatrick): Attempt to diagnose crbug.com/97775. If SwapBuffers is 1899 // TODO(apatrick): Attempt to diagnose crbug.com/97775. If SwapBuffers is
1879 // never called on an offscreen context, no data will ever be uploaded to the 1900 // never called on an offscreen context, no data will ever be uploaded to the
1880 // saved offscreen color texture (it is deferred until to when SwapBuffers 1901 // saved offscreen color texture (it is deferred until to when SwapBuffers
1881 // is called). My idea is that some nvidia drivers might have a bug where 1902 // is called). My idea is that some nvidia drivers might have a bug where
1882 // deleting a texture that has never been populated might cause a 1903 // deleting a texture that has never been populated might cause a
1883 // crash. 1904 // crash.
1884 glTexImage2D( 1905 glTexImage2D(
1885 GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); 1906 GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
1886 1907
1887 bytes_allocated_ = 16u * 16u * 4u; 1908 bytes_allocated_ = 16u * 16u * 4u;
1888 memory_tracker_.TrackMemAlloc(bytes_allocated_); 1909 memory_tracker_.TrackMemAlloc(bytes_allocated_);
1889 } 1910 }
1890 1911
1891 bool BackTexture::AllocateStorage( 1912 bool BackTexture::AllocateStorage(
1892 const gfx::Size& size, GLenum format, bool zero) { 1913 const gfx::Size& size, GLenum format, bool zero) {
1893 DCHECK_NE(id_, 0u); 1914 DCHECK_NE(id_, 0u);
1894 ScopedGLErrorSuppressor suppressor("BackTexture::AllocateStorage", 1915 ScopedGLErrorSuppressor suppressor("BackTexture::AllocateStorage",
1895 state_->GetErrorState()); 1916 state_->GetErrorState());
1896 ScopedTexture2DBinder binder(state_, id_); 1917 ScopedTextureBinder binder(state_, id_, GL_TEXTURE_2D);
1897 uint32 image_size = 0; 1918 uint32 image_size = 0;
1898 GLES2Util::ComputeImageDataSizes( 1919 GLES2Util::ComputeImageDataSizes(
1899 size.width(), size.height(), format, GL_UNSIGNED_BYTE, 8, &image_size, 1920 size.width(), size.height(), format, GL_UNSIGNED_BYTE, 8, &image_size,
1900 NULL, NULL); 1921 NULL, NULL);
1901 1922
1902 if (!memory_tracker_.EnsureGPUMemoryAvailable(image_size)) { 1923 if (!memory_tracker_.EnsureGPUMemoryAvailable(image_size)) {
1903 return false; 1924 return false;
1904 } 1925 }
1905 1926
1906 scoped_ptr<char[]> zero_data; 1927 scoped_ptr<char[]> zero_data;
(...skipping 20 matching lines...) Expand all
1927 bytes_allocated_ = image_size; 1948 bytes_allocated_ = image_size;
1928 memory_tracker_.TrackMemAlloc(bytes_allocated_); 1949 memory_tracker_.TrackMemAlloc(bytes_allocated_);
1929 } 1950 }
1930 return success; 1951 return success;
1931 } 1952 }
1932 1953
1933 void BackTexture::Copy(const gfx::Size& size, GLenum format) { 1954 void BackTexture::Copy(const gfx::Size& size, GLenum format) {
1934 DCHECK_NE(id_, 0u); 1955 DCHECK_NE(id_, 0u);
1935 ScopedGLErrorSuppressor suppressor("BackTexture::Copy", 1956 ScopedGLErrorSuppressor suppressor("BackTexture::Copy",
1936 state_->GetErrorState()); 1957 state_->GetErrorState());
1937 ScopedTexture2DBinder binder(state_, id_); 1958 ScopedTextureBinder binder(state_, id_, GL_TEXTURE_2D);
1938 glCopyTexImage2D(GL_TEXTURE_2D, 1959 glCopyTexImage2D(GL_TEXTURE_2D,
1939 0, // level 1960 0, // level
1940 format, 1961 format,
1941 0, 0, 1962 0, 0,
1942 size.width(), 1963 size.width(),
1943 size.height(), 1964 size.height(),
1944 0); // border 1965 0); // border
1945 } 1966 }
1946 1967
1947 void BackTexture::Destroy() { 1968 void BackTexture::Destroy() {
(...skipping 3929 matching lines...) Expand 10 before | Expand all | Expand 10 after
5877 } 5898 }
5878 5899
5879 void GLES2DecoderImpl::PerformanceWarning( 5900 void GLES2DecoderImpl::PerformanceWarning(
5880 const char* filename, int line, const std::string& msg) { 5901 const char* filename, int line, const std::string& msg) {
5881 logger_.LogMessage(filename, line, 5902 logger_.LogMessage(filename, line,
5882 std::string("PERFORMANCE WARNING: ") + msg); 5903 std::string("PERFORMANCE WARNING: ") + msg);
5883 } 5904 }
5884 5905
5885 void GLES2DecoderImpl::DoWillUseTexImageIfNeeded( 5906 void GLES2DecoderImpl::DoWillUseTexImageIfNeeded(
5886 Texture* texture, GLenum textarget) { 5907 Texture* texture, GLenum textarget) {
5887 // This might be supported in the future.
5888 if (textarget != GL_TEXTURE_2D)
5889 return;
5890 // Image is already in use if texture is attached to a framebuffer. 5908 // Image is already in use if texture is attached to a framebuffer.
5891 if (texture && !texture->IsAttachedToFramebuffer()) { 5909 if (texture && !texture->IsAttachedToFramebuffer()) {
5892 gfx::GLImage* image = texture->GetLevelImage(textarget, 0); 5910 gfx::GLImage* image = texture->GetLevelImage(textarget, 0);
5893 if (image) { 5911 if (image) {
5894 ScopedGLErrorSuppressor suppressor( 5912 ScopedGLErrorSuppressor suppressor(
5895 "GLES2DecoderImpl::DoWillUseTexImageIfNeeded", 5913 "GLES2DecoderImpl::DoWillUseTexImageIfNeeded",
5896 GetErrorState()); 5914 GetErrorState());
5897 glBindTexture(textarget, texture->service_id()); 5915 glBindTexture(textarget, texture->service_id());
5898 image->WillUseTexImage(); 5916 image->WillUseTexImage();
5899 RestoreCurrentTexture2DBindings(&state_); 5917 RestoreCurrentTextureBindings(&state_, textarget);
5900 } 5918 }
5901 } 5919 }
5902 } 5920 }
5903 5921
5904 void GLES2DecoderImpl::DoDidUseTexImageIfNeeded( 5922 void GLES2DecoderImpl::DoDidUseTexImageIfNeeded(
5905 Texture* texture, GLenum textarget) { 5923 Texture* texture, GLenum textarget) {
5906 // This might be supported in the future.
5907 if (textarget != GL_TEXTURE_2D)
5908 return;
5909 // Image is still in use if texture is attached to a framebuffer. 5924 // Image is still in use if texture is attached to a framebuffer.
5910 if (texture && !texture->IsAttachedToFramebuffer()) { 5925 if (texture && !texture->IsAttachedToFramebuffer()) {
5911 gfx::GLImage* image = texture->GetLevelImage(textarget, 0); 5926 gfx::GLImage* image = texture->GetLevelImage(textarget, 0);
5912 if (image) { 5927 if (image) {
5913 ScopedGLErrorSuppressor suppressor( 5928 ScopedGLErrorSuppressor suppressor(
5914 "GLES2DecoderImpl::DoDidUseTexImageIfNeeded", 5929 "GLES2DecoderImpl::DoDidUseTexImageIfNeeded",
5915 GetErrorState()); 5930 GetErrorState());
5916 glBindTexture(textarget, texture->service_id()); 5931 glBindTexture(textarget, texture->service_id());
5917 image->DidUseTexImage(); 5932 image->DidUseTexImage();
5918 RestoreCurrentTexture2DBindings(&state_); 5933 RestoreCurrentTextureBindings(&state_, textarget);
5919 } 5934 }
5920 } 5935 }
5921 } 5936 }
5922 5937
5923 bool GLES2DecoderImpl::PrepareTexturesForRender() { 5938 bool GLES2DecoderImpl::PrepareTexturesForRender() {
5924 DCHECK(state_.current_program.get()); 5939 DCHECK(state_.current_program.get());
5925 if (!texture_manager()->HaveUnrenderableTextures() && 5940 if (!texture_manager()->HaveUnrenderableTextures() &&
5926 !texture_manager()->HaveImages()) { 5941 !texture_manager()->HaveImages()) {
5927 return true; 5942 return true;
5928 } 5943 }
(...skipping 3851 matching lines...) Expand 10 before | Expand all | Expand 10 after
9780 dest_internal_format != internal_format || 9795 dest_internal_format != internal_format ||
9781 dest_type_previous != dest_type) { 9796 dest_type_previous != dest_type) {
9782 // Ensure that the glTexImage2D succeeds. 9797 // Ensure that the glTexImage2D succeeds.
9783 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTextureCHROMIUM"); 9798 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTextureCHROMIUM");
9784 glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); 9799 glBindTexture(GL_TEXTURE_2D, dest_texture->service_id());
9785 glTexImage2D( 9800 glTexImage2D(
9786 GL_TEXTURE_2D, level, internal_format, source_width, source_height, 9801 GL_TEXTURE_2D, level, internal_format, source_width, source_height,
9787 0, internal_format, dest_type, NULL); 9802 0, internal_format, dest_type, NULL);
9788 GLenum error = LOCAL_PEEK_GL_ERROR("glCopyTextureCHROMIUM"); 9803 GLenum error = LOCAL_PEEK_GL_ERROR("glCopyTextureCHROMIUM");
9789 if (error != GL_NO_ERROR) { 9804 if (error != GL_NO_ERROR) {
9790 RestoreCurrentTexture2DBindings(&state_); 9805 RestoreCurrentTextureBindings(&state_, GL_TEXTURE_2D);
9791 return; 9806 return;
9792 } 9807 }
9793 9808
9794 texture_manager()->SetLevelInfo( 9809 texture_manager()->SetLevelInfo(
9795 dest_texture_ref, GL_TEXTURE_2D, level, internal_format, source_width, 9810 dest_texture_ref, GL_TEXTURE_2D, level, internal_format, source_width,
9796 source_height, 1, 0, internal_format, dest_type, true); 9811 source_height, 1, 0, internal_format, dest_type, true);
9797 } else { 9812 } else {
9798 texture_manager()->SetLevelCleared( 9813 texture_manager()->SetLevelCleared(
9799 dest_texture_ref, GL_TEXTURE_2D, level, true); 9814 dest_texture_ref, GL_TEXTURE_2D, level, true);
9800 } 9815 }
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after
10494 DoDidUseTexImageIfNeeded(texture, texture->target()); 10509 DoDidUseTexImageIfNeeded(texture, texture->target());
10495 } 10510 }
10496 10511
10497 // Include the auto-generated part of this file. We split this because it means 10512 // Include the auto-generated part of this file. We split this because it means
10498 // we can easily edit the non-auto generated parts right here in this file 10513 // we can easily edit the non-auto generated parts right here in this file
10499 // instead of having to edit some template or the code generator. 10514 // instead of having to edit some template or the code generator.
10500 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 10515 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
10501 10516
10502 } // namespace gles2 10517 } // namespace gles2
10503 } // namespace gpu 10518 } // namespace gpu
OLDNEW
« no previous file with comments | « content/common/gpu/stream_texture_android.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698