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 "ui/native_theme/native_theme_win.h" | 5 #include "ui/native_theme/native_theme_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <uxtheme.h> | 9 #include <uxtheme.h> |
10 #include <vsstyle.h> | 10 #include <vsstyle.h> |
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 Part part, | 658 Part part, |
659 State state, | 659 State state, |
660 const gfx::Rect& rect, | 660 const gfx::Rect& rect, |
661 const ExtraParams& extra) const { | 661 const ExtraParams& extra) const { |
662 // TODO(asvitkine): This path is pretty inefficient - for each paint operation | 662 // TODO(asvitkine): This path is pretty inefficient - for each paint operation |
663 // it creates a new offscreen bitmap Skia canvas. This can | 663 // it creates a new offscreen bitmap Skia canvas. This can |
664 // be sped up by doing it only once per part/state and | 664 // be sped up by doing it only once per part/state and |
665 // keeping a cache of the resulting bitmaps. | 665 // keeping a cache of the resulting bitmaps. |
666 | 666 |
667 // Create an offscreen canvas that is backed by an HDC. | 667 // Create an offscreen canvas that is backed by an HDC. |
| 668 // This can fail if we don't have access to GDI or if lower-level Windows |
| 669 // calls fail, possibly due to GDI handle exhaustion. |
668 base::win::ScopedCreateDC offscreen_hdc( | 670 base::win::ScopedCreateDC offscreen_hdc( |
669 skia::CreateOffscreenSurface(rect.width(), rect.height())); | 671 skia::CreateOffscreenSurface(rect.width(), rect.height())); |
| 672 if (!offscreen_hdc.IsValid()) |
| 673 return; |
| 674 |
| 675 // Will be NULL if lower-level Windows calls fail, or if the backing |
| 676 // allocated is 0 pixels in size (which should never happen according to |
| 677 // Windows documentation). |
670 sk_sp<SkSurface> offscreen_surface = | 678 sk_sp<SkSurface> offscreen_surface = |
671 skia::MapPlatformSurface(offscreen_hdc.Get()); | 679 skia::MapPlatformSurface(offscreen_hdc.Get()); |
672 DCHECK(offscreen_surface); | 680 if (!offscreen_surface) |
| 681 return; |
| 682 |
673 SkCanvas* offscreen_canvas = offscreen_surface->getCanvas(); | 683 SkCanvas* offscreen_canvas = offscreen_surface->getCanvas(); |
674 DCHECK(offscreen_canvas); | 684 DCHECK(offscreen_canvas); |
675 | 685 |
676 // Some of the Windows theme drawing operations do not write correct alpha | 686 // Some of the Windows theme drawing operations do not write correct alpha |
677 // values for fully-opaque pixels; instead the pixels get alpha 0. This is | 687 // values for fully-opaque pixels; instead the pixels get alpha 0. This is |
678 // especially a problem on Windows XP or when using the Classic theme. | 688 // especially a problem on Windows XP or when using the Classic theme. |
679 // | 689 // |
680 // To work-around this, mark all pixels with a placeholder value, to detect | 690 // To work-around this, mark all pixels with a placeholder value, to detect |
681 // which pixels get touched by the paint operation. After paint, set any | 691 // which pixels get touched by the paint operation. After paint, set any |
682 // pixels that have alpha 0 to opaque and placeholders to fully-transparent. | 692 // pixels that have alpha 0 to opaque and placeholders to fully-transparent. |
(...skipping 1379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2062 break; | 2072 break; |
2063 case LAST: | 2073 case LAST: |
2064 NOTREACHED(); | 2074 NOTREACHED(); |
2065 break; | 2075 break; |
2066 } | 2076 } |
2067 theme_handles_[theme_name] = handle; | 2077 theme_handles_[theme_name] = handle; |
2068 return handle; | 2078 return handle; |
2069 } | 2079 } |
2070 | 2080 |
2071 } // namespace ui | 2081 } // namespace ui |
OLD | NEW |