| 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "skia/ext/platform_device.h" | 10 #include "skia/ext/platform_device.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 } | 55 } |
| 56 | 56 |
| 57 result->reset(info, pixels, row_bytes); | 57 result->reset(info, pixels, row_bytes); |
| 58 return true; | 58 return true; |
| 59 } | 59 } |
| 60 | 60 |
| 61 size_t PlatformCanvasStrideForWidth(unsigned width) { | 61 size_t PlatformCanvasStrideForWidth(unsigned width) { |
| 62 return 4 * width; | 62 return 4 * width; |
| 63 } | 63 } |
| 64 | 64 |
| 65 std::unique_ptr<SkCanvas> CreateCanvas(const sk_sp<SkBaseDevice>& device, | |
| 66 OnFailureType failureType) { | |
| 67 if (!device) { | |
| 68 if (CRASH_ON_FAILURE == failureType) | |
| 69 SK_CRASH(); | |
| 70 return nullptr; | |
| 71 } | |
| 72 return base::MakeUnique<SkCanvas>(device.get()); | |
| 73 } | |
| 74 | |
| 75 SkMetaData& GetMetaData(const SkCanvas& canvas) { | 65 SkMetaData& GetMetaData(const SkCanvas& canvas) { |
| 76 return const_cast<SkCanvas&>(canvas).getMetaData(); | 66 return const_cast<SkCanvas&>(canvas).getMetaData(); |
| 77 } | 67 } |
| 78 | 68 |
| 79 #if defined(OS_MACOSX) | 69 #if defined(OS_MACOSX) |
| 80 void SetIsPreviewMetafile(const SkCanvas& canvas, bool is_preview) { | 70 void SetIsPreviewMetafile(const SkCanvas& canvas, bool is_preview) { |
| 81 SetBoolMetaData(canvas, kIsPreviewMetafileKey, is_preview); | 71 SetBoolMetaData(canvas, kIsPreviewMetafileKey, is_preview); |
| 82 } | 72 } |
| 83 | 73 |
| 84 bool IsPreviewMetafile(const SkCanvas& canvas) { | 74 bool IsPreviewMetafile(const SkCanvas& canvas) { |
| 85 return GetBoolMetaData(canvas, kIsPreviewMetafileKey); | 75 return GetBoolMetaData(canvas, kIsPreviewMetafileKey); |
| 86 } | 76 } |
| 87 #endif | 77 #endif |
| 88 | 78 |
| 79 #if !defined(WIN32) |
| 80 |
| 81 std::unique_ptr<SkCanvas> CreatePlatformCanvasWithPixels( |
| 82 int width, |
| 83 int height, |
| 84 bool is_opaque, |
| 85 uint8_t* data, |
| 86 OnFailureType failureType) { |
| 87 |
| 88 SkBitmap bitmap; |
| 89 bitmap.setInfo(SkImageInfo::MakeN32(width, height, |
| 90 is_opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType)); |
| 91 |
| 92 if (data) { |
| 93 bitmap.setPixels(data); |
| 94 } else { |
| 95 if (!bitmap.tryAllocPixels()) { |
| 96 if (CRASH_ON_FAILURE == failureType) |
| 97 SK_CRASH(); |
| 98 return nullptr; |
| 99 } |
| 100 |
| 101 // Follow the logic in SkCanvas::createDevice(), initialize the bitmap if |
| 102 // it is not opaque. |
| 103 if (!is_opaque) |
| 104 bitmap.eraseARGB(0, 0, 0, 0); |
| 105 } |
| 106 |
| 107 return base::MakeUnique<SkCanvas>(bitmap); |
| 108 } |
| 109 |
| 110 #endif |
| 111 |
| 89 } // namespace skia | 112 } // namespace skia |
| OLD | NEW |