OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/at_exit.h" | 5 #include "base/at_exit.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/message_loop/message_loop.h" | |
7 #include "ui/gfx/geometry/size.h" | 8 #include "ui/gfx/geometry/size.h" |
8 #include "ui/gl/gl_bindings.h" | 9 #include "ui/gl/gl_bindings.h" |
9 #include "ui/gl/gl_context.h" | 10 #include "ui/gl/gl_context.h" |
10 #include "ui/gl/gl_surface.h" | 11 #include "ui/gl/gl_surface.h" |
11 #include "ui/ozone/public/ozone_platform.h" | 12 #include "ui/ozone/public/ozone_platform.h" |
12 #include "ui/ozone/public/surface_factory_ozone.h" | 13 #include "ui/ozone/public/surface_factory_ozone.h" |
14 #include "ui/platform_window/platform_window.h" | |
15 #include "ui/platform_window/platform_window_delegate.h" | |
16 | |
17 const int kTestWindowWidth = 800; | |
18 const int kTestWindowHeight = 600; | |
19 | |
20 class DemoWindow : public ui::PlatformWindowDelegate { | |
21 public: | |
22 DemoWindow() : widget_(gfx::kNullAcceleratedWidget), have_widget_(false) { | |
23 platform_window_ = ui::OzonePlatform::GetInstance()->CreatePlatformWindow( | |
24 this, gfx::Rect(kTestWindowWidth, kTestWindowHeight)); | |
25 } | |
26 virtual ~DemoWindow() {} | |
27 | |
28 gfx::AcceleratedWidget GetAcceleratedWidget() { | |
29 // TODO(spang): We should start rendering asynchronously. | |
30 CHECK(have_widget_) << "widget not available synchronously"; | |
dnicoara
2014/07/16 19:57:29
nit: You could just CHECK against kNullAccelerated
| |
31 return widget_; | |
32 } | |
33 | |
34 // PlatformWindowDelegate: | |
35 virtual void OnBoundsChanged(const gfx::Rect& new_bounds) OVERRIDE {} | |
36 virtual void OnDamageRect(const gfx::Rect& damaged_region) OVERRIDE {} | |
37 virtual void DispatchEvent(ui::Event* event) OVERRIDE {} | |
38 virtual void OnCloseRequest() OVERRIDE {} | |
39 virtual void OnClosed() OVERRIDE {} | |
40 virtual void OnWindowStateChanged( | |
41 ui::PlatformWindowState new_state) OVERRIDE {} | |
42 virtual void OnLostCapture() OVERRIDE {} | |
43 virtual void OnAcceleratedWidgetAvailable( | |
44 gfx::AcceleratedWidget widget) OVERRIDE { | |
45 have_widget_ = true; | |
46 widget_ = widget; | |
47 } | |
48 | |
49 private: | |
50 scoped_ptr<ui::PlatformWindow> platform_window_; | |
51 gfx::AcceleratedWidget widget_; | |
52 bool have_widget_; | |
53 | |
54 DISALLOW_COPY_AND_ASSIGN(DemoWindow); | |
55 }; | |
13 | 56 |
14 int main(int argc, char** argv) { | 57 int main(int argc, char** argv) { |
15 CommandLine::Init(argc, argv); | 58 CommandLine::Init(argc, argv); |
16 base::AtExitManager exit_manager; | 59 base::AtExitManager exit_manager; |
17 | 60 |
61 base::MessageLoopForUI message_loop; | |
62 | |
18 ui::OzonePlatform::InitializeForUI(); | 63 ui::OzonePlatform::InitializeForUI(); |
19 if (!gfx::GLSurface::InitializeOneOff()) | 64 if (!gfx::GLSurface::InitializeOneOff()) |
20 LOG(FATAL) << "Failed to initialize GL"; | 65 LOG(FATAL) << "Failed to initialize GL"; |
21 | 66 |
22 gfx::AcceleratedWidget widget = | 67 DemoWindow window; |
23 ui::SurfaceFactoryOzone::GetInstance()->GetAcceleratedWidget(); | 68 |
24 scoped_refptr<gfx::GLSurface> surface = | 69 scoped_refptr<gfx::GLSurface> surface = |
25 gfx::GLSurface::CreateViewGLSurface(widget); | 70 gfx::GLSurface::CreateViewGLSurface(window.GetAcceleratedWidget()); |
26 if (!surface) | 71 if (!surface) |
27 LOG(FATAL) << "Failed to create GL surface"; | 72 LOG(FATAL) << "Failed to create GL surface"; |
28 | 73 |
29 scoped_refptr<gfx::GLContext> context = gfx::GLContext::CreateGLContext( | 74 scoped_refptr<gfx::GLContext> context = gfx::GLContext::CreateGLContext( |
30 NULL, surface.get(), gfx::PreferIntegratedGpu); | 75 NULL, surface.get(), gfx::PreferIntegratedGpu); |
31 if (!context) | 76 if (!context) |
32 LOG(FATAL) << "Failed to create GL context"; | 77 LOG(FATAL) << "Failed to create GL context"; |
33 | 78 |
34 const gfx::Size window_size(800, 600); | 79 const gfx::Size window_size(800, 600); |
dnicoara
2014/07/16 19:59:59
Oh, and this can probably be replaced by window.Ge
| |
35 int iterations = 120; | 80 int iterations = 120; |
36 | 81 |
37 surface->Resize(window_size); | 82 surface->Resize(window_size); |
38 if (!context->MakeCurrent(surface.get())) | 83 if (!context->MakeCurrent(surface.get())) |
39 LOG(FATAL) << "Failed to make current on GL context"; | 84 LOG(FATAL) << "Failed to make current on GL context"; |
40 | 85 |
41 for (int i = 0; i < iterations; ++i) { | 86 for (int i = 0; i < iterations; ++i) { |
42 glViewport(0, 0, window_size.width(), window_size.height()); | 87 glViewport(0, 0, window_size.width(), window_size.height()); |
43 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | 88 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
44 float fraction = static_cast<float>(i) / iterations; | 89 float fraction = static_cast<float>(i) / iterations; |
45 glClearColor(1 - fraction, fraction, 0.0, 1.0); | 90 glClearColor(1 - fraction, fraction, 0.0, 1.0); |
46 | 91 |
47 if (!surface->SwapBuffers()) | 92 if (!surface->SwapBuffers()) |
48 LOG(FATAL) << "Failed to swap buffers"; | 93 LOG(FATAL) << "Failed to swap buffers"; |
49 } | 94 } |
50 | 95 |
51 return 0; | 96 return 0; |
52 } | 97 } |
OLD | NEW |