diff options
author | vandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-25 16:16:02 +0000 |
---|---|---|
committer | vandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-25 16:16:02 +0000 |
commit | f2d4c672b6d6b80e376cff979b1ec28864b73fb6 (patch) | |
tree | 679a4a8178438947f2775a6d1ba5540be99ce00c /ui | |
parent | 49578ea329dae7f711ca1cde1ecade01e19a4f1b (diff) | |
download | chromium_src-f2d4c672b6d6b80e376cff979b1ec28864b73fb6.zip chromium_src-f2d4c672b6d6b80e376cff979b1ec28864b73fb6.tar.gz chromium_src-f2d4c672b6d6b80e376cff979b1ec28864b73fb6.tar.bz2 |
Revert 86625 - 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
Review URL: http://codereview.chromium.org/7019013
TBR=twiz@chromium.org
Review URL: http://codereview.chromium.org/6987019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86629 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/base/clipboard/clipboard_linux.cc | 4 | ||||
-rw-r--r-- | ui/base/clipboard/clipboard_mac.mm | 4 | ||||
-rw-r--r-- | ui/base/clipboard/clipboard_win.cc | 4 | ||||
-rw-r--r-- | ui/gfx/blit.cc | 25 | ||||
-rw-r--r-- | ui/gfx/blit_unittest.cc | 4 | ||||
-rw-r--r-- | ui/gfx/canvas_skia.cc | 4 | ||||
-rw-r--r-- | ui/gfx/canvas_skia_linux.cc | 58 | ||||
-rw-r--r-- | ui/gfx/canvas_skia_mac.mm | 4 | ||||
-rw-r--r-- | ui/gfx/canvas_skia_win.cc | 70 | ||||
-rw-r--r-- | ui/gfx/native_theme_win.cc | 5 |
10 files changed, 87 insertions, 95 deletions
diff --git a/ui/base/clipboard/clipboard_linux.cc b/ui/base/clipboard/clipboard_linux.cc index 13cc759..883dcf5 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); - skia::ScopedPlatformPaint scoped_platform_paint(&canvas); - cairo_t* context = scoped_platform_paint.GetPlatformSurface(); + cairo_t* context = canvas.beginPlatformPaint(); 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 eb89565..63d456b 100644 --- a/ui/base/clipboard/clipboard_mac.mm +++ b/ui/base/clipboard/clipboard_mac.mm @@ -253,8 +253,7 @@ SkBitmap Clipboard::ReadImage(Buffer buffer) const { int height = [image size].height; gfx::CanvasSkia canvas(width, height, false); - skia::ScopedPlatformPaint scoped_platform_paint(&canvas); - CGContextRef gc = scoped_platform_paint.GetPlatformSurface(); + CGContextRef gc = canvas.beginPlatformPaint(); NSGraphicsContext* cocoa_gc = [NSGraphicsContext graphicsContextWithGraphicsPort:gc flipped:NO]; [NSGraphicsContext setCurrentContext:cocoa_gc]; @@ -263,6 +262,7 @@ 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 eb4f34b..013da58 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); - skia::ScopedPlatformPaint scoped_platform_paint(&canvas); - HDC destination_dc = scoped_platform_paint.GetPlatformSurface(); + HDC destination_dc = canvas.beginPlatformPaint(); ::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 a9eeef8..76411a3 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 = skia::GetTopDevice(canvas)->accessBitmap(false); + const SkBitmap& bitmap = canvas.getTopPlatformDevice().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(skia::BeginPlatformPaint(dst_canvas), dst_rect, + BlitContextToContext(dst_canvas->beginPlatformPaint(), dst_rect, src_context, src_origin); - skia::EndPlatformPaint(dst_canvas); + dst_canvas->endPlatformPaint(); } 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, - skia::BeginPlatformPaint(src_canvas), src_origin); - skia::EndPlatformPaint(src_canvas); + src_canvas->beginPlatformPaint(), src_origin); + src_canvas->endPlatformPaint(); } void BlitCanvasToCanvas(skia::PlatformCanvas *dst_canvas, const Rect& dst_rect, skia::PlatformCanvas *src_canvas, const Point& src_origin) { - BlitContextToContext(skia::BeginPlatformPaint(dst_canvas), dst_rect, - skia::BeginPlatformPaint(src_canvas), src_origin); - skia::EndPlatformPaint(src_canvas); - skia::EndPlatformPaint(dst_canvas); + BlitContextToContext(dst_canvas->beginPlatformPaint(), dst_rect, + src_canvas->beginPlatformPaint(), src_origin); + src_canvas->endPlatformPaint(); + dst_canvas->endPlatformPaint(); } #if defined(OS_WIN) @@ -125,12 +125,13 @@ void ScrollCanvas(skia::PlatformCanvas* canvas, const gfx::Rect& clip, const gfx::Point& amount) { DCHECK(!HasClipOrTransform(*canvas)); // Don't support special stuff. - skia::ScopedPlatformPaint scoped_platform_paint(canvas); - HDC hdc = scoped_platform_paint.GetPlatformSurface(); + HDC hdc = canvas->beginPlatformPaint(); RECT damaged_rect; RECT r = clip.ToRECT(); ScrollDC(hdc, amount.x(), amount.y(), NULL, &r, NULL, &damaged_rect); + + canvas->endPlatformPaint(); } #elif defined(OS_POSIX) @@ -143,7 +144,7 @@ void ScrollCanvas(skia::PlatformCanvas* canvas, const gfx::Point& amount) { DCHECK(!HasClipOrTransform(*canvas)); // Don't support special stuff. SkBitmap& bitmap = const_cast<SkBitmap&>( - skia::GetTopDevice(*canvas)->accessBitmap(true)); + canvas->getTopPlatformDevice().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 0a3217b..356c66f 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&>( - skia::GetTopDevice(*canvas)->accessBitmap(true)); + canvas->getTopPlatformDevice().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&>( - skia::GetTopDevice(*canvas)->accessBitmap(true)); + canvas->getTopPlatformDevice().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 3d88276..1cec581 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 skia::BeginPlatformPaint(this); + return beginPlatformPaint(); } void CanvasSkia::EndPlatformPaint() { - skia::EndPlatformPaint(this); + endPlatformPaint(); } void CanvasSkia::Transform(const ui::Transform& transform) { diff --git a/ui/gfx/canvas_skia_linux.cc b/ui/gfx/canvas_skia_linux.cc index 1d5d298..796bfb8 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_ = skia::BeginPlatformPaint(canvas_); + cr_ = canvas_->beginPlatformPaint(); layout_ = pango_cairo_create_layout(cr_); SetupPangoLayout(layout_, text, font, bounds_.width(), flags_); @@ -246,10 +246,8 @@ 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) { @@ -268,33 +266,32 @@ void DrawStringContext::DrawWithHalo(const SkColor& text_color, text_canvas.FillRectInt(static_cast<SkColor>(0), 0, 0, bounds_.width() + 2, bounds_.height() + 2); - { - 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); - } + 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(); const SkBitmap& text_bitmap = const_cast<SkBitmap&>( - skia::GetTopDevice(text_canvas)->accessBitmap(false)); + text_canvas.getTopPlatformDevice().accessBitmap(false)); canvas_->DrawBitmapInt(text_bitmap, text_x_ - 1, text_y_ - 1); } @@ -382,8 +379,7 @@ void CanvasSkia::DrawGdkPixbuf(GdkPixbuf* pixbuf, int x, int y) { return; } - skia::ScopedPlatformPaint scoped_platform_paint(this); - cairo_t* cr = scoped_platform_paint.GetPlatformSurface(); + cairo_t* cr = beginPlatformPaint(); 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 1c78781..aacf100 100644 --- a/ui/gfx/canvas_skia_mac.mm +++ b/ui/gfx/canvas_skia_mac.mm @@ -48,8 +48,7 @@ void CanvasSkia::DrawStringInt(const string16& text, if (!IntersectsClipRectInt(x, y, w, h)) return; - skia::ScopedPlatformPaint scoped_platform_paint(this); - CGContextRef context = scoped_platform_paint.GetPlatformSurface(); + CGContextRef context = beginPlatformPaint(); CGContextSaveGState(context); NSColor* ns_color = [NSColor colorWithDeviceRed:SkColorGetR(color) / 255.0 @@ -84,6 +83,7 @@ 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 67491fa..47d5cbb 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(SkDevice& bmp_device, +void FadeBitmapRect(skia::BitmapPlatformDevice& bmp_device, const gfx::Rect& rect, bool fade_to_right) { SkBitmap bmp = bmp_device.accessBitmap(true); @@ -164,14 +164,14 @@ void FadeBitmapRect(SkDevice& 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(SkDevice& bmp_device, +void DrawTextAndClearBackground(skia::BitmapPlatformDevice& 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 = skia::BeginPlatformPaint(&bmp_device); + HDC hdc = bmp_device.BeginPlatformPaint(); // Clear the background by filling with white. HBRUSH fill_brush = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH)); @@ -218,14 +218,14 @@ void DrawTextAndClearBackground(SkDevice& bmp_device, } } - skia::EndPlatformPaint(&bmp_device); + bmp_device.EndPlatformPaint(); } // 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, - SkDevice& bmp_device, + skia::BitmapPlatformDevice& 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 = skia::BeginPlatformPaint(&bmp_device); + HDC bmp_hdc = bmp_device.BeginPlatformPaint(); 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); - skia::EndPlatformPaint(&bmp_device); + bmp_device.EndPlatformPaint(); } enum PrimarySide { @@ -347,20 +347,16 @@ 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; - 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); - } + 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(); // Restore the old font. This way we don't have to worry if the caller // deletes the font and the DC lives longer. @@ -369,8 +365,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. - skia::MakeOpaque(this, clip.fLeft, clip.fTop, clip.width(), - clip.height()); + getTopPlatformDevice().makeOpaque(clip.fLeft, clip.fTop, + clip.width(), clip.height()); } void CanvasSkia::DrawStringInt(const string16& text, @@ -434,11 +430,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! - skia::MakeOpaque(&text_canvas, 0, 0, w + 2, h + 2); + text_canvas.getTopPlatformDevice().makeOpaque(0, 0, w + 2, h + 2); uint32_t halo_premul = SkPreMultiplyColor(halo_color); SkBitmap& text_bitmap = const_cast<SkBitmap&>( - skia::GetTopDevice(text_canvas)->accessBitmap(true)); + text_canvas.getTopPlatformDevice().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++) { @@ -557,23 +553,21 @@ void CanvasSkia::DrawFadeTruncatingString( text_rect.set_width(text_rect.width() + offset_x); // Create a temporary bitmap to draw the gradient to. - scoped_ptr<SkDevice> gradient_bitmap( + scoped_ptr<skia::BitmapPlatformDevice> gradient_bitmap( skia::BitmapPlatformDevice::create( display_rect.width(), display_rect.height(), false, NULL)); DCHECK(gradient_bitmap.get()); - { - 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); - } + 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(); // Draw the solid part. save(kClip_SaveFlag); diff --git a/ui/gfx/native_theme_win.cc b/ui/gfx/native_theme_win.cc index bb0ad558..ba33651 100644 --- a/ui/gfx/native_theme_win.cc +++ b/ui/gfx/native_theme_win.cc @@ -132,8 +132,7 @@ void NativeThemeWin::Paint(SkCanvas* canvas, State state, const gfx::Rect& rect, const ExtraParams& extra) const { - skia::ScopedPlatformPaint scoped_platform_paint(canvas); - HDC hdc = scoped_platform_paint.GetPlatformSurface(); + HDC hdc = skia::BeginPlatformPaint(canvas); switch (part) { case kCheckbox: @@ -213,6 +212,8 @@ void NativeThemeWin::Paint(SkCanvas* canvas, // unsupported parts will DCHECK here. DCHECK(false); } + + skia::EndPlatformPaint(canvas); } HRESULT NativeThemeWin::PaintScrollbarArrow( |