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

Side by Side Diff: webkit/tools/pepper_test_plugin/plugin_object.cc

Issue 552007: Resubmitting r36268 with a fix for mac:... (Closed) Base URL: svn://chrome-svn/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 | « webkit/tools/pepper_test_plugin/plugin_object.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 16 matching lines...) Expand all
27 27
28 #include <stdio.h> 28 #include <stdio.h>
29 #include <cmath> 29 #include <cmath>
30 #include <limits> 30 #include <limits>
31 #include <string> 31 #include <string>
32 32
33 #if defined(INDEPENDENT_PLUGIN) 33 #if defined(INDEPENDENT_PLUGIN)
34 #define CHECK(x) 34 #define CHECK(x)
35 #else 35 #else
36 #include "base/logging.h" 36 #include "base/logging.h"
37 #include "gpu/command_buffer/client/gles2_lib.h"
38 #include "gpu/command_buffer/client/gles2_demo_cc.h" 37 #include "gpu/command_buffer/client/gles2_demo_cc.h"
38 #include "gpu/command_buffer/common/gles2/gl2.h"
39 #include "third_party/skia/include/core/SkBitmap.h" 39 #include "third_party/skia/include/core/SkBitmap.h"
40 #include "third_party/skia/include/core/SkCanvas.h" 40 #include "third_party/skia/include/core/SkCanvas.h"
41 #include "third_party/skia/include/effects/SkGradientShader.h" 41 #include "third_party/skia/include/effects/SkGradientShader.h"
42 #endif 42 #endif
43 #include "webkit/tools/pepper_test_plugin/event_handler.h" 43 #include "webkit/tools/pepper_test_plugin/event_handler.h"
44 #include "webkit/tools/pepper_test_plugin/test_object.h" 44 #include "webkit/tools/pepper_test_plugin/test_object.h"
45 45
46 NPNetscapeFuncs* browser; 46 NPNetscapeFuncs* browser;
47 47
48 namespace { 48 namespace {
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 T* buf = reinterpret_cast<T*>(context->outBuffer); 281 T* buf = reinterpret_cast<T*>(context->outBuffer);
282 for (size_t sample = 0; sample < n_samples; ++sample) { 282 for (size_t sample = 0; sample < n_samples; ++sample) {
283 T value = static_cast<T>(sin(th * t++) * std::numeric_limits<T>::max()); 283 T value = static_cast<T>(sin(th * t++) * std::numeric_limits<T>::max());
284 for (size_t channel = 0; channel < n_channels; ++channel) { 284 for (size_t channel = 0; channel < n_channels; ++channel) {
285 *buf++ = value; 285 *buf++ = value;
286 } 286 }
287 } 287 }
288 context->config.userData = reinterpret_cast<void *>(t); 288 context->config.userData = reinterpret_cast<void *>(t);
289 } 289 }
290 290
291 const int32 kCommandBufferSize = 1024 * 1024;
292
291 } // namespace 293 } // namespace
292 294
293 295
294 // PluginObject ---------------------------------------------------------------- 296 // PluginObject ----------------------------------------------------------------
295 297
296 PluginObject::PluginObject(NPP npp) 298 PluginObject::PluginObject(NPP npp)
297 : npp_(npp), 299 : npp_(npp),
298 test_object_(browser->createobject(npp, GetTestClass())), 300 test_object_(browser->createobject(npp, GetTestClass())),
299 device2d_(NULL) { 301 device2d_(NULL),
302 device3d_(NULL),
303 deviceaudio_(NULL),
304 pgl_context_(NULL) {
300 memset(&context_audio_, 0, sizeof(context_audio_)); 305 memset(&context_audio_, 0, sizeof(context_audio_));
301 } 306 }
302 307
303 PluginObject::~PluginObject() { 308 PluginObject::~PluginObject() {
304 deviceaudio_->destroyContext(npp_, &context_audio_); 309 deviceaudio_->destroyContext(npp_, &context_audio_);
305 // FIXME(brettw) destroy the context. 310 // FIXME(brettw) destroy the context.
306 browser->releaseobject(test_object_); 311 browser->releaseobject(test_object_);
307 } 312 }
308 313
309 // static 314 // static
(...skipping 20 matching lines...) Expand all
330 } 335 }
331 336
332 if (!extensions) { 337 if (!extensions) {
333 browser->getvalue(npp_, NPNVPepperExtensions, 338 browser->getvalue(npp_, NPNVPepperExtensions,
334 reinterpret_cast<void*>(&extensions)); 339 reinterpret_cast<void*>(&extensions));
335 CHECK(extensions); 340 CHECK(extensions);
336 } 341 }
337 device2d_ = extensions->acquireDevice(npp_, NPPepper2DDevice); 342 device2d_ = extensions->acquireDevice(npp_, NPPepper2DDevice);
338 CHECK(device2d_); 343 CHECK(device2d_);
339 344
345 device3d_ = extensions->acquireDevice(npp_, NPPepper3DDevice);
346 CHECK(device3d_);
347
340 deviceaudio_ = extensions->acquireDevice(npp_, NPPepperAudioDevice); 348 deviceaudio_ = extensions->acquireDevice(npp_, NPPepperAudioDevice);
341 CHECK(deviceaudio_); 349 CHECK(deviceaudio_);
342 } 350 }
343 351
344 void PluginObject::SetWindow(const NPWindow& window) { 352 void PluginObject::SetWindow(const NPWindow& window) {
345 if (dimensions_ == 2) { 353 if (dimensions_ == 2) {
346 width_ = window.width; 354 width_ = window.width;
347 height_ = window.height; 355 height_ = window.height;
348 356
349 NPDeviceContext2DConfig config; 357 NPDeviceContext2DConfig config;
350 NPDeviceContext2D context; 358 NPDeviceContext2D context;
351 device2d_->initializeContext(npp_, &config, &context); 359 device2d_->initializeContext(npp_, &config, &context);
352 360
353 DrawSampleBitmap(context.region, width_, height_); 361 DrawSampleBitmap(context.region, width_, height_);
354 362
355 // TODO(brettw) figure out why this cast is necessary, the functions seem to 363 // TODO(brettw) figure out why this cast is necessary, the functions seem to
356 // match. Could be a calling convention mismatch? 364 // match. Could be a calling convention mismatch?
357 NPDeviceFlushContextCallbackPtr callback = 365 NPDeviceFlushContextCallbackPtr callback =
358 reinterpret_cast<NPDeviceFlushContextCallbackPtr>(&FlushCallback); 366 reinterpret_cast<NPDeviceFlushContextCallbackPtr>(&FlushCallback);
359 device2d_->flushContext(npp_, &context, callback, NULL); 367 device2d_->flushContext(npp_, &context, callback, NULL);
360 } else { 368 } else {
361 #if !defined(INDEPENDENT_PLUGIN) 369 #if !defined(INDEPENDENT_PLUGIN)
362 if (!command_buffer_.get()) { 370 if (!pgl_context_) {
363 if (!InitializeCommandBuffer()) 371 // Initialize a 3D context.
364 return; 372 NPDeviceContext3DConfig config;
373 config.commandBufferEntries = kCommandBufferSize;
374 device3d_->initializeContext(npp_, &config, &context3d_);
375
376 // Create a PGL context.
377 pgl_context_ = pglCreateContext(npp_, device3d_, &context3d_);
365 } 378 }
366 379
367 gles2_implementation_->Viewport(0, 0, window.width, window.height); 380 // Reset the viewport to new window size.
381 pglMakeCurrent(pgl_context_);
382 glViewport(0, 0, window.width, window.height);
383 pglMakeCurrent(NULL);
368 384
369 // Schedule the first call to Draw. 385 // Schedule the first call to Draw.
370 browser->pluginthreadasynccall(npp_, Draw3DCallback, this); 386 browser->pluginthreadasynccall(npp_, Draw3DCallback, this);
371 #endif 387 #endif
372 } 388 }
373 389
374 // testing any field would do 390 // testing any field would do
375 if (!context_audio_.config.callback) { 391 if (!context_audio_.config.callback) {
376 NPDeviceContextAudioConfig cfg; 392 NPDeviceContextAudioConfig cfg;
377 cfg.sampleRate = 44100; 393 cfg.sampleRate = 44100;
378 cfg.sampleType = NPAudioSampleTypeInt16; 394 cfg.sampleType = NPAudioSampleTypeInt16;
379 cfg.outputChannelMap = NPAudioChannelStereo; 395 cfg.outputChannelMap = NPAudioChannelStereo;
380 cfg.inputChannelMap = NPAudioChannelNone; 396 cfg.inputChannelMap = NPAudioChannelNone;
381 cfg.sampleFrameCount = 2048; 397 cfg.sampleFrameCount = 2048;
382 cfg.flags = 0; 398 cfg.flags = 0;
383 cfg.callback = &SineWaveCallback<200, int16>; 399 cfg.callback = &SineWaveCallback<200, int16>;
384 deviceaudio_->initializeContext(npp_, &cfg, &context_audio_); 400 deviceaudio_->initializeContext(npp_, &cfg, &context_audio_);
385 } 401 }
386 } 402 }
387 403
388 void PluginObject::Draw3D() { 404 void PluginObject::Draw3D() {
389 #if !defined(INDEPENDENT_PLUGIN) 405 #if !defined(INDEPENDENT_PLUGIN)
390 // Render some stuff. 406 // Render some stuff.
391 gles2::g_gl_impl = gles2_implementation_.get(); 407 pglMakeCurrent(pgl_context_);
392 GLFromCPPTestFunction(); 408 GLFromCPPTestFunction();
393 gles2::GetGLContext()->SwapBuffers(); 409 pglSwapBuffers();
394 helper_->Flush(); 410 pglMakeCurrent(NULL);
395 gles2::g_gl_impl = NULL;
396 411
397 // Schedule another call to Draw. 412 // Schedule another call to Draw.
398 browser->pluginthreadasynccall(npp_, Draw3DCallback, this); 413 browser->pluginthreadasynccall(npp_, Draw3DCallback, this);
399 #endif 414 #endif
400 } 415 }
401
402 bool PluginObject::InitializeCommandBuffer() {
403 #if !defined(INDEPENDENT_PLUGIN)
404 static const int32 kCommandBufferSize = 512 * 1024;
405 command_buffer_.reset(new CommandBufferPepper(npp_, browser));
406 if (command_buffer_->Initialize(kCommandBufferSize)) {
407 helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer_.get()));
408 if (helper_->Initialize()) {
409 const int32 kTransferBufferSize = 512 * 1024;
410 int32 transfer_buffer_id =
411 command_buffer_->CreateTransferBuffer(kTransferBufferSize);
412 gpu::Buffer transfer_buffer =
413 command_buffer_->GetTransferBuffer(transfer_buffer_id);
414 if (transfer_buffer.ptr) {
415 gles2_implementation_.reset(new gpu::gles2::GLES2Implementation(
416 helper_.get(),
417 transfer_buffer.size,
418 transfer_buffer.ptr,
419 transfer_buffer_id));
420 return true;
421 }
422 }
423
424 helper_.reset();
425 }
426
427 command_buffer_.reset();
428 #endif
429
430 return false;
431 }
OLDNEW
« no previous file with comments | « webkit/tools/pepper_test_plugin/plugin_object.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698