| 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 "third_party/skia/include/core/SkMetaData.h" | 10 #include "third_party/skia/include/core/SkMetaData.h" |
| 11 #include "third_party/skia/include/core/SkTypes.h" | 11 #include "third_party/skia/include/core/SkTypes.h" |
| 12 | 12 |
| 13 namespace { | |
| 14 | |
| 15 #if defined(OS_MACOSX) | |
| 16 const char kIsPreviewMetafileKey[] = "CrIsPreviewMetafile"; | |
| 17 | |
| 18 void SetBoolMetaData(const SkCanvas& canvas, const char* key, bool value) { | |
| 19 SkMetaData& meta = skia::GetMetaData(canvas); | |
| 20 meta.setBool(key, value); | |
| 21 } | |
| 22 | |
| 23 bool GetBoolMetaData(const SkCanvas& canvas, const char* key) { | |
| 24 bool value; | |
| 25 SkMetaData& meta = skia::GetMetaData(canvas); | |
| 26 if (!meta.findBool(key, &value)) | |
| 27 value = false; | |
| 28 return value; | |
| 29 } | |
| 30 #endif | |
| 31 | |
| 32 } // namespace | |
| 33 | |
| 34 namespace skia { | 13 namespace skia { |
| 35 | 14 |
| 36 SkBitmap ReadPixels(SkCanvas* canvas) { | 15 SkBitmap ReadPixels(SkCanvas* canvas) { |
| 37 SkBitmap bitmap; | 16 SkBitmap bitmap; |
| 38 bitmap.setInfo(canvas->imageInfo()); | 17 bitmap.setInfo(canvas->imageInfo()); |
| 39 canvas->readPixels(&bitmap, 0, 0); | 18 canvas->readPixels(&bitmap, 0, 0); |
| 40 return bitmap; | 19 return bitmap; |
| 41 } | 20 } |
| 42 | 21 |
| 43 bool GetWritablePixels(SkCanvas* canvas, SkPixmap* result) { | 22 bool GetWritablePixels(SkCanvas* canvas, SkPixmap* result) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 54 } | 33 } |
| 55 | 34 |
| 56 result->reset(info, pixels, row_bytes); | 35 result->reset(info, pixels, row_bytes); |
| 57 return true; | 36 return true; |
| 58 } | 37 } |
| 59 | 38 |
| 60 size_t PlatformCanvasStrideForWidth(unsigned width) { | 39 size_t PlatformCanvasStrideForWidth(unsigned width) { |
| 61 return 4 * width; | 40 return 4 * width; |
| 62 } | 41 } |
| 63 | 42 |
| 64 SkMetaData& GetMetaData(const SkCanvas& canvas) { | |
| 65 return const_cast<SkCanvas&>(canvas).getMetaData(); | |
| 66 } | |
| 67 | |
| 68 #if defined(OS_MACOSX) | |
| 69 void SetIsPreviewMetafile(const SkCanvas& canvas, bool is_preview) { | |
| 70 SetBoolMetaData(canvas, kIsPreviewMetafileKey, is_preview); | |
| 71 } | |
| 72 | |
| 73 bool IsPreviewMetafile(const SkCanvas& canvas) { | |
| 74 return GetBoolMetaData(canvas, kIsPreviewMetafileKey); | |
| 75 } | |
| 76 #endif | |
| 77 | |
| 78 #if !defined(WIN32) | 43 #if !defined(WIN32) |
| 79 | 44 |
| 80 std::unique_ptr<SkCanvas> CreatePlatformCanvasWithPixels( | 45 std::unique_ptr<SkCanvas> CreatePlatformCanvasWithPixels( |
| 81 int width, | 46 int width, |
| 82 int height, | 47 int height, |
| 83 bool is_opaque, | 48 bool is_opaque, |
| 84 uint8_t* data, | 49 uint8_t* data, |
| 85 OnFailureType failureType) { | 50 OnFailureType failureType) { |
| 86 | 51 |
| 87 SkBitmap bitmap; | 52 SkBitmap bitmap; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 102 if (!is_opaque) | 67 if (!is_opaque) |
| 103 bitmap.eraseARGB(0, 0, 0, 0); | 68 bitmap.eraseARGB(0, 0, 0, 0); |
| 104 } | 69 } |
| 105 | 70 |
| 106 return base::MakeUnique<SkCanvas>(bitmap); | 71 return base::MakeUnique<SkCanvas>(bitmap); |
| 107 } | 72 } |
| 108 | 73 |
| 109 #endif | 74 #endif |
| 110 | 75 |
| 111 } // namespace skia | 76 } // namespace skia |
| OLD | NEW |