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

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

Issue 159128: linux: add windowless plugin plumbing (Closed)
Patch Set: address review comments Created 11 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
« no previous file with comments | « webkit/glue/plugins/plugin_host.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/webplugin_delegate_impl.h" 5 #include "webkit/glue/plugins/webplugin_delegate_impl.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include <gtk/gtk.h> 10 #include <gtk/gtk.h>
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 367
368 // Otherwise, we need to recreate ourselves. 368 // Otherwise, we need to recreate ourselves.
369 g_object_unref(gdk_drawable_get_colormap(pixmap_)); 369 g_object_unref(gdk_drawable_get_colormap(pixmap_));
370 g_object_unref(pixmap_); 370 g_object_unref(pixmap_);
371 pixmap_ = NULL; 371 pixmap_ = NULL;
372 } 372 }
373 373
374 // |sys_visual| is owned by gdk; we shouldn't free it. 374 // |sys_visual| is owned by gdk; we shouldn't free it.
375 GdkVisual* sys_visual = gdk_visual_get_system(); 375 GdkVisual* sys_visual = gdk_visual_get_system();
376 pixmap_ = gdk_pixmap_new(NULL, // use width/height/depth params 376 pixmap_ = gdk_pixmap_new(NULL, // use width/height/depth params
377 width, height, sys_visual->depth); 377 std::max(1, width), std::max(1, height),
378 sys_visual->depth);
378 GdkColormap* colormap = gdk_colormap_new(gdk_visual_get_system(), 379 GdkColormap* colormap = gdk_colormap_new(gdk_visual_get_system(),
379 FALSE); 380 FALSE);
380 gdk_drawable_set_colormap(GDK_DRAWABLE(pixmap_), colormap); 381 gdk_drawable_set_colormap(GDK_DRAWABLE(pixmap_), colormap);
381 } 382 }
382 383
383 #ifdef DEBUG_RECTANGLES 384 #ifdef DEBUG_RECTANGLES
384 namespace { 385 namespace {
385 386
386 // Draw a rectangle on a Cairo surface. 387 // Draw a rectangle on a Cairo context.
387 // Useful for debugging various rectangles involved in drawing plugins. 388 // Useful for debugging various rectangles involved in drawing plugins.
388 void DrawDebugRectangle(cairo_surface_t* surface, 389 void DrawDebugRectangle(cairo_t* cairo,
389 const gfx::Rect& rect, 390 const gfx::Rect& rect,
390 float r, float g, float b) { 391 float r, float g, float b) {
391 cairo_t* cairo = cairo_create(surface);
392 cairo_set_source_rgba(cairo, r, g, b, 0.5); 392 cairo_set_source_rgba(cairo, r, g, b, 0.5);
393 cairo_rectangle(cairo, rect.x(), rect.y(), 393 cairo_rectangle(cairo, rect.x(), rect.y(),
394 rect.width(), rect.height()); 394 rect.width(), rect.height());
395 cairo_stroke(cairo); 395 cairo_stroke(cairo);
396 cairo_destroy(cairo);
397 } 396 }
398 397
399 } // namespace 398 } // namespace
400 #endif 399 #endif
401 400
402 void WebPluginDelegateImpl::WindowlessPaint(cairo_t* context, 401 void WebPluginDelegateImpl::WindowlessPaint(cairo_t* context,
403 const gfx::Rect& damage_rect) { 402 const gfx::Rect& damage_rect) {
404 // Compare to: 403 // Compare to:
405 // http://mxr.mozilla.org/firefox/source/layout/generic/nsObjectFrame.cpp: 404 // http://mxr.mozilla.org/firefox/source/layout/generic/nsObjectFrame.cpp:
406 // nsPluginInstanceOwner::Renderer::NativeDraw(). 405 // nsPluginInstanceOwner::Renderer::NativeDraw().
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 518
520 gfx::Rect pixmap_rect(0, 0, 519 gfx::Rect pixmap_rect(0, 0,
521 draw_rect.x() + offset_x + draw_rect.width(), 520 draw_rect.x() + offset_x + draw_rect.width(),
522 draw_rect.y() + offset_y + draw_rect.height()); 521 draw_rect.y() + offset_y + draw_rect.height());
523 522
524 EnsurePixmapAtLeastSize(pixmap_rect.width(), pixmap_rect.height()); 523 EnsurePixmapAtLeastSize(pixmap_rect.width(), pixmap_rect.height());
525 524
526 // Copy the current image into the pixmap, so the plugin can draw over 525 // Copy the current image into the pixmap, so the plugin can draw over
527 // this background. 526 // this background.
528 cairo_t* cairo = gdk_cairo_create(pixmap_); 527 cairo_t* cairo = gdk_cairo_create(pixmap_);
528 double surface_x = -offset_x;
529 double surface_y = -offset_y;
530 cairo_user_to_device(context, &surface_x, &surface_y);
529 cairo_set_source_surface(cairo, cairo_get_target(context), 531 cairo_set_source_surface(cairo, cairo_get_target(context),
530 offset_x, offset_y); 532 -surface_x, -surface_y);
531 cairo_rectangle(cairo, draw_rect.x() + offset_x, draw_rect.y() + offset_y, 533 cairo_rectangle(cairo, draw_rect.x() + offset_x, draw_rect.y() + offset_y,
532 draw_rect.width(), draw_rect.height()); 534 draw_rect.width(), draw_rect.height());
533 cairo_clip(cairo); 535 cairo_clip(cairo);
534 cairo_paint(cairo); 536 cairo_paint(cairo);
535 cairo_destroy(cairo); 537 cairo_destroy(cairo);
536 538
537 // Construct the paint message, targeting the pixmap. 539 // Construct the paint message, targeting the pixmap.
538 NPEvent np_event = {0}; 540 NPEvent np_event = {0};
539 XGraphicsExposeEvent &event = np_event.xgraphicsexpose; 541 XGraphicsExposeEvent &event = np_event.xgraphicsexpose;
540 event.type = GraphicsExpose; 542 event.type = GraphicsExpose;
541 event.display = GDK_DISPLAY(); 543 event.display = GDK_DISPLAY();
542 event.drawable = GDK_PIXMAP_XID(pixmap_); 544 event.drawable = GDK_PIXMAP_XID(pixmap_);
543 event.x = draw_rect.x() + offset_x; 545 event.x = draw_rect.x() + offset_x;
544 event.y = draw_rect.y() + offset_y; 546 event.y = draw_rect.y() + offset_y;
545 event.width = draw_rect.width(); 547 event.width = draw_rect.width();
546 event.height = draw_rect.height(); 548 event.height = draw_rect.height();
547 549
548 // Tell the plugin to paint into the pixmap. 550 // Tell the plugin to paint into the pixmap.
549 static StatsRate plugin_paint("Plugin.Paint"); 551 static StatsRate plugin_paint("Plugin.Paint");
550 StatsScope<StatsRate> scope(plugin_paint); 552 StatsScope<StatsRate> scope(plugin_paint);
551 NPError err = instance()->NPP_HandleEvent(&np_event); 553 NPError err = instance()->NPP_HandleEvent(&np_event);
552 DCHECK_EQ(err, NPERR_NO_ERROR); 554 DCHECK_EQ(err, NPERR_NO_ERROR);
553 555
556 cairo_save(context);
554 // Now copy the rendered image pixmap back into the drawing buffer. 557 // Now copy the rendered image pixmap back into the drawing buffer.
555 gdk_cairo_set_source_pixmap(context, pixmap_, -offset_x, -offset_y); 558 gdk_cairo_set_source_pixmap(context, pixmap_, -offset_x, -offset_y);
556 cairo_rectangle(context, draw_rect.x(), draw_rect.y(), 559 cairo_rectangle(context, draw_rect.x(), draw_rect.y(),
557 draw_rect.width(), draw_rect.height()); 560 draw_rect.width(), draw_rect.height());
558 cairo_clip(context); 561 cairo_clip(context);
559 cairo_paint(context); 562 cairo_paint(context);
560 563
561 #ifdef DEBUG_RECTANGLES 564 #ifdef DEBUG_RECTANGLES
562 // Draw some debugging rectangles. 565 // Draw some debugging rectangles.
563 // Pixmap rect = blue. 566 // Pixmap rect = blue.
564 DrawDebugRectangle(context, pixmap_rect, 0, 0, 1); 567 DrawDebugRectangle(context, pixmap_rect, 0, 0, 1);
565 // Drawing rect = red. 568 // Drawing rect = red.
566 DrawDebugRectangle(context, draw_rect, 1, 0, 0); 569 DrawDebugRectangle(context, draw_rect, 1, 0, 0);
567 #endif 570 #endif
571 cairo_restore(context);
568 } 572 }
569 573
570 void WebPluginDelegateImpl::WindowlessSetWindow(bool force_set_window) { 574 void WebPluginDelegateImpl::WindowlessSetWindow(bool force_set_window) {
571 if (!instance()) 575 if (!instance())
572 return; 576 return;
573 577
574 if (window_rect_.IsEmpty()) // wait for geometry to be set. 578 if (window_rect_.IsEmpty()) // wait for geometry to be set.
575 return; 579 return;
576 580
577 DCHECK(instance()->windowless()); 581 DCHECK(instance()->windowless());
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 return stream; 848 return stream;
845 } 849 }
846 850
847 void WebPluginDelegateImpl::URLRequestRouted(const std::string&url, 851 void WebPluginDelegateImpl::URLRequestRouted(const std::string&url,
848 bool notify_needed, 852 bool notify_needed,
849 intptr_t notify_data) { 853 intptr_t notify_data) {
850 if (notify_needed) { 854 if (notify_needed) {
851 instance()->SetURLLoadData(GURL(url.c_str()), notify_data); 855 instance()->SetURLLoadData(GURL(url.c_str()), notify_data);
852 } 856 }
853 } 857 }
OLDNEW
« no previous file with comments | « webkit/glue/plugins/plugin_host.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698