OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 10 matching lines...) Expand all Loading... |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "webkit/tools/pepper_test_plugin/plugin_object.h" | 26 #include "webkit/tools/pepper_test_plugin/plugin_object.h" |
27 | 27 |
28 #include <stdio.h> | 28 #include <stdio.h> |
29 #include <string> | 29 #include <string> |
30 | 30 |
31 #if defined(INDEPENDENT_PLUGIN) | |
32 #define CHECK(x) | |
33 #else | |
34 #include "base/logging.h" | 31 #include "base/logging.h" |
35 #include "gpu/command_buffer/client/gles2_lib.h" | 32 #include "gpu/command_buffer/client/gles2_lib.h" |
36 #include "gpu/command_buffer/client/gles2_demo_cc.h" | 33 #include "gpu/command_buffer/client/gles2_demo_cc.h" |
37 #include "third_party/skia/include/core/SkBitmap.h" | 34 #include "third_party/skia/include/core/SkBitmap.h" |
38 #include "third_party/skia/include/core/SkCanvas.h" | 35 #include "third_party/skia/include/core/SkCanvas.h" |
39 #include "third_party/skia/include/effects/SkGradientShader.h" | 36 #include "third_party/skia/include/effects/SkGradientShader.h" |
40 #endif | |
41 #include "webkit/tools/pepper_test_plugin/event_handler.h" | 37 #include "webkit/tools/pepper_test_plugin/event_handler.h" |
42 #include "webkit/tools/pepper_test_plugin/test_object.h" | 38 #include "webkit/tools/pepper_test_plugin/test_object.h" |
43 | 39 |
44 NPNetscapeFuncs* browser; | 40 NPNetscapeFuncs* browser; |
45 | 41 |
46 namespace { | 42 namespace { |
47 | 43 |
48 // Properties ------------------------------------------------------------------ | 44 // Properties ------------------------------------------------------------------ |
49 | 45 |
50 enum { | 46 enum { |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 PluginHasMethod, | 203 PluginHasMethod, |
208 PluginInvoke, | 204 PluginInvoke, |
209 PluginInvokeDefault, | 205 PluginInvokeDefault, |
210 PluginHasProperty, | 206 PluginHasProperty, |
211 PluginGetProperty, | 207 PluginGetProperty, |
212 PluginSetProperty, | 208 PluginSetProperty, |
213 }; | 209 }; |
214 | 210 |
215 // Bitmap painting ------------------------------------------------------------- | 211 // Bitmap painting ------------------------------------------------------------- |
216 | 212 |
217 #if defined(INDEPENDENT_PLUGIN) | 213 void DrawSampleBitmap(SkCanvas& canvas, int width, int height) { |
218 void DrawSampleBitmap(void *region, int width, int height) { | |
219 int32 *bitmap = reinterpret_cast<int32 *>(region); | |
220 | |
221 for (int h = 0; h < height; ++h) { | |
222 uint8 opacity = (h * 0xff) / height; | |
223 for (int w = 0; w < width; ++w) { | |
224 // kudos to apatrick for noticing we're using premultiplied alpha | |
225 uint8 greenness = (w * opacity) / width; | |
226 *bitmap++ = (opacity << 24) | (greenness << 8); | |
227 } | |
228 } | |
229 } | |
230 #else | |
231 void DrawSampleBitmap(void *region, int width, int height) { | |
232 SkBitmap bitmap; | |
233 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); | |
234 bitmap.setPixels(region); | |
235 | |
236 SkCanvas canvas(bitmap); | |
237 SkRect rect; | 214 SkRect rect; |
238 rect.set(SkIntToScalar(0), SkIntToScalar(0), | 215 rect.set(SkIntToScalar(0), SkIntToScalar(0), |
239 SkIntToScalar(width), SkIntToScalar(height)); | 216 SkIntToScalar(width), SkIntToScalar(height)); |
240 SkPath path; | 217 SkPath path; |
241 path.addOval(rect); | 218 path.addOval(rect); |
242 | 219 |
243 // Create a gradient shader going from opaque green to transparent. | 220 // Create a gradient shader going from opaque green to transparent. |
244 SkPaint paint; | 221 SkPaint paint; |
245 paint.setAntiAlias(true); | 222 paint.setAntiAlias(true); |
246 | 223 |
247 SkColor grad_colors[2]; | 224 SkColor grad_colors[2]; |
248 grad_colors[0] = SkColorSetARGB(0xFF, 0x00, 0xFF, 0x00); | 225 grad_colors[0] = SkColorSetARGB(0xFF, 0x00, 0xFF, 0x00); |
249 grad_colors[1] = SkColorSetARGB(0x00, 0x00, 0xFF, 0x00); | 226 grad_colors[1] = SkColorSetARGB(0x00, 0x00, 0xFF, 0x00); |
250 SkPoint grad_points[2]; | 227 SkPoint grad_points[2]; |
251 grad_points[0].set(SkIntToScalar(0), SkIntToScalar(0)); | 228 grad_points[0].set(SkIntToScalar(0), SkIntToScalar(0)); |
252 grad_points[1].set(SkIntToScalar(0), SkIntToScalar(height)); | 229 grad_points[1].set(SkIntToScalar(0), SkIntToScalar(height)); |
253 paint.setShader(SkGradientShader::CreateLinear( | 230 paint.setShader(SkGradientShader::CreateLinear( |
254 grad_points, grad_colors, NULL, 2, SkShader::kRepeat_TileMode)) | 231 grad_points, grad_colors, NULL, 2, SkShader::kRepeat_TileMode)) |
255 ->safeUnref(); | 232 ->safeUnref(); |
256 | 233 |
257 canvas.drawPath(path, paint); | 234 canvas.drawPath(path, paint); |
258 } | 235 } |
259 #endif | 236 |
260 void FlushCallback(NPP instance, NPDeviceContext* context, | 237 void FlushCallback(NPP instance, NPDeviceContext* context, |
261 NPError err, void* user_data) { | 238 NPError err, void* user_data) { |
262 } | 239 } |
263 | 240 |
264 NPExtensions* extensions = NULL; | 241 NPExtensions* extensions = NULL; |
265 | 242 |
266 } // namespace | 243 } // namespace |
267 | 244 |
268 | 245 |
269 // PluginObject ---------------------------------------------------------------- | 246 // PluginObject ---------------------------------------------------------------- |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 browser->getvalue(npp_, NPNVPepperExtensions, | 283 browser->getvalue(npp_, NPNVPepperExtensions, |
307 reinterpret_cast<void*>(&extensions)); | 284 reinterpret_cast<void*>(&extensions)); |
308 CHECK(extensions); | 285 CHECK(extensions); |
309 } | 286 } |
310 device2d_ = extensions->acquireDevice(npp_, NPPepper2DDevice); | 287 device2d_ = extensions->acquireDevice(npp_, NPPepper2DDevice); |
311 CHECK(device2d_); | 288 CHECK(device2d_); |
312 } | 289 } |
313 | 290 |
314 void PluginObject::SetWindow(const NPWindow& window) { | 291 void PluginObject::SetWindow(const NPWindow& window) { |
315 if (dimensions_ == 2) { | 292 if (dimensions_ == 2) { |
316 width_ = window.width; | 293 size_.set_width(window.width); |
317 height_ = window.height; | 294 size_.set_height(window.height); |
318 | 295 |
319 NPDeviceContext2DConfig config; | 296 NPDeviceContext2DConfig config; |
320 NPDeviceContext2D context; | 297 NPDeviceContext2D context; |
321 device2d_->initializeContext(npp_, &config, &context); | 298 device2d_->initializeContext(npp_, &config, &context); |
322 | 299 |
323 DrawSampleBitmap(context.region, width_, height_); | 300 SkBitmap bitmap; |
| 301 bitmap.setConfig(SkBitmap::kARGB_8888_Config, window.width, window.height); |
| 302 bitmap.setPixels(context.region); |
| 303 |
| 304 SkCanvas canvas(bitmap); |
| 305 DrawSampleBitmap(canvas, window.width, window.height); |
324 | 306 |
325 // TODO(brettw) figure out why this cast is necessary, the functions seem to | 307 // TODO(brettw) figure out why this cast is necessary, the functions seem to |
326 // match. Could be a calling convention mismatch? | 308 // match. Could be a calling convention mismatch? |
327 NPDeviceFlushContextCallbackPtr callback = | 309 NPDeviceFlushContextCallbackPtr callback = |
328 reinterpret_cast<NPDeviceFlushContextCallbackPtr>(&FlushCallback); | 310 reinterpret_cast<NPDeviceFlushContextCallbackPtr>(&FlushCallback); |
329 device2d_->flushContext(npp_, &context, callback, NULL); | 311 device2d_->flushContext(npp_, &context, callback, NULL); |
330 } else { | 312 } else { |
331 #if !defined(INDEPENDENT_PLUGIN) | |
332 if (!command_buffer_.get()) { | 313 if (!command_buffer_.get()) { |
333 if (!InitializeCommandBuffer()) | 314 if (!InitializeCommandBuffer()) |
334 return; | 315 return; |
335 } | 316 } |
336 | 317 |
337 gles2_implementation_->Viewport(0, 0, window.width, window.height); | 318 gles2_implementation_->Viewport(0, 0, window.width, window.height); |
338 | 319 |
339 // Schedule the first call to Draw. | 320 // Schedule the first call to Draw. |
340 browser->pluginthreadasynccall(npp_, Draw3DCallback, this); | 321 browser->pluginthreadasynccall(npp_, Draw3DCallback, this); |
341 #endif | |
342 } | 322 } |
343 } | 323 } |
344 | 324 |
345 void PluginObject::Draw3D() { | 325 void PluginObject::Draw3D() { |
346 #if !defined(INDEPENDENT_PLUGIN) | |
347 // Render some stuff. | 326 // Render some stuff. |
348 gles2::g_gl_impl = gles2_implementation_.get(); | 327 gles2::g_gl_impl = gles2_implementation_.get(); |
349 GLFromCPPTestFunction(); | 328 GLFromCPPTestFunction(); |
350 gles2::GetGLContext()->SwapBuffers(); | 329 gles2::GetGLContext()->SwapBuffers(); |
351 helper_->Flush(); | 330 helper_->Flush(); |
352 gles2::g_gl_impl = NULL; | 331 gles2::g_gl_impl = NULL; |
353 | 332 |
354 // Schedule another call to Draw. | 333 // Schedule another call to Draw. |
355 browser->pluginthreadasynccall(npp_, Draw3DCallback, this); | 334 browser->pluginthreadasynccall(npp_, Draw3DCallback, this); |
356 #endif | |
357 } | 335 } |
358 | 336 |
359 bool PluginObject::InitializeCommandBuffer() { | 337 bool PluginObject::InitializeCommandBuffer() { |
360 #if !defined(INDEPENDENT_PLUGIN) | |
361 const static int32 kCommandBufferSize = 512 * 1024; | 338 const static int32 kCommandBufferSize = 512 * 1024; |
362 command_buffer_.reset(new CommandBufferPepper(npp_, browser)); | 339 command_buffer_.reset(new CommandBufferPepper(npp_, browser)); |
363 if (command_buffer_->Initialize(kCommandBufferSize)) { | 340 if (command_buffer_->Initialize(kCommandBufferSize)) { |
364 helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer_.get())); | 341 helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer_.get())); |
365 if (helper_->Initialize()) { | 342 if (helper_->Initialize()) { |
366 | 343 |
367 const int32 kTransferBufferSize = 512 * 1024; | 344 const int32 kTransferBufferSize = 512 * 1024; |
368 int32 transfer_buffer_id = | 345 int32 transfer_buffer_id = |
369 command_buffer_->CreateTransferBuffer(kTransferBufferSize); | 346 command_buffer_->CreateTransferBuffer(kTransferBufferSize); |
370 gpu::Buffer transfer_buffer = | 347 gpu::Buffer transfer_buffer = |
371 command_buffer_->GetTransferBuffer(transfer_buffer_id); | 348 command_buffer_->GetTransferBuffer(transfer_buffer_id); |
372 if (transfer_buffer.ptr) { | 349 if (transfer_buffer.ptr) { |
373 gles2_implementation_.reset(new gpu::gles2::GLES2Implementation( | 350 gles2_implementation_.reset(new gpu::gles2::GLES2Implementation( |
374 helper_.get(), | 351 helper_.get(), |
375 transfer_buffer.size, | 352 transfer_buffer.size, |
376 transfer_buffer.ptr, | 353 transfer_buffer.ptr, |
377 transfer_buffer_id)); | 354 transfer_buffer_id)); |
378 return true; | 355 return true; |
379 } | 356 } |
380 } | 357 } |
381 | 358 |
382 helper_.reset(); | 359 helper_.reset(); |
383 } | 360 } |
384 | 361 |
385 command_buffer_.reset(); | 362 command_buffer_.reset(); |
386 #endif | |
387 | 363 |
388 return false; | 364 return false; |
389 } | 365 } |
OLD | NEW |