| 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/lib/gl/gles2/gl2ext_ppapi.h" | 17 #include "ppapi/lib/gl/gles2/gl2ext_ppapi.h" |
| 17 | 18 |
| 18 namespace gpu { | 19 namespace gpu { |
| 19 namespace demos { | 20 namespace demos { |
| 20 | 21 |
| 21 class PluginInstance : public pp::Instance { | 22 class PluginInstance : public pp::Instance { |
| 22 public: | 23 public: |
| 23 PluginInstance(PP_Instance instance, pp::Module* module) | 24 PluginInstance(PP_Instance instance, pp::Module* module) |
| 24 : pp::Instance(instance), | 25 : pp::Instance(instance), |
| 25 module_(module), | 26 module_(module), |
| (...skipping 17 matching lines...) Expand all Loading... |
| 43 return; | 44 return; |
| 44 | 45 |
| 45 size_ = position.size(); | 46 size_ = position.size(); |
| 46 demo_->InitWindowSize(size_.width(), size_.height()); | 47 demo_->InitWindowSize(size_.width(), size_.height()); |
| 47 | 48 |
| 48 if (context_.is_null()) { | 49 if (context_.is_null()) { |
| 49 context_ = pp::Context3D_Dev(*this, 0, pp::Context3D_Dev(), NULL); | 50 context_ = pp::Context3D_Dev(*this, 0, pp::Context3D_Dev(), NULL); |
| 50 if (context_.is_null()) | 51 if (context_.is_null()) |
| 51 return; | 52 return; |
| 52 | 53 |
| 53 if (!pp::Instance::BindGraphics(context_)) | |
| 54 return; | |
| 55 | |
| 56 glSetCurrentContextPPAPI(context_.pp_resource()); | 54 glSetCurrentContextPPAPI(context_.pp_resource()); |
| 57 demo_->InitGL(); | 55 demo_->InitGL(); |
| 58 glSetCurrentContextPPAPI(0); | 56 glSetCurrentContextPPAPI(0); |
| 57 } else { |
| 58 // Need to recreate surface. Unbind existing surface. |
| 59 pp::Instance::BindGraphics(pp::Surface3D_Dev()); |
| 60 context_.BindSurfaces(pp::Surface3D_Dev(), pp::Surface3D_Dev()); |
| 59 } | 61 } |
| 62 surface_ = pp::Surface3D_Dev(*this, 0, NULL); |
| 63 context_.BindSurfaces(surface_, surface_); |
| 64 pp::Instance::BindGraphics(surface_); |
| 60 | 65 |
| 61 if (demo_->IsAnimated()) | 66 if (demo_->IsAnimated()) |
| 62 Animate(0); | 67 Animate(0); |
| 63 else | 68 else |
| 64 Paint(); | 69 Paint(); |
| 65 } | 70 } |
| 66 | 71 |
| 67 void Paint() { | 72 void Paint() { |
| 68 glSetCurrentContextPPAPI(context_.pp_resource()); | 73 glSetCurrentContextPPAPI(context_.pp_resource()); |
| 69 demo_->Draw(); | 74 demo_->Draw(); |
| 70 context_.SwapBuffers(); | 75 surface_.SwapBuffers(); |
| 71 glSetCurrentContextPPAPI(0); | 76 glSetCurrentContextPPAPI(0); |
| 72 } | 77 } |
| 73 | 78 |
| 74 private: | 79 private: |
| 75 void Animate(int delay) { | 80 void Animate(int delay) { |
| 76 Paint(); | 81 Paint(); |
| 77 module_->core()->CallOnMainThread(delay, | 82 module_->core()->CallOnMainThread(delay, |
| 78 callback_factory_.NewCallback(&PluginInstance::Animate), delay); | 83 callback_factory_.NewCallback(&PluginInstance::Animate), delay); |
| 79 } | 84 } |
| 80 | 85 |
| 81 pp::Module* module_; | 86 pp::Module* module_; |
| 82 Demo* demo_; | 87 Demo* demo_; |
| 83 pp::Context3D_Dev context_; | 88 pp::Context3D_Dev context_; |
| 89 pp::Surface3D_Dev surface_; |
| 84 pp::Size size_; | 90 pp::Size size_; |
| 85 pp::CompletionCallbackFactory<PluginInstance> callback_factory_; | 91 pp::CompletionCallbackFactory<PluginInstance> callback_factory_; |
| 86 }; | 92 }; |
| 87 | 93 |
| 88 class PluginModule : public pp::Module { | 94 class PluginModule : public pp::Module { |
| 89 public: | 95 public: |
| 90 PluginModule() {} | 96 PluginModule() {} |
| 91 ~PluginModule() { | 97 ~PluginModule() { |
| 92 glTerminatePPAPI(); | 98 glTerminatePPAPI(); |
| 93 } | 99 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 105 } // namespace gpu | 111 } // namespace gpu |
| 106 | 112 |
| 107 namespace pp { | 113 namespace pp { |
| 108 | 114 |
| 109 Module* CreateModule() { | 115 Module* CreateModule() { |
| 110 return new gpu::demos::PluginModule(); | 116 return new gpu::demos::PluginModule(); |
| 111 } | 117 } |
| 112 | 118 |
| 113 } // namespace pp | 119 } // namespace pp |
| 114 | 120 |
| OLD | NEW |