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

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
« no previous file with comments | « gpu/demos/framework/demo.cc ('k') | gpu/demos/framework/window.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_.ResizeBuffers(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 };
91 context_ = pp::Graphics3D_Dev(*this, 0, pp::Graphics3D_Dev(), attribs);
92 if (context_.is_null())
93 return;
94
95 pp::Instance::BindGraphics(context_);
96
97 glSetCurrentContextPPAPI(context_.pp_resource());
98 demo_->InitGL();
99 demo_->Resize(size_.width(), size_.height());
74 glSetCurrentContextPPAPI(0); 100 glSetCurrentContextPPAPI(0);
75 } 101 }
76 102
77 private:
78 void OnSwap(int32_t) { 103 void OnSwap(int32_t) {
79 swap_pending_ = false; 104 swap_pending_ = false;
80 if (paint_needed_ || demo_->IsAnimated()) { 105 if (paint_needed_ || demo_->IsAnimated()) {
81 paint_needed_ = false; 106 paint_needed_ = false;
82 Paint(); 107 Paint();
83 } 108 }
84 } 109 }
85 110
86 pp::Module* module_; 111 pp::Module* module_;
87 Demo* demo_; 112 Demo* demo_;
88 pp::Graphics3D_Dev context_; 113 pp::Graphics3D_Dev context_;
89 pp::Size size_; 114 pp::Size size_;
90 bool swap_pending_; 115 bool swap_pending_;
91 bool paint_needed_; 116 bool paint_needed_;
117 bool resize_needed_;
92 pp::CompletionCallbackFactory<PluginInstance> callback_factory_; 118 pp::CompletionCallbackFactory<PluginInstance> callback_factory_;
93 }; 119 };
94 120
95 class PluginModule : public pp::Module { 121 class PluginModule : public pp::Module {
96 public: 122 public:
97 PluginModule() {} 123 PluginModule() {}
98 ~PluginModule() { 124 ~PluginModule() {
99 glTerminatePPAPI(); 125 glTerminatePPAPI();
100 } 126 }
101 127
(...skipping 10 matching lines...) Expand all
112 } // namespace gpu 138 } // namespace gpu
113 139
114 namespace pp { 140 namespace pp {
115 141
116 Module* CreateModule() { 142 Module* CreateModule() {
117 return new gpu::demos::PluginModule(); 143 return new gpu::demos::PluginModule();
118 } 144 }
119 145
120 } // namespace pp 146 } // namespace pp
121 147
OLDNEW
« no previous file with comments | « gpu/demos/framework/demo.cc ('k') | gpu/demos/framework/window.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698