| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "skia/ext/bitmap_platform_device_cairo.h" | 5 #include "skia/ext/bitmap_platform_device_cairo.h" |
| 6 #include "skia/ext/platform_canvas.h" | 6 #include "skia/ext/platform_canvas.h" |
| 7 | 7 |
| 8 #if defined(OS_OPENBSD) | 8 #if defined(OS_OPENBSD) |
| 9 #include <cairo.h> | 9 #include <cairo.h> |
| 10 #else | 10 #else |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 | 193 |
| 194 // PlatformCanvas impl | 194 // PlatformCanvas impl |
| 195 | 195 |
| 196 SkCanvas* CreatePlatformCanvas(int width, int height, bool is_opaque, | 196 SkCanvas* CreatePlatformCanvas(int width, int height, bool is_opaque, |
| 197 uint8_t* data, OnFailureType failureType) { | 197 uint8_t* data, OnFailureType failureType) { |
| 198 skia::RefPtr<SkBaseDevice> dev = skia::AdoptRef( | 198 skia::RefPtr<SkBaseDevice> dev = skia::AdoptRef( |
| 199 BitmapPlatformDevice::Create(width, height, is_opaque, data)); | 199 BitmapPlatformDevice::Create(width, height, is_opaque, data)); |
| 200 return CreateCanvas(dev, failureType); | 200 return CreateCanvas(dev, failureType); |
| 201 } | 201 } |
| 202 | 202 |
| 203 // Port of PlatformBitmap to linux | |
| 204 PlatformBitmap::~PlatformBitmap() { | |
| 205 cairo_destroy(surface_); | |
| 206 } | |
| 207 | |
| 208 bool PlatformBitmap::Allocate(int width, int height, bool is_opaque) { | |
| 209 // The SkBitmap allocates and owns the bitmap memory; PlatformBitmap owns the | |
| 210 // cairo drawing context tied to the bitmap. The SkBitmap's pixelRef can | |
| 211 // outlive the PlatformBitmap if additional copies are made. | |
| 212 int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width); | |
| 213 | |
| 214 cairo_surface_t* surf = cairo_image_surface_create( | |
| 215 CAIRO_FORMAT_ARGB32, | |
| 216 width, | |
| 217 height); | |
| 218 if (cairo_surface_status(surf) != CAIRO_STATUS_SUCCESS) { | |
| 219 cairo_surface_destroy(surf); | |
| 220 return false; | |
| 221 } | |
| 222 return InstallCairoSurfacePixels(&bitmap_, surf, is_opaque); | |
| 223 } | |
| 224 | |
| 225 } // namespace skia | 203 } // namespace skia |
| OLD | NEW |