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/demos/framework/window.h" | 5 #include "gpu/demos/framework/window.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 | 37 |
38 Window::~Window() { | 38 Window::~Window() { |
39 demo_.reset(); | 39 demo_.reset(); |
40 | 40 |
41 // must free client before service. | 41 // must free client before service. |
42 gles2_implementation_.reset(); | 42 gles2_implementation_.reset(); |
43 transfer_buffer_.reset(); | 43 transfer_buffer_.reset(); |
44 gles2_cmd_helper_.reset(); | 44 gles2_cmd_helper_.reset(); |
45 | 45 |
46 if (decoder_.get()) { | 46 if (decoder_.get()) { |
47 decoder_->Destroy(); | 47 decoder_->Destroy(true); |
48 } | 48 } |
49 } | 49 } |
50 | 50 |
51 bool Window::Init(int width, int height) { | 51 bool Window::Init(int width, int height) { |
52 window_handle_ = CreateNativeWindow(demo_->Title(), width, height); | 52 window_handle_ = CreateNativeWindow(demo_->Title(), width, height); |
53 if (window_handle_ == NULL) | 53 if (window_handle_ == NULL) |
54 return false; | 54 return false; |
55 if (!CreateRenderContext(PluginWindow(window_handle_))) | 55 if (!CreateRenderContext(PluginWindow(window_handle_))) |
56 return false; | 56 return false; |
57 | 57 |
58 demo_->Resize(width, height); | 58 demo_->Resize(width, height); |
59 return demo_->InitGL(); | 59 return demo_->InitGL(); |
60 } | 60 } |
61 | 61 |
62 void Window::OnPaint() { | 62 void Window::OnPaint() { |
63 demo_->Draw(); | 63 demo_->Draw(); |
64 ::gles2::GetGLContext()->SwapBuffers(); | 64 ::gles2::GetGLContext()->SwapBuffers(); |
65 } | 65 } |
66 | 66 |
67 bool Window::CreateRenderContext(gfx::AcceleratedWidget hwnd) { | 67 bool Window::CreateRenderContext(gfx::AcceleratedWidget hwnd) { |
68 command_buffer_.reset(new CommandBufferService); | 68 command_buffer_.reset(new CommandBufferService); |
69 if (!command_buffer_->Initialize()) { | 69 if (!command_buffer_->Initialize()) { |
70 return false; | 70 return false; |
71 } | 71 } |
72 | 72 |
73 gpu::gles2::ContextGroup::Ref group(new gpu::gles2::ContextGroup(true)); | 73 gpu::gles2::ContextGroup::Ref group(new gpu::gles2::ContextGroup(NULL, true)); |
74 | 74 |
75 decoder_.reset(gpu::gles2::GLES2Decoder::Create(group.get())); | 75 decoder_.reset(gpu::gles2::GLES2Decoder::Create(group.get())); |
76 if (!decoder_.get()) | 76 if (!decoder_.get()) |
77 return false; | 77 return false; |
78 | 78 |
79 gpu_scheduler_.reset(new gpu::GpuScheduler(command_buffer_.get(), | 79 gpu_scheduler_.reset(new gpu::GpuScheduler(command_buffer_.get(), |
80 decoder_.get(), | 80 decoder_.get(), |
81 NULL)); | 81 NULL)); |
82 | 82 |
83 decoder_->set_engine(gpu_scheduler_.get()); | 83 decoder_->set_engine(gpu_scheduler_.get()); |
84 | 84 |
85 surface_ = gfx::GLSurface::CreateViewGLSurface(false, hwnd); | 85 surface_ = gfx::GLSurface::CreateViewGLSurface(false, hwnd); |
86 if (!surface_.get()) | 86 if (!surface_.get()) |
87 return false; | 87 return false; |
88 | 88 |
89 context_ = gfx::GLContext::CreateGLContext( | 89 context_ = gfx::GLContext::CreateGLContext( |
90 NULL, surface_.get(), gfx::PreferDiscreteGpu); | 90 NULL, surface_.get(), gfx::PreferDiscreteGpu); |
91 if (!context_.get()) | 91 if (!context_.get()) |
92 return false; | 92 return false; |
93 | 93 |
| 94 context_->MakeCurrent(surface_); |
| 95 |
94 std::vector<int32> attribs; | 96 std::vector<int32> attribs; |
95 if (!decoder_->Initialize(surface_.get(), | 97 if (!decoder_->Initialize(surface_.get(), |
96 context_.get(), | 98 context_.get(), |
97 surface_->IsOffscreen(), | 99 surface_->IsOffscreen(), |
98 gfx::Size(), | 100 gfx::Size(), |
99 gpu::gles2::DisallowedFeatures(), | 101 gpu::gles2::DisallowedFeatures(), |
100 NULL, | 102 NULL, |
101 attribs)) { | 103 attribs)) { |
102 return false; | 104 return false; |
103 } | 105 } |
(...skipping 26 matching lines...) Expand all Loading... |
130 kTransferBufferSize, | 132 kTransferBufferSize, |
131 kTransferBufferSize)) { | 133 kTransferBufferSize)) { |
132 return false; | 134 return false; |
133 } | 135 } |
134 | 136 |
135 return true; | 137 return true; |
136 } | 138 } |
137 | 139 |
138 } // namespace demos | 140 } // namespace demos |
139 } // namespace gpu | 141 } // namespace gpu |
OLD | NEW |