| 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 "skia/ext/platform_canvas.h" | 5 #include "skia/ext/platform_canvas.h" |
| 6 | 6 |
| 7 #include "skia/ext/bitmap_platform_device.h" | 7 #include "skia/ext/bitmap_platform_device.h" |
| 8 #include "third_party/skia/include/core/SkTypes.h" | 8 #include "third_party/skia/include/core/SkTypes.h" |
| 9 | 9 |
| 10 namespace skia { | 10 namespace skia { |
| 11 | 11 |
| 12 PlatformCanvas::PlatformCanvas() {} | |
| 13 | |
| 14 // static | |
| 15 size_t PlatformCanvas::StrideForWidth(unsigned width) { | |
| 16 return 4 * width; | |
| 17 } | |
| 18 | |
| 19 bool PlatformCanvas::initializeWithDevice(SkDevice* device) { | |
| 20 if (!device) | |
| 21 return false; | |
| 22 | |
| 23 setDevice(device); | |
| 24 device->unref(); // Was created with refcount 1, and setDevice also refs. | |
| 25 return true; | |
| 26 } | |
| 27 | |
| 28 SkCanvas* CreateBitmapCanvas(int width, int height, bool is_opaque) { | |
| 29 return new PlatformCanvas(width, height, is_opaque); | |
| 30 } | |
| 31 | |
| 32 SkCanvas* TryCreateBitmapCanvas(int width, int height, bool is_opaque) { | |
| 33 PlatformCanvas* canvas = new PlatformCanvas(); | |
| 34 if (!canvas->initialize(width, height, is_opaque)) { | |
| 35 delete canvas; | |
| 36 canvas = NULL; | |
| 37 } | |
| 38 return canvas; | |
| 39 } | |
| 40 | |
| 41 SkDevice* GetTopDevice(const SkCanvas& canvas) { | 12 SkDevice* GetTopDevice(const SkCanvas& canvas) { |
| 42 return canvas.getTopDevice(true); | 13 return canvas.getTopDevice(true); |
| 43 } | 14 } |
| 44 | 15 |
| 45 bool SupportsPlatformPaint(const SkCanvas* canvas) { | 16 bool SupportsPlatformPaint(const SkCanvas* canvas) { |
| 46 PlatformDevice* platform_device = GetPlatformDevice(GetTopDevice(*canvas)); | 17 PlatformDevice* platform_device = GetPlatformDevice(GetTopDevice(*canvas)); |
| 47 return platform_device && platform_device->SupportsPlatformPaint(); | 18 return platform_device && platform_device->SupportsPlatformPaint(); |
| 48 } | 19 } |
| 49 | 20 |
| 50 PlatformSurface BeginPlatformPaint(SkCanvas* canvas) { | 21 PlatformSurface BeginPlatformPaint(SkCanvas* canvas) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 80 rect.setXYWH(SkIntToScalar(x), SkIntToScalar(y), | 51 rect.setXYWH(SkIntToScalar(x), SkIntToScalar(y), |
| 81 SkIntToScalar(width), SkIntToScalar(height)); | 52 SkIntToScalar(width), SkIntToScalar(height)); |
| 82 SkPaint paint; | 53 SkPaint paint; |
| 83 // so we don't draw anything on a device that ignores xfermodes | 54 // so we don't draw anything on a device that ignores xfermodes |
| 84 paint.setColor(0); | 55 paint.setColor(0); |
| 85 // install our custom mode | 56 // install our custom mode |
| 86 paint.setXfermode(new SkProcXfermode(MakeOpaqueXfermodeProc))->unref(); | 57 paint.setXfermode(new SkProcXfermode(MakeOpaqueXfermodeProc))->unref(); |
| 87 canvas->drawRect(rect, paint); | 58 canvas->drawRect(rect, paint); |
| 88 } | 59 } |
| 89 | 60 |
| 61 size_t PlatformCanvasStrideForWidth(unsigned width) { |
| 62 return 4 * width; |
| 63 } |
| 64 |
| 65 SkCanvas* CreateCanvas(SkDevice* device, OnFailureType failureType) { |
| 66 if (!device) { |
| 67 if (CRASH_ON_FAILURE == failureType) |
| 68 SK_CRASH(); |
| 69 return NULL; |
| 70 } |
| 71 SkAutoUnref aur(device); |
| 72 return new SkCanvas(device); |
| 73 } |
| 74 |
| 90 PlatformBitmap::PlatformBitmap() : surface_(0), platform_extra_(0) {} | 75 PlatformBitmap::PlatformBitmap() : surface_(0), platform_extra_(0) {} |
| 91 | 76 |
| 92 } // namespace skia | 77 } // namespace skia |
| OLD | NEW |