| 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/module.h" | 11 #include "ppapi/cpp/module.h" |
| 12 #include "ppapi/cpp/rect.h" | 12 #include "ppapi/cpp/rect.h" |
| 13 #include "ppapi/cpp/size.h" | 13 #include "ppapi/cpp/size.h" |
| 14 #include "ppapi/cpp/dev/context_3d_dev.h" | 14 #include "ppapi/cpp/dev/context_3d_dev.h" |
| 15 #include "ppapi/cpp/dev/graphics_3d_dev.h" | 15 #include "ppapi/cpp/dev/graphics_3d_dev.h" |
| 16 #include "ppapi/cpp/dev/surface_3d_dev.h" | 16 #include "ppapi/cpp/dev/surface_3d_dev.h" |
| 17 #include "ppapi/lib/gl/gles2/gl2ext_ppapi.h" | 17 #include "ppapi/lib/gl/gles2/gl2ext_ppapi.h" |
| 18 | 18 |
| 19 namespace gpu { | 19 namespace gpu { |
| 20 namespace demos { | 20 namespace demos { |
| 21 | 21 |
| 22 class PluginInstance : public pp::Instance { | 22 class PluginInstance : public pp::Instance { |
| 23 public: | 23 public: |
| 24 PluginInstance(PP_Instance instance, pp::Module* module) | 24 PluginInstance(PP_Instance instance, pp::Module* module) |
| 25 : pp::Instance(instance), | 25 : pp::Instance(instance), |
| 26 module_(module), | 26 module_(module), |
| 27 demo_(CreateDemo()) { | 27 demo_(CreateDemo()), |
| 28 swap_pending_(false), |
| 29 paint_needed_(false) { |
| 28 // Set the callback object outside of the initializer list to avoid a | 30 // Set the callback object outside of the initializer list to avoid a |
| 29 // compiler warning about using "this" in an initializer list. | 31 // compiler warning about using "this" in an initializer list. |
| 30 callback_factory_.Initialize(this); | 32 callback_factory_.Initialize(this); |
| 31 } | 33 } |
| 32 | 34 |
| 33 ~PluginInstance() { | 35 ~PluginInstance() { |
| 34 if (!context_.is_null()) { | 36 if (!context_.is_null()) { |
| 35 glSetCurrentContextPPAPI(context_.pp_resource()); | 37 glSetCurrentContextPPAPI(context_.pp_resource()); |
| 36 delete demo_; | 38 delete demo_; |
| 37 glSetCurrentContextPPAPI(0); | 39 glSetCurrentContextPPAPI(0); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 56 glSetCurrentContextPPAPI(0); | 58 glSetCurrentContextPPAPI(0); |
| 57 } else { | 59 } else { |
| 58 // Need to recreate surface. Unbind existing surface. | 60 // Need to recreate surface. Unbind existing surface. |
| 59 pp::Instance::BindGraphics(pp::Surface3D_Dev()); | 61 pp::Instance::BindGraphics(pp::Surface3D_Dev()); |
| 60 context_.BindSurfaces(pp::Surface3D_Dev(), pp::Surface3D_Dev()); | 62 context_.BindSurfaces(pp::Surface3D_Dev(), pp::Surface3D_Dev()); |
| 61 } | 63 } |
| 62 surface_ = pp::Surface3D_Dev(*this, 0, NULL); | 64 surface_ = pp::Surface3D_Dev(*this, 0, NULL); |
| 63 context_.BindSurfaces(surface_, surface_); | 65 context_.BindSurfaces(surface_, surface_); |
| 64 pp::Instance::BindGraphics(surface_); | 66 pp::Instance::BindGraphics(surface_); |
| 65 | 67 |
| 66 if (demo_->IsAnimated()) | 68 Paint(); |
| 67 Animate(0); | |
| 68 else | |
| 69 Paint(); | |
| 70 } | 69 } |
| 71 | 70 |
| 72 void Paint() { | 71 void Paint() { |
| 72 if (swap_pending_) { |
| 73 // A swap is pending. Delay paint until swap finishes. |
| 74 paint_needed_ = true; |
| 75 return; |
| 76 } |
| 73 glSetCurrentContextPPAPI(context_.pp_resource()); | 77 glSetCurrentContextPPAPI(context_.pp_resource()); |
| 74 demo_->Draw(); | 78 demo_->Draw(); |
| 75 surface_.SwapBuffers(); | 79 swap_pending_ = true; |
| 80 surface_.SwapBuffers( |
| 81 callback_factory_.NewCallback(&PluginInstance::OnSwap)); |
| 76 glSetCurrentContextPPAPI(0); | 82 glSetCurrentContextPPAPI(0); |
| 77 } | 83 } |
| 78 | 84 |
| 79 private: | 85 private: |
| 80 void Animate(int delay) { | 86 void OnSwap(int32_t) { |
| 81 Paint(); | 87 swap_pending_ = false; |
| 82 module_->core()->CallOnMainThread(delay, | 88 if (paint_needed_ || demo_->IsAnimated()) { |
| 83 callback_factory_.NewCallback(&PluginInstance::Animate), delay); | 89 paint_needed_ = false; |
| 90 Paint(); |
| 91 } |
| 84 } | 92 } |
| 85 | 93 |
| 86 pp::Module* module_; | 94 pp::Module* module_; |
| 87 Demo* demo_; | 95 Demo* demo_; |
| 88 pp::Context3D_Dev context_; | 96 pp::Context3D_Dev context_; |
| 89 pp::Surface3D_Dev surface_; | 97 pp::Surface3D_Dev surface_; |
| 90 pp::Size size_; | 98 pp::Size size_; |
| 99 bool swap_pending_; |
| 100 bool paint_needed_; |
| 91 pp::CompletionCallbackFactory<PluginInstance> callback_factory_; | 101 pp::CompletionCallbackFactory<PluginInstance> callback_factory_; |
| 92 }; | 102 }; |
| 93 | 103 |
| 94 class PluginModule : public pp::Module { | 104 class PluginModule : public pp::Module { |
| 95 public: | 105 public: |
| 96 PluginModule() {} | 106 PluginModule() {} |
| 97 ~PluginModule() { | 107 ~PluginModule() { |
| 98 glTerminatePPAPI(); | 108 glTerminatePPAPI(); |
| 99 } | 109 } |
| 100 | 110 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 111 } // namespace gpu | 121 } // namespace gpu |
| 112 | 122 |
| 113 namespace pp { | 123 namespace pp { |
| 114 | 124 |
| 115 Module* CreateModule() { | 125 Module* CreateModule() { |
| 116 return new gpu::demos::PluginModule(); | 126 return new gpu::demos::PluginModule(); |
| 117 } | 127 } |
| 118 | 128 |
| 119 } // namespace pp | 129 } // namespace pp |
| 120 | 130 |
| OLD | NEW |