| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/logging.h" | 10 #include "base/logging.h" |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 HBITMAP hbitmap = NULL; | 161 HBITMAP hbitmap = NULL; |
| 162 | 162 |
| 163 // This function contains an implementation of a Skia platform bitmap for | 163 // This function contains an implementation of a Skia platform bitmap for |
| 164 // drawing and compositing graphics. The original implementation uses Windows | 164 // drawing and compositing graphics. The original implementation uses Windows |
| 165 // GDI to create the backing bitmap memory, however it's possible for a | 165 // GDI to create the backing bitmap memory, however it's possible for a |
| 166 // process to not have access to GDI which will cause this code to fail. It's | 166 // process to not have access to GDI which will cause this code to fail. It's |
| 167 // possible to detect when GDI is unavailable and instead directly map the | 167 // possible to detect when GDI is unavailable and instead directly map the |
| 168 // shared memory as the bitmap. | 168 // shared memory as the bitmap. |
| 169 if (base::win::IsUser32AndGdi32Available()) { | 169 if (base::win::IsUser32AndGdi32Available()) { |
| 170 hbitmap = CreateHBitmap(width, height, is_opaque, shared_section, &data); | 170 hbitmap = CreateHBitmap(width, height, is_opaque, shared_section, &data); |
| 171 if (!hbitmap) | 171 if (!hbitmap) { |
| 172 LOG(ERROR) << "CreateHBitmap failed"; |
| 172 return NULL; | 173 return NULL; |
| 174 } |
| 173 } else { | 175 } else { |
| 174 DCHECK(shared_section != NULL); | 176 DCHECK(shared_section != NULL); |
| 175 data = MapViewOfFile(shared_section, FILE_MAP_WRITE, 0, 0, | 177 data = MapViewOfFile(shared_section, FILE_MAP_WRITE, 0, 0, |
| 176 PlatformCanvasStrideForWidth(width) * height); | 178 PlatformCanvasStrideForWidth(width) * height); |
| 177 if (!data) | 179 if (!data) { |
| 180 LOG(ERROR) << "MapViewOfFile failed"; |
| 178 return NULL; | 181 return NULL; |
| 182 } |
| 179 } | 183 } |
| 180 | 184 |
| 181 SkBitmap bitmap; | 185 SkBitmap bitmap; |
| 182 if (!InstallHBitmapPixels(&bitmap, width, height, is_opaque, data, hbitmap)) | 186 if (!InstallHBitmapPixels(&bitmap, width, height, is_opaque, data, hbitmap)) { |
| 187 LOG(ERROR) << "InstallHBitmapPixels failed"; |
| 183 return NULL; | 188 return NULL; |
| 189 } |
| 184 | 190 |
| 185 if (do_clear) | 191 if (do_clear) |
| 186 bitmap.eraseColor(0); | 192 bitmap.eraseColor(0); |
| 187 | 193 |
| 188 #ifndef NDEBUG | 194 #ifndef NDEBUG |
| 189 // If we were given data, then don't clobber it! | 195 // If we were given data, then don't clobber it! |
| 190 if (!shared_section && is_opaque) | 196 if (!shared_section && is_opaque) |
| 191 // To aid in finding bugs, we set the background color to something | 197 // To aid in finding bugs, we set the background color to something |
| 192 // obviously wrong so it will be noticable when it is not cleared | 198 // obviously wrong so it will be noticable when it is not cleared |
| 193 bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green | 199 bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 int height, | 316 int height, |
| 311 bool is_opaque, | 317 bool is_opaque, |
| 312 HANDLE shared_section, | 318 HANDLE shared_section, |
| 313 OnFailureType failureType) { | 319 OnFailureType failureType) { |
| 314 sk_sp<SkBaseDevice> dev( | 320 sk_sp<SkBaseDevice> dev( |
| 315 BitmapPlatformDevice::Create(width, height, is_opaque, shared_section)); | 321 BitmapPlatformDevice::Create(width, height, is_opaque, shared_section)); |
| 316 return CreateCanvas(dev, failureType); | 322 return CreateCanvas(dev, failureType); |
| 317 } | 323 } |
| 318 | 324 |
| 319 } // namespace skia | 325 } // namespace skia |
| OLD | NEW |