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 // Base class for gles2 applications using command buffer. |
6 | 6 |
7 #ifndef GPU_DEMOS_APP_FRAMEWORK_APPLICATION_H_ | 7 #ifndef GPU_DEMOS_APP_FRAMEWORK_APPLICATION_H_ |
8 #define GPU_DEMOS_APP_FRAMEWORK_APPLICATION_H_ | 8 #define GPU_DEMOS_APP_FRAMEWORK_APPLICATION_H_ |
9 | 9 |
10 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/time.h" |
12 | 13 |
13 #include "gpu/demos/app_framework/platform.h" | 14 #include "gpu/demos/app_framework/platform.h" |
14 | 15 |
15 namespace gpu_demos { | 16 namespace gpu_demos { |
16 | 17 |
17 // Acts as a base class for GLES2 applications using command buffer. | 18 // Acts as a base class for GLES2 applications using command buffer. |
18 // The derived calls needs to call InitRenderContext() to create a render | 19 // The derived calls needs to call InitRenderContext() to create a render |
19 // surface and initialize a rendering context. Currently it only creates | 20 // surface and initialize a rendering context. Currently it only creates |
20 // an on-screen window. It will be extended to support pepper/nacl plugin | 21 // an on-screen window. It will be extended to support pepper/nacl plugin |
21 // when pepper 3D api is in place. | 22 // when pepper 3D api is in place. |
22 class Application { | 23 class Application { |
23 public: | 24 public: |
24 Application(); | 25 Application(); |
25 virtual ~Application(); | 26 virtual ~Application(); |
26 | 27 |
27 // Enters the event processing loop. | 28 // Enters the event processing loop. |
28 void MainLoop(); | 29 void MainLoop(); |
29 void OnPaint(); | 30 void OnPaint(); |
30 | 31 |
31 protected: | 32 protected: |
32 // Returns the width of rendering surface. | 33 // Returns the width of rendering surface. |
33 inline int width() const { return width_; } | 34 inline int width() const { return width_; } |
34 // Returns the height of rendering surface. | 35 // Returns the height of rendering surface. |
35 inline int height() const { return height_; } | 36 inline int height() const { return height_; } |
36 | 37 |
37 bool InitRenderContext(); | 38 bool InitRenderContext(); |
38 | 39 |
39 virtual void Draw() = 0; | 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; |
40 | 47 |
41 private: | 48 private: |
42 // Creates a native on-screen window. | 49 // Creates a native on-screen window. |
43 NativeWindowHandle CreateNativeWindow(); | 50 NativeWindowHandle CreateNativeWindow(); |
44 | 51 |
45 int width_; | 52 int width_; |
46 int height_; | 53 int height_; |
47 NativeWindowHandle window_handle_; | 54 NativeWindowHandle window_handle_; |
48 | 55 |
| 56 // Time at which draw was called last. |
| 57 base::Time last_draw_time_; |
| 58 |
49 // The following two variables are just needed to satisfy | 59 // The following two variables are just needed to satisfy |
50 // the assumption that we are running inside a browser. | 60 // the assumption that we are running inside a browser. |
51 base::AtExitManager at_exit_manager_; | 61 base::AtExitManager at_exit_manager_; |
52 MessageLoopForUI message_loop_; | 62 MessageLoopForUI message_loop_; |
53 | 63 |
54 DISALLOW_COPY_AND_ASSIGN(Application); | 64 DISALLOW_COPY_AND_ASSIGN(Application); |
55 }; | 65 }; |
56 | 66 |
57 } // namespace gpu_demos | 67 } // namespace gpu_demos |
58 #endif // GPU_DEMOS_APP_FRAMEWORK_APPLICATION_H_ | 68 #endif // GPU_DEMOS_APP_FRAMEWORK_APPLICATION_H_ |
OLD | NEW |