| OLD | NEW |
| 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/sad_plugin.h" | 5 #include "webkit/plugins/sad_plugin.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "skia/ext/platform_canvas.h" | 10 #include "skia/ext/platform_canvas.h" |
| 11 #include "ui/gfx/blit.h" | 11 #include "ui/gfx/blit.h" |
| 12 #include "ui/gfx/rect.h" | 12 #include "ui/gfx/rect.h" |
| 13 | 13 |
| 14 namespace webkit { | 14 namespace webkit { |
| 15 | 15 |
| 16 void PaintSadPlugin(WebKit::WebCanvas* webcanvas, | 16 void PaintSadPlugin(WebKit::WebCanvas* webcanvas, |
| 17 const gfx::Rect& plugin_rect, | 17 const gfx::Rect& plugin_rect, |
| 18 const SkBitmap& sad_plugin_bitmap) { | 18 const SkBitmap& sad_plugin_bitmap) { |
| 19 const int width = plugin_rect.width(); | 19 const int width = plugin_rect.width(); |
| 20 const int height = plugin_rect.height(); | 20 const int height = plugin_rect.height(); |
| 21 | 21 |
| 22 #if WEBKIT_USING_SKIA | |
| 23 SkCanvas* canvas = webcanvas; | 22 SkCanvas* canvas = webcanvas; |
| 24 SkAutoCanvasRestore auto_restore(canvas, true); | 23 SkAutoCanvasRestore auto_restore(canvas, true); |
| 25 // We draw the sad-plugin bitmap at the origin of canvas. | 24 // We draw the sad-plugin bitmap at the origin of canvas. |
| 26 // Add a translation so that it appears at the origin of plugin rect. | 25 // Add a translation so that it appears at the origin of plugin rect. |
| 27 canvas->translate(plugin_rect.x(), plugin_rect.y()); | 26 canvas->translate(plugin_rect.x(), plugin_rect.y()); |
| 28 #elif WEBKIT_USING_CG | |
| 29 // Make a temporary canvas for the background image. | |
| 30 scoped_ptr<SkCanvas> canvas(skia::CreateBitmapCanvas(width, height, false)); | |
| 31 // Flip the canvas, since the context expects flipped data. | |
| 32 canvas->translate(0, height); | |
| 33 canvas->scale(1, -1); | |
| 34 #endif | |
| 35 | 27 |
| 36 SkPaint paint; | 28 SkPaint paint; |
| 37 paint.setStyle(SkPaint::kFill_Style); | 29 paint.setStyle(SkPaint::kFill_Style); |
| 38 paint.setColor(SK_ColorBLACK); | 30 paint.setColor(SK_ColorBLACK); |
| 39 canvas->drawRectCoords(0, 0, SkIntToScalar(width), SkIntToScalar(height), | 31 canvas->drawRectCoords(0, 0, SkIntToScalar(width), SkIntToScalar(height), |
| 40 paint); | 32 paint); |
| 41 canvas->drawBitmap( | 33 canvas->drawBitmap( |
| 42 sad_plugin_bitmap, | 34 sad_plugin_bitmap, |
| 43 SkIntToScalar(std::max(0, (width - sad_plugin_bitmap.width()) / 2)), | 35 SkIntToScalar(std::max(0, (width - sad_plugin_bitmap.width()) / 2)), |
| 44 SkIntToScalar(std::max(0, (height - sad_plugin_bitmap.height()) / 2))); | 36 SkIntToScalar(std::max(0, (height - sad_plugin_bitmap.height()) / 2))); |
| 45 | |
| 46 // It's slightly less code to make a big SkBitmap of the sad tab image and | |
| 47 // then copy that to the screen than to use the native APIs. The small speed | |
| 48 // penalty is not important when drawing crashed plugins. | |
| 49 #if WEBKIT_USING_CG | |
| 50 BlitCanvasToContext(webcanvas, plugin_rect, canvas.get(), gfx::Point(0, 0)); | |
| 51 #endif | |
| 52 } | 37 } |
| 53 | 38 |
| 54 } // namespace webkit | 39 } // namespace webkit |
| OLD | NEW |