OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 * | 6 * |
7 */ | 7 */ |
8 | 8 |
9 #include <android_native_app_glue.h> | 9 #include <android_native_app_glue.h> |
10 | 10 |
11 #include "SkApplication.h" | 11 #include "SkApplication.h" |
12 #include "VisualBench.h" | 12 #include "VisualBench.h" |
13 | 13 |
14 /** | 14 /** |
15 * Shared state for our app. | 15 * Shared state for our app. |
16 */ | 16 */ |
17 enum State { | 17 enum State { |
18 kInit_State, | 18 kInit_State, |
19 kAnimate_State, | 19 kAnimate_State, |
20 kDestroyRequested_State, | 20 kDestroyRequested_State, |
21 kFinished_State, | 21 kFinished_State, |
22 }; | 22 }; |
23 | 23 |
24 struct VisualBenchState { | 24 struct VisualBenchState { |
25 VisualBenchState() : fApp(NULL), fWindow(NULL), fState(kInit_State) {} | 25 VisualBenchState() : fApp(nullptr), fWindow(nullptr), fState(kInit_State) {} |
26 struct android_app* fApp; | 26 struct android_app* fApp; |
27 SkOSWindow* fWindow; | 27 SkOSWindow* fWindow; |
28 SkTArray<SkString> fFlags; | 28 SkTArray<SkString> fFlags; |
29 State fState; | 29 State fState; |
30 }; | 30 }; |
31 | 31 |
32 static void handle_cmd(struct android_app* app, int32_t cmd) { | 32 static void handle_cmd(struct android_app* app, int32_t cmd) { |
33 struct VisualBenchState* state = (struct VisualBenchState*)app->userData; | 33 struct VisualBenchState* state = (struct VisualBenchState*)app->userData; |
34 switch (cmd) { | 34 switch (cmd) { |
35 case APP_CMD_INIT_WINDOW: | 35 case APP_CMD_INIT_WINDOW: |
36 // The window is being shown, get it ready. | 36 // The window is being shown, get it ready. |
37 if (state->fApp->window != NULL && kInit_State == state->fState) { | 37 if (state->fApp->window != nullptr && kInit_State == state->fState)
{ |
38 // drain any events that occurred before |window| was assigned. | 38 // drain any events that occurred before |window| was assigned. |
39 while (SkEvent::ProcessEvent()); | 39 while (SkEvent::ProcessEvent()); |
40 | 40 |
41 // Start normal Skia sequence | 41 // Start normal Skia sequence |
42 application_init(); | 42 application_init(); |
43 | 43 |
44 SkTArray<const char*> args; | 44 SkTArray<const char*> args; |
45 args.push_back("VisualBench"); | 45 args.push_back("VisualBench"); |
46 for (int i = 0; i < state->fFlags.count(); i++) { | 46 for (int i = 0; i < state->fFlags.count(); i++) { |
47 SkDebugf(state->fFlags[i].c_str()); | 47 SkDebugf(state->fFlags[i].c_str()); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 } | 95 } |
96 jvm->DetachCurrentThread(); | 96 jvm->DetachCurrentThread(); |
97 | 97 |
98 while (1) { | 98 while (1) { |
99 // Read all pending events. | 99 // Read all pending events. |
100 int ident; | 100 int ident; |
101 int events; | 101 int events; |
102 struct android_poll_source* source; | 102 struct android_poll_source* source; |
103 | 103 |
104 // We loop until all events are read, then continue to draw the next fra
me of animation. | 104 // We loop until all events are read, then continue to draw the next fra
me of animation. |
105 while ((ident=ALooper_pollAll(0, NULL, &events, (void**)&source)) >= 0)
{ | 105 while ((ident=ALooper_pollAll(0, nullptr, &events, (void**)&source)) >=
0) { |
106 // Process this event. | 106 // Process this event. |
107 if (source != NULL) { | 107 if (source != nullptr) { |
108 source->process(state, source); | 108 source->process(state, source); |
109 } | 109 } |
110 | 110 |
111 // Check if we are exiting. | 111 // Check if we are exiting. |
112 if (state->destroyRequested != 0) { | 112 if (state->destroyRequested != 0) { |
113 return; | 113 return; |
114 } | 114 } |
115 | 115 |
116 } | 116 } |
117 | 117 |
118 if (visualBenchState.fWindow) { | 118 if (visualBenchState.fWindow) { |
119 if (visualBenchState.fWindow->destroyRequested()) { | 119 if (visualBenchState.fWindow->destroyRequested()) { |
120 visualBenchState.fState = kDestroyRequested_State; | 120 visualBenchState.fState = kDestroyRequested_State; |
121 } else { | 121 } else { |
122 visualBenchState.fWindow->update(NULL); | 122 visualBenchState.fWindow->update(nullptr); |
123 } | 123 } |
124 } | 124 } |
125 | 125 |
126 if (kDestroyRequested_State == visualBenchState.fState) { | 126 if (kDestroyRequested_State == visualBenchState.fState) { |
127 delete visualBenchState.fWindow; | 127 delete visualBenchState.fWindow; |
128 visualBenchState.fWindow = NULL; | 128 visualBenchState.fWindow = nullptr; |
129 application_term(); | 129 application_term(); |
130 ANativeActivity_finish(state->activity); | 130 ANativeActivity_finish(state->activity); |
131 visualBenchState.fState = kFinished_State; | 131 visualBenchState.fState = kFinished_State; |
132 } | 132 } |
133 } | 133 } |
134 } | 134 } |
OLD | NEW |