| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 // Base class for gles2 applications using command buffer. | 5 #ifndef GPU_DEMOS_FRAMEWORK_WINDOW_H_ |
| 6 #define GPU_DEMOS_FRAMEWORK_WINDOW_H_ |
| 6 | 7 |
| 7 #ifndef GPU_DEMOS_APP_FRAMEWORK_APPLICATION_H_ | 8 #include "base/scoped_ptr.h" |
| 8 #define GPU_DEMOS_APP_FRAMEWORK_APPLICATION_H_ | 9 #include "gpu/demos/framework/demo.h" |
| 10 #include "gpu/demos/framework/platform.h" |
| 9 | 11 |
| 10 #include "base/at_exit.h" | 12 namespace gpu { |
| 11 #include "base/message_loop.h" | 13 namespace demos { |
| 12 #include "base/time.h" | |
| 13 | 14 |
| 14 #include "gpu/demos/app_framework/platform.h" | 15 // Acts as a framework for standalone demos. It creates a window and delegates |
| 16 // all events to demo to perform rendering and other tasks. |
| 17 class Window { |
| 18 public: |
| 19 Window(); |
| 20 virtual ~Window(); |
| 15 | 21 |
| 16 namespace gpu_demos { | 22 // Initializes and creates a window with given dimensions. |
| 17 | 23 bool Init(int width, int height); |
| 18 // Acts as a base class for GLES2 applications using command buffer. | |
| 19 // The derived calls needs to call InitRenderContext() to create a render | |
| 20 // surface and initialize a rendering context. Currently it only creates | |
| 21 // an on-screen window. It will be extended to support pepper/nacl plugin | |
| 22 // when pepper 3D api is in place. | |
| 23 class Application { | |
| 24 public: | |
| 25 Application(); | |
| 26 virtual ~Application(); | |
| 27 | 24 |
| 28 // Enters the event processing loop. | 25 // Enters the event processing loop. |
| 29 void MainLoop(); | 26 void MainLoop(); |
| 27 |
| 30 void OnPaint(); | 28 void OnPaint(); |
| 31 | 29 |
| 32 protected: | 30 private: |
| 33 // Returns the width of rendering surface. | 31 NativeWindowHandle window_handle_; |
| 34 inline int width() const { return width_; } | 32 scoped_ptr<Demo> demo_; |
| 35 // Returns the height of rendering surface. | |
| 36 inline int height() const { return height_; } | |
| 37 | 33 |
| 38 bool InitRenderContext(); | 34 DISALLOW_COPY_AND_ASSIGN(Window); |
| 39 | |
| 40 // The framework calls this function for the derived classes to do custom | |
| 41 // rendering. There is no default implementation. It must be defined by the | |
| 42 // derived classes. The elapsed_sec param represents the time elapsed | |
| 43 // (in seconds) after Draw was called the last time. It can be used to | |
| 44 // make the application frame-rate independent. It is 0.0f for the | |
| 45 // first draw call. | |
| 46 virtual void Draw(float elapsed_sec) = 0; | |
| 47 | |
| 48 private: | |
| 49 // Creates a native on-screen window. | |
| 50 NativeWindowHandle CreateNativeWindow(); | |
| 51 | |
| 52 int width_; | |
| 53 int height_; | |
| 54 NativeWindowHandle window_handle_; | |
| 55 | |
| 56 // Time at which draw was called last. | |
| 57 base::Time last_draw_time_; | |
| 58 | |
| 59 // The following two variables are just needed to satisfy | |
| 60 // the assumption that we are running inside a browser. | |
| 61 base::AtExitManager at_exit_manager_; | |
| 62 MessageLoopForUI message_loop_; | |
| 63 | |
| 64 DISALLOW_COPY_AND_ASSIGN(Application); | |
| 65 }; | 35 }; |
| 66 | 36 |
| 67 } // namespace gpu_demos | 37 } // namespace demos |
| 68 #endif // GPU_DEMOS_APP_FRAMEWORK_APPLICATION_H_ | 38 } // namespace gpu |
| 39 #endif // GPU_DEMOS_FRAMEWORK_WINDOW_H_ |
| OLD | NEW |