| 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 "third_party/skia/include/core/SkPaint.h" | 7 #include "third_party/skia/include/core/SkPaint.h" |
| 8 #include "third_party/skia/include/core/SkScalar.h" | 8 #include "third_party/skia/include/core/SkScalar.h" |
| 9 #include "ui/gfx/blit.h" | 9 #include "ui/gfx/blit.h" |
| 10 #include "ui/gfx/canvas_skia.h" | 10 #include "ui/gfx/canvas_skia.h" |
| 11 #include "ui/gfx/rect.h" | 11 #include "ui/gfx/rect.h" |
| 12 | 12 |
| 13 namespace webkit { | 13 namespace webkit { |
| 14 | 14 |
| 15 void PaintSadPlugin(WebKit::WebCanvas* webcanvas, | 15 void PaintSadPlugin(WebKit::WebCanvas* webcanvas, |
| 16 const gfx::Rect& plugin_rect, | 16 const gfx::Rect& plugin_rect, |
| 17 const SkBitmap& sad_plugin_bitmap) { | 17 const SkBitmap& sad_plugin_bitmap) { |
| 18 // Make a temporary canvas for the background image. | 18 // Make a temporary canvas for the background image. |
| 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 gfx::CanvasSkia canvas(width, height, false); | 21 gfx::CanvasSkia canvas; |
| 22 if (!canvas.Init(width, height, false)) |
| 23 return; |
| 24 |
| 22 #if defined(OS_MACOSX) | 25 #if defined(OS_MACOSX) |
| 23 // Flip the canvas, since the context expects flipped data. | 26 // Flip the canvas, since the context expects flipped data. |
| 24 canvas.translate(0, height); | 27 canvas.skia_canvas()->translate(0, height); |
| 25 canvas.scale(1, -1); | 28 canvas.skia_canvas()->scale(1, -1); |
| 26 #endif | 29 #endif |
| 27 SkPaint paint; | 30 SkPaint paint; |
| 28 | 31 |
| 29 paint.setStyle(SkPaint::kFill_Style); | 32 paint.setStyle(SkPaint::kFill_Style); |
| 30 paint.setColor(SK_ColorBLACK); | 33 paint.setColor(SK_ColorBLACK); |
| 31 canvas.drawRectCoords(0, 0, SkIntToScalar(width), SkIntToScalar(height), | 34 canvas.skia_canvas()->drawRectCoords( |
| 32 paint); | 35 0, 0, SkIntToScalar(width), SkIntToScalar(height), paint); |
| 33 canvas.DrawBitmapInt(sad_plugin_bitmap, | 36 canvas.DrawBitmapInt(sad_plugin_bitmap, |
| 34 std::max(0, (width - sad_plugin_bitmap.width()) / 2), | 37 std::max(0, (width - sad_plugin_bitmap.width()) / 2), |
| 35 std::max(0, (height - sad_plugin_bitmap.height()) / 2)); | 38 std::max(0, (height - sad_plugin_bitmap.height()) / 2)); |
| 36 | 39 |
| 37 // It's slightly less code to make a big SkBitmap of the sad tab image and | 40 // It's slightly less code to make a big SkBitmap of the sad tab image and |
| 38 // then copy that to the screen than to use the native APIs. The small speed | 41 // then copy that to the screen than to use the native APIs. The small speed |
| 39 // penalty is not important when drawing crashed plugins. | 42 // penalty is not important when drawing crashed plugins. |
| 40 #if WEBKIT_USING_SKIA | 43 #if WEBKIT_USING_SKIA |
| 41 gfx::NativeDrawingContext context = skia::BeginPlatformPaint(webcanvas); | 44 canvas.BlitToNativeContext(gfx::Rect(plugin_rect.size()), |
| 42 BlitCanvasToContext(context, plugin_rect, &canvas, gfx::Point(0, 0)); | 45 plugin_rect.origin(), skia::BeginPlatformPaint(webcanvas)); |
| 43 skia::EndPlatformPaint(webcanvas); | 46 skia::EndPlatformPaint(webcanvas); |
| 44 #elif WEBKIT_USING_CG | 47 #elif WEBKIT_USING_CG |
| 45 BlitCanvasToContext(webcanvas, plugin_rect, &canvas, gfx::Point(0, 0)); | 48 canvas.BlitToNativeContext(gfx::Rect(plugin_rect.size()), |
| 49 plugin_rect.origin(), webcanvas); |
| 46 #endif | 50 #endif |
| 47 } | 51 } |
| 48 | 52 |
| 49 } // namespace webkit | 53 } // namespace webkit |
| OLD | NEW |