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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 #include "gpu/command_buffer/service/query_manager.h" | 42 #include "gpu/command_buffer/service/query_manager.h" |
43 #include "gpu/command_buffer/service/renderbuffer_manager.h" | 43 #include "gpu/command_buffer/service/renderbuffer_manager.h" |
44 #include "gpu/command_buffer/service/shader_manager.h" | 44 #include "gpu/command_buffer/service/shader_manager.h" |
45 #include "gpu/command_buffer/service/shader_translator.h" | 45 #include "gpu/command_buffer/service/shader_translator.h" |
46 #include "gpu/command_buffer/service/stream_texture.h" | 46 #include "gpu/command_buffer/service/stream_texture.h" |
47 #include "gpu/command_buffer/service/stream_texture_manager.h" | 47 #include "gpu/command_buffer/service/stream_texture_manager.h" |
48 #include "gpu/command_buffer/service/texture_definition.h" | 48 #include "gpu/command_buffer/service/texture_definition.h" |
49 #include "gpu/command_buffer/service/texture_manager.h" | 49 #include "gpu/command_buffer/service/texture_manager.h" |
50 #include "gpu/command_buffer/service/vertex_attrib_manager.h" | 50 #include "gpu/command_buffer/service/vertex_attrib_manager.h" |
51 #include "ui/gl/gl_context.h" | 51 #include "ui/gl/gl_context.h" |
52 #if defined(USE_X11) | |
53 #include "ui/gl/gl_context_glx.h" | |
54 #endif | |
52 #include "ui/gl/gl_implementation.h" | 55 #include "ui/gl/gl_implementation.h" |
53 #include "ui/gl/gl_surface.h" | 56 #include "ui/gl/gl_surface.h" |
57 #if defined(USE_X11) | |
58 #include "ui/gl/gl_surface_glx.h" | |
59 #endif | |
54 #if defined(OS_MACOSX) | 60 #if defined(OS_MACOSX) |
55 #include "ui/surface/io_surface_support_mac.h" | 61 #include "ui/surface/io_surface_support_mac.h" |
56 #endif | 62 #endif |
57 | 63 |
58 #if !defined(GL_DEPTH24_STENCIL8) | 64 #if !defined(GL_DEPTH24_STENCIL8) |
59 #define GL_DEPTH24_STENCIL8 0x88F0 | 65 #define GL_DEPTH24_STENCIL8 0x88F0 |
60 #endif | 66 #endif |
61 | 67 |
62 namespace gpu { | 68 namespace gpu { |
63 namespace gles2 { | 69 namespace gles2 { |
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
750 GLenum internal_format); | 756 GLenum internal_format); |
751 | 757 |
752 // Wrapper for TexStorage2DEXT. | 758 // Wrapper for TexStorage2DEXT. |
753 void DoTexStorage2DEXT( | 759 void DoTexStorage2DEXT( |
754 GLenum target, | 760 GLenum target, |
755 GLint levels, | 761 GLint levels, |
756 GLenum internal_format, | 762 GLenum internal_format, |
757 GLsizei width, | 763 GLsizei width, |
758 GLsizei height); | 764 GLsizei height); |
759 | 765 |
766 // Wrapper for TexImagePixmap2DCHROMIUM. | |
767 void DoTexImagePixmap2DCHROMIUM( | |
768 GLenum target, | |
769 GLuint pixmap_id); | |
770 | |
760 void DoProduceTextureCHROMIUM(GLenum target, const GLbyte* key); | 771 void DoProduceTextureCHROMIUM(GLenum target, const GLbyte* key); |
761 void DoConsumeTextureCHROMIUM(GLenum target, const GLbyte* key); | 772 void DoConsumeTextureCHROMIUM(GLenum target, const GLbyte* key); |
762 | 773 |
763 // Creates a ProgramInfo for the given program. | 774 // Creates a ProgramInfo for the given program. |
764 ProgramManager::ProgramInfo* CreateProgramInfo( | 775 ProgramManager::ProgramInfo* CreateProgramInfo( |
765 GLuint client_id, GLuint service_id) { | 776 GLuint client_id, GLuint service_id) { |
766 return program_manager()->CreateProgramInfo(client_id, service_id); | 777 return program_manager()->CreateProgramInfo(client_id, service_id); |
767 } | 778 } |
768 | 779 |
769 // Gets the program info for the given program. Returns NULL if none exists. | 780 // Gets the program info for the given program. Returns NULL if none exists. |
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1318 // the tracing system. | 1329 // the tracing system. |
1319 void UpdateBackbufferMemoryAccounting(); | 1330 void UpdateBackbufferMemoryAccounting(); |
1320 | 1331 |
1321 // Returns true if the context was just lost due to e.g. GL_ARB_robustness. | 1332 // Returns true if the context was just lost due to e.g. GL_ARB_robustness. |
1322 bool WasContextLost(); | 1333 bool WasContextLost(); |
1323 | 1334 |
1324 #if defined(OS_MACOSX) | 1335 #if defined(OS_MACOSX) |
1325 void ReleaseIOSurfaceForTexture(GLuint texture_id); | 1336 void ReleaseIOSurfaceForTexture(GLuint texture_id); |
1326 #endif | 1337 #endif |
1327 | 1338 |
1339 #if defined(USE_X11) | |
1340 void ReleaseGLXPixmapForTexture(GLuint texture_id); | |
1341 #endif | |
1342 | |
1328 // Validates the combination of texture parameters. For example validates that | 1343 // Validates the combination of texture parameters. For example validates that |
1329 // for a given format the specific type, level and targets are valid. | 1344 // for a given format the specific type, level and targets are valid. |
1330 // Synthesizes the correct GL error if invalid. Returns true if valid. | 1345 // Synthesizes the correct GL error if invalid. Returns true if valid. |
1331 bool ValidateTextureParameters( | 1346 bool ValidateTextureParameters( |
1332 const char* function_name, | 1347 const char* function_name, |
1333 GLenum target, GLenum format, GLenum type, GLint level); | 1348 GLenum target, GLenum format, GLenum type, GLint level); |
1334 | 1349 |
1335 bool ValidateCompressedTexDimensions( | 1350 bool ValidateCompressedTexDimensions( |
1336 const char* function_name, | 1351 const char* function_name, |
1337 GLint level, GLsizei width, GLsizei height, GLenum format); | 1352 GLint level, GLsizei width, GLsizei height, GLenum format); |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1542 | 1557 |
1543 bool compile_shader_always_succeeds_; | 1558 bool compile_shader_always_succeeds_; |
1544 | 1559 |
1545 bool disable_workarounds_; | 1560 bool disable_workarounds_; |
1546 | 1561 |
1547 #if defined(OS_MACOSX) | 1562 #if defined(OS_MACOSX) |
1548 typedef std::map<GLuint, CFTypeRef> TextureToIOSurfaceMap; | 1563 typedef std::map<GLuint, CFTypeRef> TextureToIOSurfaceMap; |
1549 TextureToIOSurfaceMap texture_to_io_surface_map_; | 1564 TextureToIOSurfaceMap texture_to_io_surface_map_; |
1550 #endif | 1565 #endif |
1551 | 1566 |
1567 #if defined(USE_X11) | |
1568 typedef std::map< | |
1569 GLuint, scoped_refptr<gfx::GLSurface> > TextureToPixmapGLSurfaceMap; | |
1570 TextureToPixmapGLSurfaceMap texture_to_pixmap_gl_surface_map_; | |
greggman
2012/06/13 00:15:51
What happens if I use this texture from another co
| |
1571 #endif | |
1572 | |
1552 typedef std::vector<GLES2DecoderImpl*> ChildList; | 1573 typedef std::vector<GLES2DecoderImpl*> ChildList; |
1553 ChildList children_; | 1574 ChildList children_; |
1554 | 1575 |
1555 scoped_ptr<CopyTextureCHROMIUMResourceManager> copy_texture_CHROMIUM_; | 1576 scoped_ptr<CopyTextureCHROMIUMResourceManager> copy_texture_CHROMIUM_; |
1556 | 1577 |
1557 // Cached values of the currently assigned viewport dimensions. | 1578 // Cached values of the currently assigned viewport dimensions. |
1558 GLint viewport_x_, viewport_y_; | 1579 GLint viewport_x_, viewport_y_; |
1559 GLsizei viewport_width_, viewport_height_; | 1580 GLsizei viewport_width_, viewport_height_; |
1560 GLsizei viewport_max_width_, viewport_max_height_; | 1581 GLsizei viewport_max_width_, viewport_max_height_; |
1561 | 1582 |
(...skipping 939 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2501 } | 2522 } |
2502 GLuint service_id = texture->service_id(); | 2523 GLuint service_id = texture->service_id(); |
2503 if (texture->IsStreamTexture() && stream_texture_manager_) { | 2524 if (texture->IsStreamTexture() && stream_texture_manager_) { |
2504 stream_texture_manager_->DestroyStreamTexture(service_id); | 2525 stream_texture_manager_->DestroyStreamTexture(service_id); |
2505 } | 2526 } |
2506 #if defined(OS_MACOSX) | 2527 #if defined(OS_MACOSX) |
2507 if (texture->target() == GL_TEXTURE_RECTANGLE_ARB) { | 2528 if (texture->target() == GL_TEXTURE_RECTANGLE_ARB) { |
2508 ReleaseIOSurfaceForTexture(service_id); | 2529 ReleaseIOSurfaceForTexture(service_id); |
2509 } | 2530 } |
2510 #endif | 2531 #endif |
2532 #if defined(USE_X11) | |
2533 ReleaseGLXPixmapForTexture(service_id); | |
2534 #endif | |
2511 RemoveTextureInfo(client_ids[ii]); | 2535 RemoveTextureInfo(client_ids[ii]); |
2512 } | 2536 } |
2513 } | 2537 } |
2514 } | 2538 } |
2515 | 2539 |
2516 // } // anonymous namespace | 2540 // } // anonymous namespace |
2517 | 2541 |
2518 bool GLES2DecoderImpl::MakeCurrent() { | 2542 bool GLES2DecoderImpl::MakeCurrent() { |
2519 if (!context_.get() || !context_->MakeCurrent(surface_.get())) | 2543 if (!context_.get() || !context_->MakeCurrent(surface_.get())) |
2520 return false; | 2544 return false; |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2851 offscreen_resolved_frame_buffer_.reset(); | 2875 offscreen_resolved_frame_buffer_.reset(); |
2852 offscreen_resolved_color_texture_.reset(); | 2876 offscreen_resolved_color_texture_.reset(); |
2853 | 2877 |
2854 #if defined(OS_MACOSX) | 2878 #if defined(OS_MACOSX) |
2855 for (TextureToIOSurfaceMap::iterator it = texture_to_io_surface_map_.begin(); | 2879 for (TextureToIOSurfaceMap::iterator it = texture_to_io_surface_map_.begin(); |
2856 it != texture_to_io_surface_map_.end(); ++it) { | 2880 it != texture_to_io_surface_map_.end(); ++it) { |
2857 CFRelease(it->second); | 2881 CFRelease(it->second); |
2858 } | 2882 } |
2859 texture_to_io_surface_map_.clear(); | 2883 texture_to_io_surface_map_.clear(); |
2860 #endif | 2884 #endif |
2885 | |
2886 #if defined(USE_X11) | |
2887 for (TextureToPixmapGLSurfaceMap::iterator it = | |
2888 texture_to_pixmap_gl_surface_map_.begin(); | |
2889 it != texture_to_pixmap_gl_surface_map_.end(); ++it) { | |
2890 scoped_refptr<gfx::GLSurface> pixmap_gl_surface = it->second; | |
2891 glXReleaseTexImageEXT( | |
2892 static_cast<gfx::GLContextGLX*>(GetGLContext())->display(), | |
piman
2012/06/12 23:15:38
This is not a safe cast when based only on USE_X11
| |
2893 reinterpret_cast<GLXDrawable>(pixmap_gl_surface->GetHandle()), | |
2894 GLX_FRONT_LEFT_EXT); | |
2895 } | |
2896 texture_to_pixmap_gl_surface_map_.clear(); | |
2897 #endif | |
2861 } | 2898 } |
2862 | 2899 |
2863 void GLES2DecoderImpl::SetSurface( | 2900 void GLES2DecoderImpl::SetSurface( |
2864 const scoped_refptr<gfx::GLSurface>& surface) { | 2901 const scoped_refptr<gfx::GLSurface>& surface) { |
2865 DCHECK(context_->IsCurrent(NULL)); | 2902 DCHECK(context_->IsCurrent(NULL)); |
2866 DCHECK(surface_.get()); | 2903 DCHECK(surface_.get()); |
2867 surface_ = surface; | 2904 surface_ = surface; |
2868 RestoreCurrentFramebufferBindings(); | 2905 RestoreCurrentFramebufferBindings(); |
2869 } | 2906 } |
2870 | 2907 |
(...skipping 6130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9001 | 9038 |
9002 if (!texture_manager()->Restore(info, definition.release())) { | 9039 if (!texture_manager()->Restore(info, definition.release())) { |
9003 SetGLError(GL_INVALID_OPERATION, | 9040 SetGLError(GL_INVALID_OPERATION, |
9004 "glConsumeTextureCHROMIUM", "invalid texture"); | 9041 "glConsumeTextureCHROMIUM", "invalid texture"); |
9005 return; | 9042 return; |
9006 } | 9043 } |
9007 | 9044 |
9008 BindAndApplyTextureParameters(info); | 9045 BindAndApplyTextureParameters(info); |
9009 } | 9046 } |
9010 | 9047 |
9048 #if defined(USE_X11) | |
9049 void GLES2DecoderImpl::ReleaseGLXPixmapForTexture(GLuint texture_id) { | |
9050 TextureToPixmapGLSurfaceMap::iterator it = | |
9051 texture_to_pixmap_gl_surface_map_.find(texture_id); | |
9052 if (it != texture_to_pixmap_gl_surface_map_.end()) { | |
9053 // Found a previous GLXPixmap bound to this texture; release it. | |
9054 scoped_refptr<gfx::GLSurface> pixmap_gl_surface = it->second; | |
9055 glXReleaseTexImageEXT( | |
9056 static_cast<gfx::GLContextGLX*>(GetGLContext())->display(), | |
9057 reinterpret_cast<GLXDrawable>(pixmap_gl_surface->GetHandle()), | |
9058 GLX_FRONT_LEFT_EXT); | |
9059 texture_to_pixmap_gl_surface_map_.erase(it); | |
9060 } | |
9061 } | |
9062 #endif | |
9063 | |
9064 void GLES2DecoderImpl::DoTexImagePixmap2DCHROMIUM( | |
9065 GLenum target, GLuint pixmap_id) { | |
9066 #if defined(USE_X11) | |
9067 if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGL) { | |
9068 SetGLError(GL_INVALID_OPERATION, | |
9069 "glTexImageXPixmap2DCHROMIUM", "only supported on desktop GL"); | |
9070 return; | |
9071 } | |
9072 | |
9073 if (target != GL_TEXTURE_2D) { | |
9074 // This might be supported in the future. | |
9075 SetGLError( | |
9076 GL_INVALID_OPERATION, | |
9077 "glTexImagePixmap2DCHROMIUM", "requires TEXTURE_2D target"); | |
9078 return; | |
9079 } | |
9080 | |
9081 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); | |
9082 if (!info) { | |
9083 SetGLError(GL_INVALID_OPERATION, | |
9084 "glTexImagePixmap2DCHROMIUM", "no texture bound"); | |
9085 return; | |
9086 } | |
9087 if (info == texture_manager()->GetDefaultTextureInfo(target)) { | |
greggman
2012/06/13 00:15:51
Have you considered a new function
GetTextureInfo
| |
9088 // Maybe this is conceptually valid, but disallow it to avoid accidents. | |
9089 SetGLError(GL_INVALID_OPERATION, | |
9090 "glTexImagePixmap2DCHROMIUM", "can't bind default texture"); | |
9091 return; | |
9092 } | |
9093 | |
9094 if (pixmap_id) { | |
9095 scoped_refptr<gfx::GLSurface> pixmap_gl_surface; | |
9096 | |
9097 TextureToPixmapGLSurfaceMap::iterator it = | |
9098 texture_to_pixmap_gl_surface_map_.find(info->service_id()); | |
9099 if (it == texture_to_pixmap_gl_surface_map_.end() || | |
9100 reinterpret_cast<XID>(it->second->GetShareHandle()) != pixmap_id) { | |
9101 pixmap_gl_surface = new gfx::PixmapGLSurfaceGLX(pixmap_id); | |
9102 if (!pixmap_gl_surface->Initialize()) { | |
9103 SetGLError(GL_INVALID_OPERATION, | |
9104 "glTexImagePixmap2DCHROMIUM", "fail to create GLXPixmap " | |
9105 "from Pixmap with the given ID"); | |
9106 return; | |
9107 } | |
9108 } else { | |
9109 pixmap_gl_surface = it->second; | |
9110 } | |
9111 | |
9112 // Release any GLXPixmap previously bound to this texture. | |
9113 ReleaseGLXPixmapForTexture(info->service_id()); | |
9114 | |
9115 glXBindTexImageEXT( | |
9116 static_cast<gfx::GLContextGLX*>(GetGLContext())->display(), | |
9117 reinterpret_cast<GLXDrawable>(pixmap_gl_surface->GetHandle()), | |
9118 GLX_FRONT_LEFT_EXT, | |
9119 0); | |
9120 | |
9121 texture_to_pixmap_gl_surface_map_.insert( | |
9122 std::make_pair(info->service_id(), pixmap_gl_surface)); | |
9123 | |
9124 gfx::Size size = pixmap_gl_surface->GetSize(); | |
9125 texture_manager()->SetLevelInfo( | |
greggman
2012/06/13 00:15:51
So mapping to a pix map magically sets the format
| |
9126 info, target, 0, GL_BGRA, size.width(), size.height(), 1, 0, | |
9127 GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, true); | |
9128 } else { | |
9129 // Release any GLXPixmap previously bound to this texture. | |
9130 ReleaseGLXPixmapForTexture(info->service_id()); | |
9131 | |
9132 texture_manager()->SetLevelCleared(info, GL_TEXTURE_2D, 0); | |
9133 } | |
9134 #else | |
9135 SetGLError(GL_INVALID_OPERATION, | |
9136 "glTexImagePixmap2DCHROMIUM", "not supported"); | |
9137 #endif | |
9138 } | |
9139 | |
9011 // Include the auto-generated part of this file. We split this because it means | 9140 // Include the auto-generated part of this file. We split this because it means |
9012 // we can easily edit the non-auto generated parts right here in this file | 9141 // we can easily edit the non-auto generated parts right here in this file |
9013 // instead of having to edit some template or the code generator. | 9142 // instead of having to edit some template or the code generator. |
9014 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 9143 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
9015 | 9144 |
9016 } // namespace gles2 | 9145 } // namespace gles2 |
9017 } // namespace gpu | 9146 } // namespace gpu |
OLD | NEW |