summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
Diffstat (limited to 'ui')
-rw-r--r--ui/base/clipboard/clipboard_linux.cc4
-rw-r--r--ui/base/clipboard/clipboard_mac.mm4
-rw-r--r--ui/base/clipboard/clipboard_win.cc4
-rw-r--r--ui/gfx/blit.cc25
-rw-r--r--ui/gfx/blit_unittest.cc4
-rw-r--r--ui/gfx/canvas_skia.cc4
-rw-r--r--ui/gfx/canvas_skia_linux.cc58
-rw-r--r--ui/gfx/canvas_skia_mac.mm4
-rw-r--r--ui/gfx/canvas_skia_win.cc70
-rw-r--r--ui/gfx/native_theme_win.cc5
10 files changed, 95 insertions, 87 deletions
diff --git a/ui/base/clipboard/clipboard_linux.cc b/ui/base/clipboard/clipboard_linux.cc
index 883dcf5..13cc759 100644
--- a/ui/base/clipboard/clipboard_linux.cc
+++ b/ui/base/clipboard/clipboard_linux.cc
@@ -388,10 +388,10 @@ SkBitmap Clipboard::ReadImage(Buffer buffer) const {
gfx::CanvasSkia canvas(gdk_pixbuf_get_width(pixbuf.get()),
gdk_pixbuf_get_height(pixbuf.get()),
false);
- cairo_t* context = canvas.beginPlatformPaint();
+ skia::ScopedPlatformPaint scoped_platform_paint(&canvas);
+ cairo_t* context = scoped_platform_paint.GetPlatformSurface();
gdk_cairo_set_source_pixbuf(context, pixbuf.get(), 0.0, 0.0);
cairo_paint(context);
- canvas.endPlatformPaint();
return canvas.ExtractBitmap();
}
diff --git a/ui/base/clipboard/clipboard_mac.mm b/ui/base/clipboard/clipboard_mac.mm
index 63d456b..eb89565 100644
--- a/ui/base/clipboard/clipboard_mac.mm
+++ b/ui/base/clipboard/clipboard_mac.mm
@@ -253,7 +253,8 @@ SkBitmap Clipboard::ReadImage(Buffer buffer) const {
int height = [image size].height;
gfx::CanvasSkia canvas(width, height, false);
- CGContextRef gc = canvas.beginPlatformPaint();
+ skia::ScopedPlatformPaint scoped_platform_paint(&canvas);
+ CGContextRef gc = scoped_platform_paint.GetPlatformSurface();
NSGraphicsContext* cocoa_gc =
[NSGraphicsContext graphicsContextWithGraphicsPort:gc flipped:NO];
[NSGraphicsContext setCurrentContext:cocoa_gc];
@@ -262,7 +263,6 @@ SkBitmap Clipboard::ReadImage(Buffer buffer) const {
operation:NSCompositeCopy
fraction:1.0];
[NSGraphicsContext restoreGraphicsState];
- canvas.endPlatformPaint();
return canvas.ExtractBitmap();
}
return SkBitmap();
diff --git a/ui/base/clipboard/clipboard_win.cc b/ui/base/clipboard/clipboard_win.cc
index 013da58..eb4f34b 100644
--- a/ui/base/clipboard/clipboard_win.cc
+++ b/ui/base/clipboard/clipboard_win.cc
@@ -456,9 +456,9 @@ SkBitmap Clipboard::ReadImage(Buffer buffer) const {
gfx::CanvasSkia canvas(width, height, false);
- HDC destination_dc = canvas.beginPlatformPaint();
+ skia::ScopedPlatformPaint scoped_platform_paint(&canvas);
+ HDC destination_dc = scoped_platform_paint.GetPlatformSurface();
::BitBlt(destination_dc, 0, 0, width, height, source_dc, 0, 0, SRCCOPY);
- canvas.endPlatformPaint();
return canvas.ExtractBitmap();
}
diff --git a/ui/gfx/blit.cc b/ui/gfx/blit.cc
index 76411a3..a9eeef8 100644
--- a/ui/gfx/blit.cc
+++ b/ui/gfx/blit.cc
@@ -35,7 +35,7 @@ bool HasClipOrTransform(const skia::PlatformCanvas& canvas) {
// Now we know the clip is a regular rectangle, make sure it covers the
// entire canvas.
- const SkBitmap& bitmap = canvas.getTopPlatformDevice().accessBitmap(false);
+ const SkBitmap& bitmap = skia::GetTopDevice(canvas)->accessBitmap(false);
const SkIRect& clip_bounds = clip_region.getBounds();
if (clip_bounds.fLeft != 0 || clip_bounds.fTop != 0 ||
clip_bounds.fRight != bitmap.width() ||
@@ -95,9 +95,9 @@ void BlitContextToCanvas(skia::PlatformCanvas *dst_canvas,
const Rect& dst_rect,
NativeDrawingContext src_context,
const Point& src_origin) {
- BlitContextToContext(dst_canvas->beginPlatformPaint(), dst_rect,
+ BlitContextToContext(skia::BeginPlatformPaint(dst_canvas), dst_rect,
src_context, src_origin);
- dst_canvas->endPlatformPaint();
+ skia::EndPlatformPaint(dst_canvas);
}
void BlitCanvasToContext(NativeDrawingContext dst_context,
@@ -105,18 +105,18 @@ void BlitCanvasToContext(NativeDrawingContext dst_context,
skia::PlatformCanvas *src_canvas,
const Point& src_origin) {
BlitContextToContext(dst_context, dst_rect,
- src_canvas->beginPlatformPaint(), src_origin);
- src_canvas->endPlatformPaint();
+ skia::BeginPlatformPaint(src_canvas), src_origin);
+ skia::EndPlatformPaint(src_canvas);
}
void BlitCanvasToCanvas(skia::PlatformCanvas *dst_canvas,
const Rect& dst_rect,
skia::PlatformCanvas *src_canvas,
const Point& src_origin) {
- BlitContextToContext(dst_canvas->beginPlatformPaint(), dst_rect,
- src_canvas->beginPlatformPaint(), src_origin);
- src_canvas->endPlatformPaint();
- dst_canvas->endPlatformPaint();
+ BlitContextToContext(skia::BeginPlatformPaint(dst_canvas), dst_rect,
+ skia::BeginPlatformPaint(src_canvas), src_origin);
+ skia::EndPlatformPaint(src_canvas);
+ skia::EndPlatformPaint(dst_canvas);
}
#if defined(OS_WIN)
@@ -125,13 +125,12 @@ void ScrollCanvas(skia::PlatformCanvas* canvas,
const gfx::Rect& clip,
const gfx::Point& amount) {
DCHECK(!HasClipOrTransform(*canvas)); // Don't support special stuff.
- HDC hdc = canvas->beginPlatformPaint();
+ skia::ScopedPlatformPaint scoped_platform_paint(canvas);
+ HDC hdc = scoped_platform_paint.GetPlatformSurface();
RECT damaged_rect;
RECT r = clip.ToRECT();
ScrollDC(hdc, amount.x(), amount.y(), NULL, &r, NULL, &damaged_rect);
-
- canvas->endPlatformPaint();
}
#elif defined(OS_POSIX)
@@ -144,7 +143,7 @@ void ScrollCanvas(skia::PlatformCanvas* canvas,
const gfx::Point& amount) {
DCHECK(!HasClipOrTransform(*canvas)); // Don't support special stuff.
SkBitmap& bitmap = const_cast<SkBitmap&>(
- canvas->getTopPlatformDevice().accessBitmap(true));
+ skia::GetTopDevice(*canvas)->accessBitmap(true));
SkAutoLockPixels lock(bitmap);
// We expect all coords to be inside the canvas, so clip here.
diff --git a/ui/gfx/blit_unittest.cc b/ui/gfx/blit_unittest.cc
index 356c66f..0a3217b 100644
--- a/ui/gfx/blit_unittest.cc
+++ b/ui/gfx/blit_unittest.cc
@@ -20,7 +20,7 @@ namespace {
template<int w, int h>
void SetToCanvas(skia::PlatformCanvas* canvas, uint8 values[h][w]) {
SkBitmap& bitmap = const_cast<SkBitmap&>(
- canvas->getTopPlatformDevice().accessBitmap(true));
+ skia::GetTopDevice(*canvas)->accessBitmap(true));
SkAutoLockPixels lock(bitmap);
ASSERT_EQ(w, bitmap.width());
ASSERT_EQ(h, bitmap.height());
@@ -40,7 +40,7 @@ void SetToCanvas(skia::PlatformCanvas* canvas, uint8 values[h][w]) {
template<int w, int h>
void VerifyCanvasValues(skia::PlatformCanvas* canvas, uint8 values[h][w]) {
SkBitmap& bitmap = const_cast<SkBitmap&>(
- canvas->getTopPlatformDevice().accessBitmap(true));
+ skia::GetTopDevice(*canvas)->accessBitmap(true));
SkAutoLockPixels lock(bitmap);
ASSERT_EQ(w, bitmap.width());
ASSERT_EQ(h, bitmap.height());
diff --git a/ui/gfx/canvas_skia.cc b/ui/gfx/canvas_skia.cc
index 1cec581..3d88276 100644
--- a/ui/gfx/canvas_skia.cc
+++ b/ui/gfx/canvas_skia.cc
@@ -324,11 +324,11 @@ void CanvasSkia::TileImageInt(const SkBitmap& bitmap,
}
gfx::NativeDrawingContext CanvasSkia::BeginPlatformPaint() {
- return beginPlatformPaint();
+ return skia::BeginPlatformPaint(this);
}
void CanvasSkia::EndPlatformPaint() {
- endPlatformPaint();
+ skia::EndPlatformPaint(this);
}
void CanvasSkia::Transform(const ui::Transform& transform) {
diff --git a/ui/gfx/canvas_skia_linux.cc b/ui/gfx/canvas_skia_linux.cc
index 796bfb8..1d5d298 100644
--- a/ui/gfx/canvas_skia_linux.cc
+++ b/ui/gfx/canvas_skia_linux.cc
@@ -208,7 +208,7 @@ DrawStringContext::DrawStringContext(gfx::CanvasSkia* canvas,
text_height_(0) {
DCHECK(!bounds_.IsEmpty());
- cr_ = canvas_->beginPlatformPaint();
+ cr_ = skia::BeginPlatformPaint(canvas_);
layout_ = pango_cairo_create_layout(cr_);
SetupPangoLayout(layout_, text, font, bounds_.width(), flags_);
@@ -246,8 +246,10 @@ DrawStringContext::~DrawStringContext() {
}
cairo_restore(cr_);
+ skia::EndPlatformPaint(canvas_);
+
g_object_unref(layout_);
- // NOTE: beginPlatformPaint returned its surface, we shouldn't destroy it.
+ // NOTE: BeginPlatformPaint returned its surface, we shouldn't destroy it.
}
void DrawStringContext::Draw(const SkColor& text_color) {
@@ -266,32 +268,33 @@ void DrawStringContext::DrawWithHalo(const SkColor& text_color,
text_canvas.FillRectInt(static_cast<SkColor>(0),
0, 0, bounds_.width() + 2, bounds_.height() + 2);
- cairo_t* text_cr = text_canvas.beginPlatformPaint();
-
- cairo_move_to(text_cr, 2, 1);
- pango_cairo_layout_path(text_cr, layout_);
-
- cairo_set_source_rgba(text_cr,
- SkColorGetR(halo_color) / 255.0,
- SkColorGetG(halo_color) / 255.0,
- SkColorGetB(halo_color) / 255.0,
- SkColorGetA(halo_color) / 255.0);
- cairo_set_line_width(text_cr, 2.0);
- cairo_set_line_join(text_cr, CAIRO_LINE_JOIN_ROUND);
- cairo_stroke_preserve(text_cr);
-
- cairo_set_operator(text_cr, CAIRO_OPERATOR_SOURCE);
- cairo_set_source_rgba(text_cr,
- SkColorGetR(text_color) / 255.0,
- SkColorGetG(text_color) / 255.0,
- SkColorGetB(text_color) / 255.0,
- SkColorGetA(text_color) / 255.0);
- cairo_fill(text_cr);
-
- text_canvas.endPlatformPaint();
+ {
+ skia::ScopedPlatformPaint scoped_platform_paint(&text_canvas);
+ cairo_t* text_cr = scoped_platform_paint.GetPlatformSurface();
+
+ cairo_move_to(text_cr, 2, 1);
+ pango_cairo_layout_path(text_cr, layout_);
+
+ cairo_set_source_rgba(text_cr,
+ SkColorGetR(halo_color) / 255.0,
+ SkColorGetG(halo_color) / 255.0,
+ SkColorGetB(halo_color) / 255.0,
+ SkColorGetA(halo_color) / 255.0);
+ cairo_set_line_width(text_cr, 2.0);
+ cairo_set_line_join(text_cr, CAIRO_LINE_JOIN_ROUND);
+ cairo_stroke_preserve(text_cr);
+
+ cairo_set_operator(text_cr, CAIRO_OPERATOR_SOURCE);
+ cairo_set_source_rgba(text_cr,
+ SkColorGetR(text_color) / 255.0,
+ SkColorGetG(text_color) / 255.0,
+ SkColorGetB(text_color) / 255.0,
+ SkColorGetA(text_color) / 255.0);
+ cairo_fill(text_cr);
+ }
const SkBitmap& text_bitmap = const_cast<SkBitmap&>(
- text_canvas.getTopPlatformDevice().accessBitmap(false));
+ skia::GetTopDevice(text_canvas)->accessBitmap(false));
canvas_->DrawBitmapInt(text_bitmap, text_x_ - 1, text_y_ - 1);
}
@@ -379,7 +382,8 @@ void CanvasSkia::DrawGdkPixbuf(GdkPixbuf* pixbuf, int x, int y) {
return;
}
- cairo_t* cr = beginPlatformPaint();
+ skia::ScopedPlatformPaint scoped_platform_paint(this);
+ cairo_t* cr = scoped_platform_paint.GetPlatformSurface();
gdk_cairo_set_source_pixbuf(cr, pixbuf, x, y);
cairo_paint(cr);
}
diff --git a/ui/gfx/canvas_skia_mac.mm b/ui/gfx/canvas_skia_mac.mm
index aacf100..1c78781 100644
--- a/ui/gfx/canvas_skia_mac.mm
+++ b/ui/gfx/canvas_skia_mac.mm
@@ -48,7 +48,8 @@ void CanvasSkia::DrawStringInt(const string16& text,
if (!IntersectsClipRectInt(x, y, w, h))
return;
- CGContextRef context = beginPlatformPaint();
+ skia::ScopedPlatformPaint scoped_platform_paint(this);
+ CGContextRef context = scoped_platform_paint.GetPlatformSurface();
CGContextSaveGState(context);
NSColor* ns_color = [NSColor colorWithDeviceRed:SkColorGetR(color) / 255.0
@@ -83,7 +84,6 @@ void CanvasSkia::DrawStringInt(const string16& text,
CTFramesetterCreateFrame(framesetter, CFRangeMake(0, 0), path, NULL));
CTFrameDraw(frame, context);
CGContextRestoreGState(context);
- endPlatformPaint();
}
ui::TextureID CanvasSkia::GetTextureID() {
diff --git a/ui/gfx/canvas_skia_win.cc b/ui/gfx/canvas_skia_win.cc
index 47d5cbb..67491fa 100644
--- a/ui/gfx/canvas_skia_win.cc
+++ b/ui/gfx/canvas_skia_win.cc
@@ -138,7 +138,7 @@ int ComputeFormatFlags(int flags, const string16& text) {
// Changes the alpha of the given bitmap.
// If |fade_to_right| is true then the rect fades from opaque to clear,
// otherwise the rect fades from clear to opaque.
-void FadeBitmapRect(skia::BitmapPlatformDevice& bmp_device,
+void FadeBitmapRect(SkDevice& bmp_device,
const gfx::Rect& rect,
bool fade_to_right) {
SkBitmap bmp = bmp_device.accessBitmap(true);
@@ -164,14 +164,14 @@ void FadeBitmapRect(skia::BitmapPlatformDevice& bmp_device,
// this function draws black on white. It then uses the intensity of black
// to determine how much alpha to use. The text is drawn in |gfx_text_rect| and
// clipped to |gfx_draw_rect|.
-void DrawTextAndClearBackground(skia::BitmapPlatformDevice& bmp_device,
+void DrawTextAndClearBackground(SkDevice& bmp_device,
HFONT font,
COLORREF text_color,
const string16& text,
int flags,
const gfx::Rect& gfx_text_rect,
const gfx::Rect& gfx_draw_rect) {
- HDC hdc = bmp_device.BeginPlatformPaint();
+ HDC hdc = skia::BeginPlatformPaint(&bmp_device);
// Clear the background by filling with white.
HBRUSH fill_brush = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH));
@@ -218,14 +218,14 @@ void DrawTextAndClearBackground(skia::BitmapPlatformDevice& bmp_device,
}
}
- bmp_device.EndPlatformPaint();
+ skia::EndPlatformPaint(&bmp_device);
}
// Draws the given text with a fade out gradient. |bmp_device| is a bitmap
// that is used to temporary drawing. The text is drawn in |text_rect| and
// clipped to |draw_rect|.
void DrawTextGradientPart(HDC hdc,
- skia::BitmapPlatformDevice& bmp_device,
+ SkDevice& bmp_device,
const string16& text,
const SkColor& color,
HFONT font,
@@ -238,11 +238,11 @@ void DrawTextGradientPart(HDC hdc,
FadeBitmapRect(bmp_device, draw_rect, fade_to_right);
BLENDFUNCTION blend = {AC_SRC_OVER, 0, 255, AC_SRC_ALPHA};
- HDC bmp_hdc = bmp_device.BeginPlatformPaint();
+ HDC bmp_hdc = skia::BeginPlatformPaint(&bmp_device);
AlphaBlend(hdc, draw_rect.x(), draw_rect.y(), draw_rect.width(),
draw_rect.height(), bmp_hdc, draw_rect.x(), draw_rect.y(),
draw_rect.width(), draw_rect.height(), blend);
- bmp_device.EndPlatformPaint();
+ skia::EndPlatformPaint(&bmp_device);
}
enum PrimarySide {
@@ -347,16 +347,20 @@ void CanvasSkia::DrawStringInt(const string16& text,
const int kMaxStringLength = 32768 - 1; // So the trailing \0 fits in 32K.
string16 clamped_string(text.substr(0, kMaxStringLength));
- HDC dc = beginPlatformPaint();
- SetBkMode(dc, TRANSPARENT);
- HFONT old_font = (HFONT)SelectObject(dc, font);
- COLORREF brush_color = RGB(SkColorGetR(color), SkColorGetG(color),
- SkColorGetB(color));
- SetTextColor(dc, brush_color);
-
- int f = ComputeFormatFlags(flags, clamped_string);
- DoDrawText(dc, clamped_string, &text_bounds, f);
- endPlatformPaint();
+ HDC dc;
+ HFONT old_font;
+ {
+ skia::ScopedPlatformPaint scoped_platform_paint(this);
+ dc = scoped_platform_paint.GetPlatformSurface();
+ SetBkMode(dc, TRANSPARENT);
+ old_font = (HFONT)SelectObject(dc, font);
+ COLORREF brush_color = RGB(SkColorGetR(color), SkColorGetG(color),
+ SkColorGetB(color));
+ SetTextColor(dc, brush_color);
+
+ int f = ComputeFormatFlags(flags, clamped_string);
+ DoDrawText(dc, clamped_string, &text_bounds, f);
+ }
// Restore the old font. This way we don't have to worry if the caller
// deletes the font and the DC lives longer.
@@ -365,8 +369,8 @@ void CanvasSkia::DrawStringInt(const string16& text,
// Windows will have cleared the alpha channel of the text we drew. Assume
// we're drawing to an opaque surface, or at least the text rect area is
// opaque.
- getTopPlatformDevice().makeOpaque(clip.fLeft, clip.fTop,
- clip.width(), clip.height());
+ skia::MakeOpaque(this, clip.fLeft, clip.fTop, clip.width(),
+ clip.height());
}
void CanvasSkia::DrawStringInt(const string16& text,
@@ -430,11 +434,11 @@ void CanvasSkia::DrawStringWithHalo(const string16& text,
// opaque. We have to do this first since pixelShouldGetHalo will check for
// 0 to see if a pixel has been modified to transparent, and black text that
// Windows draw will look transparent to it!
- text_canvas.getTopPlatformDevice().makeOpaque(0, 0, w + 2, h + 2);
+ skia::MakeOpaque(&text_canvas, 0, 0, w + 2, h + 2);
uint32_t halo_premul = SkPreMultiplyColor(halo_color);
SkBitmap& text_bitmap = const_cast<SkBitmap&>(
- text_canvas.getTopPlatformDevice().accessBitmap(true));
+ skia::GetTopDevice(text_canvas)->accessBitmap(true));
for (int cur_y = 0; cur_y < h + 2; cur_y++) {
uint32_t* text_row = text_bitmap.getAddr32(0, cur_y);
for (int cur_x = 0; cur_x < w + 2; cur_x++) {
@@ -553,21 +557,23 @@ void CanvasSkia::DrawFadeTruncatingString(
text_rect.set_width(text_rect.width() + offset_x);
// Create a temporary bitmap to draw the gradient to.
- scoped_ptr<skia::BitmapPlatformDevice> gradient_bitmap(
+ scoped_ptr<SkDevice> gradient_bitmap(
skia::BitmapPlatformDevice::create(
display_rect.width(), display_rect.height(), false, NULL));
DCHECK(gradient_bitmap.get());
- HDC hdc = beginPlatformPaint();
- if (is_truncating_head)
- DrawTextGradientPart(hdc, *gradient_bitmap, text, color,
- font.GetNativeFont(), text_rect, head_part, is_rtl,
- flags);
- if (is_truncating_tail)
- DrawTextGradientPart(hdc, *gradient_bitmap, text, color,
- font.GetNativeFont(), text_rect, tail_part, !is_rtl,
- flags);
- endPlatformPaint();
+ {
+ skia::ScopedPlatformPaint scoped_platform_paint(this);
+ HDC hdc = scoped_platform_paint.GetPlatformSurface();
+ if (is_truncating_head)
+ DrawTextGradientPart(hdc, *gradient_bitmap, text, color,
+ font.GetNativeFont(), text_rect, head_part, is_rtl,
+ flags);
+ if (is_truncating_tail)
+ DrawTextGradientPart(hdc, *gradient_bitmap, text, color,
+ font.GetNativeFont(), text_rect, tail_part, !is_rtl,
+ flags);
+ }
// Draw the solid part.
save(kClip_SaveFlag);
diff --git a/ui/gfx/native_theme_win.cc b/ui/gfx/native_theme_win.cc
index ba33651..bb0ad558 100644
--- a/ui/gfx/native_theme_win.cc
+++ b/ui/gfx/native_theme_win.cc
@@ -132,7 +132,8 @@ void NativeThemeWin::Paint(SkCanvas* canvas,
State state,
const gfx::Rect& rect,
const ExtraParams& extra) const {
- HDC hdc = skia::BeginPlatformPaint(canvas);
+ skia::ScopedPlatformPaint scoped_platform_paint(canvas);
+ HDC hdc = scoped_platform_paint.GetPlatformSurface();
switch (part) {
case kCheckbox:
@@ -212,8 +213,6 @@ void NativeThemeWin::Paint(SkCanvas* canvas,
// unsupported parts will DCHECK here.
DCHECK(false);
}
-
- skia::EndPlatformPaint(canvas);
}
HRESULT NativeThemeWin::PaintScrollbarArrow(