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

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

Issue 416893002: ozone: demo: Add software support & use message loop (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 4 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 | ui/ozone/demo/ozone_demo.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/at_exit.h"
6 #include "base/command_line.h"
7 #include "base/message_loop/message_loop.h"
8 #include "ui/gfx/geometry/size.h"
9 #include "ui/gl/gl_bindings.h"
10 #include "ui/gl/gl_context.h"
11 #include "ui/gl/gl_surface.h"
12 #include "ui/ozone/public/ozone_platform.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 virtual void OnActivationChanged(bool active) OVERRIDE {}
52
53 private:
54 scoped_ptr<ui::PlatformWindow> platform_window_;
55 gfx::AcceleratedWidget widget_;
56
57 DISALLOW_COPY_AND_ASSIGN(DemoWindow);
58 };
59
60 int main(int argc, char** argv) {
61 CommandLine::Init(argc, argv);
62 base::AtExitManager exit_manager;
63
64 base::MessageLoopForUI message_loop;
65
66 ui::OzonePlatform::InitializeForUI();
67 if (!gfx::GLSurface::InitializeOneOff())
68 LOG(FATAL) << "Failed to initialize GL";
69
70 DemoWindow window;
71
72 scoped_refptr<gfx::GLSurface> surface =
73 gfx::GLSurface::CreateViewGLSurface(window.GetAcceleratedWidget());
74 if (!surface)
75 LOG(FATAL) << "Failed to create GL surface";
76
77 scoped_refptr<gfx::GLContext> context = gfx::GLContext::CreateGLContext(
78 NULL, surface.get(), gfx::PreferIntegratedGpu);
79 if (!context)
80 LOG(FATAL) << "Failed to create GL context";
81
82 gfx::Size window_size = window.GetSize();
83
84 int iterations = 120;
85
86 surface->Resize(window_size);
87 if (!context->MakeCurrent(surface.get()))
88 LOG(FATAL) << "Failed to make current on GL context";
89
90 for (int i = 0; i < iterations; ++i) {
91 glViewport(0, 0, window_size.width(), window_size.height());
92 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
93 float fraction = static_cast<float>(i) / iterations;
94 glClearColor(1 - fraction, fraction, 0.0, 1.0);
95
96 if (!surface->SwapBuffers())
97 LOG(FATAL) << "Failed to swap buffers";
98 }
99
100 return 0;
101 }
OLDNEW
« no previous file with comments | « no previous file | ui/ozone/demo/ozone_demo.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698