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 <uxtheme.h> | 8 #include <uxtheme.h> |
9 #include <vsstyle.h> | 9 #include <vsstyle.h> |
10 #include <vssym32.h> | 10 #include <vssym32.h> |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 // then copy it to another bitmap. The temporary bitmap doesn't take | 74 // then copy it to another bitmap. The temporary bitmap doesn't take |
75 // ownership of the pixel data, and so will point to garbage when this | 75 // ownership of the pixel data, and so will point to garbage when this |
76 // function returns. The copy will copy the pixel data into a place owned by | 76 // function returns. The copy will copy the pixel data into a place owned by |
77 // the bitmap, which is in turn owned by the shader, etc., so it will live | 77 // the bitmap, which is in turn owned by the shader, etc., so it will live |
78 // until we're done using it. | 78 // until we're done using it. |
79 SkBitmap temp_bitmap; | 79 SkBitmap temp_bitmap; |
80 temp_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 2, 2); | 80 temp_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 2, 2); |
81 temp_bitmap.setPixels(buffer); | 81 temp_bitmap.setPixels(buffer); |
82 SkBitmap bitmap; | 82 SkBitmap bitmap; |
83 temp_bitmap.copyTo(&bitmap, temp_bitmap.config()); | 83 temp_bitmap.copyTo(&bitmap, temp_bitmap.config()); |
84 SkShader* shader = SkShader::CreateBitmapShader(bitmap, | 84 skia::RefPtr<SkShader> shader = SkShader::CreateBitmapShader( |
85 SkShader::kRepeat_TileMode, | 85 bitmap, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode)); |
86 SkShader::kRepeat_TileMode); | |
87 | 86 |
88 // Align the pattern with the upper corner of |align_rect|. | 87 // Align the pattern with the upper corner of |align_rect|. |
89 SkMatrix matrix; | 88 SkMatrix matrix; |
90 matrix.setTranslate(SkIntToScalar(align_rect.left), | 89 matrix.setTranslate(SkIntToScalar(align_rect.left), |
91 SkIntToScalar(align_rect.top)); | 90 SkIntToScalar(align_rect.top)); |
92 shader->setLocalMatrix(matrix); | 91 shader->setLocalMatrix(matrix); |
93 SkSafeUnref(paint->setShader(shader)); | 92 skia::RefPtr<SkShader>(paint->setShader(shader.get())); |
94 } | 93 } |
95 | 94 |
96 // <-a-> | 95 // <-a-> |
97 // [ ***** ] | 96 // [ ***** ] |
98 // ____ | | | 97 // ____ | | |
99 // <-a-> <------b-----> | 98 // <-a-> <------b-----> |
100 // a: object_width | 99 // a: object_width |
101 // b: frame_width | 100 // b: frame_width |
102 // *: animating object | 101 // *: animating object |
103 // | 102 // |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 Part part, | 501 Part part, |
503 State state, | 502 State state, |
504 const gfx::Rect& rect, | 503 const gfx::Rect& rect, |
505 const ExtraParams& extra) const { | 504 const ExtraParams& extra) const { |
506 // TODO(asvitkine): This path is pretty inefficient - for each paint operation | 505 // TODO(asvitkine): This path is pretty inefficient - for each paint operation |
507 // it creates a new offscreen bitmap Skia canvas. This can | 506 // it creates a new offscreen bitmap Skia canvas. This can |
508 // be sped up by doing it only once per part/state and | 507 // be sped up by doing it only once per part/state and |
509 // keeping a cache of the resulting bitmaps. | 508 // keeping a cache of the resulting bitmaps. |
510 | 509 |
511 // Create an offscreen canvas that is backed by an HDC. | 510 // Create an offscreen canvas that is backed by an HDC. |
512 skia::BitmapPlatformDevice* device = skia::BitmapPlatformDevice::Create( | 511 skia::RefPtr<skia::BitmapPlatformDevice> device = |
513 rect.width(), rect.height(), false, NULL); | 512 skia::BitmapPlatformDevice::Create( |
| 513 rect.width(), rect.height(), false, NULL); |
514 DCHECK(device); | 514 DCHECK(device); |
515 SkCanvas offscreen_canvas(device); | 515 SkCanvas offscreen_canvas(device.get()); |
516 device->unref(); | |
517 DCHECK(skia::SupportsPlatformPaint(&offscreen_canvas)); | 516 DCHECK(skia::SupportsPlatformPaint(&offscreen_canvas)); |
518 | 517 |
519 // Some of the Windows theme drawing operations do not write correct alpha | 518 // Some of the Windows theme drawing operations do not write correct alpha |
520 // values for fully-opaque pixels; instead the pixels get alpha 0. This is | 519 // values for fully-opaque pixels; instead the pixels get alpha 0. This is |
521 // especially a problem on Windows XP or when using the Classic theme. | 520 // especially a problem on Windows XP or when using the Classic theme. |
522 // | 521 // |
523 // To work-around this, mark all pixels with a placeholder value, to detect | 522 // To work-around this, mark all pixels with a placeholder value, to detect |
524 // which pixels get touched by the paint operation. After paint, set any | 523 // which pixels get touched by the paint operation. After paint, set any |
525 // pixels that have alpha 0 to opaque and placeholders to fully-transparent. | 524 // pixels that have alpha 0 to opaque and placeholders to fully-transparent. |
526 const SkColor placeholder = SkColorSetARGB(1, 0, 0, 0); | 525 const SkColor placeholder = SkColorSetARGB(1, 0, 0, 0); |
(...skipping 1431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1958 handle = open_theme_(NULL, L"Spin"); | 1957 handle = open_theme_(NULL, L"Spin"); |
1959 break; | 1958 break; |
1960 default: | 1959 default: |
1961 NOTREACHED(); | 1960 NOTREACHED(); |
1962 } | 1961 } |
1963 theme_handles_[theme_name] = handle; | 1962 theme_handles_[theme_name] = handle; |
1964 return handle; | 1963 return handle; |
1965 } | 1964 } |
1966 | 1965 |
1967 } // namespace ui | 1966 } // namespace ui |
OLD | NEW |