Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(161)

Side by Side Diff: ui/ozone/demo/egl_demo.cc

Issue 397103002: ozone: Port egl_demo on top of PlatformWindow (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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) {
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_NE(widget_, gfx::kNullAcceleratedWidget)
31 << "widget not available synchronously";
32 return widget_;
33 }
34
35 gfx::Size GetSize() { return platform_window_->GetBounds().size(); }
36
37 // PlatformWindowDelegate:
38 virtual void OnBoundsChanged(const gfx::Rect& new_bounds) OVERRIDE {}
39 virtual void OnDamageRect(const gfx::Rect& damaged_region) OVERRIDE {}
40 virtual void DispatchEvent(ui::Event* event) OVERRIDE {}
41 virtual void OnCloseRequest() OVERRIDE {}
42 virtual void OnClosed() OVERRIDE {}
43 virtual void OnWindowStateChanged(
44 ui::PlatformWindowState new_state) OVERRIDE {}
45 virtual void OnLostCapture() OVERRIDE {}
46 virtual void OnAcceleratedWidgetAvailable(
47 gfx::AcceleratedWidget widget) OVERRIDE {
48 CHECK_NE(widget, gfx::kNullAcceleratedWidget);
49 widget_ = widget;
50 }
51
52 private:
53 scoped_ptr<ui::PlatformWindow> platform_window_;
54 gfx::AcceleratedWidget widget_;
55
56 DISALLOW_COPY_AND_ASSIGN(DemoWindow);
57 };
13 58
14 int main(int argc, char** argv) { 59 int main(int argc, char** argv) {
15 CommandLine::Init(argc, argv); 60 CommandLine::Init(argc, argv);
16 base::AtExitManager exit_manager; 61 base::AtExitManager exit_manager;
17 62
63 base::MessageLoopForUI message_loop;
64
18 ui::OzonePlatform::InitializeForUI(); 65 ui::OzonePlatform::InitializeForUI();
19 if (!gfx::GLSurface::InitializeOneOff()) 66 if (!gfx::GLSurface::InitializeOneOff())
20 LOG(FATAL) << "Failed to initialize GL"; 67 LOG(FATAL) << "Failed to initialize GL";
21 68
22 gfx::AcceleratedWidget widget = 69 DemoWindow window;
23 ui::SurfaceFactoryOzone::GetInstance()->GetAcceleratedWidget(); 70
24 scoped_refptr<gfx::GLSurface> surface = 71 scoped_refptr<gfx::GLSurface> surface =
25 gfx::GLSurface::CreateViewGLSurface(widget); 72 gfx::GLSurface::CreateViewGLSurface(window.GetAcceleratedWidget());
26 if (!surface) 73 if (!surface)
27 LOG(FATAL) << "Failed to create GL surface"; 74 LOG(FATAL) << "Failed to create GL surface";
28 75
29 scoped_refptr<gfx::GLContext> context = gfx::GLContext::CreateGLContext( 76 scoped_refptr<gfx::GLContext> context = gfx::GLContext::CreateGLContext(
30 NULL, surface.get(), gfx::PreferIntegratedGpu); 77 NULL, surface.get(), gfx::PreferIntegratedGpu);
31 if (!context) 78 if (!context)
32 LOG(FATAL) << "Failed to create GL context"; 79 LOG(FATAL) << "Failed to create GL context";
33 80
34 const gfx::Size window_size(800, 600); 81 gfx::Size window_size = window.GetSize();
82
35 int iterations = 120; 83 int iterations = 120;
36 84
37 surface->Resize(window_size); 85 surface->Resize(window_size);
38 if (!context->MakeCurrent(surface.get())) 86 if (!context->MakeCurrent(surface.get()))
39 LOG(FATAL) << "Failed to make current on GL context"; 87 LOG(FATAL) << "Failed to make current on GL context";
40 88
41 for (int i = 0; i < iterations; ++i) { 89 for (int i = 0; i < iterations; ++i) {
42 glViewport(0, 0, window_size.width(), window_size.height()); 90 glViewport(0, 0, window_size.width(), window_size.height());
43 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 91 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
44 float fraction = static_cast<float>(i) / iterations; 92 float fraction = static_cast<float>(i) / iterations;
45 glClearColor(1 - fraction, fraction, 0.0, 1.0); 93 glClearColor(1 - fraction, fraction, 0.0, 1.0);
46 94
47 if (!surface->SwapBuffers()) 95 if (!surface->SwapBuffers())
48 LOG(FATAL) << "Failed to swap buffers"; 96 LOG(FATAL) << "Failed to swap buffers";
49 } 97 }
50 98
51 return 0; 99 return 0;
52 } 100 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698