OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #include "app/gfx/canvas.h" | 9 #include "app/gfx/canvas.h" |
10 #if defined(OS_WIN) | 10 #if defined(OS_WIN) |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 return; | 369 return; |
370 #endif | 370 #endif |
371 | 371 |
372 // Clear the damaged area so that if the plugin doesn't paint there we won't | 372 // Clear the damaged area so that if the plugin doesn't paint there we won't |
373 // end up with the old values. | 373 // end up with the old values. |
374 gfx::Rect offset_rect = rect; | 374 gfx::Rect offset_rect = rect; |
375 offset_rect.Offset(delegate_->GetRect().origin()); | 375 offset_rect.Offset(delegate_->GetRect().origin()); |
376 #if defined(OS_WIN) || defined(OS_LINUX) | 376 #if defined(OS_WIN) || defined(OS_LINUX) |
377 windowless_canvas_->save(); | 377 windowless_canvas_->save(); |
378 | 378 |
379 // The given clip rect is in global coordinates, so install it before the | 379 // The given clip rect is relative to the plugin coordinate system. |
380 // transformation is done for the coordinate system. | |
381 SkRect sk_rect = { SkIntToScalar(rect.x()), | 380 SkRect sk_rect = { SkIntToScalar(rect.x()), |
382 SkIntToScalar(rect.y()), | 381 SkIntToScalar(rect.y()), |
383 SkIntToScalar(rect.right()), | 382 SkIntToScalar(rect.right()), |
384 SkIntToScalar(rect.bottom()) }; | 383 SkIntToScalar(rect.bottom()) }; |
385 windowless_canvas_->clipRect(sk_rect); | 384 windowless_canvas_->clipRect(sk_rect); |
386 windowless_canvas_->translate(SkIntToScalar(-delegate_->GetRect().x()), | |
387 SkIntToScalar(-delegate_->GetRect().y())); | |
388 | 385 |
389 // Setup the background. | 386 // Setup the background. |
390 if (!background_canvas_.get()) { | 387 if (background_canvas_.get()) { |
| 388 // When a background canvas is given, we're in transparent mode. This means |
| 389 // the plugin wants to have the image of the page in the canvas it's drawing |
| 390 // into (which is windowless_canvas_) so it can do blending. So we copy the |
| 391 // background bitmap into the windowless_canvas_. |
| 392 const SkBitmap& background_bitmap = |
| 393 background_canvas_->getTopPlatformDevice().accessBitmap(false); |
| 394 windowless_canvas_->drawBitmap(background_bitmap, 0, 0); |
| 395 } else { |
| 396 // In non-transparent mode, the plugin doesn't care what's underneath, so we |
| 397 // can just give it black. |
391 SkPaint black_fill_paint; | 398 SkPaint black_fill_paint; |
392 black_fill_paint.setARGB(0xFF, 0x00, 0x00, 0x00); | 399 black_fill_paint.setARGB(0xFF, 0x00, 0x00, 0x00); |
393 windowless_canvas_->drawPaint(black_fill_paint); | 400 windowless_canvas_->drawPaint(black_fill_paint); |
394 } else { | 401 } |
395 SkIRect src_rect = { rect.x(), rect.y(), | |
396 rect.x() + offset_rect.width(), | |
397 rect.y() + offset_rect.height() }; | |
398 | 402 |
399 SkRect dest_rect = { SkIntToScalar(offset_rect.x()), | 403 // Bring the windowless_canvas_ into the window coordinate system, which is |
400 SkIntToScalar(offset_rect.y()), | 404 // how the plugin expects to draw (since the windowless API was originally |
401 SkIntToScalar(offset_rect.right()), | 405 // designed just for scribbling over the web page). |
402 SkIntToScalar(offset_rect.bottom()) }; | 406 windowless_canvas_->translate(SkIntToScalar(-delegate_->GetRect().x()), |
403 const SkBitmap& background_bitmap = | 407 SkIntToScalar(-delegate_->GetRect().y())); |
404 background_canvas_->getTopPlatformDevice().accessBitmap(false); | |
405 windowless_canvas_->drawBitmapRect(background_bitmap, &src_rect, dest_rect); | |
406 } | |
407 | 408 |
408 // Before we send the invalidate, paint so that renderer uses the updated | 409 // Before we send the invalidate, paint so that renderer uses the updated |
409 // bitmap. | 410 // bitmap. |
410 delegate_->Paint(windowless_canvas_.get(), offset_rect); | 411 delegate_->Paint(windowless_canvas_.get(), offset_rect); |
411 | 412 |
412 windowless_canvas_->restore(); | 413 windowless_canvas_->restore(); |
413 #elif defined(OS_MACOSX) | 414 #elif defined(OS_MACOSX) |
414 CGContextSaveGState(windowless_context_); | 415 CGContextSaveGState(windowless_context_); |
415 if (!background_context_.get()) { | 416 if (!background_context_.get()) { |
416 CGContextSetFillColorWithColor(windowless_context_, | 417 CGContextSetFillColorWithColor(windowless_context_, |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 while (index != resource_clients_.end()) { | 584 while (index != resource_clients_.end()) { |
584 WebPluginResourceClient* client = (*index).second; | 585 WebPluginResourceClient* client = (*index).second; |
585 | 586 |
586 if (client == resource_client) { | 587 if (client == resource_client) { |
587 resource_clients_.erase(index++); | 588 resource_clients_.erase(index++); |
588 } else { | 589 } else { |
589 index++; | 590 index++; |
590 } | 591 } |
591 } | 592 } |
592 } | 593 } |
OLD | NEW |