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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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/shader_translator_cache.h" | 46 #include "gpu/command_buffer/service/shader_translator_cache.h" |
47 #include "gpu/command_buffer/service/stream_texture.h" | 47 #include "gpu/command_buffer/service/stream_texture.h" |
48 #include "gpu/command_buffer/service/stream_texture_manager.h" | 48 #include "gpu/command_buffer/service/stream_texture_manager.h" |
49 #include "gpu/command_buffer/service/texture_definition.h" | 49 #include "gpu/command_buffer/service/texture_definition.h" |
50 #include "gpu/command_buffer/service/texture_manager.h" | 50 #include "gpu/command_buffer/service/texture_manager.h" |
51 #include "gpu/command_buffer/service/vertex_attrib_manager.h" | 51 #include "gpu/command_buffer/service/vertex_attrib_manager.h" |
52 #include "ui/gl/gl_context.h" | 52 #include "ui/gl/gl_context.h" |
| 53 #include "ui/gl/gl_image.h" |
53 #include "ui/gl/gl_implementation.h" | 54 #include "ui/gl/gl_implementation.h" |
54 #include "ui/gl/gl_surface.h" | 55 #include "ui/gl/gl_surface.h" |
55 #if defined(OS_MACOSX) | 56 #if defined(OS_MACOSX) |
56 #include "ui/surface/io_surface_support_mac.h" | 57 #include "ui/surface/io_surface_support_mac.h" |
57 #endif | 58 #endif |
58 | 59 |
59 #if !defined(GL_DEPTH24_STENCIL8) | 60 #if !defined(GL_DEPTH24_STENCIL8) |
60 #define GL_DEPTH24_STENCIL8 0x88F0 | 61 #define GL_DEPTH24_STENCIL8 0x88F0 |
61 #endif | 62 #endif |
62 | 63 |
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 GLenum internal_format); | 759 GLenum internal_format); |
759 | 760 |
760 // Wrapper for TexStorage2DEXT. | 761 // Wrapper for TexStorage2DEXT. |
761 void DoTexStorage2DEXT( | 762 void DoTexStorage2DEXT( |
762 GLenum target, | 763 GLenum target, |
763 GLint levels, | 764 GLint levels, |
764 GLenum internal_format, | 765 GLenum internal_format, |
765 GLsizei width, | 766 GLsizei width, |
766 GLsizei height); | 767 GLsizei height); |
767 | 768 |
| 769 // Wrapper for TexImagePixmap2DCHROMIUM. |
| 770 void DoTexImagePixmap2DCHROMIUM( |
| 771 GLenum target, |
| 772 GLuint pixmap_id); |
| 773 |
768 void DoProduceTextureCHROMIUM(GLenum target, const GLbyte* key); | 774 void DoProduceTextureCHROMIUM(GLenum target, const GLbyte* key); |
769 void DoConsumeTextureCHROMIUM(GLenum target, const GLbyte* key); | 775 void DoConsumeTextureCHROMIUM(GLenum target, const GLbyte* key); |
770 | 776 |
771 // Creates a ProgramInfo for the given program. | 777 // Creates a ProgramInfo for the given program. |
772 ProgramManager::ProgramInfo* CreateProgramInfo( | 778 ProgramManager::ProgramInfo* CreateProgramInfo( |
773 GLuint client_id, GLuint service_id) { | 779 GLuint client_id, GLuint service_id) { |
774 return program_manager()->CreateProgramInfo(client_id, service_id); | 780 return program_manager()->CreateProgramInfo(client_id, service_id); |
775 } | 781 } |
776 | 782 |
777 // Gets the program info for the given program. Returns NULL if none exists. | 783 // Gets the program info for the given program. Returns NULL if none exists. |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1254 case GL_TEXTURE_RECTANGLE_ARB: | 1260 case GL_TEXTURE_RECTANGLE_ARB: |
1255 info = unit.bound_texture_rectangle_arb; | 1261 info = unit.bound_texture_rectangle_arb; |
1256 break; | 1262 break; |
1257 default: | 1263 default: |
1258 NOTREACHED(); | 1264 NOTREACHED(); |
1259 return NULL; | 1265 return NULL; |
1260 } | 1266 } |
1261 return info; | 1267 return info; |
1262 } | 1268 } |
1263 | 1269 |
| 1270 TextureManager::TextureInfo* GetTextureInfoForTargetUnlessDefault( |
| 1271 GLenum target) { |
| 1272 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); |
| 1273 if (!info) |
| 1274 return NULL; |
| 1275 if (info == texture_manager()->GetDefaultTextureInfo(target)) |
| 1276 return NULL; |
| 1277 return info; |
| 1278 } |
| 1279 |
1264 GLenum GetBindTargetForSamplerType(GLenum type) { | 1280 GLenum GetBindTargetForSamplerType(GLenum type) { |
1265 DCHECK(type == GL_SAMPLER_2D || type == GL_SAMPLER_CUBE || | 1281 DCHECK(type == GL_SAMPLER_2D || type == GL_SAMPLER_CUBE || |
1266 type == GL_SAMPLER_EXTERNAL_OES || type == GL_SAMPLER_2D_RECT_ARB); | 1282 type == GL_SAMPLER_EXTERNAL_OES || type == GL_SAMPLER_2D_RECT_ARB); |
1267 switch (type) { | 1283 switch (type) { |
1268 case GL_SAMPLER_2D: | 1284 case GL_SAMPLER_2D: |
1269 return GL_TEXTURE_2D; | 1285 return GL_TEXTURE_2D; |
1270 case GL_SAMPLER_CUBE: | 1286 case GL_SAMPLER_CUBE: |
1271 return GL_TEXTURE_CUBE_MAP; | 1287 return GL_TEXTURE_CUBE_MAP; |
1272 case GL_SAMPLER_EXTERNAL_OES: | 1288 case GL_SAMPLER_EXTERNAL_OES: |
1273 return GL_TEXTURE_EXTERNAL_OES; | 1289 return GL_TEXTURE_EXTERNAL_OES; |
(...skipping 7521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8795 // support for binding an IOSurface to a NPOT TEXTURE_2D texture, we | 8811 // support for binding an IOSurface to a NPOT TEXTURE_2D texture, we |
8796 // could delete a lot of code. For now, perform strict validation so we | 8812 // could delete a lot of code. For now, perform strict validation so we |
8797 // know what's going on. | 8813 // know what's going on. |
8798 SetGLError( | 8814 SetGLError( |
8799 GL_INVALID_OPERATION, | 8815 GL_INVALID_OPERATION, |
8800 "glTexImageIOSurface2DCHROMIUM", | 8816 "glTexImageIOSurface2DCHROMIUM", |
8801 "requires TEXTURE_RECTANGLE_ARB target"); | 8817 "requires TEXTURE_RECTANGLE_ARB target"); |
8802 return; | 8818 return; |
8803 } | 8819 } |
8804 | 8820 |
8805 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); | 8821 // Default target might be conceptually valid, but disallow it to avoid |
| 8822 // accidents. |
| 8823 TextureManager::TextureInfo* info = GetTextureInfoForTargetUnlessDefault( |
| 8824 target); |
8806 if (!info) { | 8825 if (!info) { |
8807 SetGLError(GL_INVALID_OPERATION, | 8826 SetGLError(GL_INVALID_OPERATION, |
8808 "glTexImageIOSurface2DCHROMIUM", "no rectangle texture bound"); | 8827 "glTexImageIOSurface2DCHROMIUM", "no rectangle texture bound"); |
8809 return; | 8828 return; |
8810 } | 8829 } |
8811 if (info == texture_manager()->GetDefaultTextureInfo(target)) { | |
8812 // Maybe this is conceptually valid, but disallow it to avoid accidents. | |
8813 SetGLError(GL_INVALID_OPERATION, | |
8814 "glTexImageIOSurface2DCHROMIUM", "can't bind default texture"); | |
8815 return; | |
8816 } | |
8817 | 8830 |
8818 // Look up the new IOSurface. Note that because of asynchrony | 8831 // Look up the new IOSurface. Note that because of asynchrony |
8819 // between processes this might fail; during live resizing the | 8832 // between processes this might fail; during live resizing the |
8820 // plugin process might allocate and release an IOSurface before | 8833 // plugin process might allocate and release an IOSurface before |
8821 // this process gets a chance to look it up. Hold on to any old | 8834 // this process gets a chance to look it up. Hold on to any old |
8822 // IOSurface in this case. | 8835 // IOSurface in this case. |
8823 CFTypeRef surface = surface_support->IOSurfaceLookup(io_surface_id); | 8836 CFTypeRef surface = surface_support->IOSurfaceLookup(io_surface_id); |
8824 if (!surface) { | 8837 if (!surface) { |
8825 SetGLError( | 8838 SetGLError( |
8826 GL_INVALID_OPERATION, | 8839 GL_INVALID_OPERATION, |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9182 | 9195 |
9183 if (!texture_manager()->Restore(info, definition.release())) { | 9196 if (!texture_manager()->Restore(info, definition.release())) { |
9184 SetGLError(GL_INVALID_OPERATION, | 9197 SetGLError(GL_INVALID_OPERATION, |
9185 "glConsumeTextureCHROMIUM", "invalid texture"); | 9198 "glConsumeTextureCHROMIUM", "invalid texture"); |
9186 return; | 9199 return; |
9187 } | 9200 } |
9188 | 9201 |
9189 BindAndApplyTextureParameters(info); | 9202 BindAndApplyTextureParameters(info); |
9190 } | 9203 } |
9191 | 9204 |
| 9205 void GLES2DecoderImpl::DoTexImagePixmap2DCHROMIUM( |
| 9206 GLenum target, GLuint pixmap_id) { |
| 9207 if (target != GL_TEXTURE_2D) { |
| 9208 // This might be supported in the future. |
| 9209 SetGLError( |
| 9210 GL_INVALID_OPERATION, |
| 9211 "glTexImagePixmap2DCHROMIUM", "requires TEXTURE_2D target"); |
| 9212 return; |
| 9213 } |
| 9214 |
| 9215 // Default target might be conceptually valid, but disallow it to avoid |
| 9216 // accidents. |
| 9217 TextureManager::TextureInfo* info = GetTextureInfoForTargetUnlessDefault( |
| 9218 target); |
| 9219 if (!info) { |
| 9220 SetGLError(GL_INVALID_OPERATION, |
| 9221 "glTexImagePixmap2DCHROMIUM", "no texture bound"); |
| 9222 return; |
| 9223 } |
| 9224 |
| 9225 scoped_refptr<gfx::GLImage> pixmap_gl_image = info->GetLevelImage(target, 0); |
| 9226 if (pixmap_id) { |
| 9227 if (!pixmap_gl_image) { |
| 9228 pixmap_gl_image = gfx::GLImage::CreatePixmapGLImage(surface_); |
| 9229 if (!pixmap_gl_image) { |
| 9230 SetGLError(GL_INVALID_OPERATION, |
| 9231 "glTexImagePixmap2DCHROMIUM", |
| 9232 "fail to create PixmapGLImage"); |
| 9233 return; |
| 9234 } |
| 9235 } |
| 9236 |
| 9237 // Update GL image and bind to texture. |
| 9238 if (!pixmap_gl_image->RebindPixmap(pixmap_id)) { |
| 9239 SetGLError(GL_INVALID_OPERATION, |
| 9240 "glTexImagePixmap2DCHROMIUM", |
| 9241 "fail to bind Pixmap with the given ID"); |
| 9242 return; |
| 9243 } |
| 9244 |
| 9245 gfx::Size size = pixmap_gl_image->GetSize(); |
| 9246 texture_manager()->SetLevelInfo( |
| 9247 info, target, 0, GL_RGBA, size.width(), size.height(), 1, 0, |
| 9248 GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, true); |
| 9249 texture_manager()->SetLevelImage(info, target, 0, pixmap_gl_image); |
| 9250 } else { |
| 9251 // Release pixmap image previously bound to this texture. |
| 9252 if (pixmap_gl_image) |
| 9253 pixmap_gl_image->RebindPixmap(0); |
| 9254 |
| 9255 texture_manager()->SetLevelInfo( |
| 9256 info, 0, 0, GL_RGBA, 0, 0, 1, 0, |
| 9257 GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, false); |
| 9258 } |
| 9259 } |
| 9260 |
9192 // Include the auto-generated part of this file. We split this because it means | 9261 // Include the auto-generated part of this file. We split this because it means |
9193 // we can easily edit the non-auto generated parts right here in this file | 9262 // we can easily edit the non-auto generated parts right here in this file |
9194 // instead of having to edit some template or the code generator. | 9263 // instead of having to edit some template or the code generator. |
9195 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 9264 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
9196 | 9265 |
9197 } // namespace gles2 | 9266 } // namespace gles2 |
9198 } // namespace gpu | 9267 } // namespace gpu |
OLD | NEW |