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

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

Issue 554053: Added infrastructure to run gpu demos under Pepper3D. Created a Demo class th... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 11 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/plugin.h ('k') | gpu/demos/framework/plugin.def » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(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 "gpu/demos/framework/plugin.h"
6
7 #include "base/logging.h"
8 #include "gpu/demos/framework/demo_factory.h"
9
10 namespace {
11 const int32 kCommandBufferSize = 1024 * 1024;
12 NPExtensions* g_extensions = NULL;
13
14 // Plugin class functions.
15 using gpu::demos::Plugin;
16 NPObject* PluginAllocate(NPP npp, NPClass* the_class) {
17 Plugin* plugin = new Plugin(npp);
18 return plugin;
19 }
20
21 void PluginDeallocate(NPObject* header) {
22 Plugin* plugin = static_cast<Plugin*>(header);
23 delete plugin;
24 }
25
26 void PluginInvalidate(NPObject* obj) {
27 }
28
29 bool PluginHasMethod(NPObject* obj, NPIdentifier name) {
30 return false;
31 }
32
33 bool PluginInvoke(NPObject* header,
34 NPIdentifier name,
35 const NPVariant* args, uint32 arg_count,
36 NPVariant* result) {
37 return false;
38 }
39
40 bool PluginInvokeDefault(NPObject* obj,
41 const NPVariant* args, uint32 arg_count,
42 NPVariant* result) {
43 VOID_TO_NPVARIANT(*result);
44 return true;
45 }
46
47 bool PluginHasProperty(NPObject* obj, NPIdentifier name) {
48 return false;
49 }
50
51 bool PluginGetProperty(NPObject* obj,
52 NPIdentifier name,
53 NPVariant* result) {
54 return false;
55 }
56
57 bool PluginSetProperty(NPObject* obj,
58 NPIdentifier name,
59 const NPVariant* variant) {
60 return false;
61 }
62
63 NPClass plugin_class = {
64 NP_CLASS_STRUCT_VERSION,
65 PluginAllocate,
66 PluginDeallocate,
67 PluginInvalidate,
68 PluginHasMethod,
69 PluginInvoke,
70 PluginInvokeDefault,
71 PluginHasProperty,
72 PluginGetProperty,
73 PluginSetProperty,
74 };
75
76 void PaintCallback(void* data) {
77 reinterpret_cast<gpu::demos::Plugin*>(data)->Paint();
78 }
79 }
80
81 namespace gpu {
82 namespace demos {
83
84 NPNetscapeFuncs* g_browser;
85
86 Plugin::Plugin(NPP npp)
87 : npp_(npp),
88 device3d_(NULL),
89 pgl_context_(NULL),
90 demo_(CreateDemo()) {
91 memset(&context3d_, 0, sizeof(context3d_));
92 }
93
94 Plugin::~Plugin() {
95 pglMakeCurrent(NULL);
96 pglDestroyContext(pgl_context_);
97 }
98
99 NPClass* Plugin::GetPluginClass() {
100 return &plugin_class;
101 }
102
103 void Plugin::New(NPMIMEType pluginType,
104 int16 argc, char* argn[], char* argv[]) {
105 if (!g_extensions) {
106 g_browser->getvalue(npp_, NPNVPepperExtensions, &g_extensions);
107 CHECK(g_extensions);
108 }
109
110 device3d_ = g_extensions->acquireDevice(npp_, NPPepper3DDevice);
111 CHECK(device3d_);
112 }
113
114 void Plugin::SetWindow(const NPWindow& window) {
115 if (!pgl_context_) {
116 // Initialize a 3D context.
117 NPDeviceContext3DConfig config;
118 config.commandBufferEntries = kCommandBufferSize;
119 device3d_->initializeContext(npp_, &config, &context3d_);
120
121 // Create a PGL context.
122 pgl_context_ = pglCreateContext(npp_, device3d_, &context3d_);
123
124 // Initialize demo.
125 pglMakeCurrent(pgl_context_);
126 demo_->InitWindowSize(window.width, window.height);
127 CHECK(demo_->InitGL());
128 pglMakeCurrent(NULL);
129 }
130
131 // Schedule the first call to Draw.
132 g_browser->pluginthreadasynccall(npp_, PaintCallback, this);
133 }
134
135 void Plugin::Paint() {
136 // Render some stuff.
137 pglMakeCurrent(pgl_context_);
138 demo_->Draw();
139 pglSwapBuffers();
140 pglMakeCurrent(NULL);
141
142 // Schedule another call to Paint.
143 g_browser->pluginthreadasynccall(npp_, PaintCallback, this);
144 }
145
146 } // namespace demos
147 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/demos/framework/plugin.h ('k') | gpu/demos/framework/plugin.def » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698