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 // This file implements a standalone executable demo of using GLES2 over | 5 // This file implements a standalone executable demo of using GLES2 over |
6 // command buffers. This code is temporary as the setup that happens | 6 // command buffers. This code is temporary as the setup that happens |
7 // here is in a state of flux. Eventually there will be several versions of | 7 // here is in a state of flux. Eventually there will be several versions of |
8 // setup, one for trusted code, one for pepper, one for NaCl, and maybe others. | 8 // setup, one for trusted code, one for pepper, one for NaCl, and maybe others. |
9 | 9 |
10 #include <windows.h> | 10 #include <windows.h> |
11 #include <windowsx.h> | 11 #include <windowsx.h> |
12 #include <shellapi.h> | 12 #include <shellapi.h> |
13 #include <stdlib.h> | 13 #include <stdlib.h> |
14 #include <stdio.h> | 14 #include <stdio.h> |
15 #include "base/at_exit.h" | 15 #include "base/at_exit.h" |
16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
17 #include "base/callback.h" | 17 #include "base/callback.h" |
18 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
19 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
20 #include "base/message_loop.h" | 20 #include "base/message_loop.h" |
21 #include "base/shared_memory.h" | 21 #include "base/shared_memory.h" |
| 22 #include "gpu/command_buffer/service/context_group.h" |
22 #include "gpu/command_buffer/service/gpu_scheduler.h" | 23 #include "gpu/command_buffer/service/gpu_scheduler.h" |
23 #include "gpu/command_buffer/service/command_buffer_service.h" | 24 #include "gpu/command_buffer/service/command_buffer_service.h" |
24 #include "gpu/command_buffer/client/gles2_implementation.h" | 25 #include "gpu/command_buffer/client/gles2_implementation.h" |
25 #include "gpu/command_buffer/client/gles2_lib.h" | 26 #include "gpu/command_buffer/client/gles2_lib.h" |
26 #include "gpu/command_buffer/client/gles2_demo_c.h" | 27 #include "gpu/command_buffer/client/gles2_demo_c.h" |
27 #include "gpu/command_buffer/client/gles2_demo_cc.h" | 28 #include "gpu/command_buffer/client/gles2_demo_cc.h" |
| 29 #include "ui/gfx/gl/gl_implementation.h" |
28 #include "ui/gfx/gl/gl_surface.h" | 30 #include "ui/gfx/gl/gl_surface.h" |
29 | 31 |
30 using base::SharedMemory; | 32 using base::SharedMemory; |
31 using gpu::Buffer; | 33 using gpu::Buffer; |
32 using gpu::GpuScheduler; | 34 using gpu::GpuScheduler; |
33 using gpu::CommandBufferService; | 35 using gpu::CommandBufferService; |
34 using gpu::gles2::GLES2CmdHelper; | 36 using gpu::gles2::GLES2CmdHelper; |
35 using gpu::gles2::GLES2Implementation; | 37 using gpu::gles2::GLES2Implementation; |
36 | 38 |
37 #if defined(OS_WIN) | 39 #if defined(OS_WIN) |
38 HINSTANCE g_instance; | 40 HINSTANCE g_instance; |
39 #endif | 41 #endif |
40 | 42 |
41 class GLES2Demo { | 43 class GLES2Demo { |
42 public: | 44 public: |
43 GLES2Demo(); | 45 GLES2Demo(); |
44 | 46 |
45 bool GLES2Demo::Setup(void* hwnd, int32 size); | 47 bool GLES2Demo::Setup(void* hwnd, int32 size); |
46 | 48 |
47 private: | 49 private: |
48 DISALLOW_COPY_AND_ASSIGN(GLES2Demo); | 50 DISALLOW_COPY_AND_ASSIGN(GLES2Demo); |
49 }; | 51 }; |
50 | 52 |
51 GLES2Demo::GLES2Demo() { | 53 GLES2Demo::GLES2Demo() { |
52 } | 54 } |
53 | 55 |
54 bool GLES2Demo::Setup(void* hwnd, int32 size) { | 56 bool GLES2Demo::Setup(void* hwnd, int32 size) { |
| 57 #if defined(OS_WIN) |
| 58 InitializeGLBindings(gfx::kGLImplementationEGLGLES2); |
| 59 #else |
| 60 InitializeGLBindings(gfx::kGLImplementationDesktopGL); |
| 61 #endif |
| 62 |
55 scoped_ptr<CommandBufferService> command_buffer(new CommandBufferService); | 63 scoped_ptr<CommandBufferService> command_buffer(new CommandBufferService); |
56 if (!command_buffer->Initialize(size)) | 64 if (!command_buffer->Initialize(size)) |
57 return NULL; | 65 return NULL; |
58 | 66 |
| 67 gpu::gles2::ContextGroup::Ref group(new gpu::gles2::ContextGroup()); |
59 GpuScheduler* gpu_scheduler = GpuScheduler::Create(command_buffer.get(), | 68 GpuScheduler* gpu_scheduler = GpuScheduler::Create(command_buffer.get(), |
60 NULL, | 69 NULL, |
61 NULL); | 70 group.get()); |
62 if (!gpu_scheduler->Initialize(reinterpret_cast<HWND>(hwnd), | 71 if (!gpu_scheduler->Initialize(reinterpret_cast<HWND>(hwnd), |
63 gfx::Size(), | 72 gfx::Size(), |
64 false, | 73 false, |
65 gpu::gles2::DisallowedExtensions(), | 74 gpu::gles2::DisallowedExtensions(), |
66 NULL, | 75 NULL, |
67 std::vector<int32>(), | 76 std::vector<int32>(), |
68 NULL)) { | 77 NULL)) { |
69 return NULL; | 78 return NULL; |
70 } | 79 } |
71 | 80 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 ::fprintf(stdout, "Could not setup window.\n"); | 232 ::fprintf(stdout, "Could not setup window.\n"); |
224 return EXIT_FAILURE; | 233 return EXIT_FAILURE; |
225 } | 234 } |
226 | 235 |
227 demo->Setup(hwnd, kCommandBufferSize); | 236 demo->Setup(hwnd, kCommandBufferSize); |
228 | 237 |
229 ProcessMessages(hwnd); | 238 ProcessMessages(hwnd); |
230 | 239 |
231 return EXIT_SUCCESS; | 240 return EXIT_SUCCESS; |
232 } | 241 } |
OLD | NEW |