OLD | NEW |
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/gpu_scheduler.h" | 5 #include "gpu/command_buffer/service/gpu_scheduler.h" |
6 #include "ui/gfx/gl/gl_context.h" | 6 #include "ui/gfx/gl/gl_context.h" |
7 #include "ui/gfx/gl/gl_surface.h" | 7 #include "ui/gfx/gl/gl_surface.h" |
8 | 8 |
9 using ::base::SharedMemory; | 9 using ::base::SharedMemory; |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... |
32 scoped_ptr<gfx::GLSurface> surface( | 32 scoped_ptr<gfx::GLSurface> surface( |
33 gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1))); | 33 gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1))); |
34 if (!surface.get()) { | 34 if (!surface.get()) { |
35 LOG(ERROR) << "CreateOffscreenGLSurface failed.\n"; | 35 LOG(ERROR) << "CreateOffscreenGLSurface failed.\n"; |
36 Destroy(); | 36 Destroy(); |
37 return false; | 37 return false; |
38 } | 38 } |
39 | 39 |
40 // Create a GLContext and attach the surface. | 40 // Create a GLContext and attach the surface. |
41 scoped_ptr<gfx::GLContext> context( | 41 scoped_ptr<gfx::GLContext> context( |
42 gfx::GLContext::CreateGLContext(surface.release(), parent_context)); | 42 gfx::GLContext::CreateGLContext(parent_context, surface.get())); |
43 if (!context.get()) { | 43 if (!context.get()) { |
44 LOG(ERROR) << "CreateGLContext failed.\n"; | 44 LOG(ERROR) << "CreateGLContext failed.\n"; |
45 Destroy(); | 45 Destroy(); |
46 return false; | 46 return false; |
47 } | 47 } |
48 | 48 |
49 // On Mac OS X since we can not render on-screen we don't even | 49 // On Mac OS X since we can not render on-screen we don't even |
50 // attempt to create a view based GLContext. The only difference | 50 // attempt to create a view based GLContext. The only difference |
51 // between "on-screen" and "off-screen" rendering on this platform | 51 // between "on-screen" and "off-screen" rendering on this platform |
52 // is whether we allocate an AcceleratedSurface, which transmits the | 52 // is whether we allocate an AcceleratedSurface, which transmits the |
53 // rendering results back to the browser. | 53 // rendering results back to the browser. |
54 if (window) { | 54 if (window) { |
55 surface_.reset(new AcceleratedSurface()); | 55 surface_.reset(new AcceleratedSurface()); |
56 | 56 |
57 // Note that although the GLContext is passed to Initialize and the | 57 // Note that although the GLContext is passed to Initialize and the |
58 // GLContext will later be owned by the decoder, AcceleratedSurface does | 58 // GLContext will later be owned by the decoder, AcceleratedSurface does |
59 // not hold on to the reference. It simply extracts the underlying GL | 59 // not hold on to the reference. It simply extracts the underlying GL |
60 // context in order to share the namespace with another context. | 60 // context in order to share the namespace with another context. |
61 if (!surface_->Initialize(context.get(), false)) { | 61 if (!surface_->Initialize(context.get(), false)) { |
62 LOG(ERROR) << "GpuScheduler::Initialize failed to " | 62 LOG(ERROR) << "GpuScheduler::Initialize failed to " |
63 << "initialize AcceleratedSurface."; | 63 << "initialize AcceleratedSurface."; |
64 Destroy(); | 64 Destroy(); |
65 return false; | 65 return false; |
66 } | 66 } |
67 } | 67 } |
68 | 68 |
69 return InitializeCommon(context.release(), | 69 return InitializeCommon(surface.release(), |
| 70 context.release(), |
70 size, | 71 size, |
71 disallowed_extensions, | 72 disallowed_extensions, |
72 allowed_extensions, | 73 allowed_extensions, |
73 attribs, | 74 attribs, |
74 parent_decoder, | 75 parent_decoder, |
75 parent_texture_id); | 76 parent_texture_id); |
76 } | 77 } |
77 | 78 |
78 void GpuScheduler::Destroy() { | 79 void GpuScheduler::Destroy() { |
79 if (surface_.get()) { | 80 if (surface_.get()) { |
80 surface_->Destroy(); | 81 surface_->Destroy(); |
81 surface_.reset(); | 82 surface_.reset(); |
82 } | 83 } |
83 | 84 |
84 DestroyCommon(); | 85 DestroyCommon(); |
85 } | 86 } |
86 | 87 |
87 uint64 GpuScheduler::SetWindowSizeForIOSurface(const gfx::Size& size) { | 88 uint64 GpuScheduler::SetWindowSizeForIOSurface(const gfx::Size& size) { |
88 // This is called from an IPC handler, so it's undefined which context is | 89 // This is called from an IPC handler, so it's undefined which context is |
89 // current. Make sure the right one is. | 90 // current. Make sure the right one is. |
90 decoder_->GetGLContext()->MakeCurrent(); | 91 decoder_->GetGLContext()->MakeCurrent(decoder_->GetGLSurface()); |
91 | 92 |
92 ResizeOffscreenFrameBuffer(size); | 93 ResizeOffscreenFrameBuffer(size); |
93 decoder_->UpdateOffscreenFrameBufferSize(); | 94 decoder_->UpdateOffscreenFrameBufferSize(); |
94 | 95 |
95 // Note: The following line changes the current context again. | 96 // Note: The following line changes the current context again. |
96 return surface_->SetSurfaceSize(size); | 97 return surface_->SetSurfaceSize(size); |
97 } | 98 } |
98 | 99 |
99 TransportDIB::Handle GpuScheduler::SetWindowSizeForTransportDIB( | 100 TransportDIB::Handle GpuScheduler::SetWindowSizeForTransportDIB( |
100 const gfx::Size& size) { | 101 const gfx::Size& size) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 // but since the browser window is already closed, it will never arrive. | 137 // but since the browser window is already closed, it will never arrive. |
137 // To break this infinite loop, the browser tells the GPU process that the | 138 // To break this infinite loop, the browser tells the GPU process that the |
138 // surface became invalid, which causes the GPU process to not wait for paint | 139 // surface became invalid, which causes the GPU process to not wait for paint |
139 // acks. | 140 // acks. |
140 surface_.reset(); | 141 surface_.reset(); |
141 } | 142 } |
142 | 143 |
143 void GpuScheduler::WillSwapBuffers() { | 144 void GpuScheduler::WillSwapBuffers() { |
144 DCHECK(decoder_.get()); | 145 DCHECK(decoder_.get()); |
145 DCHECK(decoder_->GetGLContext()); | 146 DCHECK(decoder_->GetGLContext()); |
146 DCHECK(decoder_->GetGLContext()->IsCurrent()); | 147 DCHECK(decoder_->GetGLContext()->IsCurrent(decoder_->GetGLSurface())); |
147 | 148 |
148 ++swap_buffers_count_; | 149 ++swap_buffers_count_; |
149 | 150 |
150 if (surface_.get()) { | 151 if (surface_.get()) { |
151 surface_->SwapBuffers(); | 152 surface_->SwapBuffers(); |
152 } | 153 } |
153 | 154 |
154 if (wrapped_swap_buffers_callback_.get()) { | 155 if (wrapped_swap_buffers_callback_.get()) { |
155 wrapped_swap_buffers_callback_->Run(); | 156 wrapped_swap_buffers_callback_->Run(); |
156 } | 157 } |
157 } | 158 } |
158 | 159 |
159 } // namespace gpu | 160 } // namespace gpu |
OLD | NEW |