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

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

Issue 7021014: GLContext no longer holds a pointer to a GLSurface. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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
OLDNEW
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 20 matching lines...) Expand all
31 #include "gpu/command_buffer/service/gl_utils.h" 31 #include "gpu/command_buffer/service/gl_utils.h"
32 #include "gpu/command_buffer/service/gles2_cmd_validation.h" 32 #include "gpu/command_buffer/service/gles2_cmd_validation.h"
33 #include "gpu/command_buffer/service/program_manager.h" 33 #include "gpu/command_buffer/service/program_manager.h"
34 #include "gpu/command_buffer/service/renderbuffer_manager.h" 34 #include "gpu/command_buffer/service/renderbuffer_manager.h"
35 #include "gpu/command_buffer/service/shader_manager.h" 35 #include "gpu/command_buffer/service/shader_manager.h"
36 #include "gpu/command_buffer/service/shader_translator.h" 36 #include "gpu/command_buffer/service/shader_translator.h"
37 #include "gpu/command_buffer/service/texture_manager.h" 37 #include "gpu/command_buffer/service/texture_manager.h"
38 #include "gpu/GLES2/gles2_command_buffer.h" 38 #include "gpu/GLES2/gles2_command_buffer.h"
39 #include "ui/gfx/gl/gl_context.h" 39 #include "ui/gfx/gl/gl_context.h"
40 #include "ui/gfx/gl/gl_implementation.h" 40 #include "ui/gfx/gl/gl_implementation.h"
41 #include "ui/gfx/gl/gl_surface.h"
41 42
42 #if !defined(GL_DEPTH24_STENCIL8) 43 #if !defined(GL_DEPTH24_STENCIL8)
43 #define GL_DEPTH24_STENCIL8 0x88F0 44 #define GL_DEPTH24_STENCIL8 0x88F0
44 #endif 45 #endif
45 46
46 namespace gpu { 47 namespace gpu {
47 namespace gles2 { 48 namespace gles2 {
48 49
49 class GLES2DecoderImpl; 50 class GLES2DecoderImpl;
50 51
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 665
665 // Overridden from AsyncAPIInterface. 666 // Overridden from AsyncAPIInterface.
666 virtual Error DoCommand(unsigned int command, 667 virtual Error DoCommand(unsigned int command,
667 unsigned int arg_count, 668 unsigned int arg_count,
668 const void* args); 669 const void* args);
669 670
670 // Overridden from AsyncAPIInterface. 671 // Overridden from AsyncAPIInterface.
671 virtual const char* GetCommandName(unsigned int command_id) const; 672 virtual const char* GetCommandName(unsigned int command_id) const;
672 673
673 // Overridden from GLES2Decoder. 674 // Overridden from GLES2Decoder.
674 virtual bool Initialize(gfx::GLContext* context, 675 virtual bool Initialize(gfx::GLSurface* surface,
676 gfx::GLContext* context,
675 const gfx::Size& size, 677 const gfx::Size& size,
676 const DisallowedExtensions& disallowed_extensions, 678 const DisallowedExtensions& disallowed_extensions,
677 const char* allowed_extensions, 679 const char* allowed_extensions,
678 const std::vector<int32>& attribs, 680 const std::vector<int32>& attribs,
679 GLES2Decoder* parent, 681 GLES2Decoder* parent,
680 uint32 parent_client_texture_id); 682 uint32 parent_client_texture_id);
681 virtual void Destroy(); 683 virtual void Destroy();
682 virtual void ResizeOffscreenFrameBuffer(const gfx::Size& size); 684 virtual void ResizeOffscreenFrameBuffer(const gfx::Size& size);
683 virtual bool UpdateOffscreenFrameBufferSize(); 685 virtual bool UpdateOffscreenFrameBufferSize();
684 virtual bool MakeCurrent(); 686 virtual bool MakeCurrent();
685 virtual GLES2Util* GetGLES2Util() { return &util_; } 687 virtual GLES2Util* GetGLES2Util() { return &util_; }
686 virtual gfx::GLContext* GetGLContext() { return context_.get(); } 688 virtual gfx::GLContext* GetGLContext() { return context_.get(); }
689 virtual gfx::GLSurface* GetGLSurface() { return surface_.get(); }
687 virtual ContextGroup* GetContextGroup() { return group_.get(); } 690 virtual ContextGroup* GetContextGroup() { return group_.get(); }
688 691
689 virtual void SetResizeCallback(Callback1<gfx::Size>::Type* callback); 692 virtual void SetResizeCallback(Callback1<gfx::Size>::Type* callback);
690 virtual void SetSwapBuffersCallback(Callback0::Type* callback); 693 virtual void SetSwapBuffersCallback(Callback0::Type* callback);
691 virtual void SetLatchCallback(const base::Callback<void(bool)>& callback);; 694 virtual void SetLatchCallback(const base::Callback<void(bool)>& callback);;
692 virtual bool GetServiceTextureId(uint32 client_texture_id, 695 virtual bool GetServiceTextureId(uint32 client_texture_id,
693 uint32* service_texture_id); 696 uint32* service_texture_id);
694 697
695 // Restores the current state to the user's settings. 698 // Restores the current state to the user's settings.
696 void RestoreCurrentFramebufferBindings(); 699 void RestoreCurrentFramebufferBindings();
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
1330 #define GLES2_CMD_OP(name) \ 1333 #define GLES2_CMD_OP(name) \
1331 Error Handle ## name( \ 1334 Error Handle ## name( \
1332 uint32 immediate_data_size, \ 1335 uint32 immediate_data_size, \
1333 const gles2::name& args); \ 1336 const gles2::name& args); \
1334 1337
1335 GLES2_COMMAND_LIST(GLES2_CMD_OP) 1338 GLES2_COMMAND_LIST(GLES2_CMD_OP)
1336 1339
1337 #undef GLES2_CMD_OP 1340 #undef GLES2_CMD_OP
1338 1341
1339 // The GL context this decoder renders to on behalf of the client. 1342 // The GL context this decoder renders to on behalf of the client.
1343 scoped_ptr<gfx::GLSurface> surface_;
1340 scoped_ptr<gfx::GLContext> context_; 1344 scoped_ptr<gfx::GLContext> context_;
1341 1345
1342 // The ContextGroup for this decoder uses to track resources. 1346 // The ContextGroup for this decoder uses to track resources.
1343 ContextGroup::Ref group_; 1347 ContextGroup::Ref group_;
1344 1348
1345 // A parent decoder can access this decoders saved offscreen frame buffer. 1349 // A parent decoder can access this decoders saved offscreen frame buffer.
1346 // The parent pointer is reset if the parent is destroyed. 1350 // The parent pointer is reset if the parent is destroyed.
1347 base::WeakPtr<GLES2DecoderImpl> parent_; 1351 base::WeakPtr<GLES2DecoderImpl> parent_;
1348 1352
1349 // Width and height to which an offscreen frame buffer should be resized on 1353 // Width and height to which an offscreen frame buffer should be resized on
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
1820 // empty string to CompileShader and this is not a valid shader. 1824 // empty string to CompileShader and this is not a valid shader.
1821 // TODO(apatrick): fix this test. 1825 // TODO(apatrick): fix this test.
1822 if ((gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2 && 1826 if ((gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2 &&
1823 !feature_info_->feature_flags().chromium_webglsl) || 1827 !feature_info_->feature_flags().chromium_webglsl) ||
1824 gfx::GetGLImplementation() == gfx::kGLImplementationMockGL) { 1828 gfx::GetGLImplementation() == gfx::kGLImplementationMockGL) {
1825 use_shader_translator_ = false; 1829 use_shader_translator_ = false;
1826 } 1830 }
1827 } 1831 }
1828 1832
1829 bool GLES2DecoderImpl::Initialize( 1833 bool GLES2DecoderImpl::Initialize(
1834 gfx::GLSurface* surface,
1830 gfx::GLContext* context, 1835 gfx::GLContext* context,
1831 const gfx::Size& size, 1836 const gfx::Size& size,
1832 const DisallowedExtensions& disallowed_extensions, 1837 const DisallowedExtensions& disallowed_extensions,
1833 const char* allowed_extensions, 1838 const char* allowed_extensions,
1834 const std::vector<int32>& attribs, 1839 const std::vector<int32>& attribs,
1835 GLES2Decoder* parent, 1840 GLES2Decoder* parent,
1836 uint32 parent_client_texture_id) { 1841 uint32 parent_client_texture_id) {
1837 DCHECK(context); 1842 DCHECK(context);
1838 DCHECK(!context_.get()); 1843 DCHECK(!context_.get());
1839 1844
1845 // Take ownership of the GLSurface. TODO(apatrick): the decoder should not
1846 // own the surface. It should be possible to freely switch the surface the
1847 // context renders to.
1848 surface_.reset(surface);
1849
1840 // Take ownership of the GLContext. 1850 // Take ownership of the GLContext.
1841 context_.reset(context); 1851 context_.reset(context);
1842 1852
1843 // Keep only a weak pointer to the parent so we don't unmap its client 1853 // Keep only a weak pointer to the parent so we don't unmap its client
1844 // frame buffer after it has been destroyed. 1854 // frame buffer after it has been destroyed.
1845 if (parent) 1855 if (parent)
1846 parent_ = static_cast<GLES2DecoderImpl*>(parent)->AsWeakPtr(); 1856 parent_ = static_cast<GLES2DecoderImpl*>(parent)->AsWeakPtr();
1847 1857
1848 if (!MakeCurrent()) { 1858 if (!MakeCurrent()) {
1849 LOG(ERROR) << "GLES2DecoderImpl::Initialize failed because " 1859 LOG(ERROR) << "GLES2DecoderImpl::Initialize failed because "
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1888 texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_CUBE_MAP); 1898 texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_CUBE_MAP);
1889 texture_units_[tt].bound_texture_cube_map = info; 1899 texture_units_[tt].bound_texture_cube_map = info;
1890 glBindTexture(GL_TEXTURE_CUBE_MAP, info->service_id()); 1900 glBindTexture(GL_TEXTURE_CUBE_MAP, info->service_id());
1891 info = texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_2D); 1901 info = texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_2D);
1892 texture_units_[tt].bound_texture_2d = info; 1902 texture_units_[tt].bound_texture_2d = info;
1893 glBindTexture(GL_TEXTURE_2D, info->service_id()); 1903 glBindTexture(GL_TEXTURE_2D, info->service_id());
1894 } 1904 }
1895 glActiveTexture(GL_TEXTURE0); 1905 glActiveTexture(GL_TEXTURE0);
1896 CHECK_GL_ERROR(); 1906 CHECK_GL_ERROR();
1897 1907
1898 if (context_->IsOffscreen()) { 1908 if (surface_->IsOffscreen()) {
1899 ContextCreationAttribParser attrib_parser; 1909 ContextCreationAttribParser attrib_parser;
1900 if (!attrib_parser.Parse(attribs)) 1910 if (!attrib_parser.Parse(attribs))
1901 return false; 1911 return false;
1902 1912
1903 if (attrib_parser.samples_ > 0 && attrib_parser.sample_buffers_ > 0 && 1913 if (attrib_parser.samples_ > 0 && attrib_parser.sample_buffers_ > 0 &&
1904 (context_->HasExtension("GL_EXT_framebuffer_multisample") || 1914 (context_->HasExtension("GL_EXT_framebuffer_multisample") ||
1905 context_->HasExtension("GL_ANGLE_framebuffer_multisample"))) { 1915 context_->HasExtension("GL_ANGLE_framebuffer_multisample"))) {
1906 // Per ext_framebuffer_multisample spec, need max bound on sample count. 1916 // Per ext_framebuffer_multisample spec, need max bound on sample count.
1907 // max_sample_count must be initialized to a sane value. If 1917 // max_sample_count must be initialized to a sane value. If
1908 // glGetIntegerv() throws a GL error, it leaves its argument unchanged. 1918 // glGetIntegerv() throws a GL error, it leaves its argument unchanged.
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
2196 GLuint service_id = info->service_id(); 2206 GLuint service_id = info->service_id();
2197 glDeleteTextures(1, &service_id); 2207 glDeleteTextures(1, &service_id);
2198 RemoveTextureInfo(client_ids[ii]); 2208 RemoveTextureInfo(client_ids[ii]);
2199 } 2209 }
2200 } 2210 }
2201 } 2211 }
2202 2212
2203 // } // anonymous namespace 2213 // } // anonymous namespace
2204 2214
2205 bool GLES2DecoderImpl::MakeCurrent() { 2215 bool GLES2DecoderImpl::MakeCurrent() {
2206 return context_.get() ? context_->MakeCurrent() : false; 2216 return context_.get() ? context_->MakeCurrent(surface_.get()) : false;
2207 } 2217 }
2208 2218
2209 void GLES2DecoderImpl::RestoreCurrentRenderbufferBindings() { 2219 void GLES2DecoderImpl::RestoreCurrentRenderbufferBindings() {
2210 glBindRenderbufferEXT( 2220 glBindRenderbufferEXT(
2211 GL_RENDERBUFFER, 2221 GL_RENDERBUFFER,
2212 bound_renderbuffer_ ? bound_renderbuffer_->service_id() : 0); 2222 bound_renderbuffer_ ? bound_renderbuffer_->service_id() : 0);
2213 } 2223 }
2214 2224
2215 static void RebindCurrentFramebuffer( 2225 static void RebindCurrentFramebuffer(
2216 GLenum target, 2226 GLenum target,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
2267 if (bound_read_framebuffer_ != 0) { 2277 if (bound_read_framebuffer_ != 0) {
2268 const FramebufferManager::FramebufferInfo::Attachment* attachment = 2278 const FramebufferManager::FramebufferInfo::Attachment* attachment =
2269 bound_read_framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT0); 2279 bound_read_framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT0);
2270 if (attachment) { 2280 if (attachment) {
2271 return gfx::Size(attachment->width(), attachment->height()); 2281 return gfx::Size(attachment->width(), attachment->height());
2272 } 2282 }
2273 return gfx::Size(0, 0); 2283 return gfx::Size(0, 0);
2274 } else if (offscreen_target_frame_buffer_.get()) { 2284 } else if (offscreen_target_frame_buffer_.get()) {
2275 return offscreen_size_; 2285 return offscreen_size_;
2276 } else { 2286 } else {
2277 return context_->GetSize(); 2287 return surface_->GetSize();
2278 } 2288 }
2279 } 2289 }
2280 2290
2281 GLenum GLES2DecoderImpl::GetBoundReadFrameBufferInternalFormat() { 2291 GLenum GLES2DecoderImpl::GetBoundReadFrameBufferInternalFormat() {
2282 if (bound_read_framebuffer_ != 0) { 2292 if (bound_read_framebuffer_ != 0) {
2283 const FramebufferManager::FramebufferInfo::Attachment* attachment = 2293 const FramebufferManager::FramebufferInfo::Attachment* attachment =
2284 bound_read_framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT0); 2294 bound_read_framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT0);
2285 if (attachment) { 2295 if (attachment) {
2286 return attachment->internal_format(); 2296 return attachment->internal_format();
2287 } 2297 }
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
2761 CreateFramebufferInfo(client_id, service_id); 2771 CreateFramebufferInfo(client_id, service_id);
2762 info = GetFramebufferInfo(client_id); 2772 info = GetFramebufferInfo(client_id);
2763 IdAllocator* id_allocator = 2773 IdAllocator* id_allocator =
2764 group_->GetIdAllocator(id_namespaces::kFramebuffers); 2774 group_->GetIdAllocator(id_namespaces::kFramebuffers);
2765 id_allocator->MarkAsUsed(client_id); 2775 id_allocator->MarkAsUsed(client_id);
2766 } else { 2776 } else {
2767 service_id = info->service_id(); 2777 service_id = info->service_id();
2768 } 2778 }
2769 info->MarkAsValid(); 2779 info->MarkAsValid();
2770 } else { 2780 } else {
2771 service_id = context_->GetBackingFrameBufferObject(); 2781 service_id = 0;
2772 } 2782 }
2773 2783
2774 if (target == GL_FRAMEBUFFER || target == GL_DRAW_FRAMEBUFFER_EXT) { 2784 if (target == GL_FRAMEBUFFER || target == GL_DRAW_FRAMEBUFFER_EXT) {
2775 bound_draw_framebuffer_ = info; 2785 bound_draw_framebuffer_ = info;
2776 } 2786 }
2777 if (target == GL_FRAMEBUFFER || target == GL_READ_FRAMEBUFFER_EXT) { 2787 if (target == GL_FRAMEBUFFER || target == GL_READ_FRAMEBUFFER_EXT) {
2778 bound_read_framebuffer_ = info; 2788 bound_read_framebuffer_ = info;
2779 } 2789 }
2780 2790
2781 // When rendering to an offscreen frame buffer, instead of unbinding from 2791 // When rendering to an offscreen frame buffer, instead of unbinding from
(...skipping 3595 matching lines...) Expand 10 before | Expand all | Expand 10 after
6377 6387
6378 // Run the callback with |binder| in scope, so that the callback can call 6388 // Run the callback with |binder| in scope, so that the callback can call
6379 // ReadPixels or CopyTexImage2D. 6389 // ReadPixels or CopyTexImage2D.
6380 if (swap_buffers_callback_.get()) { 6390 if (swap_buffers_callback_.get()) {
6381 swap_buffers_callback_->Run(); 6391 swap_buffers_callback_->Run();
6382 } 6392 }
6383 return error::kNoError; 6393 return error::kNoError;
6384 } 6394 }
6385 } else { 6395 } else {
6386 TRACE_EVENT1("gpu", "GLContext::SwapBuffers", "frame", this_frame_number); 6396 TRACE_EVENT1("gpu", "GLContext::SwapBuffers", "frame", this_frame_number);
6387 if (!context_->SwapBuffers()) { 6397 if (!surface_->SwapBuffers()) {
6388 LOG(ERROR) << "Context lost because SwapBuffers failed."; 6398 LOG(ERROR) << "Context lost because SwapBuffers failed.";
6389 return error::kLostContext; 6399 return error::kLostContext;
6390 } 6400 }
6391 } 6401 }
6392 6402
6393 if (swap_buffers_callback_.get()) { 6403 if (swap_buffers_callback_.get()) {
6394 swap_buffers_callback_->Run(); 6404 swap_buffers_callback_->Run();
6395 } 6405 }
6396 6406
6397 return error::kNoError; 6407 return error::kNoError;
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
6531 return error::kNoError; 6541 return error::kNoError;
6532 } 6542 }
6533 6543
6534 // Include the auto-generated part of this file. We split this because it means 6544 // Include the auto-generated part of this file. We split this because it means
6535 // we can easily edit the non-auto generated parts right here in this file 6545 // we can easily edit the non-auto generated parts right here in this file
6536 // instead of having to edit some template or the code generator. 6546 // instead of having to edit some template or the code generator.
6537 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 6547 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
6538 6548
6539 } // namespace gles2 6549 } // namespace gles2
6540 } // namespace gpu 6550 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698