Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Side by Side Diff: ui/native_theme/native_theme_win.cc

Issue 11299262: ui: Use skia::RefPtr<T> for implicit safe reference counting. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: winbuild Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/native_theme/native_theme_base.cc ('k') | ui/views/controls/glow_hover_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 = skia::AdoptRef(
85 SkShader::kRepeat_TileMode, 85 SkShader::CreateBitmapShader(
86 SkShader::kRepeat_TileMode); 86 bitmap, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode));
87 87
88 // Align the pattern with the upper corner of |align_rect|. 88 // Align the pattern with the upper corner of |align_rect|.
89 SkMatrix matrix; 89 SkMatrix matrix;
90 matrix.setTranslate(SkIntToScalar(align_rect.left), 90 matrix.setTranslate(SkIntToScalar(align_rect.left),
91 SkIntToScalar(align_rect.top)); 91 SkIntToScalar(align_rect.top));
92 shader->setLocalMatrix(matrix); 92 shader->setLocalMatrix(matrix);
93 SkSafeUnref(paint->setShader(shader)); 93 paint->setShader(shader.get());
94 } 94 }
95 95
96 // <-a-> 96 // <-a->
97 // [ ***** ] 97 // [ ***** ]
98 // ____ | | 98 // ____ | |
99 // <-a-> <------b-----> 99 // <-a-> <------b----->
100 // a: object_width 100 // a: object_width
101 // b: frame_width 101 // b: frame_width
102 // *: animating object 102 // *: animating object
103 // 103 //
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 Part part, 502 Part part,
503 State state, 503 State state,
504 const gfx::Rect& rect, 504 const gfx::Rect& rect,
505 const ExtraParams& extra) const { 505 const ExtraParams& extra) const {
506 // TODO(asvitkine): This path is pretty inefficient - for each paint operation 506 // TODO(asvitkine): This path is pretty inefficient - for each paint operation
507 // it creates a new offscreen bitmap Skia canvas. This can 507 // it creates a new offscreen bitmap Skia canvas. This can
508 // be sped up by doing it only once per part/state and 508 // be sped up by doing it only once per part/state and
509 // keeping a cache of the resulting bitmaps. 509 // keeping a cache of the resulting bitmaps.
510 510
511 // Create an offscreen canvas that is backed by an HDC. 511 // Create an offscreen canvas that is backed by an HDC.
512 skia::BitmapPlatformDevice* device = skia::BitmapPlatformDevice::Create( 512 skia::RefPtr<skia::BitmapPlatformDevice> device = skia::AdoptRef(
513 rect.width(), rect.height(), false, NULL); 513 skia::BitmapPlatformDevice::Create(
514 rect.width(), rect.height(), false, NULL));
514 DCHECK(device); 515 DCHECK(device);
515 SkCanvas offscreen_canvas(device); 516 SkCanvas offscreen_canvas(device.get());
516 device->unref();
517 DCHECK(skia::SupportsPlatformPaint(&offscreen_canvas)); 517 DCHECK(skia::SupportsPlatformPaint(&offscreen_canvas));
518 518
519 // Some of the Windows theme drawing operations do not write correct alpha 519 // 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 520 // 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. 521 // especially a problem on Windows XP or when using the Classic theme.
522 // 522 //
523 // To work-around this, mark all pixels with a placeholder value, to detect 523 // 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 524 // 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. 525 // pixels that have alpha 0 to opaque and placeholders to fully-transparent.
526 const SkColor placeholder = SkColorSetARGB(1, 0, 0, 0); 526 const SkColor placeholder = SkColorSetARGB(1, 0, 0, 0);
(...skipping 1431 matching lines...) Expand 10 before | Expand all | Expand 10 after
1958 handle = open_theme_(NULL, L"Spin"); 1958 handle = open_theme_(NULL, L"Spin");
1959 break; 1959 break;
1960 default: 1960 default:
1961 NOTREACHED(); 1961 NOTREACHED();
1962 } 1962 }
1963 theme_handles_[theme_name] = handle; 1963 theme_handles_[theme_name] = handle;
1964 return handle; 1964 return handle;
1965 } 1965 }
1966 1966
1967 } // namespace ui 1967 } // namespace ui
OLDNEW
« no previous file with comments | « ui/native_theme/native_theme_base.cc ('k') | ui/views/controls/glow_hover_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698