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

Side by Side Diff: chrome/plugin/webplugin_proxy.cc

Issue 113637: Wire up windowless plugins. Mostly Mac related, some cross (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' 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 | Annotate | Revision Log
« no previous file with comments | « chrome/plugin/webplugin_proxy.h ('k') | chrome/renderer/render_view.cc » ('j') | 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 "chrome/plugin/webplugin_proxy.h" 5 #include "chrome/plugin/webplugin_proxy.h"
6 6
7 #include "app/gfx/canvas.h" 7 #include "app/gfx/canvas.h"
8 #if defined(OS_WIN) 8 #if defined(OS_WIN)
9 #include "app/win_util.h" 9 #include "app/win_util.h"
10 #endif 10 #endif
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 bool success = false; 362 bool success = false;
363 Send(new PluginHostMsg_SetDropEffect(route_id_, event_param, effect, 363 Send(new PluginHostMsg_SetDropEffect(route_id_, event_param, effect,
364 &success)); 364 &success));
365 return success; 365 return success;
366 } 366 }
367 367
368 void WebPluginProxy::Paint(const gfx::Rect& rect) { 368 void WebPluginProxy::Paint(const gfx::Rect& rect) {
369 #if defined(OS_WIN) 369 #if defined(OS_WIN)
370 if (!windowless_hdc_) 370 if (!windowless_hdc_)
371 return; 371 return;
372 #elif defined(OS_MACOSX)
373 if (!windowless_context_.get())
374 return;
375 #endif
372 376
373 // Clear the damaged area so that if the plugin doesn't paint there we won't 377 // Clear the damaged area so that if the plugin doesn't paint there we won't
374 // end up with the old values. 378 // end up with the old values.
375 gfx::Rect offset_rect = rect; 379 gfx::Rect offset_rect = rect;
376 offset_rect.Offset(delegate_->GetRect().origin()); 380 offset_rect.Offset(delegate_->GetRect().origin());
381 #if defined(OS_WIN)
377 if (!background_hdc_) { 382 if (!background_hdc_) {
378 FillRect(windowless_hdc_, &offset_rect.ToRECT(), 383 FillRect(windowless_hdc_, &offset_rect.ToRECT(),
379 static_cast<HBRUSH>(GetStockObject(BLACK_BRUSH))); 384 static_cast<HBRUSH>(GetStockObject(BLACK_BRUSH)));
380 } else { 385 } else {
381 BitBlt(windowless_hdc_, offset_rect.x(), offset_rect.y(), 386 BitBlt(windowless_hdc_, offset_rect.x(), offset_rect.y(),
382 offset_rect.width(), offset_rect.height(), background_hdc_, 387 offset_rect.width(), offset_rect.height(), background_hdc_,
383 rect.x(), rect.y(), SRCCOPY); 388 rect.x(), rect.y(), SRCCOPY);
384 } 389 }
385 390
386 RECT clip_rect = rect.ToRECT(); 391 RECT clip_rect = rect.ToRECT();
387 HRGN clip_region = CreateRectRgnIndirect(&clip_rect); 392 HRGN clip_region = CreateRectRgnIndirect(&clip_rect);
388 SelectClipRgn(windowless_hdc_, clip_region); 393 SelectClipRgn(windowless_hdc_, clip_region);
389 394
390 // Before we send the invalidate, paint so that renderer uses the updated 395 // Before we send the invalidate, paint so that renderer uses the updated
391 // bitmap. 396 // bitmap.
392 delegate_->Paint(windowless_hdc_, offset_rect); 397 delegate_->Paint(windowless_hdc_, offset_rect);
393 398
394 SelectClipRgn(windowless_hdc_, NULL); 399 SelectClipRgn(windowless_hdc_, NULL);
395 DeleteObject(clip_region); 400 DeleteObject(clip_region);
401 #elif defined(OS_MACOSX)
402 CGContextSaveGState(windowless_context_);
403 if (!background_context_.get()) {
404 CGContextSetFillColorWithColor(windowless_context_,
405 CGColorGetConstantColor(kCGColorWhite));
406 CGContextFillRect(windowless_context_, rect.ToCGRect());
407 } else {
408 scoped_cftyperef<CGImageRef> image(
409 CGBitmapContextCreateImage(background_context_));
410 scoped_cftyperef<CGImageRef> sub_image(
411 CGImageCreateWithImageInRect(image, rect.ToCGRect()));
412 CGContextDrawImage(background_context_, rect.ToCGRect(), sub_image);
413 }
414 CGContextClipToRect(windowless_context_, rect.ToCGRect());
415 delegate_->Paint(windowless_context_, rect);
416 CGContextRestoreGState(windowless_context_);
396 #else 417 #else
397 // TODO(port): windowless painting. 418 // TODO(port): windowless painting.
398 NOTIMPLEMENTED(); 419 NOTIMPLEMENTED();
399 #endif 420 #endif
400 } 421 }
401 422
402 void WebPluginProxy::UpdateGeometry( 423 void WebPluginProxy::UpdateGeometry(
403 const gfx::Rect& window_rect, 424 const gfx::Rect& window_rect,
404 const gfx::Rect& clip_rect, 425 const gfx::Rect& clip_rect,
405 const TransportDIB::Id& windowless_buffer_id, 426 const TransportDIB::Handle& windowless_buffer,
406 const TransportDIB::Id& background_buffer_id) { 427 const TransportDIB::Handle& background_buffer) {
407 // TODO(port): this isn't correct usage of a TransportDIB; for now,
408 // the caller temporarly just stuffs the handle into the HANDLE
409 // field of the TransportDIB::Id so it should behave like the older
410 // code.
411 gfx::Rect old = delegate_->GetRect(); 428 gfx::Rect old = delegate_->GetRect();
412 gfx::Rect old_clip_rect = delegate_->GetClipRect(); 429 gfx::Rect old_clip_rect = delegate_->GetClipRect();
413 430
414 delegate_->UpdateGeometry(window_rect, clip_rect); 431 delegate_->UpdateGeometry(window_rect, clip_rect);
415 #if defined(OS_WIN)
416 bool moved = old.x() != window_rect.x() || old.y() != window_rect.y(); 432 bool moved = old.x() != window_rect.x() || old.y() != window_rect.y();
417 if (windowless_buffer_id.handle) { 433 #if defined(OS_MACOSX)
434 if (windowless_buffer.fd > 0) {
435 #else
436 if (windowless_buffer) {
437 #endif
418 // The plugin's rect changed, so now we have a new buffer to draw into. 438 // The plugin's rect changed, so now we have a new buffer to draw into.
419 SetWindowlessBuffer(windowless_buffer_id.handle, 439 SetWindowlessBuffer(windowless_buffer,
420 background_buffer_id.handle); 440 background_buffer);
421 } else if (moved) { 441 } else if (moved) {
422 // The plugin moved, so update our world transform. 442 // The plugin moved, so update our world transform.
423 UpdateTransform(); 443 UpdateTransform();
424 } 444 }
425 // Send over any pending invalidates which occured when the plugin was 445 // Send over any pending invalidates which occured when the plugin was
426 // off screen. 446 // off screen.
427 if (delegate_->IsWindowless() && !clip_rect.IsEmpty() && 447 if (delegate_->IsWindowless() && !clip_rect.IsEmpty() &&
428 old_clip_rect.IsEmpty() && !damaged_rect_.IsEmpty()) { 448 old_clip_rect.IsEmpty() && !damaged_rect_.IsEmpty()) {
429 InvalidateRect(damaged_rect_); 449 InvalidateRect(damaged_rect_);
430 } 450 }
431 #else
432 NOTIMPLEMENTED();
433 #endif
434 } 451 }
435 452
436 #if defined(OS_WIN) 453 #if defined(OS_WIN)
437 void WebPluginProxy::SetWindowlessBuffer( 454 void WebPluginProxy::SetWindowlessBuffer(
438 const base::SharedMemoryHandle& windowless_buffer, 455 const TransportDIB::Handle& windowless_buffer,
439 const base::SharedMemoryHandle& background_buffer) { 456 const TransportDIB::Handle& background_buffer) {
440 // Convert the shared memory handle to a handle that works in our process, 457 // Convert the shared memory handle to a handle that works in our process,
441 // and then use that to create an HDC. 458 // and then use that to create an HDC.
442 ConvertBuffer(windowless_buffer, 459 ConvertBuffer(windowless_buffer,
443 &windowless_shared_section_, 460 &windowless_shared_section_,
444 &windowless_bitmap_, 461 &windowless_bitmap_,
445 &windowless_hdc_); 462 &windowless_hdc_);
446 if (background_buffer) { 463 if (background_buffer) {
447 ConvertBuffer(background_buffer, 464 ConvertBuffer(background_buffer,
448 &background_shared_section_, 465 &background_shared_section_,
449 &background_bitmap_, 466 &background_bitmap_,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 511
495 XFORM xf; 512 XFORM xf;
496 xf.eDx = static_cast<FLOAT>(-delegate_->GetRect().x()); 513 xf.eDx = static_cast<FLOAT>(-delegate_->GetRect().x());
497 xf.eDy = static_cast<FLOAT>(-delegate_->GetRect().y()); 514 xf.eDy = static_cast<FLOAT>(-delegate_->GetRect().y());
498 xf.eM11 = 1; 515 xf.eM11 = 1;
499 xf.eM21 = 0; 516 xf.eM21 = 0;
500 xf.eM12 = 0; 517 xf.eM12 = 0;
501 xf.eM22 = 1; 518 xf.eM22 = 1;
502 SetWorldTransform(windowless_hdc_, &xf); 519 SetWorldTransform(windowless_hdc_, &xf);
503 } 520 }
521 #elif defined(OS_MACOSX)
522 void WebPluginProxy::UpdateTransform() {
523 NOTIMPLEMENTED();
524 }
525
526 void WebPluginProxy::SetWindowlessBuffer(
527 const TransportDIB::Handle& windowless_buffer,
528 const TransportDIB::Handle& background_buffer) {
529 // Convert the shared memory handle to a handle that works in our process,
530 // and then use that to create a CGContextRef.
531 windowless_dib_.reset(TransportDIB::Map(windowless_buffer));
532 background_dib_.reset(TransportDIB::Map(background_buffer));
533 scoped_cftyperef<CGColorSpaceRef> rgb_colorspace(
534 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB));
535 windowless_context_.reset(CGBitmapContextCreate(
536 windowless_dib_->memory(),
537 delegate_->GetRect().width(),
538 delegate_->GetRect().height(),
539 8, 4 * delegate_->GetRect().width(),
540 rgb_colorspace,
541 kCGImageAlphaPremultipliedFirst |
542 kCGBitmapByteOrder32Host));
543 CGContextTranslateCTM(windowless_context_, 0, delegate_->GetRect().height());
544 CGContextScaleCTM(windowless_context_, 1, -1);
545 if (background_dib_.get()) {
546 background_context_.reset(CGBitmapContextCreate(
547 background_dib_->memory(),
548 delegate_->GetRect().width(),
549 delegate_->GetRect().height(),
550 8, 4 * delegate_->GetRect().width(),
551 rgb_colorspace,
552 kCGImageAlphaPremultipliedFirst |
553 kCGBitmapByteOrder32Host));
554 CGContextTranslateCTM(background_context_, 0,
555 delegate_->GetRect().height());
556 CGContextScaleCTM(background_context_, 1, -1);
557 }
558 }
559 #elif defined (OS_LINUX)
560 void WebPluginProxy::UpdateTransform() {
561 NOTIMPLEMENTED();
562 }
563
564 void WebPluginProxy::SetWindowlessBuffer(
565 const TransportDIB::Handle& windowless_buffer,
566 const TransportDIB::Handle& background_buffer) {
567 NOTIMPLEMENTED();
568 }
504 #endif 569 #endif
505 570
506 void WebPluginProxy::CancelDocumentLoad() { 571 void WebPluginProxy::CancelDocumentLoad() {
507 Send(new PluginHostMsg_CancelDocumentLoad(route_id_)); 572 Send(new PluginHostMsg_CancelDocumentLoad(route_id_));
508 } 573 }
509 574
510 void WebPluginProxy::InitiateHTTPRangeRequest(const char* url, 575 void WebPluginProxy::InitiateHTTPRangeRequest(const char* url,
511 const char* range_info, 576 const char* range_info,
512 intptr_t existing_stream, 577 intptr_t existing_stream,
513 bool notify_needed, 578 bool notify_needed,
(...skipping 21 matching lines...) Expand all
535 while (index != resource_clients_.end()) { 600 while (index != resource_clients_.end()) {
536 WebPluginResourceClient* client = (*index).second; 601 WebPluginResourceClient* client = (*index).second;
537 602
538 if (client == resource_client) { 603 if (client == resource_client) {
539 resource_clients_.erase(index++); 604 resource_clients_.erase(index++);
540 } else { 605 } else {
541 index++; 606 index++;
542 } 607 }
543 } 608 }
544 } 609 }
OLDNEW
« no previous file with comments | « chrome/plugin/webplugin_proxy.h ('k') | chrome/renderer/render_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698