blob: 52d613d5d4f21859baa6dc47c06f18a20d712fa0 [file] [log] [blame]
[email protected]976127072012-05-10 20:08:111// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]277a1112011-03-19 06:03:562// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]e2adfc42013-08-08 23:35:175#include "content/renderer/sad_plugin.h"
[email protected]277a1112011-03-19 06:03:566
[email protected]c74f9902011-06-14 15:57:307#include <algorithm>
8
9#include "base/memory/scoped_ptr.h"
10#include "skia/ext/platform_canvas.h"
[email protected]277a1112011-03-19 06:03:5611#include "ui/gfx/blit.h"
[email protected]277a1112011-03-19 06:03:5612#include "ui/gfx/rect.h"
13
[email protected]e2adfc42013-08-08 23:35:1714namespace content {
[email protected]277a1112011-03-19 06:03:5615
[email protected]180ef242013-11-07 06:50:4616void PaintSadPlugin(blink::WebCanvas* webcanvas,
[email protected]277a1112011-03-19 06:03:5617 const gfx::Rect& plugin_rect,
18 const SkBitmap& sad_plugin_bitmap) {
[email protected]277a1112011-03-19 06:03:5619 const int width = plugin_rect.width();
20 const int height = plugin_rect.height();
[email protected]277a1112011-03-19 06:03:5621
[email protected]c74f9902011-06-14 15:57:3022 SkCanvas* canvas = webcanvas;
[email protected]56e9c782011-07-22 15:08:0223 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]c74f9902011-06-14 15:57:3027
28 SkPaint paint;
[email protected]277a1112011-03-19 06:03:5629 paint.setStyle(SkPaint::kFill_Style);
30 paint.setColor(SK_ColorBLACK);
[email protected]c74f9902011-06-14 15:57:3031 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]277a1112011-03-19 06:03:5637}
38
[email protected]e2adfc42013-08-08 23:35:1739} // namespace content