| 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 | 7 |
| 8 #include "base/debug/gdi_debug_util_win.h" | 8 #include "base/debug/gdi_debug_util_win.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/win/win_util.h" | 10 #include "base/win/win_util.h" |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 SkCanvas* CreatePlatformCanvas(int width, | 310 SkCanvas* CreatePlatformCanvas(int width, |
| 311 int height, | 311 int height, |
| 312 bool is_opaque, | 312 bool is_opaque, |
| 313 HANDLE shared_section, | 313 HANDLE shared_section, |
| 314 OnFailureType failureType) { | 314 OnFailureType failureType) { |
| 315 skia::RefPtr<SkBaseDevice> dev = skia::AdoptRef( | 315 skia::RefPtr<SkBaseDevice> dev = skia::AdoptRef( |
| 316 BitmapPlatformDevice::Create(width, height, is_opaque, shared_section)); | 316 BitmapPlatformDevice::Create(width, height, is_opaque, shared_section)); |
| 317 return CreateCanvas(dev, failureType); | 317 return CreateCanvas(dev, failureType); |
| 318 } | 318 } |
| 319 | 319 |
| 320 // Port of PlatformBitmap to win | |
| 321 | |
| 322 PlatformBitmap::~PlatformBitmap() { | |
| 323 if (surface_) { | |
| 324 if (platform_extra_) | |
| 325 SelectObject(surface_, reinterpret_cast<HGDIOBJ>(platform_extra_)); | |
| 326 DeleteDC(surface_); | |
| 327 } | |
| 328 } | |
| 329 | |
| 330 bool PlatformBitmap::Allocate(int width, int height, bool is_opaque) { | |
| 331 void* data; | |
| 332 HBITMAP hbitmap = CreateHBitmap(width, height, is_opaque, 0, &data); | |
| 333 if (!hbitmap) | |
| 334 return false; | |
| 335 | |
| 336 surface_ = CreateCompatibleDC(NULL); | |
| 337 InitializeDC(surface_); | |
| 338 // When the memory DC is created, its display surface is exactly one | |
| 339 // monochrome pixel wide and one monochrome pixel high. Save this object | |
| 340 // off, we'll restore it just before deleting the memory DC. | |
| 341 HGDIOBJ stock_bitmap = SelectObject(surface_, hbitmap); | |
| 342 platform_extra_ = reinterpret_cast<intptr_t>(stock_bitmap); | |
| 343 | |
| 344 if (!InstallHBitmapPixels(&bitmap_, width, height, is_opaque, data, hbitmap)) | |
| 345 return false; | |
| 346 bitmap_.lockPixels(); | |
| 347 | |
| 348 return true; | |
| 349 } | |
| 350 | |
| 351 } // namespace skia | 320 } // namespace skia |
| OLD | NEW |