Index: ui/native_theme/native_theme_win.cc |
diff --git a/ui/native_theme/native_theme_win.cc b/ui/native_theme/native_theme_win.cc |
index 69954dd8d2bedcede4e6fb5a7c83566b33f0be09..ec724027065b3e7335cd3cfa2c454cc43ceec788 100644 |
--- a/ui/native_theme/native_theme_win.cc |
+++ b/ui/native_theme/native_theme_win.cc |
@@ -16,7 +16,6 @@ |
#include "base/win/scoped_hdc.h" |
#include "base/win/scoped_select_object.h" |
#include "base/win/windows_version.h" |
-#include "skia/ext/bitmap_platform_device.h" |
#include "skia/ext/platform_canvas.h" |
#include "skia/ext/skia_utils_win.h" |
#include "third_party/skia/include/core/SkCanvas.h" |
@@ -24,6 +23,7 @@ |
#include "third_party/skia/include/core/SkColorPriv.h" |
#include "third_party/skia/include/core/SkRefCnt.h" |
#include "third_party/skia/include/core/SkShader.h" |
+#include "third_party/skia/include/core/SkSurface.h" |
#include "ui/base/material_design/material_design_controller.h" |
#include "ui/display/win/dpi.h" |
#include "ui/gfx/color_palette.h" |
@@ -284,10 +284,12 @@ void NativeThemeWin::Paint(SkCanvas* canvas, |
} |
} |
+ skia::ScopedPlatformPaint paint(canvas); |
+ HDC surface = paint.GetPlatformSurface(); |
if (needs_paint_indirect) |
- PaintIndirect(canvas, part, state, rect, extra); |
+ PaintIndirect(surface, part, state, rect, extra); |
else |
- PaintDirect(canvas, part, state, rect, extra); |
+ PaintDirect(surface, part, state, rect, extra); |
} |
NativeThemeWin::NativeThemeWin() |
@@ -376,14 +378,11 @@ void NativeThemeWin::PaintMenuBackground(SkCanvas* canvas, |
canvas->drawRect(gfx::RectToSkRect(rect), paint); |
} |
-void NativeThemeWin::PaintDirect(SkCanvas* canvas, |
+void NativeThemeWin::PaintDirect(HDC hdc, |
Part part, |
State state, |
const gfx::Rect& rect, |
const ExtraParams& extra) const { |
- skia::ScopedPlatformPaint scoped_platform_paint(canvas); |
- HDC hdc = scoped_platform_paint.GetPlatformSurface(); |
- |
switch (part) { |
case kCheckbox: |
PaintCheckbox(hdc, part, state, rect, extra.button); |
@@ -438,12 +437,15 @@ void NativeThemeWin::PaintDirect(SkCanvas* canvas, |
return; |
case kScrollbarHorizontalTrack: |
case kScrollbarVerticalTrack: |
- PaintScrollbarTrack(canvas, hdc, part, state, rect, |
- extra.scrollbar_track); |
+ PaintScrollbarTrack(hdc, part, state, rect, extra.scrollbar_track); |
return; |
- case kScrollbarCorner: |
- canvas->drawColor(SK_ColorWHITE, SkXfermode::kSrc_Mode); |
+ case kScrollbarCorner: { |
+ sk_sp<SkSurface> surface(skia::MapPlatformSurface(hdc)); |
+ SkCanvas* canvas = surface ? surface->getCanvas() : nullptr; |
+ if (canvas) |
+ canvas->drawColor(SK_ColorWHITE, SkXfermode::kSrc_Mode); |
return; |
+ } |
case kTabPanelBackground: |
PaintTabPanelBackground(hdc, rect); |
return; |
@@ -452,7 +454,7 @@ void NativeThemeWin::PaintDirect(SkCanvas* canvas, |
return; |
case kTrackbarThumb: |
case kTrackbarTrack: |
- PaintTrackbar(canvas, hdc, part, state, rect, extra.trackbar); |
+ PaintTrackbar(hdc, part, state, rect, extra.trackbar); |
return; |
case kWindowResizeGripper: |
PaintWindowResizeGripper(hdc, rect); |
@@ -672,7 +674,7 @@ SkColor NativeThemeWin::GetSystemColor(ColorId color_id) const { |
return GetAuraColor(color_id, this); |
} |
-void NativeThemeWin::PaintIndirect(SkCanvas* canvas, |
+void NativeThemeWin::PaintIndirect(HDC hdc, |
Part part, |
State state, |
const gfx::Rect& rect, |
@@ -683,12 +685,13 @@ void NativeThemeWin::PaintIndirect(SkCanvas* canvas, |
// keeping a cache of the resulting bitmaps. |
// Create an offscreen canvas that is backed by an HDC. |
- sk_sp<skia::BitmapPlatformDevice> device( |
- skia::BitmapPlatformDevice::Create( |
- rect.width(), rect.height(), false, NULL)); |
- DCHECK(device); |
- SkCanvas offscreen_canvas(device.get()); |
- DCHECK(skia::SupportsPlatformPaint(&offscreen_canvas)); |
+ base::win::ScopedCreateDC offscreen_hdc |
+ (skia::CreateOffscreenSurface(rect.width(), rect.height())); |
+ sk_sp<SkSurface> offscreen_surface |
+ (skia::MapPlatformSurface(offscreen_hdc.Get())); |
+ DCHECK(offscreen_surface); |
+ SkCanvas* offscreen_canvas = offscreen_surface->getCanvas(); |
+ DCHECK(offscreen_canvas); |
// Some of the Windows theme drawing operations do not write correct alpha |
// values for fully-opaque pixels; instead the pixels get alpha 0. This is |
@@ -698,7 +701,7 @@ void NativeThemeWin::PaintIndirect(SkCanvas* canvas, |
// which pixels get touched by the paint operation. After paint, set any |
// pixels that have alpha 0 to opaque and placeholders to fully-transparent. |
const SkColor placeholder = SkColorSetARGB(1, 0, 0, 0); |
- offscreen_canvas.clear(placeholder); |
+ offscreen_canvas->clear(placeholder); |
// Offset destination rects to have origin (0,0). |
gfx::Rect adjusted_rect(rect.size()); |
@@ -716,15 +719,16 @@ void NativeThemeWin::PaintIndirect(SkCanvas* canvas, |
default: |
break; |
} |
- // Draw the theme controls using existing HDC-drawing code. |
- PaintDirect(&offscreen_canvas, part, state, adjusted_rect, adjusted_extra); |
- SkBitmap bitmap = skia::ReadPixels(&offscreen_canvas); |
+ SkBitmap bitmap = skia::ReadPixels(offscreen_canvas); |
+ // Draw the theme controls using existing HDC-drawing code. |
+ PaintDirect(offscreen_hdc.Get(), part, state, adjusted_rect, adjusted_extra); |
// Post-process the pixels to fix up the alpha values (see big comment above). |
+ SkBitmap offscreen_bitmap = skia::MapPlatformBitmap(offscreen_hdc.Get()); |
const SkPMColor placeholder_value = SkPreMultiplyColor(placeholder); |
const int pixel_count = rect.width() * rect.height(); |
- SkPMColor* pixels = bitmap.getAddr32(0, 0); |
+ SkPMColor* pixels = offscreen_bitmap.getAddr32(0, 0); |
for (int i = 0; i < pixel_count; i++) { |
if (pixels[i] == placeholder_value) { |
// Pixel wasn't touched - make it fully transparent. |
@@ -738,8 +742,11 @@ void NativeThemeWin::PaintIndirect(SkCanvas* canvas, |
} |
} |
- // Draw the offscreen bitmap to the destination canvas. |
- canvas->drawBitmap(bitmap, rect.x(), rect.y()); |
+ sk_sp<SkSurface> destination_surface(skia::MapPlatformSurface(hdc)); |
+ DCHECK(destination_surface); |
+ SkCanvas* destination_canvas = destination_surface->getCanvas(); |
+ DCHECK(destination_canvas); |
+ destination_canvas->drawBitmap(offscreen_bitmap, rect.x(), rect.y()); |
} |
HRESULT NativeThemeWin::GetThemePartSize(ThemeName theme_name, |
@@ -1256,7 +1263,6 @@ HRESULT NativeThemeWin::PaintScrollbarThumb( |
} |
HRESULT NativeThemeWin::PaintScrollbarTrack( |
- SkCanvas* canvas, |
HDC hdc, |
Part part, |
State state, |
@@ -1297,6 +1303,10 @@ HRESULT NativeThemeWin::PaintScrollbarTrack( |
(system_colors_[COLOR_SCROLLBAR] != system_colors_[COLOR_WINDOW])) { |
FillRect(hdc, &rect_win, reinterpret_cast<HBRUSH>(COLOR_SCROLLBAR + 1)); |
} else { |
+ sk_sp<SkSurface> surface(skia::MapPlatformSurface(hdc)); |
+ SkCanvas* canvas = surface ? surface->getCanvas() : nullptr; |
+ if (!canvas) |
+ return E_FAIL; |
SkPaint paint; |
RECT align_rect = gfx::Rect(extra.track_x, extra.track_y, extra.track_width, |
extra.track_height).ToRECT(); |
@@ -1342,7 +1352,6 @@ HRESULT NativeThemeWin::PaintSpinButton( |
} |
HRESULT NativeThemeWin::PaintTrackbar( |
- SkCanvas* canvas, |
HDC hdc, |
Part part, |
State state, |
@@ -1416,6 +1425,10 @@ HRESULT NativeThemeWin::PaintTrackbar( |
// If the button is pressed, draw hatching. |
if (extra.classic_state & DFCS_PUSHED) { |
+ sk_sp<SkSurface> surface(skia::MapPlatformSurface(hdc)); |
+ SkCanvas* canvas = surface ? surface->getCanvas() : nullptr; |
+ if (!canvas) |
+ return E_FAIL; |
SkPaint paint; |
SetCheckerboardShader(&paint, rect_win); |