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

Side by Side Diff: content/renderer/pepper/pepper_plugin_instance_impl.cc

Issue 298023004: [PPAPI] Compositor API implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@compositor_api_def_new
Patch Set: Fix reivew issues Created 6 years, 6 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
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 "content/renderer/pepper/pepper_plugin_instance_impl.h" 5 #include "content/renderer/pepper/pepper_plugin_instance_impl.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/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 17 matching lines...) Expand all
28 #include "content/renderer/pepper/common.h" 28 #include "content/renderer/pepper/common.h"
29 #include "content/renderer/pepper/content_decryptor_delegate.h" 29 #include "content/renderer/pepper/content_decryptor_delegate.h"
30 #include "content/renderer/pepper/event_conversion.h" 30 #include "content/renderer/pepper/event_conversion.h"
31 #include "content/renderer/pepper/fullscreen_container.h" 31 #include "content/renderer/pepper/fullscreen_container.h"
32 #include "content/renderer/pepper/gfx_conversion.h" 32 #include "content/renderer/pepper/gfx_conversion.h"
33 #include "content/renderer/pepper/host_dispatcher_wrapper.h" 33 #include "content/renderer/pepper/host_dispatcher_wrapper.h"
34 #include "content/renderer/pepper/host_globals.h" 34 #include "content/renderer/pepper/host_globals.h"
35 #include "content/renderer/pepper/message_channel.h" 35 #include "content/renderer/pepper/message_channel.h"
36 #include "content/renderer/pepper/npapi_glue.h" 36 #include "content/renderer/pepper/npapi_glue.h"
37 #include "content/renderer/pepper/pepper_browser_connection.h" 37 #include "content/renderer/pepper/pepper_browser_connection.h"
38 #include "content/renderer/pepper/pepper_compositor_host.h"
38 #include "content/renderer/pepper/pepper_file_ref_renderer_host.h" 39 #include "content/renderer/pepper/pepper_file_ref_renderer_host.h"
39 #include "content/renderer/pepper/pepper_graphics_2d_host.h" 40 #include "content/renderer/pepper/pepper_graphics_2d_host.h"
40 #include "content/renderer/pepper/pepper_in_process_router.h" 41 #include "content/renderer/pepper/pepper_in_process_router.h"
41 #include "content/renderer/pepper/pepper_url_loader_host.h" 42 #include "content/renderer/pepper/pepper_url_loader_host.h"
42 #include "content/renderer/pepper/plugin_module.h" 43 #include "content/renderer/pepper/plugin_module.h"
43 #include "content/renderer/pepper/plugin_object.h" 44 #include "content/renderer/pepper/plugin_object.h"
44 #include "content/renderer/pepper/ppb_buffer_impl.h" 45 #include "content/renderer/pepper/ppb_buffer_impl.h"
45 #include "content/renderer/pepper/ppb_graphics_3d_impl.h" 46 #include "content/renderer/pepper/ppb_graphics_3d_impl.h"
46 #include "content/renderer/pepper/ppb_image_data_impl.h" 47 #include "content/renderer/pepper/ppb_image_data_impl.h"
47 #include "content/renderer/pepper/renderer_ppapi_host_impl.h" 48 #include "content/renderer/pepper/renderer_ppapi_host_impl.h"
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 render_frame_(render_frame), 517 render_frame_(render_frame),
517 module_(module), 518 module_(module),
518 instance_interface_(instance_interface), 519 instance_interface_(instance_interface),
519 pp_instance_(0), 520 pp_instance_(0),
520 container_(container), 521 container_(container),
521 layer_bound_to_fullscreen_(false), 522 layer_bound_to_fullscreen_(false),
522 plugin_url_(plugin_url), 523 plugin_url_(plugin_url),
523 full_frame_(false), 524 full_frame_(false),
524 sent_initial_did_change_view_(false), 525 sent_initial_did_change_view_(false),
525 bound_graphics_2d_platform_(NULL), 526 bound_graphics_2d_platform_(NULL),
527 bound_compositor_(NULL),
526 has_webkit_focus_(false), 528 has_webkit_focus_(false),
527 has_content_area_focus_(false), 529 has_content_area_focus_(false),
528 find_identifier_(-1), 530 find_identifier_(-1),
529 plugin_find_interface_(NULL), 531 plugin_find_interface_(NULL),
530 plugin_input_event_interface_(NULL), 532 plugin_input_event_interface_(NULL),
531 plugin_mouse_lock_interface_(NULL), 533 plugin_mouse_lock_interface_(NULL),
532 plugin_pdf_interface_(NULL), 534 plugin_pdf_interface_(NULL),
533 plugin_private_interface_(NULL), 535 plugin_private_interface_(NULL),
534 plugin_selection_interface_(NULL), 536 plugin_selection_interface_(NULL),
535 plugin_textinput_interface_(NULL), 537 plugin_textinput_interface_(NULL),
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 fullscreen_container_->InvalidateRect(rect); 725 fullscreen_container_->InvalidateRect(rect);
724 } else { 726 } else {
725 if (!container_ || view_data_.rect.size.width == 0 || 727 if (!container_ || view_data_.rect.size.width == 0 ||
726 view_data_.rect.size.height == 0) 728 view_data_.rect.size.height == 0)
727 return; // Nothing to do. 729 return; // Nothing to do.
728 if (rect.IsEmpty()) 730 if (rect.IsEmpty())
729 container_->invalidate(); 731 container_->invalidate();
730 else 732 else
731 container_->invalidateRect(rect); 733 container_->invalidateRect(rect);
732 } 734 }
733 if (texture_layer_) { 735
736 cc::Layer* layer =
737 texture_layer_ ? texture_layer_.get() : compositor_layer_.get();
738 if (layer) {
734 if (rect.IsEmpty()) { 739 if (rect.IsEmpty()) {
735 texture_layer_->SetNeedsDisplay(); 740 layer->SetNeedsDisplay();
736 } else { 741 } else {
737 texture_layer_->SetNeedsDisplayRect(rect); 742 layer->SetNeedsDisplayRect(rect);
738 } 743 }
739 } 744 }
740 } 745 }
741 746
742 void PepperPluginInstanceImpl::ScrollRect(int dx, 747 void PepperPluginInstanceImpl::ScrollRect(int dx,
743 int dy, 748 int dy,
744 const gfx::Rect& rect) { 749 const gfx::Rect& rect) {
745 if (texture_layer_) { 750 cc::Layer* layer =
751 texture_layer_ ? texture_layer_.get() : compositor_layer_.get();
752 if (layer) {
746 InvalidateRect(rect); 753 InvalidateRect(rect);
747 } else if (fullscreen_container_) { 754 } else if (fullscreen_container_) {
748 fullscreen_container_->ScrollRect(dx, dy, rect); 755 fullscreen_container_->ScrollRect(dx, dy, rect);
749 } else { 756 } else {
750 if (full_frame_ && !IsViewAccelerated()) { 757 if (full_frame_ && !IsViewAccelerated()) {
751 container_->scrollRect(dx, dy, rect); 758 container_->scrollRect(dx, dy, rect);
752 } else { 759 } else {
753 // Can't do optimized scrolling since there could be other elements on top 760 // Can't do optimized scrolling since there could be other elements on top
754 // of us or the view renders via the accelerated compositor which is 761 // of us or the view renders via the accelerated compositor which is
755 // incompatible with the move and backfill scrolling model. 762 // incompatible with the move and backfill scrolling model.
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
1269 // |view_data_| haven't been properly initialized. 1276 // |view_data_| haven't been properly initialized.
1270 if (sent_initial_did_change_view_) 1277 if (sent_initial_did_change_view_)
1271 SendDidChangeView(); 1278 SendDidChangeView();
1272 } 1279 }
1273 1280
1274 void PepperPluginInstanceImpl::ViewInitiatedPaint() { 1281 void PepperPluginInstanceImpl::ViewInitiatedPaint() {
1275 if (bound_graphics_2d_platform_) 1282 if (bound_graphics_2d_platform_)
1276 bound_graphics_2d_platform_->ViewInitiatedPaint(); 1283 bound_graphics_2d_platform_->ViewInitiatedPaint();
1277 else if (bound_graphics_3d_.get()) 1284 else if (bound_graphics_3d_.get())
1278 bound_graphics_3d_->ViewInitiatedPaint(); 1285 bound_graphics_3d_->ViewInitiatedPaint();
1286 else if (bound_compositor_)
1287 bound_compositor_->ViewInitiatedPaint();
1279 } 1288 }
1280 1289
1281 void PepperPluginInstanceImpl::ViewFlushedPaint() { 1290 void PepperPluginInstanceImpl::ViewFlushedPaint() {
1282 // Keep a reference on the stack. See NOTE above. 1291 // Keep a reference on the stack. See NOTE above.
1283 scoped_refptr<PepperPluginInstanceImpl> ref(this); 1292 scoped_refptr<PepperPluginInstanceImpl> ref(this);
1284 if (bound_graphics_2d_platform_) 1293 if (bound_graphics_2d_platform_)
1285 bound_graphics_2d_platform_->ViewFlushedPaint(); 1294 bound_graphics_2d_platform_->ViewFlushedPaint();
1286 else if (bound_graphics_3d_.get()) 1295 else if (bound_graphics_3d_.get())
1287 bound_graphics_3d_->ViewFlushedPaint(); 1296 bound_graphics_3d_->ViewFlushedPaint();
1297 else if (bound_compositor_)
1298 bound_compositor_->ViewFlushedPaint();
1288 } 1299 }
1289 1300
1290 void PepperPluginInstanceImpl::SetSelectedText( 1301 void PepperPluginInstanceImpl::SetSelectedText(
1291 const base::string16& selected_text) { 1302 const base::string16& selected_text) {
1292 selected_text_ = selected_text; 1303 selected_text_ = selected_text;
1293 } 1304 }
1294 1305
1295 void PepperPluginInstanceImpl::SetLinkUnderCursor(const std::string& url) { 1306 void PepperPluginInstanceImpl::SetLinkUnderCursor(const std::string& url) {
1296 link_under_cursor_ = base::UTF8ToUTF16(url); 1307 link_under_cursor_ = base::UTF8ToUTF16(url);
1297 } 1308 }
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after
1963 return; 1974 return;
1964 1975
1965 gpu::Mailbox mailbox; 1976 gpu::Mailbox mailbox;
1966 uint32 sync_point = 0; 1977 uint32 sync_point = 0;
1967 if (bound_graphics_3d_.get()) { 1978 if (bound_graphics_3d_.get()) {
1968 bound_graphics_3d_->GetBackingMailbox(&mailbox, &sync_point); 1979 bound_graphics_3d_->GetBackingMailbox(&mailbox, &sync_point);
1969 DCHECK_EQ(mailbox.IsZero(), sync_point == 0); 1980 DCHECK_EQ(mailbox.IsZero(), sync_point == 0);
1970 } 1981 }
1971 bool want_3d_layer = !mailbox.IsZero(); 1982 bool want_3d_layer = !mailbox.IsZero();
1972 bool want_2d_layer = !!bound_graphics_2d_platform_; 1983 bool want_2d_layer = !!bound_graphics_2d_platform_;
1973 bool want_layer = want_3d_layer || want_2d_layer; 1984 bool want_texture_layer = want_3d_layer || want_2d_layer;
1985 bool want_compositor_layer = !!bound_compositor_;
1974 1986
1975 if ((want_layer == !!texture_layer_.get()) && 1987 if ((want_texture_layer == !!texture_layer_.get()) &&
1976 (want_3d_layer == layer_is_hardware_) && 1988 (want_3d_layer == layer_is_hardware_) &&
1989 (want_compositor_layer == ! compositor_layer_) &&
1977 layer_bound_to_fullscreen_ == !!fullscreen_container_) { 1990 layer_bound_to_fullscreen_ == !!fullscreen_container_) {
1978 UpdateLayerTransform(); 1991 UpdateLayerTransform();
1979 return; 1992 return;
1980 } 1993 }
1981 1994
1982 if (texture_layer_) { 1995 if (texture_layer_ || compositor_layer_) {
1983 if (!layer_bound_to_fullscreen_) 1996 if (!layer_bound_to_fullscreen_)
1984 container_->setWebLayer(NULL); 1997 container_->setWebLayer(NULL);
1985 else if (fullscreen_container_) 1998 else if (fullscreen_container_)
1986 fullscreen_container_->SetLayer(NULL); 1999 fullscreen_container_->SetLayer(NULL);
1987 web_layer_.reset(); 2000 web_layer_.reset();
1988 texture_layer_ = NULL; 2001 texture_layer_ = NULL;
2002 compositor_layer_ = NULL;
1989 } 2003 }
1990 if (want_layer) { 2004
2005 if (want_texture_layer) {
1991 bool opaque = false; 2006 bool opaque = false;
1992 if (want_3d_layer) { 2007 if (want_3d_layer) {
1993 DCHECK(bound_graphics_3d_.get()); 2008 DCHECK(bound_graphics_3d_.get());
1994 texture_layer_ = cc::TextureLayer::CreateForMailbox(NULL); 2009 texture_layer_ = cc::TextureLayer::CreateForMailbox(NULL);
1995 opaque = bound_graphics_3d_->IsOpaque(); 2010 opaque = bound_graphics_3d_->IsOpaque();
1996 texture_layer_->SetTextureMailboxWithoutReleaseCallback( 2011 texture_layer_->SetTextureMailboxWithoutReleaseCallback(
1997 cc::TextureMailbox(mailbox, GL_TEXTURE_2D, sync_point)); 2012 cc::TextureMailbox(mailbox, GL_TEXTURE_2D, sync_point));
1998 } else { 2013 } else {
1999 DCHECK(bound_graphics_2d_platform_); 2014 DCHECK(bound_graphics_2d_platform_);
2000 texture_layer_ = cc::TextureLayer::CreateForMailbox(this); 2015 texture_layer_ = cc::TextureLayer::CreateForMailbox(this);
2001 bound_graphics_2d_platform_->AttachedToNewLayer(); 2016 bound_graphics_2d_platform_->AttachedToNewLayer();
2002 opaque = bound_graphics_2d_platform_->IsAlwaysOpaque(); 2017 opaque = bound_graphics_2d_platform_->IsAlwaysOpaque();
2003 texture_layer_->SetFlipped(false); 2018 texture_layer_->SetFlipped(false);
2004 } 2019 }
2020
2021 // Ignore transparency in fullscreen, since that's what Flash always
2022 // wants to do, and that lets it not recreate a context if
2023 // wmode=transparent was specified.
2024 opaque = opaque || fullscreen_container_;
2025 texture_layer_->SetContentsOpaque(opaque);
2005 web_layer_.reset(new webkit::WebLayerImpl(texture_layer_)); 2026 web_layer_.reset(new webkit::WebLayerImpl(texture_layer_));
2027 } else if (want_compositor_layer) {
2028 compositor_layer_ = bound_compositor_->layer();
2029 web_layer_.reset(new webkit::WebLayerImpl(compositor_layer_));
2030 }
2031
2032 if (web_layer_) {
2006 if (fullscreen_container_) { 2033 if (fullscreen_container_) {
2007 fullscreen_container_->SetLayer(web_layer_.get()); 2034 fullscreen_container_->SetLayer(web_layer_.get());
2008 // Ignore transparency in fullscreen, since that's what Flash always
2009 // wants to do, and that lets it not recreate a context if
2010 // wmode=transparent was specified.
2011 texture_layer_->SetContentsOpaque(true);
2012 } else { 2035 } else {
2013 container_->setWebLayer(web_layer_.get()); 2036 container_->setWebLayer(web_layer_.get());
2014 texture_layer_->SetContentsOpaque(opaque);
2015 } 2037 }
2016 } 2038 }
2039
2017 layer_bound_to_fullscreen_ = !!fullscreen_container_; 2040 layer_bound_to_fullscreen_ = !!fullscreen_container_;
2018 layer_is_hardware_ = want_3d_layer; 2041 layer_is_hardware_ = want_3d_layer;
2019 UpdateLayerTransform(); 2042 UpdateLayerTransform();
2020 } 2043 }
2021 2044
2022 bool PepperPluginInstanceImpl::PrepareTextureMailbox( 2045 bool PepperPluginInstanceImpl::PrepareTextureMailbox(
2023 cc::TextureMailbox* mailbox, 2046 cc::TextureMailbox* mailbox,
2024 scoped_ptr<cc::SingleReleaseCallback>* release_callback, 2047 scoped_ptr<cc::SingleReleaseCallback>* release_callback,
2025 bool use_shared_memory) { 2048 bool use_shared_memory) {
2026 if (!bound_graphics_2d_platform_) 2049 if (!bound_graphics_2d_platform_)
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
2188 // UpdateLayer(). 2211 // UpdateLayer().
2189 scoped_refptr<ppapi::Resource> old_graphics = bound_graphics_3d_.get(); 2212 scoped_refptr<ppapi::Resource> old_graphics = bound_graphics_3d_.get();
2190 if (bound_graphics_3d_.get()) { 2213 if (bound_graphics_3d_.get()) {
2191 bound_graphics_3d_->BindToInstance(false); 2214 bound_graphics_3d_->BindToInstance(false);
2192 bound_graphics_3d_ = NULL; 2215 bound_graphics_3d_ = NULL;
2193 } 2216 }
2194 if (bound_graphics_2d_platform_) { 2217 if (bound_graphics_2d_platform_) {
2195 bound_graphics_2d_platform_->BindToInstance(NULL); 2218 bound_graphics_2d_platform_->BindToInstance(NULL);
2196 bound_graphics_2d_platform_ = NULL; 2219 bound_graphics_2d_platform_ = NULL;
2197 } 2220 }
2221 if (bound_compositor_) {
2222 bound_compositor_->BindToInstance(NULL);
2223 bound_compositor_ = NULL;
2224 }
2198 2225
2199 // Special-case clearing the current device. 2226 // Special-case clearing the current device.
2200 if (!device) { 2227 if (!device) {
2201 UpdateLayer(); 2228 UpdateLayer();
2202 InvalidateRect(gfx::Rect()); 2229 InvalidateRect(gfx::Rect());
2203 return PP_TRUE; 2230 return PP_TRUE;
2204 } 2231 }
2205 2232
2206 // Refuse to bind if in transition to fullscreen with PPB_FlashFullscreen or 2233 // Refuse to bind if in transition to fullscreen with PPB_FlashFullscreen or
2207 // to/from fullscreen with PPB_Fullscreen. 2234 // to/from fullscreen with PPB_Fullscreen.
2208 if ((fullscreen_container_ && !flash_fullscreen_) || 2235 if ((fullscreen_container_ && !flash_fullscreen_) ||
2209 desired_fullscreen_state_ != view_data_.is_fullscreen) 2236 desired_fullscreen_state_ != view_data_.is_fullscreen)
2210 return PP_FALSE; 2237 return PP_FALSE;
2211 2238
2212 const ppapi::host::PpapiHost* ppapi_host = 2239 const ppapi::host::PpapiHost* ppapi_host =
2213 RendererPpapiHost::GetForPPInstance(instance)->GetPpapiHost(); 2240 RendererPpapiHost::GetForPPInstance(instance)->GetPpapiHost();
2214 ppapi::host::ResourceHost* host = ppapi_host->GetResourceHost(device); 2241 ppapi::host::ResourceHost* host = ppapi_host->GetResourceHost(device);
2215 PepperGraphics2DHost* graphics_2d = NULL; 2242 PepperGraphics2DHost* graphics_2d = NULL;
2243 PepperCompositorHost* compositor = NULL;
2216 if (host) { 2244 if (host) {
2217 if (host->IsGraphics2DHost()) 2245 if (host->IsGraphics2DHost()) {
2218 graphics_2d = static_cast<PepperGraphics2DHost*>(host); 2246 graphics_2d = static_cast<PepperGraphics2DHost*>(host);
2219 DLOG_IF(ERROR, !graphics_2d) << "Resource is not PepperGraphics2DHost."; 2247 } else if (host->IsCompositorHost()) {
2248 compositor = static_cast<PepperCompositorHost*>(host);
2249 } else {
2250 DLOG(ERROR) <<
2251 "Resource is not PepperCompositorHost or PepperGraphics2DHost.";
2252 }
2220 } 2253 }
2221 2254
2222 EnterResourceNoLock<PPB_Graphics3D_API> enter_3d(device, false); 2255 EnterResourceNoLock<PPB_Graphics3D_API> enter_3d(device, false);
2223 PPB_Graphics3D_Impl* graphics_3d = 2256 PPB_Graphics3D_Impl* graphics_3d =
2224 enter_3d.succeeded() 2257 enter_3d.succeeded()
2225 ? static_cast<PPB_Graphics3D_Impl*>(enter_3d.object()) 2258 ? static_cast<PPB_Graphics3D_Impl*>(enter_3d.object())
2226 : NULL; 2259 : NULL;
2227 2260
2228 if (graphics_2d) { 2261 if (compositor) {
2262 if (compositor->BindToInstance(this)) {
2263 bound_compositor_ = compositor;
2264 UpdateLayer();
2265 return PP_TRUE;
2266 }
2267 } else if (graphics_2d) {
2229 if (graphics_2d->BindToInstance(this)) { 2268 if (graphics_2d->BindToInstance(this)) {
2230 bound_graphics_2d_platform_ = graphics_2d; 2269 bound_graphics_2d_platform_ = graphics_2d;
2231 UpdateLayer(); 2270 UpdateLayer();
2232 return PP_TRUE; 2271 return PP_TRUE;
2233 } 2272 }
2234 } else if (graphics_3d) { 2273 } else if (graphics_3d) {
2235 // Make sure graphics can only be bound to the instance it is 2274 // Make sure graphics can only be bound to the instance it is
2236 // associated with. 2275 // associated with.
2237 if (graphics_3d->pp_instance() == pp_instance() && 2276 if (graphics_3d->pp_instance() == pp_instance() &&
2238 graphics_3d->BindToInstance(true)) { 2277 graphics_3d->BindToInstance(true)) {
(...skipping 960 matching lines...) Expand 10 before | Expand all | Expand 10 after
3199 // Running out-of-process. Initiate an IPC call to notify the plugin 3238 // Running out-of-process. Initiate an IPC call to notify the plugin
3200 // process. 3239 // process.
3201 ppapi::proxy::HostDispatcher* dispatcher = 3240 ppapi::proxy::HostDispatcher* dispatcher =
3202 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance()); 3241 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance());
3203 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad( 3242 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad(
3204 ppapi::API_ID_PPP_INSTANCE, pp_instance(), pending_host_id, data)); 3243 ppapi::API_ID_PPP_INSTANCE, pp_instance(), pending_host_id, data));
3205 } 3244 }
3206 } 3245 }
3207 3246
3208 } // namespace content 3247 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698