| OLD | NEW |
| 1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2017 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 <windows.h> | 5 #include <windows.h> |
| 6 #include <psapi.h> | 6 #include <psapi.h> |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/debug/gdi_debug_util_win.h" | 9 #include "base/debug/gdi_debug_util_win.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 skia::LoadTransformToDC(hdc, ctm); | 101 skia::LoadTransformToDC(hdc, ctm); |
| 102 | 102 |
| 103 HRGN hrgn = CreateRectRgnIndirect(&skia::SkIRectToRECT(clip_bounds)); | 103 HRGN hrgn = CreateRectRgnIndirect(&skia::SkIRectToRECT(clip_bounds)); |
| 104 int result = SelectClipRgn(hdc, hrgn); | 104 int result = SelectClipRgn(hdc, hrgn); |
| 105 DCHECK(result != ERROR); | 105 DCHECK(result != ERROR); |
| 106 result = DeleteObject(hrgn); | 106 result = DeleteObject(hrgn); |
| 107 DCHECK(result != 0); | 107 DCHECK(result != 0); |
| 108 } | 108 } |
| 109 }; | 109 }; |
| 110 | 110 |
| 111 void unmap_view_proc(void* pixels, void*) { |
| 112 UnmapViewOfFile(pixels); |
| 113 } |
| 114 |
| 111 } // namespace | 115 } // namespace |
| 112 | 116 |
| 113 namespace skia { | 117 namespace skia { |
| 114 | 118 |
| 115 std::unique_ptr<SkCanvas> CreatePlatformCanvasWithSharedSection( | 119 std::unique_ptr<SkCanvas> CreatePlatformCanvasWithSharedSection( |
| 116 int width, | 120 int width, |
| 117 int height, | 121 int height, |
| 118 bool is_opaque, | 122 bool is_opaque, |
| 119 HANDLE shared_section, | 123 HANDLE shared_section, |
| 120 OnFailureType failure_type) { | 124 OnFailureType failure_type) { |
| 121 SkAlphaType alpha = is_opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType; | 125 SkAlphaType alpha = is_opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType; |
| 122 SkImageInfo info = SkImageInfo::MakeN32(width, height, alpha); | 126 SkImageInfo info = SkImageInfo::MakeN32(width, height, alpha); |
| 123 size_t row_bytes = PlatformCanvasStrideForWidth(width); | 127 size_t row_bytes = PlatformCanvasStrideForWidth(width); |
| 124 | 128 |
| 125 // This function contains an implementation of a Skia platform bitmap for | 129 // This function contains an implementation of a Skia platform bitmap for |
| 126 // drawing and compositing graphics. The original implementation uses Windows | 130 // drawing and compositing graphics. The original implementation uses Windows |
| 127 // GDI to create the backing bitmap memory, however it's possible for a | 131 // GDI to create the backing bitmap memory, however it's possible for a |
| 128 // process to not have access to GDI which will cause this code to fail. It's | 132 // process to not have access to GDI which will cause this code to fail. It's |
| 129 // possible to detect when GDI is unavailable and instead directly map the | 133 // possible to detect when GDI is unavailable and instead directly map the |
| 130 // shared memory as the bitmap. | 134 // shared memory as the bitmap. |
| 131 if (base::win::IsUser32AndGdi32Available()) { | 135 if (base::win::IsUser32AndGdi32Available()) { |
| 132 SkRasterHandleAllocator::Rec rec; | 136 SkRasterHandleAllocator::Rec rec; |
| 133 if (Create(width, height, is_opaque, shared_section, false, &rec)) | 137 if (Create(width, height, is_opaque, shared_section, false, &rec)) |
| 134 return SkRasterHandleAllocator::MakeCanvas( | 138 return SkRasterHandleAllocator::MakeCanvas( |
| 135 base::MakeUnique<GDIAllocator>(), info, &rec); | 139 base::MakeUnique<GDIAllocator>(), info, &rec); |
| 136 } else { | 140 } else { |
| 137 DCHECK(shared_section != NULL); | 141 DCHECK(shared_section != NULL); |
| 138 void* pixels = | 142 void* pixels = |
| 139 MapViewOfFile(shared_section, FILE_MAP_WRITE, 0, 0, row_bytes * height); | 143 MapViewOfFile(shared_section, FILE_MAP_WRITE, 0, 0, row_bytes * height); |
| 140 if (pixels) | 144 if (pixels) { |
| 141 return SkCanvas::MakeRasterDirect(info, pixels, row_bytes); | 145 SkBitmap bitmap; |
| 146 if (bitmap.installPixels(info, pixels, row_bytes, nullptr, |
| 147 unmap_view_proc, nullptr)) { |
| 148 return base::MakeUnique<SkCanvas>(bitmap); |
| 149 } |
| 150 } |
| 142 } | 151 } |
| 143 | 152 |
| 144 if (failure_type == CRASH_ON_FAILURE) | 153 if (failure_type == CRASH_ON_FAILURE) |
| 145 SK_CRASH(); | 154 SK_CRASH(); |
| 146 return nullptr; | 155 return nullptr; |
| 147 } | 156 } |
| 148 | 157 |
| 149 HDC GetNativeDrawingContext(SkCanvas* canvas) { | 158 HDC GetNativeDrawingContext(SkCanvas* canvas) { |
| 150 return canvas ? static_cast<HDC>(canvas->accessTopRasterHandle()) : nullptr; | 159 return canvas ? static_cast<HDC>(canvas->accessTopRasterHandle()) : nullptr; |
| 151 } | 160 } |
| 152 | 161 |
| 153 } // namespace skia | 162 } // namespace skia |
| OLD | NEW |