| 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 "base/message_loop/message_loop.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/timer/timer.h" | 9 #include "base/timer/timer.h" |
| 10 #include "third_party/skia/include/core/SkCanvas.h" | 10 #include "third_party/skia/include/core/SkCanvas.h" |
| 11 #include "third_party/skia/include/core/SkColor.h" | 11 #include "third_party/skia/include/core/SkColor.h" |
| 12 #include "ui/gfx/geometry/size.h" | 12 #include "ui/gfx/geometry/size.h" |
| 13 #include "ui/gl/gl_bindings.h" | 13 #include "ui/gl/gl_bindings.h" |
| 14 #include "ui/gl/gl_context.h" | 14 #include "ui/gl/gl_context.h" |
| 15 #include "ui/gl/gl_surface.h" | 15 #include "ui/gl/gl_surface.h" |
| 16 #include "ui/ozone/public/ozone_platform.h" | 16 #include "ui/ozone/public/ozone_platform.h" |
| 17 #include "ui/ozone/public/surface_factory_ozone.h" | 17 #include "ui/ozone/public/surface_factory_ozone.h" |
| 18 #include "ui/ozone/public/surface_ozone_canvas.h" | 18 #include "ui/ozone/public/surface_ozone_canvas.h" |
| 19 #include "ui/ozone/public/ui_thread_gpu.h" |
| 19 #include "ui/platform_window/platform_window.h" | 20 #include "ui/platform_window/platform_window.h" |
| 20 #include "ui/platform_window/platform_window_delegate.h" | 21 #include "ui/platform_window/platform_window_delegate.h" |
| 21 | 22 |
| 22 const int kTestWindowWidth = 800; | 23 const int kTestWindowWidth = 800; |
| 23 const int kTestWindowHeight = 600; | 24 const int kTestWindowHeight = 600; |
| 24 | 25 |
| 25 const int kFrameDelayMilliseconds = 16; | 26 const int kFrameDelayMilliseconds = 16; |
| 26 | 27 |
| 27 const int kAnimationSteps = 240; | 28 const int kAnimationSteps = 240; |
| 28 | 29 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 40 // TODO(spang): We should start rendering asynchronously. | 41 // TODO(spang): We should start rendering asynchronously. |
| 41 DCHECK_NE(widget_, gfx::kNullAcceleratedWidget) | 42 DCHECK_NE(widget_, gfx::kNullAcceleratedWidget) |
| 42 << "Widget not available synchronously"; | 43 << "Widget not available synchronously"; |
| 43 return widget_; | 44 return widget_; |
| 44 } | 45 } |
| 45 | 46 |
| 46 gfx::Size GetSize() { return platform_window_->GetBounds().size(); } | 47 gfx::Size GetSize() { return platform_window_->GetBounds().size(); } |
| 47 | 48 |
| 48 void Start() { | 49 void Start() { |
| 49 if (!CommandLine::ForCurrentProcess()->HasSwitch(kDisableGpu) && | 50 if (!CommandLine::ForCurrentProcess()->HasSwitch(kDisableGpu) && |
| 50 gfx::GLSurface::InitializeOneOff() && InitializeGLSurface()) { | 51 gfx::GLSurface::InitializeOneOff() && StartInProcessGpu() && |
| 52 InitializeGLSurface()) { |
| 51 StartAnimationGL(); | 53 StartAnimationGL(); |
| 52 } else if (InitializeSoftwareSurface()) { | 54 } else if (InitializeSoftwareSurface()) { |
| 53 StartAnimationSoftware(); | 55 StartAnimationSoftware(); |
| 54 } else { | 56 } else { |
| 55 LOG(ERROR) << "Failed to create drawing surface"; | 57 LOG(ERROR) << "Failed to create drawing surface"; |
| 56 Quit(); | 58 Quit(); |
| 57 } | 59 } |
| 58 } | 60 } |
| 59 | 61 |
| 60 void Quit() { | 62 void Quit() { |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 skia::RefPtr<SkCanvas> canvas = software_surface_->GetCanvas(); | 168 skia::RefPtr<SkCanvas> canvas = software_surface_->GetCanvas(); |
| 167 | 169 |
| 168 SkColor color = | 170 SkColor color = |
| 169 SkColorSetARGB(0xff, 0, 0xff * fraction, 0xff * (1 - fraction)); | 171 SkColorSetARGB(0xff, 0, 0xff * fraction, 0xff * (1 - fraction)); |
| 170 | 172 |
| 171 canvas->clear(color); | 173 canvas->clear(color); |
| 172 | 174 |
| 173 software_surface_->PresentCanvas(gfx::Rect(window_size)); | 175 software_surface_->PresentCanvas(gfx::Rect(window_size)); |
| 174 } | 176 } |
| 175 | 177 |
| 178 bool StartInProcessGpu() { return ui_thread_gpu_.Initialize(); } |
| 179 |
| 176 // Timer for animation. | 180 // Timer for animation. |
| 177 base::RepeatingTimer<DemoWindow> timer_; | 181 base::RepeatingTimer<DemoWindow> timer_; |
| 178 | 182 |
| 179 // Bits for GL rendering. | 183 // Bits for GL rendering. |
| 180 scoped_refptr<gfx::GLSurface> surface_; | 184 scoped_refptr<gfx::GLSurface> surface_; |
| 181 scoped_refptr<gfx::GLContext> context_; | 185 scoped_refptr<gfx::GLContext> context_; |
| 182 | 186 |
| 183 // Bits for software rendeirng. | 187 // Bits for software rendeirng. |
| 184 scoped_ptr<ui::SurfaceOzoneCanvas> software_surface_; | 188 scoped_ptr<ui::SurfaceOzoneCanvas> software_surface_; |
| 185 | 189 |
| 186 // Window-related state. | 190 // Window-related state. |
| 187 scoped_ptr<ui::PlatformWindow> platform_window_; | 191 scoped_ptr<ui::PlatformWindow> platform_window_; |
| 188 gfx::AcceleratedWidget widget_; | 192 gfx::AcceleratedWidget widget_; |
| 189 | 193 |
| 194 // Helper for applications that do GL on main thread. |
| 195 ui::UiThreadGpu ui_thread_gpu_; |
| 196 |
| 190 // Animation state. | 197 // Animation state. |
| 191 int iteration_; | 198 int iteration_; |
| 192 | 199 |
| 193 DISALLOW_COPY_AND_ASSIGN(DemoWindow); | 200 DISALLOW_COPY_AND_ASSIGN(DemoWindow); |
| 194 }; | 201 }; |
| 195 | 202 |
| 196 int main(int argc, char** argv) { | 203 int main(int argc, char** argv) { |
| 197 CommandLine::Init(argc, argv); | 204 CommandLine::Init(argc, argv); |
| 198 base::AtExitManager exit_manager; | 205 base::AtExitManager exit_manager; |
| 199 | 206 |
| 200 // Build UI thread message loop. This is used by platform | 207 // Build UI thread message loop. This is used by platform |
| 201 // implementations for event polling & running background tasks. | 208 // implementations for event polling & running background tasks. |
| 202 base::MessageLoopForUI message_loop; | 209 base::MessageLoopForUI message_loop; |
| 203 | 210 |
| 204 ui::OzonePlatform::InitializeForUI(); | 211 ui::OzonePlatform::InitializeForUI(); |
| 205 | 212 |
| 206 DemoWindow* window = new DemoWindow; | 213 DemoWindow* window = new DemoWindow; |
| 207 window->Start(); | 214 window->Start(); |
| 208 | 215 |
| 209 // Run the message loop until there's nothing left to do. | 216 // Run the message loop until there's nothing left to do. |
| 210 // TODO(spang): Should we use QuitClosure instead? | 217 // TODO(spang): Should we use QuitClosure instead? |
| 211 base::RunLoop run_loop; | 218 base::RunLoop run_loop; |
| 212 run_loop.RunUntilIdle(); | 219 run_loop.RunUntilIdle(); |
| 213 | 220 |
| 214 return 0; | 221 return 0; |
| 215 } | 222 } |
| OLD | NEW |