[email protected] | 97612707 | 2012-05-10 20:08:11 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 277a111 | 2011-03-19 06:03:56 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | e2adfc4 | 2013-08-08 23:35:17 | [diff] [blame] | 5 | #include "content/renderer/sad_plugin.h" |
[email protected] | 277a111 | 2011-03-19 06:03:56 | [diff] [blame] | 6 | |
[email protected] | c74f990 | 2011-06-14 15:57:30 | [diff] [blame] | 7 | #include <algorithm> |
| 8 | |
| 9 | #include "base/memory/scoped_ptr.h" |
| 10 | #include "skia/ext/platform_canvas.h" |
[email protected] | 277a111 | 2011-03-19 06:03:56 | [diff] [blame] | 11 | #include "ui/gfx/blit.h" |
[email protected] | 277a111 | 2011-03-19 06:03:56 | [diff] [blame] | 12 | #include "ui/gfx/rect.h" |
| 13 | |
[email protected] | e2adfc4 | 2013-08-08 23:35:17 | [diff] [blame] | 14 | namespace content { |
[email protected] | 277a111 | 2011-03-19 06:03:56 | [diff] [blame] | 15 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 16 | void PaintSadPlugin(blink::WebCanvas* webcanvas, |
[email protected] | 277a111 | 2011-03-19 06:03:56 | [diff] [blame] | 17 | const gfx::Rect& plugin_rect, |
| 18 | const SkBitmap& sad_plugin_bitmap) { |
[email protected] | 277a111 | 2011-03-19 06:03:56 | [diff] [blame] | 19 | const int width = plugin_rect.width(); |
| 20 | const int height = plugin_rect.height(); |
[email protected] | 277a111 | 2011-03-19 06:03:56 | [diff] [blame] | 21 | |
[email protected] | c74f990 | 2011-06-14 15:57:30 | [diff] [blame] | 22 | SkCanvas* canvas = webcanvas; |
[email protected] | 56e9c78 | 2011-07-22 15:08:02 | [diff] [blame] | 23 | SkAutoCanvasRestore auto_restore(canvas, true); |
| 24 | // We draw the sad-plugin bitmap at the origin of canvas. |
| 25 | // Add a translation so that it appears at the origin of plugin rect. |
| 26 | canvas->translate(plugin_rect.x(), plugin_rect.y()); |
[email protected] | c74f990 | 2011-06-14 15:57:30 | [diff] [blame] | 27 | |
| 28 | SkPaint paint; |
[email protected] | 277a111 | 2011-03-19 06:03:56 | [diff] [blame] | 29 | paint.setStyle(SkPaint::kFill_Style); |
| 30 | paint.setColor(SK_ColorBLACK); |
[email protected] | c74f990 | 2011-06-14 15:57:30 | [diff] [blame] | 31 | canvas->drawRectCoords(0, 0, SkIntToScalar(width), SkIntToScalar(height), |
| 32 | paint); |
| 33 | canvas->drawBitmap( |
| 34 | sad_plugin_bitmap, |
| 35 | SkIntToScalar(std::max(0, (width - sad_plugin_bitmap.width()) / 2)), |
| 36 | SkIntToScalar(std::max(0, (height - sad_plugin_bitmap.height()) / 2))); |
[email protected] | 277a111 | 2011-03-19 06:03:56 | [diff] [blame] | 37 | } |
| 38 | |
[email protected] | e2adfc4 | 2013-08-08 23:35:17 | [diff] [blame] | 39 | } // namespace content |