Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2105)

Side by Side Diff: gpu/demos/framework/pepper.cc

Issue 7529009: Updated demo to use resizable plugin element. This exercises the new PPB_Graphics3D_Dev::Resize()... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/graphics_3d_dev.h" 14 #include "ppapi/cpp/dev/graphics_3d_dev.h"
15 #include "ppapi/lib/gl/gles2/gl2ext_ppapi.h" 15 #include "ppapi/lib/gl/gles2/gl2ext_ppapi.h"
16 16
17 namespace gpu { 17 namespace gpu {
18 namespace demos { 18 namespace demos {
19 19
20 class PluginInstance : public pp::Instance { 20 class PluginInstance : public pp::Instance {
21 public: 21 public:
22 PluginInstance(PP_Instance instance, pp::Module* module) 22 PluginInstance(PP_Instance instance, pp::Module* module)
23 : pp::Instance(instance), 23 : pp::Instance(instance),
24 module_(module), 24 module_(module),
25 demo_(CreateDemo()), 25 demo_(CreateDemo()),
26 swap_pending_(false), 26 swap_pending_(false),
27 paint_needed_(false) { 27 paint_needed_(false),
28 resize_needed_(false) {
28 // Set the callback object outside of the initializer list to avoid a 29 // Set the callback object outside of the initializer list to avoid a
29 // compiler warning about using "this" in an initializer list. 30 // compiler warning about using "this" in an initializer list.
30 callback_factory_.Initialize(this); 31 callback_factory_.Initialize(this);
31 } 32 }
32 33
33 ~PluginInstance() { 34 ~PluginInstance() {
34 if (!context_.is_null()) { 35 if (!context_.is_null()) {
35 glSetCurrentContextPPAPI(context_.pp_resource()); 36 glSetCurrentContextPPAPI(context_.pp_resource());
36 delete demo_; 37 delete demo_;
37 glSetCurrentContextPPAPI(0); 38 glSetCurrentContextPPAPI(0);
38 } 39 }
39 } 40 }
40 41
41 virtual void DidChangeView(const pp::Rect& position, 42 virtual void DidChangeView(const pp::Rect& position,
42 const pp::Rect& /*clip*/) { 43 const pp::Rect& /*clip*/) {
43 if (size_ == position.size()) 44 if (size_ == position.size())
44 return; 45 return;
45 46
46 size_ = position.size(); 47 size_ = position.size();
47 demo_->InitWindowSize(size_.width(), size_.height());
48 48
49 if (context_.is_null()) { 49 if (context_.is_null())
50 context_ = pp::Graphics3D_Dev(*this, 0, pp::Graphics3D_Dev(), NULL); 50 CreateContext();
51 if (context_.is_null()) 51 else
52 return; 52 resize_needed_ = true;
53
54 pp::Instance::BindGraphics(context_);
55 glSetCurrentContextPPAPI(context_.pp_resource());
56 demo_->InitGL();
57 glSetCurrentContextPPAPI(0);
58 }
59 53
60 Paint(); 54 Paint();
61 } 55 }
62 56
63 void Paint() { 57 void Paint() {
64 if (swap_pending_) { 58 if (swap_pending_) {
65 // A swap is pending. Delay paint until swap finishes. 59 // A swap is pending. Delay paint until swap finishes.
66 paint_needed_ = true; 60 paint_needed_ = true;
67 return; 61 return;
68 } 62 }
63
64 if (resize_needed_) {
65 context_.Resize(size_.width(), size_.height());
66 demo_->Resize(size_.width(), size_.height());
67 resize_needed_ = false;
68 }
69
69 glSetCurrentContextPPAPI(context_.pp_resource()); 70 glSetCurrentContextPPAPI(context_.pp_resource());
70 demo_->Draw(); 71 demo_->Draw();
72 glSetCurrentContextPPAPI(0);
73
71 swap_pending_ = true; 74 swap_pending_ = true;
72 context_.SwapBuffers( 75 context_.SwapBuffers(
73 callback_factory_.NewCallback(&PluginInstance::OnSwap)); 76 callback_factory_.NewCallback(&PluginInstance::OnSwap));
77 }
78
79 private:
80 void CreateContext() {
81 int32_t attribs[] = {
82 PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 8,
83 PP_GRAPHICS3DATTRIB_DEPTH_SIZE, 24,
84 PP_GRAPHICS3DATTRIB_STENCIL_SIZE, 8,
85 PP_GRAPHICS3DATTRIB_SAMPLES, 0,
86 PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS, 0,
87 PP_GRAPHICS3DATTRIB_WIDTH, size_.width(),
88 PP_GRAPHICS3DATTRIB_HEIGHT, size_.height(),
89 PP_GRAPHICS3DATTRIB_NONE};
90 context_ = pp::Graphics3D_Dev(*this, 0, pp::Graphics3D_Dev(), attribs);
91 if (context_.is_null())
92 return;
93
94 pp::Instance::BindGraphics(context_);
95
96 glSetCurrentContextPPAPI(context_.pp_resource());
97 demo_->InitGL();
98 demo_->Resize(size_.width(), size_.height());
74 glSetCurrentContextPPAPI(0); 99 glSetCurrentContextPPAPI(0);
75 } 100 }
76 101
77 private:
78 void OnSwap(int32_t) { 102 void OnSwap(int32_t) {
79 swap_pending_ = false; 103 swap_pending_ = false;
80 if (paint_needed_ || demo_->IsAnimated()) { 104 if (paint_needed_ || demo_->IsAnimated()) {
81 paint_needed_ = false; 105 paint_needed_ = false;
82 Paint(); 106 Paint();
83 } 107 }
84 } 108 }
85 109
86 pp::Module* module_; 110 pp::Module* module_;
87 Demo* demo_; 111 Demo* demo_;
88 pp::Graphics3D_Dev context_; 112 pp::Graphics3D_Dev context_;
89 pp::Size size_; 113 pp::Size size_;
90 bool swap_pending_; 114 bool swap_pending_;
91 bool paint_needed_; 115 bool paint_needed_;
116 bool resize_needed_;
92 pp::CompletionCallbackFactory<PluginInstance> callback_factory_; 117 pp::CompletionCallbackFactory<PluginInstance> callback_factory_;
93 }; 118 };
94 119
95 class PluginModule : public pp::Module { 120 class PluginModule : public pp::Module {
96 public: 121 public:
97 PluginModule() {} 122 PluginModule() {}
98 ~PluginModule() { 123 ~PluginModule() {
99 glTerminatePPAPI(); 124 glTerminatePPAPI();
100 } 125 }
101 126
(...skipping 10 matching lines...) Expand all
112 } // namespace gpu 137 } // namespace gpu
113 138
114 namespace pp { 139 namespace pp {
115 140
116 Module* CreateModule() { 141 Module* CreateModule() {
117 return new gpu::demos::PluginModule(); 142 return new gpu::demos::PluginModule();
118 } 143 }
119 144
120 } // namespace pp 145 } // namespace pp
121 146
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698