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

Side by Side Diff: webkit/glue/plugins/pepper_plugin_instance.cc

Issue 3531008: Integrated Pepper3D v2 with the accelerated compositor.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month 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
OLDNEW
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/glue/plugins/pepper_plugin_instance.h" 5 #include "webkit/glue/plugins/pepper_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 #if defined(OS_MACOSX) 9 #if defined(OS_MACOSX)
10 #include "base/mac_util.h" 10 #include "base/mac_util.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "third_party/WebKit/WebKit/chromium/public/WebElement.h" 42 #include "third_party/WebKit/WebKit/chromium/public/WebElement.h"
43 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" 43 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
44 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" 44 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h"
45 #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h" 45 #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h"
46 #include "third_party/WebKit/WebKit/chromium/public/WebRect.h" 46 #include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
47 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" 47 #include "third_party/WebKit/WebKit/chromium/public/WebString.h"
48 #include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h" 48 #include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h"
49 #include "third_party/WebKit/WebKit/chromium/public/WebView.h" 49 #include "third_party/WebKit/WebKit/chromium/public/WebView.h"
50 #include "webkit/glue/plugins/pepper_buffer.h" 50 #include "webkit/glue/plugins/pepper_buffer.h"
51 #include "webkit/glue/plugins/pepper_graphics_2d.h" 51 #include "webkit/glue/plugins/pepper_graphics_2d.h"
52 #include "webkit/glue/plugins/pepper_graphics_3d.h"
52 #include "webkit/glue/plugins/pepper_event_conversion.h" 53 #include "webkit/glue/plugins/pepper_event_conversion.h"
53 #include "webkit/glue/plugins/pepper_fullscreen_container.h" 54 #include "webkit/glue/plugins/pepper_fullscreen_container.h"
54 #include "webkit/glue/plugins/pepper_image_data.h" 55 #include "webkit/glue/plugins/pepper_image_data.h"
55 #include "webkit/glue/plugins/pepper_plugin_delegate.h" 56 #include "webkit/glue/plugins/pepper_plugin_delegate.h"
56 #include "webkit/glue/plugins/pepper_plugin_module.h" 57 #include "webkit/glue/plugins/pepper_plugin_module.h"
58 #include "webkit/glue/plugins/pepper_resource.h"
57 #include "webkit/glue/plugins/pepper_string.h" 59 #include "webkit/glue/plugins/pepper_string.h"
58 #include "webkit/glue/plugins/pepper_url_loader.h" 60 #include "webkit/glue/plugins/pepper_url_loader.h"
59 #include "webkit/glue/plugins/pepper_var.h" 61 #include "webkit/glue/plugins/pepper_var.h"
60 #include "webkit/glue/plugins/ppp_private.h" 62 #include "webkit/glue/plugins/ppp_private.h"
61 63
62 using WebKit::WebBindings; 64 using WebKit::WebBindings;
63 using WebKit::WebCanvas; 65 using WebKit::WebCanvas;
64 using WebKit::WebCursorInfo; 66 using WebKit::WebCursorInfo;
65 using WebKit::WebDocument; 67 using WebKit::WebDocument;
66 using WebKit::WebFrame; 68 using WebKit::WebFrame;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 return instance->GetWindowObject(); 155 return instance->GetWindowObject();
154 } 156 }
155 157
156 PP_Var GetOwnerElementObject(PP_Instance instance_id) { 158 PP_Var GetOwnerElementObject(PP_Instance instance_id) {
157 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); 159 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
158 if (!instance) 160 if (!instance)
159 return PP_MakeUndefined(); 161 return PP_MakeUndefined();
160 return instance->GetOwnerElementObject(); 162 return instance->GetOwnerElementObject();
161 } 163 }
162 164
163 bool BindGraphics(PP_Instance instance_id, PP_Resource device_id) { 165 bool BindGraphics(PP_Instance instance_id, PP_Resource graphics_id) {
164 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); 166 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
165 if (!instance) 167 if (!instance)
166 return false; 168 return false;
167 return instance->BindGraphics(device_id); 169 return instance->BindGraphics(graphics_id);
168 } 170 }
169 171
170 bool IsFullFrame(PP_Instance instance_id) { 172 bool IsFullFrame(PP_Instance instance_id) {
171 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); 173 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
172 if (!instance) 174 if (!instance)
173 return false; 175 return false;
174 return instance->full_frame(); 176 return instance->full_frame();
175 } 177 }
176 178
177 PP_Var ExecuteScript(PP_Instance instance_id, 179 PP_Var ExecuteScript(PP_Instance instance_id,
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 } 333 }
332 334
333 // static 335 // static
334 const PPB_Zoom_Dev* PluginInstance::GetZoomInterface() { 336 const PPB_Zoom_Dev* PluginInstance::GetZoomInterface() {
335 return &ppb_zoom; 337 return &ppb_zoom;
336 } 338 }
337 339
338 void PluginInstance::Paint(WebCanvas* canvas, 340 void PluginInstance::Paint(WebCanvas* canvas,
339 const gfx::Rect& plugin_rect, 341 const gfx::Rect& plugin_rect,
340 const gfx::Rect& paint_rect) { 342 const gfx::Rect& paint_rect) {
341 if (bound_graphics_2d_) 343 if (bound_graphics_2d())
342 bound_graphics_2d_->Paint(canvas, plugin_rect, paint_rect); 344 bound_graphics_2d()->Paint(canvas, plugin_rect, paint_rect);
343 } 345 }
344 346
345 void PluginInstance::InvalidateRect(const gfx::Rect& rect) { 347 void PluginInstance::InvalidateRect(const gfx::Rect& rect) {
346 if (fullscreen_container_) { 348 if (fullscreen_container_) {
347 if (rect.IsEmpty()) 349 if (rect.IsEmpty())
348 fullscreen_container_->Invalidate(); 350 fullscreen_container_->Invalidate();
349 else 351 else
350 fullscreen_container_->InvalidateRect(rect); 352 fullscreen_container_->InvalidateRect(rect);
351 } else { 353 } else {
352 if (!container_ || position_.IsEmpty()) 354 if (!container_ || position_.IsEmpty())
(...skipping 12 matching lines...) Expand all
365 if (full_frame_) { 367 if (full_frame_) {
366 container_->scrollRect(dx, dy, rect); 368 container_->scrollRect(dx, dy, rect);
367 } else { 369 } else {
368 // Can't do optimized scrolling since there could be other elements on top 370 // Can't do optimized scrolling since there could be other elements on top
369 // of us. 371 // of us.
370 InvalidateRect(rect); 372 InvalidateRect(rect);
371 } 373 }
372 } 374 }
373 } 375 }
374 376
377 unsigned PluginInstance::GetBackingTextureId() {
378 if (!bound_graphics_3d())
379 return 0;
380
381 return bound_graphics_3d()->GetBackingTextureId();
382 }
383
384 void PluginInstance::CommitBackingTexture() {
385 container_->commitBackingTexture();
386 }
387
375 PP_Var PluginInstance::GetWindowObject() { 388 PP_Var PluginInstance::GetWindowObject() {
376 if (!container_) 389 if (!container_)
377 return PP_MakeUndefined(); 390 return PP_MakeUndefined();
378 391
379 WebFrame* frame = container_->element().document().frame(); 392 WebFrame* frame = container_->element().document().frame();
380 if (!frame) 393 if (!frame)
381 return PP_MakeUndefined(); 394 return PP_MakeUndefined();
382 395
383 return ObjectVar::NPObjectToPPVar(module(), frame->windowObject()); 396 return ObjectVar::NPObjectToPPVar(module(), frame->windowObject());
384 } 397 }
385 398
386 PP_Var PluginInstance::GetOwnerElementObject() { 399 PP_Var PluginInstance::GetOwnerElementObject() {
387 if (!container_) 400 if (!container_)
388 return PP_MakeUndefined(); 401 return PP_MakeUndefined();
389 return ObjectVar::NPObjectToPPVar(module(), 402 return ObjectVar::NPObjectToPPVar(module(),
390 container_->scriptableObjectForElement()); 403 container_->scriptableObjectForElement());
391 } 404 }
392 405
393 bool PluginInstance::BindGraphics(PP_Resource device_id) { 406 bool PluginInstance::BindGraphics(PP_Resource graphics_id) {
394 if (!device_id) { 407 if (!graphics_id) {
395 // Special-case clearing the current device. 408 // Special-case clearing the current device.
396 if (bound_graphics_2d_) { 409 if (bound_graphics_.get()) {
397 bound_graphics_2d_->BindToInstance(NULL); 410 if (bound_graphics_2d()) {
398 bound_graphics_2d_ = NULL; 411 bound_graphics_2d()->BindToInstance(NULL);
412 } else if (bound_graphics_.get()) {
413 bound_graphics_3d()->SetSwapBuffersCallback(NULL);
414 bound_graphics_3d()->BindToInstance(NULL);
415 }
399 InvalidateRect(gfx::Rect()); 416 InvalidateRect(gfx::Rect());
400 } 417 }
418 bound_graphics_ = NULL;
401 return true; 419 return true;
402 } 420 }
403 421
404 scoped_refptr<Graphics2D> device_2d = Resource::GetAs<Graphics2D>(device_id); 422 scoped_refptr<Graphics2D> graphics_2d =
423 Resource::GetAs<Graphics2D>(graphics_id);
424 scoped_refptr<Graphics3D> graphics_3d =
425 Resource::GetAs<Graphics3D>(graphics_id);
405 426
406 if (device_2d) { 427 if (graphics_2d) {
407 if (!device_2d->BindToInstance(this)) 428 if (!graphics_2d->BindToInstance(this))
408 return false; // Can't bind to more than one instance. 429 return false; // Can't bind to more than one instance.
430 bound_graphics_ = graphics_2d;
jam 2010/11/15 21:24:19 moving this line up makes the code below it (434-4
apatrick_chromium 2010/11/15 22:24:54 No that looks like a bad refactor. Are you going t
409 431
410 // See http://crbug.com/49403: this can be further optimized by keeping the 432 // See http://crbug.com/49403: this can be further optimized by keeping the
411 // old device around and painting from it. 433 // old device around and painting from it.
412 if (bound_graphics_2d_.get()) { 434 if (bound_graphics_2d()) {
413 // Start the new image with the content of the old image until the plugin 435 // Start the new image with the content of the old image until the plugin
414 // repaints. 436 // repaints.
415 const SkBitmap* old_backing_bitmap = 437 const SkBitmap* old_backing_bitmap =
416 bound_graphics_2d_->image_data()->GetMappedBitmap(); 438 bound_graphics_2d()->image_data()->GetMappedBitmap();
417 SkRect old_size = SkRect::MakeWH( 439 SkRect old_size = SkRect::MakeWH(
418 SkScalar(static_cast<float>(old_backing_bitmap->width())), 440 SkScalar(static_cast<float>(old_backing_bitmap->width())),
419 SkScalar(static_cast<float>(old_backing_bitmap->height()))); 441 SkScalar(static_cast<float>(old_backing_bitmap->height())));
420 442
421 SkCanvas canvas(*device_2d->image_data()->GetMappedBitmap()); 443 SkCanvas canvas(*graphics_2d->image_data()->GetMappedBitmap());
422 canvas.drawBitmap(*old_backing_bitmap, 0, 0); 444 canvas.drawBitmap(*old_backing_bitmap, 0, 0);
423 445
424 // Fill in any extra space with white. 446 // Fill in any extra space with white.
425 canvas.clipRect(old_size, SkRegion::kDifference_Op); 447 canvas.clipRect(old_size, SkRegion::kDifference_Op);
426 canvas.drawARGB(255, 255, 255, 255); 448 canvas.drawARGB(255, 255, 255, 255);
427 } 449 }
428 450
429 bound_graphics_2d_ = device_2d;
430 // BindToInstance will have invalidated the plugin if necessary. 451 // BindToInstance will have invalidated the plugin if necessary.
452 } else if (graphics_3d) {
453 if (!graphics_3d->BindToInstance(this))
454 return false;
455
456 bound_graphics_ = graphics_3d;
457 bound_graphics_3d()->SetSwapBuffersCallback(
458 NewCallback(this, &PluginInstance::CommitBackingTexture));
431 } 459 }
432 460
433 return true; 461 return true;
434 } 462 }
435 463
436 bool PluginInstance::SetCursor(PP_CursorType_Dev type) { 464 bool PluginInstance::SetCursor(PP_CursorType_Dev type) {
437 cursor_.reset(new WebCursorInfo(static_cast<WebCursorInfo::Type>(type))); 465 cursor_.reset(new WebCursorInfo(static_cast<WebCursorInfo::Type>(type)));
438 return true; 466 return true;
439 } 467 }
440 468
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 *cursor_info = *cursor_; 553 *cursor_info = *cursor_;
526 return rv; 554 return rv;
527 } 555 }
528 556
529 PP_Var PluginInstance::GetInstanceObject() { 557 PP_Var PluginInstance::GetInstanceObject() {
530 return instance_interface_->GetInstanceObject(pp_instance()); 558 return instance_interface_->GetInstanceObject(pp_instance());
531 } 559 }
532 560
533 void PluginInstance::ViewChanged(const gfx::Rect& position, 561 void PluginInstance::ViewChanged(const gfx::Rect& position,
534 const gfx::Rect& clip) { 562 const gfx::Rect& clip) {
563 if (position.size() != position_.size() && bound_graphics_3d()) {
564 // TODO(apatrick): This is a hack to force the back buffer to resize.
565 // It is obviously wrong to call SwapBuffers when a partial frame has
566 // potentially been rendered. Plan is to embed resize commands in the
567 // command buffer just before ViewChanged is called.
568 bound_graphics_3d()->ResizeBackingTexture(position.size());
569 bound_graphics_3d()->SwapBuffers();
570 }
571
535 position_ = position; 572 position_ = position;
573
536 if (clip.IsEmpty()) { 574 if (clip.IsEmpty()) {
537 // WebKit can give weird (x,y) positions for empty clip rects (since the 575 // WebKit can give weird (x,y) positions for empty clip rects (since the
538 // position technically doesn't matter). But we want to make these 576 // position technically doesn't matter). But we want to make these
539 // consistent since this is given to the plugin, so force everything to 0 577 // consistent since this is given to the plugin, so force everything to 0
540 // in the "everything is clipped" case. 578 // in the "everything is clipped" case.
541 clip_ = gfx::Rect(); 579 clip_ = gfx::Rect();
542 } else { 580 } else {
543 clip_ = clip; 581 clip_ = clip;
544 } 582 }
545 583
(...skipping 17 matching lines...) Expand all
563 if (has_content_area_focus_ == has_focus) 601 if (has_content_area_focus_ == has_focus)
564 return; 602 return;
565 603
566 bool old_plugin_focus = PluginHasFocus(); 604 bool old_plugin_focus = PluginHasFocus();
567 has_content_area_focus_ = has_focus; 605 has_content_area_focus_ = has_focus;
568 if (PluginHasFocus() != old_plugin_focus) 606 if (PluginHasFocus() != old_plugin_focus)
569 instance_interface_->DidChangeFocus(pp_instance(), PluginHasFocus()); 607 instance_interface_->DidChangeFocus(pp_instance(), PluginHasFocus());
570 } 608 }
571 609
572 void PluginInstance::ViewInitiatedPaint() { 610 void PluginInstance::ViewInitiatedPaint() {
573 if (bound_graphics_2d_) 611 if (bound_graphics_2d())
574 bound_graphics_2d_->ViewInitiatedPaint(); 612 bound_graphics_2d()->ViewInitiatedPaint();
575 } 613 }
576 614
577 void PluginInstance::ViewFlushedPaint() { 615 void PluginInstance::ViewFlushedPaint() {
578 if (bound_graphics_2d_) 616 if (bound_graphics_2d())
579 bound_graphics_2d_->ViewFlushedPaint(); 617 bound_graphics_2d()->ViewFlushedPaint();
580 } 618 }
581 619
582 bool PluginInstance::GetBitmapForOptimizedPluginPaint( 620 bool PluginInstance::GetBitmapForOptimizedPluginPaint(
583 const gfx::Rect& paint_bounds, 621 const gfx::Rect& paint_bounds,
584 TransportDIB** dib, 622 TransportDIB** dib,
585 gfx::Rect* location, 623 gfx::Rect* location,
586 gfx::Rect* clip) { 624 gfx::Rect* clip) {
587 if (!always_on_top_) 625 if (!always_on_top_)
588 return false; 626 return false;
589 if (!bound_graphics_2d_ || !bound_graphics_2d_->is_always_opaque()) 627 if (!bound_graphics_2d() || !bound_graphics_2d()->is_always_opaque())
590 return false; 628 return false;
591 629
592 // We specifically want to compare against the area covered by the backing 630 // We specifically want to compare against the area covered by the backing
593 // store when seeing if we cover the given paint bounds, since the backing 631 // store when seeing if we cover the given paint bounds, since the backing
594 // store could be smaller than the declared plugin area. 632 // store could be smaller than the declared plugin area.
595 ImageData* image_data = bound_graphics_2d_->image_data(); 633 ImageData* image_data = bound_graphics_2d()->image_data();
596 gfx::Rect plugin_backing_store_rect(position_.origin(), 634 gfx::Rect plugin_backing_store_rect(position_.origin(),
597 gfx::Size(image_data->width(), 635 gfx::Size(image_data->width(),
598 image_data->height())); 636 image_data->height()));
599 gfx::Rect plugin_paint_rect = plugin_backing_store_rect.Intersect(clip_); 637 gfx::Rect plugin_paint_rect = plugin_backing_store_rect.Intersect(clip_);
600 if (!plugin_paint_rect.Contains(paint_bounds)) 638 if (!plugin_paint_rect.Contains(paint_bounds))
601 return false; 639 return false;
602 640
603 *dib = image_data->platform_image()->GetTransportDIB(); 641 *dib = image_data->platform_image()->GetTransportDIB();
604 *location = plugin_backing_store_rect; 642 *location = plugin_backing_store_rect;
605 *clip = clip_; 643 *clip = clip_;
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 plugin_print_interface_->End(pp_instance()); 854 plugin_print_interface_->End(pp_instance());
817 memset(&current_print_settings_, 0, sizeof(current_print_settings_)); 855 memset(&current_print_settings_, 0, sizeof(current_print_settings_));
818 #if defined(OS_MACOSX) 856 #if defined(OS_MACOSX)
819 last_printed_page_ = NULL; 857 last_printed_page_ = NULL;
820 #elif defined(OS_LINUX) 858 #elif defined(OS_LINUX)
821 num_pages_ = 0; 859 num_pages_ = 0;
822 pdf_output_done_ = false; 860 pdf_output_done_ = false;
823 #endif // defined(OS_LINUX) 861 #endif // defined(OS_LINUX)
824 } 862 }
825 863
826 void PluginInstance::Graphics3DContextLost() {
827 if (!plugin_graphics_3d_interface_) {
828 plugin_graphics_3d_interface_ =
829 reinterpret_cast<const PPP_Graphics3D_Dev*>(module_->GetPluginInterface(
830 PPP_GRAPHICS_3D_DEV_INTERFACE));
831 }
832 if (plugin_graphics_3d_interface_)
833 plugin_graphics_3d_interface_->Graphics3DContextLost(pp_instance());
834 }
835
836 bool PluginInstance::IsFullscreen() { 864 bool PluginInstance::IsFullscreen() {
837 return fullscreen_container_ != NULL; 865 return fullscreen_container_ != NULL;
838 } 866 }
839 867
840 bool PluginInstance::SetFullscreen(bool fullscreen) { 868 bool PluginInstance::SetFullscreen(bool fullscreen) {
841 bool is_fullscreen = (fullscreen_container_ != NULL); 869 bool is_fullscreen = (fullscreen_container_ != NULL);
842 if (fullscreen == is_fullscreen) 870 if (fullscreen == is_fullscreen)
843 return true; 871 return true;
844 VLOG(1) << "Setting fullscreen to " << (fullscreen ? "on" : "off"); 872 VLOG(1) << "Setting fullscreen to " << (fullscreen ? "on" : "off");
845 if (fullscreen) { 873 if (fullscreen) {
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 bounds.origin.x = dest_rect.x(); 1124 bounds.origin.x = dest_rect.x();
1097 bounds.origin.y = canvas_height - dest_rect.y() - dest_rect.height(); 1125 bounds.origin.y = canvas_height - dest_rect.y() - dest_rect.height();
1098 bounds.size.width = dest_rect.width(); 1126 bounds.size.width = dest_rect.width();
1099 bounds.size.height = dest_rect.height(); 1127 bounds.size.height = dest_rect.height();
1100 1128
1101 CGContextDrawImage(canvas, bounds, image); 1129 CGContextDrawImage(canvas, bounds, image);
1102 CGContextRestoreGState(canvas); 1130 CGContextRestoreGState(canvas);
1103 } 1131 }
1104 #endif // defined(OS_MACOSX) 1132 #endif // defined(OS_MACOSX)
1105 1133
1134 Graphics2D* PluginInstance::bound_graphics_2d() const {
1135 if (bound_graphics_.get() == NULL)
1136 return NULL;
1137
1138 return bound_graphics_->Cast<Graphics2D>();
1139 }
1140
1141 Graphics3D* PluginInstance::bound_graphics_3d() const {
1142 if (bound_graphics_.get() == NULL)
1143 return NULL;
1144
1145 return bound_graphics_->Cast<Graphics3D>();
1146 }
1106 1147
1107 } // namespace pepper 1148 } // namespace pepper
OLDNEW
« no previous file with comments | « webkit/glue/plugins/pepper_plugin_instance.h ('k') | webkit/glue/plugins/pepper_webplugin_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698