OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <GLES2/gl2.h> | 5 #include <GLES2/gl2.h> |
6 | 6 |
7 #include "gpu/demos/framework/demo.h" | 7 #include "gpu/demos/framework/demo.h" |
8 #include "gpu/demos/framework/demo_factory.h" | 8 #include "gpu/demos/framework/demo_factory.h" |
9 #include "ppapi/cpp/completion_callback.h" | 9 #include "ppapi/cpp/completion_callback.h" |
10 #include "ppapi/cpp/instance.h" | 10 #include "ppapi/cpp/instance.h" |
11 #include "ppapi/cpp/dev/graphics_3d_dev.h" | |
12 #include "ppapi/cpp/module.h" | 11 #include "ppapi/cpp/module.h" |
13 #include "ppapi/cpp/rect.h" | 12 #include "ppapi/cpp/rect.h" |
14 #include "ppapi/cpp/size.h" | 13 #include "ppapi/cpp/size.h" |
| 14 #include "ppapi/cpp/dev/context_3d_dev.h" |
| 15 #include "ppapi/cpp/dev/graphics_3d_dev.h" |
15 #include "ppapi/lib/gl/gles2/gl2ext_ppapi.h" | 16 #include "ppapi/lib/gl/gles2/gl2ext_ppapi.h" |
16 | 17 |
17 namespace gpu { | 18 namespace gpu { |
18 namespace demos { | 19 namespace demos { |
19 | 20 |
20 class PluginInstance : public pp::Instance { | 21 class PluginInstance : public pp::Instance { |
21 public: | 22 public: |
22 PluginInstance(PP_Instance instance, pp::Module* module) | 23 PluginInstance(PP_Instance instance, pp::Module* module) |
23 : pp::Instance(instance), | 24 : pp::Instance(instance), |
24 module_(module), | 25 module_(module), |
25 demo_(CreateDemo()) { | 26 demo_(CreateDemo()) { |
26 // Set the callback object outside of the initializer list to avoid a | 27 // Set the callback object outside of the initializer list to avoid a |
27 // compiler warning about using "this" in an initializer list. | 28 // compiler warning about using "this" in an initializer list. |
28 callback_factory_.Initialize(this); | 29 callback_factory_.Initialize(this); |
29 } | 30 } |
30 | 31 |
31 ~PluginInstance() { | 32 ~PluginInstance() { |
32 if (!graphics_.is_null()) { | 33 if (!context_.is_null()) { |
33 glSetCurrentContextPPAPI(graphics_.pp_resource()); | 34 glSetCurrentContextPPAPI(context_.pp_resource()); |
34 delete demo_; | 35 delete demo_; |
35 glSetCurrentContextPPAPI(0); | 36 glSetCurrentContextPPAPI(0); |
36 } | 37 } |
37 } | 38 } |
38 | 39 |
39 virtual void DidChangeView(const pp::Rect& position, | 40 virtual void DidChangeView(const pp::Rect& position, |
40 const pp::Rect& /*clip*/) { | 41 const pp::Rect& /*clip*/) { |
41 if (size_ == position.size()) | 42 if (size_ == position.size()) |
42 return; | 43 return; |
43 | 44 |
44 size_ = position.size(); | 45 size_ = position.size(); |
45 demo_->InitWindowSize(size_.width(), size_.height()); | 46 demo_->InitWindowSize(size_.width(), size_.height()); |
46 | 47 |
47 if (graphics_.is_null()) { | 48 if (context_.is_null()) { |
48 graphics_ = pp::Graphics3D_Dev(*this, 0, NULL, NULL); | 49 context_ = pp::Context3D_Dev(*this, 0, pp::Context3D_Dev(), NULL); |
49 if (graphics_.is_null()) | 50 if (context_.is_null()) |
50 return; | 51 return; |
51 | 52 |
52 if (!pp::Instance::BindGraphics(graphics_)) | 53 if (!pp::Instance::BindGraphics(context_)) |
53 return; | 54 return; |
54 | 55 |
55 glSetCurrentContextPPAPI(graphics_.pp_resource()); | 56 glSetCurrentContextPPAPI(context_.pp_resource()); |
56 demo_->InitGL(); | 57 demo_->InitGL(); |
57 glSetCurrentContextPPAPI(0); | 58 glSetCurrentContextPPAPI(0); |
58 } | 59 } |
59 | 60 |
60 if (demo_->IsAnimated()) | 61 if (demo_->IsAnimated()) |
61 Animate(0); | 62 Animate(0); |
62 else | 63 else |
63 Paint(); | 64 Paint(); |
64 } | 65 } |
65 | 66 |
66 void Paint() { | 67 void Paint() { |
67 glSetCurrentContextPPAPI(graphics_.pp_resource()); | 68 glSetCurrentContextPPAPI(context_.pp_resource()); |
68 demo_->Draw(); | 69 demo_->Draw(); |
69 graphics_.SwapBuffers(); | 70 context_.SwapBuffers(); |
70 glSetCurrentContextPPAPI(0); | 71 glSetCurrentContextPPAPI(0); |
71 } | 72 } |
72 | 73 |
73 private: | 74 private: |
74 void Animate(int delay) { | 75 void Animate(int delay) { |
75 Paint(); | 76 Paint(); |
76 module_->core()->CallOnMainThread(delay, | 77 module_->core()->CallOnMainThread(delay, |
77 callback_factory_.NewCallback(&PluginInstance::Animate), delay); | 78 callback_factory_.NewCallback(&PluginInstance::Animate), delay); |
78 } | 79 } |
79 | 80 |
80 pp::Module* module_; | 81 pp::Module* module_; |
81 Demo* demo_; | 82 Demo* demo_; |
82 pp::Graphics3D_Dev graphics_; | 83 pp::Context3D_Dev context_; |
83 pp::Size size_; | 84 pp::Size size_; |
84 pp::CompletionCallbackFactory<PluginInstance> callback_factory_; | 85 pp::CompletionCallbackFactory<PluginInstance> callback_factory_; |
85 }; | 86 }; |
86 | 87 |
87 class PluginModule : public pp::Module { | 88 class PluginModule : public pp::Module { |
88 public: | 89 public: |
89 PluginModule() {} | 90 PluginModule() {} |
90 ~PluginModule() { | 91 ~PluginModule() { |
91 glTerminatePPAPI(); | 92 glTerminatePPAPI(); |
92 } | 93 } |
(...skipping 11 matching lines...) Expand all Loading... |
104 } // namespace gpu | 105 } // namespace gpu |
105 | 106 |
106 namespace pp { | 107 namespace pp { |
107 | 108 |
108 Module* CreateModule() { | 109 Module* CreateModule() { |
109 return new gpu::demos::PluginModule(); | 110 return new gpu::demos::PluginModule(); |
110 } | 111 } |
111 | 112 |
112 } // namespace pp | 113 } // namespace pp |
113 | 114 |
OLD | NEW |