| OLD | NEW |
| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 #include "gpu/command_buffer/service/vertex_array_manager.h" | 58 #include "gpu/command_buffer/service/vertex_array_manager.h" |
| 59 #include "gpu/command_buffer/service/vertex_attrib_manager.h" | 59 #include "gpu/command_buffer/service/vertex_attrib_manager.h" |
| 60 #include "third_party/smhasher/src/City.h" | 60 #include "third_party/smhasher/src/City.h" |
| 61 #include "ui/gl/gl_bindings.h" | 61 #include "ui/gl/gl_bindings.h" |
| 62 #include "ui/gl/gl_fence.h" | 62 #include "ui/gl/gl_fence.h" |
| 63 #include "ui/gl/gl_image.h" | 63 #include "ui/gl/gl_image.h" |
| 64 #include "ui/gl/gl_implementation.h" | 64 #include "ui/gl/gl_implementation.h" |
| 65 #include "ui/gl/gl_surface.h" | 65 #include "ui/gl/gl_surface.h" |
| 66 | 66 |
| 67 #if defined(OS_MACOSX) | 67 #if defined(OS_MACOSX) |
| 68 #include "ui/gl/io_surface_support_mac.h" | 68 #include <IOSurface/IOSurfaceAPI.h> |
| 69 // Note that this must be included after gl_bindings.h to avoid conflicts. |
| 70 #include <OpenGL/CGLIOSurface.h> |
| 69 #endif | 71 #endif |
| 70 | 72 |
| 71 #if defined(OS_WIN) | 73 #if defined(OS_WIN) |
| 72 #include "base/win/win_util.h" | 74 #include "base/win/win_util.h" |
| 73 #endif | 75 #endif |
| 74 | 76 |
| 75 namespace gpu { | 77 namespace gpu { |
| 76 namespace gles2 { | 78 namespace gles2 { |
| 77 | 79 |
| 78 namespace { | 80 namespace { |
| (...skipping 1674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1753 | 1755 |
| 1754 bool compile_shader_always_succeeds_; | 1756 bool compile_shader_always_succeeds_; |
| 1755 | 1757 |
| 1756 // An optional behaviour to lose the context and group when OOM. | 1758 // An optional behaviour to lose the context and group when OOM. |
| 1757 bool lose_context_when_out_of_memory_; | 1759 bool lose_context_when_out_of_memory_; |
| 1758 | 1760 |
| 1759 // Log extra info. | 1761 // Log extra info. |
| 1760 bool service_logging_; | 1762 bool service_logging_; |
| 1761 | 1763 |
| 1762 #if defined(OS_MACOSX) | 1764 #if defined(OS_MACOSX) |
| 1763 typedef std::map<GLuint, CFTypeRef> TextureToIOSurfaceMap; | 1765 typedef std::map<GLuint, IOSurfaceRef> TextureToIOSurfaceMap; |
| 1764 TextureToIOSurfaceMap texture_to_io_surface_map_; | 1766 TextureToIOSurfaceMap texture_to_io_surface_map_; |
| 1765 #endif | 1767 #endif |
| 1766 | 1768 |
| 1767 scoped_ptr<CopyTextureCHROMIUMResourceManager> copy_texture_CHROMIUM_; | 1769 scoped_ptr<CopyTextureCHROMIUMResourceManager> copy_texture_CHROMIUM_; |
| 1768 | 1770 |
| 1769 // Cached values of the currently assigned viewport dimensions. | 1771 // Cached values of the currently assigned viewport dimensions. |
| 1770 GLsizei viewport_max_width_; | 1772 GLsizei viewport_max_width_; |
| 1771 GLsizei viewport_max_height_; | 1773 GLsizei viewport_max_height_; |
| 1772 | 1774 |
| 1773 // Command buffer stats. | 1775 // Command buffer stats. |
| (...skipping 7970 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9744 GetVertexAttribManager(client_id); | 9746 GetVertexAttribManager(client_id); |
| 9745 return vao && vao->IsValid() && !vao->IsDeleted(); | 9747 return vao && vao->IsValid() && !vao->IsDeleted(); |
| 9746 } | 9748 } |
| 9747 | 9749 |
| 9748 #if defined(OS_MACOSX) | 9750 #if defined(OS_MACOSX) |
| 9749 void GLES2DecoderImpl::ReleaseIOSurfaceForTexture(GLuint texture_id) { | 9751 void GLES2DecoderImpl::ReleaseIOSurfaceForTexture(GLuint texture_id) { |
| 9750 TextureToIOSurfaceMap::iterator it = texture_to_io_surface_map_.find( | 9752 TextureToIOSurfaceMap::iterator it = texture_to_io_surface_map_.find( |
| 9751 texture_id); | 9753 texture_id); |
| 9752 if (it != texture_to_io_surface_map_.end()) { | 9754 if (it != texture_to_io_surface_map_.end()) { |
| 9753 // Found a previous IOSurface bound to this texture; release it. | 9755 // Found a previous IOSurface bound to this texture; release it. |
| 9754 CFTypeRef surface = it->second; | 9756 IOSurfaceRef surface = it->second; |
| 9755 CFRelease(surface); | 9757 CFRelease(surface); |
| 9756 texture_to_io_surface_map_.erase(it); | 9758 texture_to_io_surface_map_.erase(it); |
| 9757 } | 9759 } |
| 9758 } | 9760 } |
| 9759 #endif | 9761 #endif |
| 9760 | 9762 |
| 9761 void GLES2DecoderImpl::DoTexImageIOSurface2DCHROMIUM( | 9763 void GLES2DecoderImpl::DoTexImageIOSurface2DCHROMIUM( |
| 9762 GLenum target, GLsizei width, GLsizei height, | 9764 GLenum target, GLsizei width, GLsizei height, |
| 9763 GLuint io_surface_id, GLuint plane) { | 9765 GLuint io_surface_id, GLuint plane) { |
| 9764 #if defined(OS_MACOSX) | 9766 #if defined(OS_MACOSX) |
| 9765 if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGL) { | 9767 if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGL) { |
| 9766 LOCAL_SET_GL_ERROR( | 9768 LOCAL_SET_GL_ERROR( |
| 9767 GL_INVALID_OPERATION, | 9769 GL_INVALID_OPERATION, |
| 9768 "glTexImageIOSurface2DCHROMIUM", "only supported on desktop GL."); | 9770 "glTexImageIOSurface2DCHROMIUM", "only supported on desktop GL."); |
| 9769 return; | 9771 return; |
| 9770 } | 9772 } |
| 9771 | 9773 |
| 9772 IOSurfaceSupport* surface_support = IOSurfaceSupport::Initialize(); | |
| 9773 if (!surface_support) { | |
| 9774 LOCAL_SET_GL_ERROR( | |
| 9775 GL_INVALID_OPERATION, | |
| 9776 "glTexImageIOSurface2DCHROMIUM", "only supported on 10.6."); | |
| 9777 return; | |
| 9778 } | |
| 9779 | |
| 9780 if (target != GL_TEXTURE_RECTANGLE_ARB) { | 9774 if (target != GL_TEXTURE_RECTANGLE_ARB) { |
| 9781 // This might be supported in the future, and if we could require | 9775 // This might be supported in the future, and if we could require |
| 9782 // support for binding an IOSurface to a NPOT TEXTURE_2D texture, we | 9776 // support for binding an IOSurface to a NPOT TEXTURE_2D texture, we |
| 9783 // could delete a lot of code. For now, perform strict validation so we | 9777 // could delete a lot of code. For now, perform strict validation so we |
| 9784 // know what's going on. | 9778 // know what's going on. |
| 9785 LOCAL_SET_GL_ERROR( | 9779 LOCAL_SET_GL_ERROR( |
| 9786 GL_INVALID_OPERATION, | 9780 GL_INVALID_OPERATION, |
| 9787 "glTexImageIOSurface2DCHROMIUM", | 9781 "glTexImageIOSurface2DCHROMIUM", |
| 9788 "requires TEXTURE_RECTANGLE_ARB target"); | 9782 "requires TEXTURE_RECTANGLE_ARB target"); |
| 9789 return; | 9783 return; |
| 9790 } | 9784 } |
| 9791 | 9785 |
| 9792 // Default target might be conceptually valid, but disallow it to avoid | 9786 // Default target might be conceptually valid, but disallow it to avoid |
| 9793 // accidents. | 9787 // accidents. |
| 9794 TextureRef* texture_ref = | 9788 TextureRef* texture_ref = |
| 9795 texture_manager()->GetTextureInfoForTargetUnlessDefault(&state_, target); | 9789 texture_manager()->GetTextureInfoForTargetUnlessDefault(&state_, target); |
| 9796 if (!texture_ref) { | 9790 if (!texture_ref) { |
| 9797 LOCAL_SET_GL_ERROR( | 9791 LOCAL_SET_GL_ERROR( |
| 9798 GL_INVALID_OPERATION, | 9792 GL_INVALID_OPERATION, |
| 9799 "glTexImageIOSurface2DCHROMIUM", "no rectangle texture bound"); | 9793 "glTexImageIOSurface2DCHROMIUM", "no rectangle texture bound"); |
| 9800 return; | 9794 return; |
| 9801 } | 9795 } |
| 9802 | 9796 |
| 9803 // Look up the new IOSurface. Note that because of asynchrony | 9797 // Look up the new IOSurface. Note that because of asynchrony |
| 9804 // between processes this might fail; during live resizing the | 9798 // between processes this might fail; during live resizing the |
| 9805 // plugin process might allocate and release an IOSurface before | 9799 // plugin process might allocate and release an IOSurface before |
| 9806 // this process gets a chance to look it up. Hold on to any old | 9800 // this process gets a chance to look it up. Hold on to any old |
| 9807 // IOSurface in this case. | 9801 // IOSurface in this case. |
| 9808 CFTypeRef surface = surface_support->IOSurfaceLookup(io_surface_id); | 9802 IOSurfaceRef surface = IOSurfaceLookup(io_surface_id); |
| 9809 if (!surface) { | 9803 if (!surface) { |
| 9810 LOCAL_SET_GL_ERROR( | 9804 LOCAL_SET_GL_ERROR( |
| 9811 GL_INVALID_OPERATION, | 9805 GL_INVALID_OPERATION, |
| 9812 "glTexImageIOSurface2DCHROMIUM", "no IOSurface with the given ID"); | 9806 "glTexImageIOSurface2DCHROMIUM", "no IOSurface with the given ID"); |
| 9813 return; | 9807 return; |
| 9814 } | 9808 } |
| 9815 | 9809 |
| 9816 // Release any IOSurface previously bound to this texture. | 9810 // Release any IOSurface previously bound to this texture. |
| 9817 ReleaseIOSurfaceForTexture(texture_ref->service_id()); | 9811 ReleaseIOSurfaceForTexture(texture_ref->service_id()); |
| 9818 | 9812 |
| 9819 // Make sure we release the IOSurface even if CGLTexImageIOSurface2D fails. | 9813 // Make sure we release the IOSurface even if CGLTexImageIOSurface2D fails. |
| 9820 texture_to_io_surface_map_.insert( | 9814 texture_to_io_surface_map_.insert( |
| 9821 std::make_pair(texture_ref->service_id(), surface)); | 9815 std::make_pair(texture_ref->service_id(), surface)); |
| 9822 | 9816 |
| 9823 CGLContextObj context = | 9817 CGLContextObj context = |
| 9824 static_cast<CGLContextObj>(context_->GetHandle()); | 9818 static_cast<CGLContextObj>(context_->GetHandle()); |
| 9825 | 9819 |
| 9826 CGLError err = surface_support->CGLTexImageIOSurface2D( | 9820 CGLError err = CGLTexImageIOSurface2D( |
| 9827 context, | 9821 context, |
| 9828 target, | 9822 target, |
| 9829 GL_RGBA, | 9823 GL_RGBA, |
| 9830 width, | 9824 width, |
| 9831 height, | 9825 height, |
| 9832 GL_BGRA, | 9826 GL_BGRA, |
| 9833 GL_UNSIGNED_INT_8_8_8_8_REV, | 9827 GL_UNSIGNED_INT_8_8_8_8_REV, |
| 9834 surface, | 9828 surface, |
| 9835 plane); | 9829 plane); |
| 9836 | 9830 |
| (...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10775 } | 10769 } |
| 10776 } | 10770 } |
| 10777 | 10771 |
| 10778 // Include the auto-generated part of this file. We split this because it means | 10772 // Include the auto-generated part of this file. We split this because it means |
| 10779 // we can easily edit the non-auto generated parts right here in this file | 10773 // we can easily edit the non-auto generated parts right here in this file |
| 10780 // instead of having to edit some template or the code generator. | 10774 // instead of having to edit some template or the code generator. |
| 10781 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 10775 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
| 10782 | 10776 |
| 10783 } // namespace gles2 | 10777 } // namespace gles2 |
| 10784 } // namespace gpu | 10778 } // namespace gpu |
| OLD | NEW |