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
3 // found in the LICENSE file.
5 #include "skia/ext/platform_canvas.h"
7 #include "skia/ext/bitmap_platform_device.h"
8 #include "third_party/skia/include/core/SkTypes.h"
12 SkBaseDevice
* GetTopDevice(const SkCanvas
& canvas
) {
13 return canvas
.getTopDevice(true);
16 bool SupportsPlatformPaint(const SkCanvas
* canvas
) {
17 PlatformDevice
* platform_device
= GetPlatformDevice(GetTopDevice(*canvas
));
18 return platform_device
&& platform_device
->SupportsPlatformPaint();
21 PlatformSurface
BeginPlatformPaint(SkCanvas
* canvas
) {
22 PlatformDevice
* platform_device
= GetPlatformDevice(GetTopDevice(*canvas
));
24 return platform_device
->BeginPlatformPaint();
29 void EndPlatformPaint(SkCanvas
* canvas
) {
30 PlatformDevice
* platform_device
= GetPlatformDevice(GetTopDevice(*canvas
));
32 platform_device
->EndPlatformPaint();
35 void MakeOpaque(SkCanvas
* canvas
, int x
, int y
, int width
, int height
) {
36 if (width
<= 0 || height
<= 0)
40 rect
.setXYWH(SkIntToScalar(x
), SkIntToScalar(y
),
41 SkIntToScalar(width
), SkIntToScalar(height
));
43 paint
.setColor(SK_ColorBLACK
);
44 paint
.setXfermodeMode(SkXfermode::kDstATop_Mode
);
45 canvas
->drawRect(rect
, paint
);
48 size_t PlatformCanvasStrideForWidth(unsigned width
) {
52 SkCanvas
* CreateCanvas(const skia::RefPtr
<SkBaseDevice
>& device
, OnFailureType failureType
) {
54 if (CRASH_ON_FAILURE
== failureType
)
58 return new SkCanvas(device
.get());
61 PlatformBitmap::PlatformBitmap() : surface_(0), platform_extra_(0) {}