| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/at_exit.h" |
| 6 #include "base/scoped_ptr.h" |
| 7 #include "gpu/demos/framework/demo.h" |
| 8 #include "gpu/demos/framework/demo_factory.h" |
| 9 #include "ppapi/cpp/completion_callback.h" |
| 10 #include "ppapi/cpp/instance.h" |
| 11 #include "ppapi/cpp/dev/graphics_3d_dev.h" |
| 12 #include "ppapi/cpp/module.h" |
| 13 #include "ppapi/cpp/rect.h" |
| 14 #include "ppapi/cpp/size.h" |
| 15 |
| 16 namespace gpu { |
| 17 namespace demos { |
| 18 |
| 19 class PluginInstance : public pp::Instance { |
| 20 public: |
| 21 PluginInstance(PP_Instance instance, pp::Module* module) |
| 22 : pp::Instance(instance), |
| 23 module_(module), |
| 24 demo_(CreateDemo()) { |
| 25 // Set the callback object outside of the initializer list to avoid a |
| 26 // compiler warning about using "this" in an initializer list. |
| 27 callback_factory_.Initialize(this); |
| 28 } |
| 29 |
| 30 ~PluginInstance() { |
| 31 if (!graphics_.is_null()) { |
| 32 graphics_.MakeCurrent(); |
| 33 demo_.reset(); |
| 34 pp::Graphics3D_Dev::ResetCurrent(); |
| 35 } |
| 36 } |
| 37 |
| 38 virtual void ViewChanged(const pp::Rect& position, const pp::Rect& /*clip*/) { |
| 39 if (size_.IsEmpty() && !position.IsEmpty()) { |
| 40 size_ = position.size(); |
| 41 demo_->InitWindowSize(size_.width(), size_.height()); |
| 42 graphics_ = pp::Graphics3D_Dev(*this, 0, NULL, NULL); |
| 43 if (!graphics_.is_null()) { |
| 44 graphics_.MakeCurrent(); |
| 45 demo_->InitGL(); |
| 46 pp::Graphics3D_Dev::ResetCurrent(); |
| 47 |
| 48 // TODO(neb): Remove this once the startup order bug (51842) is fixed. |
| 49 if (true) |
| 50 // if (demo_->IsAnimated()) |
| 51 Animate(0); |
| 52 else |
| 53 Paint(); |
| 54 } |
| 55 } |
| 56 } |
| 57 |
| 58 virtual void Graphics3DContextLost() { |
| 59 // TODO(neb): Replace this with the correct code once 53889 is fixed. |
| 60 Paint(); |
| 61 // pp::Rect fake_position(size_); |
| 62 // size_ = pp::Size(); |
| 63 // ViewChanged(fake_position, fake_position); |
| 64 } |
| 65 |
| 66 void Paint() { |
| 67 graphics_.MakeCurrent(); |
| 68 demo_->Draw(); |
| 69 graphics_.SwapBuffers(); |
| 70 pp::Graphics3D_Dev::ResetCurrent(); |
| 71 } |
| 72 |
| 73 private: |
| 74 void Animate(int delay) { |
| 75 Paint(); |
| 76 module_->core()->CallOnMainThread(delay, |
| 77 callback_factory_.NewCallback(&PluginInstance::Animate), delay); |
| 78 } |
| 79 |
| 80 pp::Module* module_; |
| 81 scoped_ptr<Demo> demo_; |
| 82 pp::Graphics3D_Dev graphics_; |
| 83 pp::Size size_; |
| 84 pp::CompletionCallbackFactory<PluginInstance> callback_factory_; |
| 85 }; |
| 86 |
| 87 class PluginModule : public pp::Module { |
| 88 public: |
| 89 PluginModule() : pp::Module(), at_exit_manager_(new base::AtExitManager) {} |
| 90 |
| 91 virtual pp::Instance* CreateInstance(PP_Instance instance) { |
| 92 return new PluginInstance(instance, this); |
| 93 } |
| 94 |
| 95 private: |
| 96 scoped_ptr<base::AtExitManager> at_exit_manager_; |
| 97 }; |
| 98 |
| 99 } // namespace demos |
| 100 } // namespace gpu |
| 101 |
| 102 namespace pp { |
| 103 |
| 104 Module* CreateModule() { |
| 105 return new gpu::demos::PluginModule(); |
| 106 } |
| 107 |
| 108 } // namespace pp |
| 109 |
| OLD | NEW |