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 <limits.h> | 7 #include <limits.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <stdio.h> | 10 #include <stdio.h> |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 #include "gpu/command_buffer/service/program_manager.h" | 58 #include "gpu/command_buffer/service/program_manager.h" |
59 #include "gpu/command_buffer/service/query_manager.h" | 59 #include "gpu/command_buffer/service/query_manager.h" |
60 #include "gpu/command_buffer/service/renderbuffer_manager.h" | 60 #include "gpu/command_buffer/service/renderbuffer_manager.h" |
61 #include "gpu/command_buffer/service/sampler_manager.h" | 61 #include "gpu/command_buffer/service/sampler_manager.h" |
62 #include "gpu/command_buffer/service/shader_manager.h" | 62 #include "gpu/command_buffer/service/shader_manager.h" |
63 #include "gpu/command_buffer/service/shader_translator.h" | 63 #include "gpu/command_buffer/service/shader_translator.h" |
64 #include "gpu/command_buffer/service/texture_manager.h" | 64 #include "gpu/command_buffer/service/texture_manager.h" |
65 #include "gpu/command_buffer/service/transform_feedback_manager.h" | 65 #include "gpu/command_buffer/service/transform_feedback_manager.h" |
66 #include "gpu/command_buffer/service/vertex_array_manager.h" | 66 #include "gpu/command_buffer/service/vertex_array_manager.h" |
67 #include "gpu/command_buffer/service/vertex_attrib_manager.h" | 67 #include "gpu/command_buffer/service/vertex_attrib_manager.h" |
68 #include "gpu/ipc/common/gpu_surface_lookup.h" | |
68 #include "third_party/angle/src/image_util/loadimage.h" | 69 #include "third_party/angle/src/image_util/loadimage.h" |
69 #include "third_party/smhasher/src/City.h" | 70 #include "third_party/smhasher/src/City.h" |
70 #include "ui/gfx/buffer_types.h" | 71 #include "ui/gfx/buffer_types.h" |
71 #include "ui/gfx/geometry/point.h" | 72 #include "ui/gfx/geometry/point.h" |
72 #include "ui/gfx/geometry/rect.h" | 73 #include "ui/gfx/geometry/rect.h" |
73 #include "ui/gfx/geometry/rect_conversions.h" | 74 #include "ui/gfx/geometry/rect_conversions.h" |
74 #include "ui/gfx/geometry/size.h" | 75 #include "ui/gfx/geometry/size.h" |
75 #include "ui/gfx/gpu_memory_buffer.h" | 76 #include "ui/gfx/gpu_memory_buffer.h" |
76 #include "ui/gfx/overlay_transform.h" | 77 #include "ui/gfx/overlay_transform.h" |
77 #include "ui/gfx/transform.h" | 78 #include "ui/gfx/transform.h" |
78 #include "ui/gl/ca_renderer_layer_params.h" | 79 #include "ui/gl/ca_renderer_layer_params.h" |
79 #include "ui/gl/gl_bindings.h" | 80 #include "ui/gl/gl_bindings.h" |
80 #include "ui/gl/gl_context.h" | 81 #include "ui/gl/gl_context.h" |
81 #include "ui/gl/gl_fence.h" | 82 #include "ui/gl/gl_fence.h" |
82 #include "ui/gl/gl_image.h" | 83 #include "ui/gl/gl_image.h" |
83 #include "ui/gl/gl_implementation.h" | 84 #include "ui/gl/gl_implementation.h" |
84 #include "ui/gl/gl_surface.h" | 85 #include "ui/gl/gl_surface.h" |
86 #include "ui/gl/gl_surface_egl.h" | |
85 #include "ui/gl/gl_version_info.h" | 87 #include "ui/gl/gl_version_info.h" |
86 #include "ui/gl/gpu_timing.h" | 88 #include "ui/gl/gpu_timing.h" |
87 | 89 |
88 #if defined(OS_MACOSX) | 90 #if defined(OS_MACOSX) |
89 #include <IOSurface/IOSurface.h> | 91 #include <IOSurface/IOSurface.h> |
90 // Note that this must be included after gl_bindings.h to avoid conflicts. | 92 // Note that this must be included after gl_bindings.h to avoid conflicts. |
91 #include <OpenGL/CGLIOSurface.h> | 93 #include <OpenGL/CGLIOSurface.h> |
92 #endif | 94 #endif |
93 | 95 |
94 namespace gpu { | 96 namespace gpu { |
(...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1028 | 1030 |
1029 void DoMatrixLoadfCHROMIUM(GLenum matrix_mode, | 1031 void DoMatrixLoadfCHROMIUM(GLenum matrix_mode, |
1030 const volatile GLfloat* matrix); | 1032 const volatile GLfloat* matrix); |
1031 void DoMatrixLoadIdentityCHROMIUM(GLenum matrix_mode); | 1033 void DoMatrixLoadIdentityCHROMIUM(GLenum matrix_mode); |
1032 void DoScheduleCALayerInUseQueryCHROMIUM(GLsizei count, | 1034 void DoScheduleCALayerInUseQueryCHROMIUM(GLsizei count, |
1033 const volatile GLuint* textures); | 1035 const volatile GLuint* textures); |
1034 | 1036 |
1035 void DoFlushMappedBufferRange( | 1037 void DoFlushMappedBufferRange( |
1036 GLenum target, GLintptr offset, GLsizeiptr size); | 1038 GLenum target, GLintptr offset, GLsizeiptr size); |
1037 | 1039 |
1040 void DoSetSurfaceHandleCHROMIUM(GLint surface_handle); | |
1041 | |
1038 // Creates a Program for the given program. | 1042 // Creates a Program for the given program. |
1039 Program* CreateProgram(GLuint client_id, GLuint service_id) { | 1043 Program* CreateProgram(GLuint client_id, GLuint service_id) { |
1040 return program_manager()->CreateProgram(client_id, service_id); | 1044 return program_manager()->CreateProgram(client_id, service_id); |
1041 } | 1045 } |
1042 | 1046 |
1043 // Gets the program info for the given program. Returns NULL if none exists. | 1047 // Gets the program info for the given program. Returns NULL if none exists. |
1044 Program* GetProgram(GLuint client_id) { | 1048 Program* GetProgram(GLuint client_id) { |
1045 return program_manager()->GetProgram(client_id); | 1049 return program_manager()->GetProgram(client_id); |
1046 } | 1050 } |
1047 | 1051 |
(...skipping 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2125 Error Handle##name(uint32_t immediate_data_size, const volatile void* data); | 2129 Error Handle##name(uint32_t immediate_data_size, const volatile void* data); |
2126 | 2130 |
2127 GLES2_COMMAND_LIST(GLES2_CMD_OP) | 2131 GLES2_COMMAND_LIST(GLES2_CMD_OP) |
2128 | 2132 |
2129 #undef GLES2_CMD_OP | 2133 #undef GLES2_CMD_OP |
2130 | 2134 |
2131 // The GL context this decoder renders to on behalf of the client. | 2135 // The GL context this decoder renders to on behalf of the client. |
2132 scoped_refptr<gl::GLSurface> surface_; | 2136 scoped_refptr<gl::GLSurface> surface_; |
2133 scoped_refptr<gl::GLContext> context_; | 2137 scoped_refptr<gl::GLContext> context_; |
2134 | 2138 |
2139 // Direct render mode data for switching and restoring the | |
2140 // underlying destination surface, cf. DoSetSurfaceHandleCHROMIUM. | |
2141 scoped_refptr<gl::GLSurface> direct_render_surface_; | |
2142 scoped_refptr<gl::GLSurface> direct_render_orig_surface_; | |
2143 std::unique_ptr<BackFramebuffer> | |
2144 direct_render_orig_offscreen_target_frame_buffer_; | |
2145 bool direct_render_orig_supports_async_swap_; | |
2146 bool direct_render_orig_back_buffer_has_depth_; | |
2147 | |
2135 // The ContextGroup for this decoder uses to track resources. | 2148 // The ContextGroup for this decoder uses to track resources. |
2136 scoped_refptr<ContextGroup> group_; | 2149 scoped_refptr<ContextGroup> group_; |
2137 | 2150 |
2138 DebugMarkerManager debug_marker_manager_; | 2151 DebugMarkerManager debug_marker_manager_; |
2139 Logger logger_; | 2152 Logger logger_; |
2140 | 2153 |
2141 // All the state for this context. | 2154 // All the state for this context. |
2142 ContextState state_; | 2155 ContextState state_; |
2143 | 2156 |
2144 std::unique_ptr<TransformFeedbackManager> transform_feedback_manager_; | 2157 std::unique_ptr<TransformFeedbackManager> transform_feedback_manager_; |
(...skipping 14772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
16917 static const char kFunctionName[] = | 16930 static const char kFunctionName[] = |
16918 "glApplyScreenSpaceAntialiasingCHROMIUM"; | 16931 "glApplyScreenSpaceAntialiasingCHROMIUM"; |
16919 if (!InitializeCopyTextureCHROMIUM(kFunctionName)) | 16932 if (!InitializeCopyTextureCHROMIUM(kFunctionName)) |
16920 return; | 16933 return; |
16921 apply_framebuffer_attachment_cmaa_intel_ | 16934 apply_framebuffer_attachment_cmaa_intel_ |
16922 ->ApplyFramebufferAttachmentCMAAINTEL(this, bound_framebuffer, | 16935 ->ApplyFramebufferAttachmentCMAAINTEL(this, bound_framebuffer, |
16923 copy_texture_CHROMIUM_.get()); | 16936 copy_texture_CHROMIUM_.get()); |
16924 } | 16937 } |
16925 } | 16938 } |
16926 | 16939 |
16940 void GLES2DecoderImpl::DoSetSurfaceHandleCHROMIUM(GLint surface_handle) { | |
16941 #if defined(OS_ANDROID) | |
16942 if (surface_handle) { | |
16943 // Use the specified surface as a render target, saving the offscreen | |
16944 // render buffer so that we can restore it later. | |
16945 | |
16946 // Ignore redundant calls. For now we don't support switching between | |
16947 // different surfaces, if you need this you have to make a call with | |
16948 // surface_handle=0 in between. | |
16949 if (direct_render_surface_) { | |
16950 return; | |
16951 } | |
16952 | |
16953 // One-time initialization when first activating a direct draw surface. | |
16954 ANativeWindow* window = | |
16955 gpu::GpuSurfaceLookup::GetInstance()->AcquireNativeWidget( | |
16956 surface_handle); | |
16957 direct_render_surface_ = new gl::NativeViewGLSurfaceEGL(window); | |
16958 // TODO(klausw): need to add a depth buffer for doing 3D rendering. | |
16959 // Currently it's just used for a 2D copy. | |
16960 bool initialize_success = | |
16961 direct_render_surface_->Initialize(gl::GLSurface::SURFACE_ARGB8888); | |
bajones
2016/11/08 05:17:01
The format of this surface should be the same as t
klausw
2016/11/08 18:45:05
Yes, done, and added a comment explaining why we c
| |
16962 if (!initialize_success) { | |
16963 LOG(ERROR) << "Direct render surface init failed for handle " << | |
16964 surface_handle; | |
16965 } | |
16966 ANativeWindow_release(window); | |
16967 | |
16968 direct_render_orig_surface_ = surface_; | |
16969 | |
16970 // We don't want async swap since we want full control over when the | |
16971 // SurfaceTexture gets updated. | |
16972 direct_render_orig_supports_async_swap_ = supports_async_swap_; | |
16973 supports_async_swap_ = false; | |
16974 direct_render_orig_back_buffer_has_depth_ = back_buffer_has_depth_; | |
16975 back_buffer_has_depth_ = true; | |
16976 // override back_buffer_has_stencil_ too? | |
16977 | |
16978 // Offscreen surfaces don't support SwapBuffers, make sure it's not | |
16979 // considered offscreen. Various code in this file checks for is_offscreen | |
16980 // = !!offscreen_target_frame_buffer_.get(). | |
16981 direct_render_orig_offscreen_target_frame_buffer_ = | |
16982 std::move(offscreen_target_frame_buffer_); | |
16983 offscreen_target_frame_buffer_.reset(nullptr); | |
16984 | |
16985 // Activate the surface. This does *not* rebind the active framebuffer, | |
16986 // callers must do so themselves. | |
16987 SetSurface(direct_render_surface_); | |
16988 | |
16989 // TODO(klausw): is any additional cleanup needed in destructor, or | |
16990 // do smart pointers do the right thing already? | |
16991 } else { | |
16992 // Restore original state for drawing offscreen. | |
16993 | |
16994 // Ignore redundant calls. | |
16995 if (!direct_render_surface_) return; | |
16996 | |
16997 // TODO(klausw): check if this is sufficient cleanup, I'm assuming that | |
16998 // clearing the smart pointer calls the appropriate destructor. | |
bajones
2016/11/08 05:17:01
Correct. The smart pointers will call the destruct
klausw
2016/11/08 18:45:05
OK, removed the comment.
| |
16999 direct_render_surface_ = nullptr; | |
17000 | |
17001 supports_async_swap_ = direct_render_orig_supports_async_swap_; | |
17002 back_buffer_has_depth_ = direct_render_orig_back_buffer_has_depth_; | |
17003 | |
17004 offscreen_target_frame_buffer_ = | |
17005 std::move(direct_render_orig_offscreen_target_frame_buffer_); | |
17006 direct_render_orig_offscreen_target_frame_buffer_.reset(nullptr); | |
17007 | |
17008 SetSurface(direct_render_orig_surface_); | |
17009 } | |
17010 #else // !OS_ANDROID | |
17011 LOCAL_SET_GL_ERROR( | |
17012 GL_INVALID_OPERATION, | |
17013 "glSetSurfaceHandleCHROMIUM", | |
17014 "Direct render surface is unsupported on this platform"); | |
17015 #endif | |
17016 } | |
17017 | |
16927 void GLES2DecoderImpl::DoInsertEventMarkerEXT( | 17018 void GLES2DecoderImpl::DoInsertEventMarkerEXT( |
16928 GLsizei length, const GLchar* marker) { | 17019 GLsizei length, const GLchar* marker) { |
16929 if (!marker) { | 17020 if (!marker) { |
16930 marker = ""; | 17021 marker = ""; |
16931 } | 17022 } |
16932 debug_marker_manager_.SetMarker( | 17023 debug_marker_manager_.SetMarker( |
16933 length ? std::string(marker, length) : std::string(marker)); | 17024 length ? std::string(marker, length) : std::string(marker)); |
16934 } | 17025 } |
16935 | 17026 |
16936 void GLES2DecoderImpl::DoPushGroupMarkerEXT( | 17027 void GLES2DecoderImpl::DoPushGroupMarkerEXT( |
(...skipping 1846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
18783 } | 18874 } |
18784 | 18875 |
18785 // Include the auto-generated part of this file. We split this because it means | 18876 // Include the auto-generated part of this file. We split this because it means |
18786 // we can easily edit the non-auto generated parts right here in this file | 18877 // we can easily edit the non-auto generated parts right here in this file |
18787 // instead of having to edit some template or the code generator. | 18878 // instead of having to edit some template or the code generator. |
18788 #include "base/macros.h" | 18879 #include "base/macros.h" |
18789 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 18880 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
18790 | 18881 |
18791 } // namespace gles2 | 18882 } // namespace gles2 |
18792 } // namespace gpu | 18883 } // namespace gpu |
OLD | NEW |