diff options
author | twiz@chromium.org <twiz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-26 14:28:35 +0000 |
---|---|---|
committer | twiz@chromium.org <twiz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-26 14:28:35 +0000 |
commit | 62f2e80c79f7d660d7871b14287cef9082fcc32f (patch) | |
tree | 310edb9b2c0aa8409defc654979719cb4d8a4059 /ui/gfx/canvas_skia_win.cc | |
parent | c89b244483969aa8859a1d4bb3396f6ceb54f875 (diff) | |
download | chromium_src-62f2e80c79f7d660d7871b14287cef9082fcc32f.zip chromium_src-62f2e80c79f7d660d7871b14287cef9082fcc32f.tar.gz chromium_src-62f2e80c79f7d660d7871b14287cef9082fcc32f.tar.bz2 |
This change implements a first pass in the effort to remove the dependency of PlatformDevice within Chrome. The Skia library now provides multiple back-ends for the SkDevice class, so PlatformDevice's inheritance of SkDevice, and the assumption of instances of PlatformDevice limits the use of these new back-ends.
A new set of helper functions is provided for the PlatformDevice entry points. Upon construction of a PlatformDevice, a pointer to the interface is cached in the parent SkDevice's SkMetaData. The new helper functions forward calls to the interface cached in the metadata.
BUG=NONE
TEST=NONE
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=86625
Reverted: http://src.chromium.org/viewvc/chrome?view=rev&revision=86625
Review URL: http://codereview.chromium.org/7019013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86823 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/canvas_skia_win.cc')
-rw-r--r-- | ui/gfx/canvas_skia_win.cc | 70 |
1 files changed, 38 insertions, 32 deletions
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); |