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

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

Issue 7409003: Binding Graphics3D with Instance and OpenGLES2 interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 #include "ui/gfx/skia_util.h" 48 #include "ui/gfx/skia_util.h"
49 #include "webkit/plugins/ppapi/common.h" 49 #include "webkit/plugins/ppapi/common.h"
50 #include "webkit/plugins/ppapi/event_conversion.h" 50 #include "webkit/plugins/ppapi/event_conversion.h"
51 #include "webkit/plugins/ppapi/fullscreen_container.h" 51 #include "webkit/plugins/ppapi/fullscreen_container.h"
52 #include "webkit/plugins/ppapi/message_channel.h" 52 #include "webkit/plugins/ppapi/message_channel.h"
53 #include "webkit/plugins/ppapi/plugin_delegate.h" 53 #include "webkit/plugins/ppapi/plugin_delegate.h"
54 #include "webkit/plugins/ppapi/plugin_module.h" 54 #include "webkit/plugins/ppapi/plugin_module.h"
55 #include "webkit/plugins/ppapi/plugin_object.h" 55 #include "webkit/plugins/ppapi/plugin_object.h"
56 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" 56 #include "webkit/plugins/ppapi/ppb_buffer_impl.h"
57 #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" 57 #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h"
58 #include "webkit/plugins/ppapi/ppb_graphics_3d_impl.h"
58 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" 59 #include "webkit/plugins/ppapi/ppb_image_data_impl.h"
59 #include "webkit/plugins/ppapi/ppb_input_event_impl.h" 60 #include "webkit/plugins/ppapi/ppb_input_event_impl.h"
60 #include "webkit/plugins/ppapi/ppb_surface_3d_impl.h" 61 #include "webkit/plugins/ppapi/ppb_surface_3d_impl.h"
61 #include "webkit/plugins/ppapi/ppb_url_loader_impl.h" 62 #include "webkit/plugins/ppapi/ppb_url_loader_impl.h"
62 #include "webkit/plugins/ppapi/ppb_url_request_info_impl.h" 63 #include "webkit/plugins/ppapi/ppb_url_request_info_impl.h"
63 #include "webkit/plugins/ppapi/ppp_pdf.h" 64 #include "webkit/plugins/ppapi/ppp_pdf.h"
64 #include "webkit/plugins/ppapi/string.h" 65 #include "webkit/plugins/ppapi/string.h"
65 #include "webkit/plugins/ppapi/var.h" 66 #include "webkit/plugins/ppapi/var.h"
66 #include "webkit/plugins/sad_plugin.h" 67 #include "webkit/plugins/sad_plugin.h"
67 68
(...skipping 14 matching lines...) Expand all
82 #include "ui/gfx/gdi_util.h" 83 #include "ui/gfx/gdi_util.h"
83 #endif 84 #endif
84 85
85 #if defined(OS_MACOSX) && defined(USE_SKIA) 86 #if defined(OS_MACOSX) && defined(USE_SKIA)
86 #include "skia/ext/skia_utils_mac.h" 87 #include "skia/ext/skia_utils_mac.h"
87 #endif 88 #endif
88 89
89 using ppapi::thunk::EnterResourceNoLock; 90 using ppapi::thunk::EnterResourceNoLock;
90 using ppapi::thunk::PPB_Buffer_API; 91 using ppapi::thunk::PPB_Buffer_API;
91 using ppapi::thunk::PPB_Graphics2D_API; 92 using ppapi::thunk::PPB_Graphics2D_API;
93 using ppapi::thunk::PPB_Graphics3D_API;
92 using ppapi::thunk::PPB_ImageData_API; 94 using ppapi::thunk::PPB_ImageData_API;
93 using ppapi::thunk::PPB_Instance_FunctionAPI; 95 using ppapi::thunk::PPB_Instance_FunctionAPI;
94 using ppapi::thunk::PPB_Surface3D_API; 96 using ppapi::thunk::PPB_Surface3D_API;
95 using WebKit::WebBindings; 97 using WebKit::WebBindings;
96 using WebKit::WebCanvas; 98 using WebKit::WebCanvas;
97 using WebKit::WebCursorInfo; 99 using WebKit::WebCursorInfo;
98 using WebKit::WebDocument; 100 using WebKit::WebDocument;
99 using WebKit::WebFrame; 101 using WebKit::WebFrame;
100 using WebKit::WebInputEvent; 102 using WebKit::WebInputEvent;
101 using WebKit::WebPluginContainer; 103 using WebKit::WebPluginContainer;
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 const gfx::Rect& paint_rect) { 281 const gfx::Rect& paint_rect) {
280 if (module()->is_crashed()) { 282 if (module()->is_crashed()) {
281 // Crashed plugin painting. 283 // Crashed plugin painting.
282 if (!sad_plugin_) // Lazily initialize bitmap. 284 if (!sad_plugin_) // Lazily initialize bitmap.
283 sad_plugin_ = delegate_->GetSadPluginBitmap(); 285 sad_plugin_ = delegate_->GetSadPluginBitmap();
284 if (sad_plugin_) 286 if (sad_plugin_)
285 webkit::PaintSadPlugin(canvas, plugin_rect, *sad_plugin_); 287 webkit::PaintSadPlugin(canvas, plugin_rect, *sad_plugin_);
286 return; 288 return;
287 } 289 }
288 290
289 if (bound_graphics_2d()) 291 if (GetBoundGraphics2D())
290 bound_graphics_2d()->Paint(canvas, plugin_rect, paint_rect); 292 GetBoundGraphics2D()->Paint(canvas, plugin_rect, paint_rect);
291 } 293 }
292 294
293 void PluginInstance::InvalidateRect(const gfx::Rect& rect) { 295 void PluginInstance::InvalidateRect(const gfx::Rect& rect) {
294 if (fullscreen_container_) { 296 if (fullscreen_container_) {
295 if (rect.IsEmpty()) 297 if (rect.IsEmpty())
296 fullscreen_container_->Invalidate(); 298 fullscreen_container_->Invalidate();
297 else 299 else
298 fullscreen_container_->InvalidateRect(rect); 300 fullscreen_container_->InvalidateRect(rect);
299 } else { 301 } else {
300 if (!container_ || position_.IsEmpty()) 302 if (!container_ || position_.IsEmpty())
(...skipping 13 matching lines...) Expand all
314 container_->scrollRect(dx, dy, rect); 316 container_->scrollRect(dx, dy, rect);
315 } else { 317 } else {
316 // Can't do optimized scrolling since there could be other elements on top 318 // Can't do optimized scrolling since there could be other elements on top
317 // of us. 319 // of us.
318 InvalidateRect(rect); 320 InvalidateRect(rect);
319 } 321 }
320 } 322 }
321 } 323 }
322 324
323 unsigned PluginInstance::GetBackingTextureId() { 325 unsigned PluginInstance::GetBackingTextureId() {
324 if (!bound_graphics_3d()) 326 if (GetBoundGraphics3D())
325 return 0; 327 return GetBoundGraphics3D()->GetBackingTextureId();
328 else if (GetBoundSurface3D())
329 return GetBoundSurface3D()->GetBackingTextureId();
326 330
327 return bound_graphics_3d()->GetBackingTextureId(); 331 return 0;
328 } 332 }
329 333
330 void PluginInstance::CommitBackingTexture() { 334 void PluginInstance::CommitBackingTexture() {
331 if (fullscreen_container_) 335 if (fullscreen_container_)
332 fullscreen_container_->Invalidate(); 336 fullscreen_container_->Invalidate();
333 else 337 else
334 container_->commitBackingTexture(); 338 container_->commitBackingTexture();
335 } 339 }
336 340
337 void PluginInstance::InstanceCrashed() { 341 void PluginInstance::InstanceCrashed() {
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 543
540 bool old_plugin_focus = PluginHasFocus(); 544 bool old_plugin_focus = PluginHasFocus();
541 has_content_area_focus_ = has_focus; 545 has_content_area_focus_ = has_focus;
542 if (PluginHasFocus() != old_plugin_focus) { 546 if (PluginHasFocus() != old_plugin_focus) {
543 instance_interface_->DidChangeFocus(pp_instance(), 547 instance_interface_->DidChangeFocus(pp_instance(),
544 BoolToPPBool(PluginHasFocus())); 548 BoolToPPBool(PluginHasFocus()));
545 } 549 }
546 } 550 }
547 551
548 void PluginInstance::ViewInitiatedPaint() { 552 void PluginInstance::ViewInitiatedPaint() {
549 if (bound_graphics_2d()) 553 if (GetBoundGraphics2D())
550 bound_graphics_2d()->ViewInitiatedPaint(); 554 GetBoundGraphics2D()->ViewInitiatedPaint();
551 if (bound_graphics_3d()) 555 else if (GetBoundGraphics3D())
552 bound_graphics_3d()->ViewInitiatedPaint(); 556 GetBoundGraphics3D()->ViewInitiatedPaint();
557 else if (GetBoundSurface3D())
558 GetBoundSurface3D()->ViewInitiatedPaint();
553 } 559 }
554 560
555 void PluginInstance::ViewFlushedPaint() { 561 void PluginInstance::ViewFlushedPaint() {
556 // Keep a reference on the stack. See NOTE above. 562 // Keep a reference on the stack. See NOTE above.
557 scoped_refptr<PluginInstance> ref(this); 563 scoped_refptr<PluginInstance> ref(this);
558 if (bound_graphics_2d()) 564 if (GetBoundGraphics2D())
559 bound_graphics_2d()->ViewFlushedPaint(); 565 GetBoundGraphics2D()->ViewFlushedPaint();
560 if (bound_graphics_3d()) 566 else if (GetBoundGraphics3D())
561 bound_graphics_3d()->ViewFlushedPaint(); 567 GetBoundGraphics3D()->ViewFlushedPaint();
568 else if (GetBoundSurface3D())
569 GetBoundSurface3D()->ViewFlushedPaint();
562 } 570 }
563 571
564 bool PluginInstance::GetBitmapForOptimizedPluginPaint( 572 bool PluginInstance::GetBitmapForOptimizedPluginPaint(
565 const gfx::Rect& paint_bounds, 573 const gfx::Rect& paint_bounds,
566 TransportDIB** dib, 574 TransportDIB** dib,
567 gfx::Rect* location, 575 gfx::Rect* location,
568 gfx::Rect* clip) { 576 gfx::Rect* clip) {
569 if (!always_on_top_) 577 if (!always_on_top_)
570 return false; 578 return false;
571 if (!bound_graphics_2d() || !bound_graphics_2d()->is_always_opaque()) 579 if (!GetBoundGraphics2D() || !GetBoundGraphics2D()->is_always_opaque())
572 return false; 580 return false;
573 581
574 // We specifically want to compare against the area covered by the backing 582 // We specifically want to compare against the area covered by the backing
575 // store when seeing if we cover the given paint bounds, since the backing 583 // store when seeing if we cover the given paint bounds, since the backing
576 // store could be smaller than the declared plugin area. 584 // store could be smaller than the declared plugin area.
577 PPB_ImageData_Impl* image_data = bound_graphics_2d()->image_data(); 585 PPB_ImageData_Impl* image_data = GetBoundGraphics2D()->image_data();
578 gfx::Rect plugin_backing_store_rect(position_.origin(), 586 gfx::Rect plugin_backing_store_rect(position_.origin(),
579 gfx::Size(image_data->width(), 587 gfx::Size(image_data->width(),
580 image_data->height())); 588 image_data->height()));
581 gfx::Rect clip_page(clip_); 589 gfx::Rect clip_page(clip_);
582 clip_page.Offset(position_.origin()); 590 clip_page.Offset(position_.origin());
583 gfx::Rect plugin_paint_rect = plugin_backing_store_rect.Intersect(clip_page); 591 gfx::Rect plugin_paint_rect = plugin_backing_store_rect.Intersect(clip_page);
584 if (!plugin_paint_rect.Contains(paint_bounds)) 592 if (!plugin_paint_rect.Contains(paint_bounds))
585 return false; 593 return false;
586 594
587 *dib = image_data->platform_image()->GetTransportDIB(); 595 *dib = image_data->platform_image()->GetTransportDIB();
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after
1253 bounds.origin.x = dest_rect.x(); 1261 bounds.origin.x = dest_rect.x();
1254 bounds.origin.y = canvas_height - dest_rect.y() - dest_rect.height(); 1262 bounds.origin.y = canvas_height - dest_rect.y() - dest_rect.height();
1255 bounds.size.width = dest_rect.width(); 1263 bounds.size.width = dest_rect.width();
1256 bounds.size.height = dest_rect.height(); 1264 bounds.size.height = dest_rect.height();
1257 1265
1258 CGContextDrawImage(canvas, bounds, image); 1266 CGContextDrawImage(canvas, bounds, image);
1259 CGContextRestoreGState(canvas); 1267 CGContextRestoreGState(canvas);
1260 } 1268 }
1261 #endif // defined(OS_MACOSX) && !defined(USE_SKIA) 1269 #endif // defined(OS_MACOSX) && !defined(USE_SKIA)
1262 1270
1263 PPB_Graphics2D_Impl* PluginInstance::bound_graphics_2d() const { 1271 PPB_Graphics2D_Impl* PluginInstance::GetBoundGraphics2D() const {
1264 if (bound_graphics_.get() == NULL) 1272 if (bound_graphics_.get() == NULL)
1265 return NULL; 1273 return NULL;
1266 1274
1267 if (bound_graphics_->AsPPB_Graphics2D_API()) 1275 if (bound_graphics_->AsPPB_Graphics2D_API())
1268 return static_cast<PPB_Graphics2D_Impl*>(bound_graphics_.get()); 1276 return static_cast<PPB_Graphics2D_Impl*>(bound_graphics_.get());
1269 return NULL; 1277 return NULL;
1270 } 1278 }
1271 1279
1272 PPB_Surface3D_Impl* PluginInstance::bound_graphics_3d() const { 1280 PPB_Graphics3D_Impl* PluginInstance::GetBoundGraphics3D() const {
1281 if (bound_graphics_.get() == NULL)
1282 return NULL;
1283
1284 if (bound_graphics_->AsPPB_Graphics3D_API())
1285 return static_cast<PPB_Graphics3D_Impl*>(bound_graphics_.get());
1286 return NULL;
1287 }
1288
1289 PPB_Surface3D_Impl* PluginInstance::GetBoundSurface3D() const {
1273 if (bound_graphics_.get() == NULL) 1290 if (bound_graphics_.get() == NULL)
1274 return NULL; 1291 return NULL;
1275 1292
1276 if (bound_graphics_->AsPPB_Surface3D_API()) 1293 if (bound_graphics_->AsPPB_Surface3D_API())
1277 return static_cast<PPB_Surface3D_Impl*>(bound_graphics_.get()); 1294 return static_cast<PPB_Surface3D_Impl*>(bound_graphics_.get());
1278 return NULL; 1295 return NULL;
1279 } 1296 }
1280 1297
1281 void PluginInstance::setBackingTextureId(unsigned int id) { 1298 void PluginInstance::setBackingTextureId(unsigned int id) {
1282 // If we have a full-screen container_ then the plugin is fullscreen, 1299 // If we have a full-screen container_ then the plugin is fullscreen,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1338 return frame->view()->mainFrame()->document().isPluginDocument(); 1355 return frame->view()->mainFrame()->document().isPluginDocument();
1339 } 1356 }
1340 1357
1341 PPB_Instance_FunctionAPI* PluginInstance::AsPPB_Instance_FunctionAPI() { 1358 PPB_Instance_FunctionAPI* PluginInstance::AsPPB_Instance_FunctionAPI() {
1342 return this; 1359 return this;
1343 } 1360 }
1344 1361
1345 PP_Bool PluginInstance::BindGraphics(PP_Instance instance, 1362 PP_Bool PluginInstance::BindGraphics(PP_Instance instance,
1346 PP_Resource device) { 1363 PP_Resource device) {
1347 if (bound_graphics_.get()) { 1364 if (bound_graphics_.get()) {
1348 if (bound_graphics_2d()) { 1365 if (GetBoundGraphics2D()) {
1349 bound_graphics_2d()->BindToInstance(NULL); 1366 GetBoundGraphics2D()->BindToInstance(NULL);
1350 } else if (bound_graphics_.get()) { 1367 } else if (GetBoundGraphics3D()) {
1351 bound_graphics_3d()->BindToInstance(false); 1368 GetBoundGraphics3D()->BindToInstance(false);
1369 } else if (GetBoundSurface3D()) {
1370 GetBoundSurface3D()->BindToInstance(false);
1352 } 1371 }
1353 // Special-case clearing the current device. 1372 bound_graphics_ = NULL;
1354 if (!device) {
1355 setBackingTextureId(0);
1356 InvalidateRect(gfx::Rect());
1357 }
1358 } 1373 }
1359 bound_graphics_ = NULL;
1360 1374
1361 if (!device) 1375 // Special-case clearing the current device.
1376 if (!device) {
1377 setBackingTextureId(0);
1378 InvalidateRect(gfx::Rect());
1362 return PP_TRUE; 1379 return PP_TRUE;
1380 }
1381
1382 // Refuse to bind if we're transitioning to fullscreen.
1383 if (fullscreen_container_ && !fullscreen_)
1384 return PP_FALSE;
1363 1385
1364 EnterResourceNoLock<PPB_Graphics2D_API> enter_2d(device, false); 1386 EnterResourceNoLock<PPB_Graphics2D_API> enter_2d(device, false);
1365 PPB_Graphics2D_Impl* graphics_2d = enter_2d.succeeded() ? 1387 PPB_Graphics2D_Impl* graphics_2d = enter_2d.succeeded() ?
1366 static_cast<PPB_Graphics2D_Impl*>(enter_2d.object()) : NULL; 1388 static_cast<PPB_Graphics2D_Impl*>(enter_2d.object()) : NULL;
1367 EnterResourceNoLock<PPB_Surface3D_API> enter_3d(device, false); 1389 EnterResourceNoLock<PPB_Graphics3D_API> enter_3d(device, false);
1368 PPB_Surface3D_Impl* graphics_3d = enter_3d.succeeded() ? 1390 PPB_Graphics3D_Impl* graphics_3d = enter_3d.succeeded() ?
1369 static_cast<PPB_Surface3D_Impl*>(enter_3d.object()) : NULL; 1391 static_cast<PPB_Graphics3D_Impl*>(enter_3d.object()) : NULL;
1392 EnterResourceNoLock<PPB_Surface3D_API> enter_surface_3d(device, false);
1393 PPB_Surface3D_Impl* surface_3d = enter_surface_3d.succeeded() ?
1394 static_cast<PPB_Surface3D_Impl*>(enter_surface_3d.object()) : NULL;
1370 1395
1371 if (graphics_2d) { 1396 if (graphics_2d) {
1372 // Refuse to bind if we're transitioning to fullscreen.
1373 if (fullscreen_container_ && !fullscreen_)
1374 return PP_FALSE;
1375 if (graphics_2d->instance() != this) 1397 if (graphics_2d->instance() != this)
1376 return PP_FALSE; // Can't bind other instance's contexts. 1398 return PP_FALSE; // Can't bind other instance's contexts.
1377 if (!graphics_2d->BindToInstance(this)) 1399 if (!graphics_2d->BindToInstance(this))
1378 return PP_FALSE; // Can't bind to more than one instance. 1400 return PP_FALSE; // Can't bind to more than one instance.
1379 1401
1380 bound_graphics_ = graphics_2d; 1402 bound_graphics_ = graphics_2d;
1381 setBackingTextureId(0); 1403 setBackingTextureId(0);
1382 // BindToInstance will have invalidated the plugin if necessary. 1404 // BindToInstance will have invalidated the plugin if necessary.
1383 } else if (graphics_3d) { 1405 } else if (graphics_3d) {
1384 // Refuse to bind if we're transitioning to fullscreen.
1385 if (fullscreen_container_ && !fullscreen_)
1386 return PP_FALSE;
1387 // Make sure graphics can only be bound to the instance it is 1406 // Make sure graphics can only be bound to the instance it is
1388 // associated with. 1407 // associated with.
1389 if (graphics_3d->instance() != this) 1408 if (graphics_3d->instance() != this)
1390 return PP_FALSE; 1409 return PP_FALSE;
1391 if (!graphics_3d->BindToInstance(true)) 1410 if (!graphics_3d->BindToInstance(true))
1392 return PP_FALSE; 1411 return PP_FALSE;
1393 1412
1413 bound_graphics_ = graphics_3d;
1394 setBackingTextureId(graphics_3d->GetBackingTextureId()); 1414 setBackingTextureId(graphics_3d->GetBackingTextureId());
1395 bound_graphics_ = graphics_3d; 1415 } else if (surface_3d) {
1416 // Make sure graphics can only be bound to the instance it is
1417 // associated with.
1418 if (surface_3d->instance() != this)
1419 return PP_FALSE;
1420 if (!surface_3d->BindToInstance(true))
1421 return PP_FALSE;
1422
1423 bound_graphics_ = surface_3d;
1424 setBackingTextureId(surface_3d->GetBackingTextureId());
1396 } else { 1425 } else {
1397 // The device is not a valid resource type. 1426 // The device is not a valid resource type.
1398 return PP_FALSE; 1427 return PP_FALSE;
1399 } 1428 }
1400 1429
1401 return PP_TRUE; 1430 return PP_TRUE;
1402 } 1431 }
1403 1432
1404 PP_Bool PluginInstance::IsFullFrame(PP_Instance instance) { 1433 PP_Bool PluginInstance::IsFullFrame(PP_Instance instance) {
1405 return PP_FromBool(full_frame()); 1434 return PP_FromBool(full_frame());
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1541 } 1570 }
1542 delegate()->ZoomLimitsChanged(minimum_factor, maximium_factor); 1571 delegate()->ZoomLimitsChanged(minimum_factor, maximium_factor);
1543 } 1572 }
1544 1573
1545 void PluginInstance::PostMessage(PP_Instance instance, PP_Var message) { 1574 void PluginInstance::PostMessage(PP_Instance instance, PP_Var message) {
1546 message_channel_->PostMessageToJavaScript(message); 1575 message_channel_->PostMessageToJavaScript(message);
1547 } 1576 }
1548 1577
1549 } // namespace ppapi 1578 } // namespace ppapi
1550 } // namespace webkit 1579 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppapi_plugin_instance.h ('k') | webkit/plugins/ppapi/ppb_context_3d_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698