OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 5 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 27 matching lines...) Expand all Loading... | |
38 #include "third_party/WebKit/WebKit/chromium/public/WebRect.h" | 38 #include "third_party/WebKit/WebKit/chromium/public/WebRect.h" |
39 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" | 39 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" |
40 #include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h" | 40 #include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h" |
41 #include "third_party/WebKit/WebKit/chromium/public/WebView.h" | 41 #include "third_party/WebKit/WebKit/chromium/public/WebView.h" |
42 #include "webkit/plugins/ppapi/common.h" | 42 #include "webkit/plugins/ppapi/common.h" |
43 #include "webkit/plugins/ppapi/event_conversion.h" | 43 #include "webkit/plugins/ppapi/event_conversion.h" |
44 #include "webkit/plugins/ppapi/fullscreen_container.h" | 44 #include "webkit/plugins/ppapi/fullscreen_container.h" |
45 #include "webkit/plugins/ppapi/plugin_delegate.h" | 45 #include "webkit/plugins/ppapi/plugin_delegate.h" |
46 #include "webkit/plugins/ppapi/plugin_module.h" | 46 #include "webkit/plugins/ppapi/plugin_module.h" |
47 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" | 47 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" |
48 #include "webkit/plugins/ppapi/ppb_context_3d_impl.h" | |
49 #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" | 48 #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" |
50 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" | 49 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" |
50 #include "webkit/plugins/ppapi/ppb_surface_3d_impl.h" | |
51 #include "webkit/plugins/ppapi/ppb_url_loader_impl.h" | 51 #include "webkit/plugins/ppapi/ppb_url_loader_impl.h" |
52 #include "webkit/plugins/ppapi/ppp_pdf.h" | 52 #include "webkit/plugins/ppapi/ppp_pdf.h" |
53 #include "webkit/plugins/ppapi/string.h" | 53 #include "webkit/plugins/ppapi/string.h" |
54 #include "webkit/plugins/ppapi/var.h" | 54 #include "webkit/plugins/ppapi/var.h" |
55 | 55 |
56 #if defined(OS_MACOSX) | 56 #if defined(OS_MACOSX) |
57 #include "base/mac_util.h" | 57 #include "base/mac_util.h" |
58 #include "base/mac/scoped_cftyperef.h" | 58 #include "base/mac/scoped_cftyperef.h" |
59 #endif | 59 #endif |
60 | 60 |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
416 return ObjectVar::NPObjectToPPVar(module(), frame->windowObject()); | 416 return ObjectVar::NPObjectToPPVar(module(), frame->windowObject()); |
417 } | 417 } |
418 | 418 |
419 PP_Var PluginInstance::GetOwnerElementObject() { | 419 PP_Var PluginInstance::GetOwnerElementObject() { |
420 if (!container_) | 420 if (!container_) |
421 return PP_MakeUndefined(); | 421 return PP_MakeUndefined(); |
422 return ObjectVar::NPObjectToPPVar(module(), | 422 return ObjectVar::NPObjectToPPVar(module(), |
423 container_->scriptableObjectForElement()); | 423 container_->scriptableObjectForElement()); |
424 } | 424 } |
425 | 425 |
426 bool PluginInstance::BindGraphics(PP_Resource graphics_id) { | 426 bool PluginInstance::BindGraphics(PP_Resource graphics_id) { |
alokp
2010/12/23 22:07:54
I think there is redundancy in BindGraphics API. T
| |
427 if (!graphics_id) { | 427 if (!graphics_id) { |
428 // Special-case clearing the current device. | 428 // Special-case clearing the current device. |
429 if (bound_graphics_.get()) { | 429 if (bound_graphics_.get()) { |
430 if (bound_graphics_2d()) { | 430 if (bound_graphics_2d()) { |
431 bound_graphics_2d()->BindToInstance(NULL); | 431 bound_graphics_2d()->BindToInstance(NULL); |
432 } else if (bound_graphics_.get()) { | 432 } else if (bound_graphics_.get()) { |
433 bound_graphics_3d()->SetSwapBuffersCallback(NULL); | 433 bound_graphics_3d()->BindToInstance(false); |
434 bound_graphics_3d()->BindToInstance(NULL); | |
435 } | 434 } |
436 InvalidateRect(gfx::Rect()); | 435 InvalidateRect(gfx::Rect()); |
437 } | 436 } |
438 bound_graphics_ = NULL; | 437 bound_graphics_ = NULL; |
439 return true; | 438 return true; |
440 } | 439 } |
441 | 440 |
442 scoped_refptr<PPB_Graphics2D_Impl> graphics_2d = | 441 scoped_refptr<PPB_Graphics2D_Impl> graphics_2d = |
443 Resource::GetAs<PPB_Graphics2D_Impl>(graphics_id); | 442 Resource::GetAs<PPB_Graphics2D_Impl>(graphics_id); |
444 scoped_refptr<PPB_Context3D_Impl> graphics_3d = | 443 scoped_refptr<PPB_Surface3D_Impl> graphics_3d = |
445 Resource::GetAs<PPB_Context3D_Impl>(graphics_id); | 444 Resource::GetAs<PPB_Surface3D_Impl>(graphics_id); |
446 | 445 |
447 if (graphics_2d) { | 446 if (graphics_2d) { |
448 if (!graphics_2d->BindToInstance(this)) | 447 if (!graphics_2d->BindToInstance(this)) |
449 return false; // Can't bind to more than one instance. | 448 return false; // Can't bind to more than one instance. |
450 | 449 |
451 // See http://crbug.com/49403: this can be further optimized by keeping the | 450 // See http://crbug.com/49403: this can be further optimized by keeping the |
452 // old device around and painting from it. | 451 // old device around and painting from it. |
453 if (bound_graphics_2d()) { | 452 if (bound_graphics_2d()) { |
454 // Start the new image with the content of the old image until the plugin | 453 // Start the new image with the content of the old image until the plugin |
455 // repaints. | 454 // repaints. |
456 const SkBitmap* old_backing_bitmap = | 455 const SkBitmap* old_backing_bitmap = |
457 bound_graphics_2d()->image_data()->GetMappedBitmap(); | 456 bound_graphics_2d()->image_data()->GetMappedBitmap(); |
458 SkRect old_size = SkRect::MakeWH( | 457 SkRect old_size = SkRect::MakeWH( |
459 SkScalar(static_cast<float>(old_backing_bitmap->width())), | 458 SkScalar(static_cast<float>(old_backing_bitmap->width())), |
460 SkScalar(static_cast<float>(old_backing_bitmap->height()))); | 459 SkScalar(static_cast<float>(old_backing_bitmap->height()))); |
461 | 460 |
462 SkCanvas canvas(*graphics_2d->image_data()->GetMappedBitmap()); | 461 SkCanvas canvas(*graphics_2d->image_data()->GetMappedBitmap()); |
463 canvas.drawBitmap(*old_backing_bitmap, 0, 0); | 462 canvas.drawBitmap(*old_backing_bitmap, 0, 0); |
464 | 463 |
465 // Fill in any extra space with white. | 464 // Fill in any extra space with white. |
466 canvas.clipRect(old_size, SkRegion::kDifference_Op); | 465 canvas.clipRect(old_size, SkRegion::kDifference_Op); |
467 canvas.drawARGB(255, 255, 255, 255); | 466 canvas.drawARGB(255, 255, 255, 255); |
468 } | 467 } |
469 | 468 |
470 bound_graphics_ = graphics_2d; | 469 bound_graphics_ = graphics_2d; |
471 // BindToInstance will have invalidated the plugin if necessary. | 470 // BindToInstance will have invalidated the plugin if necessary. |
472 } else if (graphics_3d) { | 471 } else if (graphics_3d) { |
473 if (!graphics_3d->BindToInstance(this)) | 472 // Make sure graphics can only be bound to the instance it is |
473 // associated with. | |
474 if (graphics_3d->instance() != this) | |
alokp
2010/12/23 22:07:54
moving this function to graphics will also elimina
| |
475 return false; | |
476 if (!graphics_3d->BindToInstance(true)) | |
474 return false; | 477 return false; |
475 | 478 |
476 bound_graphics_ = graphics_3d; | 479 bound_graphics_ = graphics_3d; |
477 bound_graphics_3d()->SetSwapBuffersCallback( | |
478 NewCallback(this, &PluginInstance::CommitBackingTexture)); | |
479 } | 480 } |
480 | 481 |
481 return true; | 482 return true; |
482 } | 483 } |
483 | 484 |
484 bool PluginInstance::SetCursor(PP_CursorType_Dev type) { | 485 bool PluginInstance::SetCursor(PP_CursorType_Dev type) { |
485 cursor_.reset(new WebCursorInfo(static_cast<WebCursorInfo::Type>(type))); | 486 cursor_.reset(new WebCursorInfo(static_cast<WebCursorInfo::Type>(type))); |
486 return true; | 487 return true; |
487 } | 488 } |
488 | 489 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
578 *cursor_info = *cursor_; | 579 *cursor_info = *cursor_; |
579 return rv; | 580 return rv; |
580 } | 581 } |
581 | 582 |
582 PP_Var PluginInstance::GetInstanceObject() { | 583 PP_Var PluginInstance::GetInstanceObject() { |
583 return instance_interface_->GetInstanceObject(pp_instance()); | 584 return instance_interface_->GetInstanceObject(pp_instance()); |
584 } | 585 } |
585 | 586 |
586 void PluginInstance::ViewChanged(const gfx::Rect& position, | 587 void PluginInstance::ViewChanged(const gfx::Rect& position, |
587 const gfx::Rect& clip) { | 588 const gfx::Rect& clip) { |
588 if (position.size() != position_.size() && bound_graphics_3d()) { | |
589 // TODO(apatrick): This is a hack to force the back buffer to resize. | |
590 // It is obviously wrong to call SwapBuffers when a partial frame has | |
591 // potentially been rendered. Plan is to embed resize commands in the | |
592 // command buffer just before ViewChanged is called. | |
593 bound_graphics_3d()->ResizeBackingTexture(position.size()); | |
594 bound_graphics_3d()->SwapBuffers(); | |
595 } | |
596 | |
597 position_ = position; | 589 position_ = position; |
598 | 590 |
599 if (clip.IsEmpty()) { | 591 if (clip.IsEmpty()) { |
600 // WebKit can give weird (x,y) positions for empty clip rects (since the | 592 // WebKit can give weird (x,y) positions for empty clip rects (since the |
601 // position technically doesn't matter). But we want to make these | 593 // position technically doesn't matter). But we want to make these |
602 // consistent since this is given to the plugin, so force everything to 0 | 594 // consistent since this is given to the plugin, so force everything to 0 |
603 // in the "everything is clipped" case. | 595 // in the "everything is clipped" case. |
604 clip_ = gfx::Rect(); | 596 clip_ = gfx::Rect(); |
605 } else { | 597 } else { |
606 clip_ = clip; | 598 clip_ = clip; |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1167 } | 1159 } |
1168 #endif // defined(OS_MACOSX) | 1160 #endif // defined(OS_MACOSX) |
1169 | 1161 |
1170 PPB_Graphics2D_Impl* PluginInstance::bound_graphics_2d() const { | 1162 PPB_Graphics2D_Impl* PluginInstance::bound_graphics_2d() const { |
1171 if (bound_graphics_.get() == NULL) | 1163 if (bound_graphics_.get() == NULL) |
1172 return NULL; | 1164 return NULL; |
1173 | 1165 |
1174 return bound_graphics_->Cast<PPB_Graphics2D_Impl>(); | 1166 return bound_graphics_->Cast<PPB_Graphics2D_Impl>(); |
1175 } | 1167 } |
1176 | 1168 |
1177 PPB_Context3D_Impl* PluginInstance::bound_graphics_3d() const { | 1169 PPB_Surface3D_Impl* PluginInstance::bound_graphics_3d() const { |
1178 if (bound_graphics_.get() == NULL) | 1170 if (bound_graphics_.get() == NULL) |
1179 return NULL; | 1171 return NULL; |
1180 | 1172 |
1181 return bound_graphics_->Cast<PPB_Context3D_Impl>(); | 1173 return bound_graphics_->Cast<PPB_Surface3D_Impl>(); |
1182 } | 1174 } |
1183 | 1175 |
1184 } // namespace ppapi | 1176 } // namespace ppapi |
1185 } // namespace webkit | 1177 } // namespace webkit |
1186 | 1178 |
OLD | NEW |