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

Side by Side Diff: webkit/plugins/ppapi/ppapi_plugin_instance.cc

Issue 11053003: Migrate Graphics2D to new design. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: temp dependencies Created 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 #include "webkit/plugins/ppapi/common.h" 79 #include "webkit/plugins/ppapi/common.h"
80 #include "webkit/plugins/ppapi/event_conversion.h" 80 #include "webkit/plugins/ppapi/event_conversion.h"
81 #include "webkit/plugins/ppapi/fullscreen_container.h" 81 #include "webkit/plugins/ppapi/fullscreen_container.h"
82 #include "webkit/plugins/ppapi/gfx_conversion.h" 82 #include "webkit/plugins/ppapi/gfx_conversion.h"
83 #include "webkit/plugins/ppapi/host_globals.h" 83 #include "webkit/plugins/ppapi/host_globals.h"
84 #include "webkit/plugins/ppapi/message_channel.h" 84 #include "webkit/plugins/ppapi/message_channel.h"
85 #include "webkit/plugins/ppapi/npapi_glue.h" 85 #include "webkit/plugins/ppapi/npapi_glue.h"
86 #include "webkit/plugins/ppapi/plugin_module.h" 86 #include "webkit/plugins/ppapi/plugin_module.h"
87 #include "webkit/plugins/ppapi/plugin_object.h" 87 #include "webkit/plugins/ppapi/plugin_object.h"
88 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" 88 #include "webkit/plugins/ppapi/ppb_buffer_impl.h"
89 #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h"
90 #include "webkit/plugins/ppapi/ppb_graphics_3d_impl.h" 89 #include "webkit/plugins/ppapi/ppb_graphics_3d_impl.h"
91 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" 90 #include "webkit/plugins/ppapi/ppb_image_data_impl.h"
92 #include "webkit/plugins/ppapi/ppb_url_loader_impl.h" 91 #include "webkit/plugins/ppapi/ppb_url_loader_impl.h"
93 #include "webkit/plugins/ppapi/url_request_info_util.h" 92 #include "webkit/plugins/ppapi/url_request_info_util.h"
94 #include "webkit/plugins/ppapi/ppp_pdf.h" 93 #include "webkit/plugins/ppapi/ppp_pdf.h"
95 #include "webkit/plugins/sad_plugin.h" 94 #include "webkit/plugins/sad_plugin.h"
96 95
97 #if defined(OS_MACOSX) 96 #if defined(OS_MACOSX)
98 #include "printing/metafile_impl.h" 97 #include "printing/metafile_impl.h"
99 #if !defined(USE_SKIA) 98 #if !defined(USE_SKIA)
(...skipping 15 matching lines...) Expand all
115 #include "ui/gfx/codec/jpeg_codec.h" 114 #include "ui/gfx/codec/jpeg_codec.h"
116 #include "ui/gfx/gdi_util.h" 115 #include "ui/gfx/gdi_util.h"
117 #endif 116 #endif
118 117
119 using base::StringPrintf; 118 using base::StringPrintf;
120 using ppapi::InputEventData; 119 using ppapi::InputEventData;
121 using ppapi::PpapiGlobals; 120 using ppapi::PpapiGlobals;
122 using ppapi::PPB_InputEvent_Shared; 121 using ppapi::PPB_InputEvent_Shared;
123 using ppapi::PPB_View_Shared; 122 using ppapi::PPB_View_Shared;
124 using ppapi::PPP_Instance_Combined; 123 using ppapi::PPP_Instance_Combined;
124 using ppapi::Resource;
125 using ppapi::ScopedPPResource; 125 using ppapi::ScopedPPResource;
126 using ppapi::StringVar; 126 using ppapi::StringVar;
127 using ppapi::TrackedCallback; 127 using ppapi::TrackedCallback;
128 using ppapi::thunk::EnterResourceNoLock; 128 using ppapi::thunk::EnterResourceNoLock;
129 using ppapi::thunk::PPB_Buffer_API; 129 using ppapi::thunk::PPB_Buffer_API;
130 using ppapi::thunk::PPB_Graphics2D_API; 130 using ppapi::thunk::PPB_Graphics2D_API;
131 using ppapi::thunk::PPB_Graphics3D_API; 131 using ppapi::thunk::PPB_Graphics3D_API;
132 using ppapi::thunk::PPB_ImageData_API; 132 using ppapi::thunk::PPB_ImageData_API;
133 using ppapi::Var; 133 using ppapi::Var;
134 using ppapi::ArrayBufferVar; 134 using ppapi::ArrayBufferVar;
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 PluginModule* module, 562 PluginModule* module,
563 ::ppapi::PPP_Instance_Combined* instance_interface) 563 ::ppapi::PPP_Instance_Combined* instance_interface)
564 : delegate_(delegate), 564 : delegate_(delegate),
565 module_(module), 565 module_(module),
566 instance_interface_(instance_interface), 566 instance_interface_(instance_interface),
567 pp_instance_(0), 567 pp_instance_(0),
568 container_(NULL), 568 container_(NULL),
569 full_frame_(false), 569 full_frame_(false),
570 sent_initial_did_change_view_(false), 570 sent_initial_did_change_view_(false),
571 view_change_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 571 view_change_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
572 bound_graphics_2d_platform_(NULL),
572 has_webkit_focus_(false), 573 has_webkit_focus_(false),
573 has_content_area_focus_(false), 574 has_content_area_focus_(false),
574 find_identifier_(-1), 575 find_identifier_(-1),
575 plugin_decryption_interface_(NULL), 576 plugin_decryption_interface_(NULL),
576 plugin_find_interface_(NULL), 577 plugin_find_interface_(NULL),
577 plugin_input_event_interface_(NULL), 578 plugin_input_event_interface_(NULL),
578 plugin_messaging_interface_(NULL), 579 plugin_messaging_interface_(NULL),
579 plugin_mouse_lock_interface_(NULL), 580 plugin_mouse_lock_interface_(NULL),
580 plugin_pdf_interface_(NULL), 581 plugin_pdf_interface_(NULL),
581 plugin_private_interface_(NULL), 582 plugin_private_interface_(NULL),
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 TRACE_EVENT0("ppapi", "PluginInstance::Paint"); 689 TRACE_EVENT0("ppapi", "PluginInstance::Paint");
689 if (module()->is_crashed()) { 690 if (module()->is_crashed()) {
690 // Crashed plugin painting. 691 // Crashed plugin painting.
691 if (!sad_plugin_) // Lazily initialize bitmap. 692 if (!sad_plugin_) // Lazily initialize bitmap.
692 sad_plugin_ = delegate_->GetSadPluginBitmap(); 693 sad_plugin_ = delegate_->GetSadPluginBitmap();
693 if (sad_plugin_) 694 if (sad_plugin_)
694 webkit::PaintSadPlugin(canvas, plugin_rect, *sad_plugin_); 695 webkit::PaintSadPlugin(canvas, plugin_rect, *sad_plugin_);
695 return; 696 return;
696 } 697 }
697 698
698 PPB_Graphics2D_Impl* bound_graphics_2d = GetBoundGraphics2D(); 699 PluginDelegate::PlatformGraphics2D* bound_graphics_2d = GetBoundGraphics2D();
699 if (bound_graphics_2d) 700 if (bound_graphics_2d)
700 bound_graphics_2d->Paint(canvas, plugin_rect, paint_rect); 701 bound_graphics_2d->Paint(canvas, plugin_rect, paint_rect);
701 } 702 }
702 703
703 void PluginInstance::InvalidateRect(const gfx::Rect& rect) { 704 void PluginInstance::InvalidateRect(const gfx::Rect& rect) {
704 if (fullscreen_container_) { 705 if (fullscreen_container_) {
705 if (rect.IsEmpty()) 706 if (rect.IsEmpty())
706 fullscreen_container_->Invalidate(); 707 fullscreen_container_->Invalidate();
707 else 708 else
708 fullscreen_container_->InvalidateRect(rect); 709 fullscreen_container_->InvalidateRect(rect);
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
1147 } 1148 }
1148 1149
1149 bool PluginInstance::GetBitmapForOptimizedPluginPaint( 1150 bool PluginInstance::GetBitmapForOptimizedPluginPaint(
1150 const gfx::Rect& paint_bounds, 1151 const gfx::Rect& paint_bounds,
1151 TransportDIB** dib, 1152 TransportDIB** dib,
1152 gfx::Rect* location, 1153 gfx::Rect* location,
1153 gfx::Rect* clip, 1154 gfx::Rect* clip,
1154 float* scale_factor) { 1155 float* scale_factor) {
1155 if (!always_on_top_) 1156 if (!always_on_top_)
1156 return false; 1157 return false;
1157 if (!GetBoundGraphics2D() || !GetBoundGraphics2D()->is_always_opaque()) 1158 if (!GetBoundGraphics2D() || !GetBoundGraphics2D()->IsAlwaysOpaque())
1158 return false; 1159 return false;
1159 1160
1160 // We specifically want to compare against the area covered by the backing 1161 // We specifically want to compare against the area covered by the backing
1161 // store when seeing if we cover the given paint bounds, since the backing 1162 // store when seeing if we cover the given paint bounds, since the backing
1162 // store could be smaller than the declared plugin area. 1163 // store could be smaller than the declared plugin area.
1163 PPB_ImageData_Impl* image_data = GetBoundGraphics2D()->image_data(); 1164 PPB_ImageData_Impl* image_data = GetBoundGraphics2D()->ImageData();
1164 // ImageDatas created by NaCl don't have a PlatformImage, so can't be 1165 // ImageDatas created by NaCl don't have a PlatformImage, so can't be
1165 // optimized this way. 1166 // optimized this way.
1166 if (!image_data->PlatformImage()) 1167 if (!image_data->PlatformImage())
1167 return false; 1168 return false;
1168 1169
1169 gfx::Point plugin_origin = PP_ToGfxPoint(view_data_.rect.point); 1170 gfx::Point plugin_origin = PP_ToGfxPoint(view_data_.rect.point);
1170 gfx::Vector2d plugin_offset = plugin_origin.OffsetFromOrigin(); 1171 gfx::Vector2d plugin_offset = plugin_origin.OffsetFromOrigin();
1171 // Convert |paint_bounds| to be relative to the left-top corner of the plugin. 1172 // Convert |paint_bounds| to be relative to the left-top corner of the plugin.
1172 gfx::Rect relative_paint_bounds(paint_bounds); 1173 gfx::Rect relative_paint_bounds(paint_bounds);
1173 relative_paint_bounds.Offset(-plugin_offset); 1174 relative_paint_bounds.Offset(-plugin_offset);
(...skipping 1071 matching lines...) Expand 10 before | Expand all | Expand 10 after
2245 skia::EndPlatformPaint(canvas); 2246 skia::EndPlatformPaint(canvas);
2246 } 2247 }
2247 #endif // defined(OS_WIN) 2248 #endif // defined(OS_WIN)
2248 2249
2249 return ret; 2250 return ret;
2250 #else // defined(ENABLE_PRINTING) 2251 #else // defined(ENABLE_PRINTING)
2251 return false; 2252 return false;
2252 #endif 2253 #endif
2253 } 2254 }
2254 2255
2255 PPB_Graphics2D_Impl* PluginInstance::GetBoundGraphics2D() const { 2256 PluginDelegate::PlatformGraphics2D* PluginInstance::GetBoundGraphics2D() const {
2256 if (bound_graphics_.get() == NULL) 2257 return bound_graphics_2d_platform_;
2257 return NULL;
2258
2259 if (bound_graphics_->AsPPB_Graphics2D_API())
2260 return static_cast<PPB_Graphics2D_Impl*>(bound_graphics_.get());
2261 return NULL;
2262 } 2258 }
2263 2259
2264 PPB_Graphics3D_Impl* PluginInstance::GetBoundGraphics3D() const { 2260 PPB_Graphics3D_Impl* PluginInstance::GetBoundGraphics3D() const {
2265 if (bound_graphics_.get() == NULL) 2261 if (bound_graphics_3d_.get() == NULL)
2266 return NULL; 2262 return NULL;
2267 2263 return static_cast<PPB_Graphics3D_Impl*>(bound_graphics_3d_.get());
2268 if (bound_graphics_->AsPPB_Graphics3D_API())
2269 return static_cast<PPB_Graphics3D_Impl*>(bound_graphics_.get());
2270 return NULL;
2271 } 2264 }
2272 2265
2273 void PluginInstance::setBackingTextureId(unsigned int id, bool is_opaque) { 2266 void PluginInstance::setBackingTextureId(unsigned int id, bool is_opaque) {
2274 // If we have a fullscreen_container_ (under PPB_FlashFullscreen) 2267 // If we have a fullscreen_container_ (under PPB_FlashFullscreen)
2275 // or desired_fullscreen_state is true (under PPB_Fullscreen), 2268 // or desired_fullscreen_state is true (under PPB_Fullscreen),
2276 // then the plugin is fullscreen or transitioning to fullscreen 2269 // then the plugin is fullscreen or transitioning to fullscreen
2277 // and the parent context is not the one for the browser page, 2270 // and the parent context is not the one for the browser page,
2278 // but for the fullscreen window, and so the parent texture ID 2271 // but for the fullscreen window, and so the parent texture ID
2279 // doesn't correspond to anything in the page's context. 2272 // doesn't correspond to anything in the page's context.
2280 // 2273 //
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
2407 // Do nothing so that the pending user gesture will stay open for 2400 // Do nothing so that the pending user gesture will stay open for
2408 // kUserGestureDurationInSeconds. 2401 // kUserGestureDurationInSeconds.
2409 // TODO(yzshen): remove the code for closing pending user gesture. 2402 // TODO(yzshen): remove the code for closing pending user gesture.
2410 } 2403 }
2411 2404
2412 PP_Bool PluginInstance::BindGraphics(PP_Instance instance, 2405 PP_Bool PluginInstance::BindGraphics(PP_Instance instance,
2413 PP_Resource device) { 2406 PP_Resource device) {
2414 TRACE_EVENT0("ppapi", "PluginInstance::BindGraphics"); 2407 TRACE_EVENT0("ppapi", "PluginInstance::BindGraphics");
2415 // The Graphics3D instance can't be destroyed until we call 2408 // The Graphics3D instance can't be destroyed until we call
2416 // setBackingTextureId. 2409 // setBackingTextureId.
2417 scoped_refptr< ::ppapi::Resource> old_graphics = bound_graphics_; 2410 scoped_refptr< ::ppapi::Resource> old_graphics = bound_graphics_3d_;
2418 if (bound_graphics_.get()) { 2411 if (bound_graphics_3d_.get()) {
2419 if (GetBoundGraphics2D()) { 2412 if (GetBoundGraphics3D()) {
2420 GetBoundGraphics2D()->BindToInstance(NULL);
2421 } else if (GetBoundGraphics3D()) {
2422 GetBoundGraphics3D()->BindToInstance(false); 2413 GetBoundGraphics3D()->BindToInstance(false);
2423 } 2414 }
2424 bound_graphics_ = NULL; 2415 bound_graphics_3d_ = NULL;
2416 }
2417 if (bound_graphics_2d_platform_) {
2418 GetBoundGraphics2D()->BindToInstance(NULL);
2419 bound_graphics_2d_platform_ = NULL;
2425 } 2420 }
2426 2421
2427 // Special-case clearing the current device. 2422 // Special-case clearing the current device.
2428 if (!device) { 2423 if (!device) {
2429 setBackingTextureId(0, false); 2424 setBackingTextureId(0, false);
2430 InvalidateRect(gfx::Rect()); 2425 InvalidateRect(gfx::Rect());
2431 return PP_TRUE; 2426 return PP_TRUE;
2432 } 2427 }
2433 2428
2434 // Refuse to bind if in transition to fullscreen with PPB_FlashFullscreen or 2429 // Refuse to bind if in transition to fullscreen with PPB_FlashFullscreen or
2435 // to/from fullscreen with PPB_Fullscreen. 2430 // to/from fullscreen with PPB_Fullscreen.
2436 if ((fullscreen_container_ && !flash_fullscreen_) || 2431 if ((fullscreen_container_ && !flash_fullscreen_) ||
2437 desired_fullscreen_state_ != view_data_.is_fullscreen) 2432 desired_fullscreen_state_ != view_data_.is_fullscreen)
2438 return PP_FALSE; 2433 return PP_FALSE;
2439 2434
2440 EnterResourceNoLock<PPB_Graphics2D_API> enter_2d(device, false); 2435 bound_graphics_2d_platform_ = delegate_->GetGraphics2D(this, device);
2441 PPB_Graphics2D_Impl* graphics_2d = enter_2d.succeeded() ?
2442 static_cast<PPB_Graphics2D_Impl*>(enter_2d.object()) : NULL;
2443 EnterResourceNoLock<PPB_Graphics3D_API> enter_3d(device, false); 2436 EnterResourceNoLock<PPB_Graphics3D_API> enter_3d(device, false);
2444 PPB_Graphics3D_Impl* graphics_3d = enter_3d.succeeded() ? 2437 PPB_Graphics3D_Impl* graphics_3d = enter_3d.succeeded() ?
2445 static_cast<PPB_Graphics3D_Impl*>(enter_3d.object()) : NULL; 2438 static_cast<PPB_Graphics3D_Impl*>(enter_3d.object()) : NULL;
2446 2439
2447 if (graphics_2d) { 2440 if (bound_graphics_2d_platform_) {
2448 if (graphics_2d->pp_instance() != pp_instance()) 2441 if (!bound_graphics_2d_platform_->BindToInstance(this))
2449 return PP_FALSE; // Can't bind other instance's contexts.
2450 if (!graphics_2d->BindToInstance(this))
2451 return PP_FALSE; // Can't bind to more than one instance. 2442 return PP_FALSE; // Can't bind to more than one instance.
2452 2443
2453 bound_graphics_ = graphics_2d; 2444 setBackingTextureId(0, bound_graphics_2d_platform_->IsAlwaysOpaque());
2454 setBackingTextureId(0, graphics_2d->is_always_opaque());
2455 // BindToInstance will have invalidated the plugin if necessary. 2445 // BindToInstance will have invalidated the plugin if necessary.
2456 } else if (graphics_3d) { 2446 } else if (graphics_3d) {
2457 // Make sure graphics can only be bound to the instance it is 2447 // Make sure graphics can only be bound to the instance it is
2458 // associated with. 2448 // associated with.
2459 if (graphics_3d->pp_instance() != pp_instance()) 2449 if (graphics_3d->pp_instance() != pp_instance())
2460 return PP_FALSE; 2450 return PP_FALSE;
2461 if (!graphics_3d->BindToInstance(true)) 2451 if (!graphics_3d->BindToInstance(true))
2462 return PP_FALSE; 2452 return PP_FALSE;
2463 2453
2464 bound_graphics_ = graphics_3d; 2454 bound_graphics_3d_ = graphics_3d;
2465 setBackingTextureId(graphics_3d->GetBackingTextureId(), 2455 setBackingTextureId(graphics_3d->GetBackingTextureId(),
2466 graphics_3d->IsOpaque()); 2456 graphics_3d->IsOpaque());
2467 } else { 2457 } else {
2468 // The device is not a valid resource type. 2458 // The device is not a valid resource type.
2469 return PP_FALSE; 2459 return PP_FALSE;
2470 } 2460 }
2471 2461
2472 return PP_TRUE; 2462 return PP_TRUE;
2473 } 2463 }
2474 2464
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after
3244 screen_size_for_fullscreen_ = gfx::Size(); 3234 screen_size_for_fullscreen_ = gfx::Size();
3245 WebElement element = container_->element(); 3235 WebElement element = container_->element();
3246 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); 3236 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_);
3247 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); 3237 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_);
3248 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); 3238 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_);
3249 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); 3239 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_);
3250 } 3240 }
3251 3241
3252 } // namespace ppapi 3242 } // namespace ppapi
3253 } // namespace webkit 3243 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698