diff options
-rw-r--r-- | chrome/browser/ui/gtk/gtk_theme_service.cc | 5 | ||||
-rw-r--r-- | chrome/browser/ui/libgtk2ui/gtk2_ui.cc | 5 | ||||
-rw-r--r-- | chrome/browser/ui/views/detachable_toolbar_view.cc | 12 | ||||
-rw-r--r-- | ui/gfx/blit_unittest.cc | 12 | ||||
-rw-r--r-- | ui/gfx/canvas.cc | 59 | ||||
-rw-r--r-- | ui/gfx/canvas.h | 3 | ||||
-rw-r--r-- | ui/gfx/canvas_mac.mm | 8 | ||||
-rw-r--r-- | ui/gfx/platform_font_pango.cc | 28 | ||||
-rw-r--r-- | ui/gfx/platform_font_pango.h | 18 | ||||
-rw-r--r-- | ui/gfx/render_text.cc | 35 | ||||
-rw-r--r-- | ui/gfx/skbitmap_operations.cc | 14 | ||||
-rw-r--r-- | ui/gfx/skia_util.cc | 48 | ||||
-rw-r--r-- | ui/gfx/skia_util.h | 29 | ||||
-rw-r--r-- | ui/native_theme/native_theme_base.cc | 16 | ||||
-rw-r--r-- | ui/native_theme/native_theme_win.cc | 16 | ||||
-rw-r--r-- | ui/views/controls/glow_hover_controller.cc | 9 | ||||
-rw-r--r-- | ui/views/controls/menu/menu_image_util.cc | 21 | ||||
-rw-r--r-- | ui/views/controls/progress_bar.cc | 8 | ||||
-rw-r--r-- | ui/views/painter.cc | 7 | ||||
-rw-r--r-- | ui/views/touchui/touch_selection_controller_impl.cc | 11 |
20 files changed, 176 insertions, 188 deletions
diff --git a/chrome/browser/ui/gtk/gtk_theme_service.cc b/chrome/browser/ui/gtk/gtk_theme_service.cc index 5c0f73c..bcf6a2d 100644 --- a/chrome/browser/ui/gtk/gtk_theme_service.cc +++ b/chrome/browser/ui/gtk/gtk_theme_service.cc @@ -1016,13 +1016,12 @@ SkBitmap GtkThemeService::GenerateFrameImage( color_utils::HSLShift(base, kGtkFrameShift); if (gradient_top_color) gdk_color_free(gradient_top_color); - SkShader* shader = gfx::CreateGradientShader( + skia::RefPtr<SkShader> shader = gfx::CreateGradientShader( 0, gradient_size, lighter, base); SkPaint paint; paint.setStyle(SkPaint::kFill_Style); paint.setAntiAlias(true); - paint.setShader(shader); - shader->unref(); + paint.setShader(shader.get()); canvas.DrawRect(gfx::Rect(0, 0, kToolbarImageWidth, gradient_size), paint); } diff --git a/chrome/browser/ui/libgtk2ui/gtk2_ui.cc b/chrome/browser/ui/libgtk2ui/gtk2_ui.cc index 2886e46..ea2fbef 100644 --- a/chrome/browser/ui/libgtk2ui/gtk2_ui.cc +++ b/chrome/browser/ui/libgtk2ui/gtk2_ui.cc @@ -762,13 +762,12 @@ SkBitmap Gtk2UI::GenerateFrameImage( color_utils::HSLShift(base, kGtkFrameShift); if (gradient_top_color) gdk_color_free(gradient_top_color); - SkShader* shader = gfx::CreateGradientShader( + skia::RefPtr<SkShader> shader = gfx::CreateGradientShader( 0, gradient_size, lighter, base); SkPaint paint; paint.setStyle(SkPaint::kFill_Style); paint.setAntiAlias(true); - paint.setShader(shader); - shader->unref(); + paint.setShader(shader.get()); canvas.DrawRect(gfx::Rect(0, 0, kToolbarImageWidth, gradient_size), paint); } diff --git a/chrome/browser/ui/views/detachable_toolbar_view.cc b/chrome/browser/ui/views/detachable_toolbar_view.cc index 354af9f..fd9db04 100644 --- a/chrome/browser/ui/views/detachable_toolbar_view.cc +++ b/chrome/browser/ui/views/detachable_toolbar_view.cc @@ -121,10 +121,9 @@ void DetachableToolbarView::PaintVerticalDivider(gfx::Canvas* canvas, SkColor bottom_color) { // Draw the upper half of the divider. SkPaint paint; - SkSafeUnref(paint.setShader(gfx::CreateGradientShader(vertical_padding + 1, - height / 2, - top_color, - middle_color))); + skia::RefPtr<SkShader> shader = gfx::CreateGradientShader( + vertical_padding + 1, height / 2, top_color, middle_color); + paint.setShader(shader.get()); SkRect rc = { SkIntToScalar(x), SkIntToScalar(vertical_padding + 1), SkIntToScalar(x + 1), @@ -133,8 +132,9 @@ void DetachableToolbarView::PaintVerticalDivider(gfx::Canvas* canvas, // Draw the lower half of the divider. SkPaint paint_down; - SkSafeUnref(paint_down.setShader(gfx::CreateGradientShader( - height / 2, height - vertical_padding, middle_color, bottom_color))); + shader = gfx::CreateGradientShader( + height / 2, height - vertical_padding, middle_color, bottom_color); + paint_down.setShader(shader.get()); SkRect rc_down = { SkIntToScalar(x), SkIntToScalar(height / 2), SkIntToScalar(x + 1), diff --git a/ui/gfx/blit_unittest.cc b/ui/gfx/blit_unittest.cc index f71be18..b8d3ab6 100644 --- a/ui/gfx/blit_unittest.cc +++ b/ui/gfx/blit_unittest.cc @@ -143,10 +143,10 @@ TEST(Blit, WithSharedMemory) { base::SharedMemory shared_mem; ASSERT_TRUE(shared_mem.CreateAnonymous(kCanvasWidth * kCanvasHeight)); base::SharedMemoryHandle section = shared_mem.handle(); - SkCanvas* canvas = skia::CreatePlatformCanvas(kCanvasWidth, kCanvasHeight, - true, section, skia::RETURN_NULL_ON_FAILURE); - ASSERT_TRUE(NULL != canvas); - SkAutoUnref aur(canvas); + skia::RefPtr<SkCanvas> canvas = skia::AdoptRef( + skia::CreatePlatformCanvas(kCanvasWidth, kCanvasHeight, true, section, + skia::RETURN_NULL_ON_FAILURE)); + ASSERT_TRUE(canvas); shared_mem.Close(); uint8 initial_values[kCanvasHeight][kCanvasWidth] = { @@ -155,10 +155,10 @@ TEST(Blit, WithSharedMemory) { { 0x20, 0x21, 0x22, 0x23, 0x24 }, { 0x30, 0x31, 0x32, 0x33, 0x34 }, { 0x40, 0x41, 0x42, 0x43, 0x44 }}; - SetToCanvas<5, 5>(canvas, initial_values); + SetToCanvas<5, 5>(canvas.get(), initial_values); // Sanity check on input. - VerifyCanvasValues<5, 5>(canvas, initial_values); + VerifyCanvasValues<5, 5>(canvas.get(), initial_values); } #endif diff --git a/ui/gfx/canvas.cc b/ui/gfx/canvas.cc index 831f4fc..4b4a0f4 100644 --- a/ui/gfx/canvas.cc +++ b/ui/gfx/canvas.cc @@ -27,13 +27,12 @@ Canvas::Canvas(const gfx::Size& size, ui::ScaleFactor scale_factor, bool is_opaque) : scale_factor_(scale_factor), - owned_canvas_(NULL), canvas_(NULL) { gfx::Size pixel_size = gfx::ToFlooredSize( gfx::ScaleSize(size, ui::GetScaleFactorScale(scale_factor))); - owned_canvas_.reset(skia::CreatePlatformCanvas(pixel_size.width(), - pixel_size.height(), - is_opaque)); + owned_canvas_ = skia::AdoptRef(skia::CreatePlatformCanvas(pixel_size.width(), + pixel_size.height(), + is_opaque)); canvas_ = owned_canvas_.get(); #if defined(OS_WIN) || defined(OS_MACOSX) // skia::PlatformCanvas instances are initialized to 0 by Cairo on Linux, but @@ -48,9 +47,10 @@ Canvas::Canvas(const gfx::Size& size, Canvas::Canvas(const gfx::ImageSkiaRep& image_rep, bool is_opaque) : scale_factor_(image_rep.scale_factor()), - owned_canvas_(skia::CreatePlatformCanvas(image_rep.pixel_width(), - image_rep.pixel_height(), - is_opaque)), + owned_canvas_(skia::AdoptRef( + skia::CreatePlatformCanvas(image_rep.pixel_width(), + image_rep.pixel_height(), + is_opaque))), canvas_(owned_canvas_.get()) { SkScalar scale = SkFloatToScalar(ui::GetScaleFactorScale(scale_factor_)); canvas_->scale(scale, scale); @@ -59,7 +59,7 @@ Canvas::Canvas(const gfx::ImageSkiaRep& image_rep, bool is_opaque) Canvas::Canvas() : scale_factor_(ui::SCALE_FACTOR_100P), - owned_canvas_(skia::CreatePlatformCanvas(0, 0, false)), + owned_canvas_(skia::AdoptRef(skia::CreatePlatformCanvas(0, 0, false))), canvas_(owned_canvas_.get()) { } @@ -78,9 +78,9 @@ void Canvas::RecreateBackingCanvas(const gfx::Size& size, scale_factor_ = scale_factor; gfx::Size pixel_size = gfx::ToFlooredSize( gfx::ScaleSize(size, ui::GetScaleFactorScale(scale_factor))); - owned_canvas_.reset(skia::CreatePlatformCanvas(pixel_size.width(), - pixel_size.height(), - is_opaque)); + owned_canvas_ = skia::AdoptRef(skia::CreatePlatformCanvas(pixel_size.width(), + pixel_size.height(), + is_opaque)); canvas_ = owned_canvas_.get(); SkScalar scale = SkFloatToScalar(ui::GetScaleFactorScale(scale_factor_)); canvas_->scale(scale, scale); @@ -140,14 +140,14 @@ void Canvas::DrawDashedRect(const gfx::Rect& rect, SkColor color) { // Make a shader for the bitmap with an origin of the box we'll draw. This // shader is refcounted and will have an initial refcount of 1. - SkShader* shader = SkShader::CreateBitmapShader( - *dots, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode); + skia::RefPtr<SkShader> shader = skia::AdoptRef( + SkShader::CreateBitmapShader( + *dots, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode)); // Assign the shader to the paint & release our reference. The paint will // now own the shader and the shader will be destroyed when the paint goes // out of scope. SkPaint paint; - paint.setShader(shader); - shader->unref(); + paint.setShader(shader.get()); DrawRect(gfx::Rect(rect.x(), rect.y(), rect.width(), 1), paint); DrawRect(gfx::Rect(rect.x(), rect.y() + rect.height() - 1, rect.width(), 1), @@ -373,16 +373,16 @@ void Canvas::DrawImageInt(const gfx::ImageSkia& image, shader_scale.preTranslate(SkIntToScalar(-src_x), SkIntToScalar(-src_y)); shader_scale.postTranslate(SkIntToScalar(dest_x), SkIntToScalar(dest_y)); - SkShader* shader = gfx::CreateImageRepShader(image_rep, - SkShader::kRepeat_TileMode, - shader_scale); + skia::RefPtr<SkShader> shader = gfx::CreateImageRepShader( + image_rep, + SkShader::kRepeat_TileMode, + shader_scale); // Set up our paint to use the shader & release our reference (now just owned // by the paint). SkPaint p(paint); p.setFilterBitmap(filter); - p.setShader(shader); - shader->unref(); + p.setShader(shader.get()); // The rect will be filled by the bitmap. canvas_->drawRect(dest_rect, p); @@ -399,12 +399,13 @@ void Canvas::DrawImageInPath(const gfx::ImageSkia& image, SkMatrix matrix; matrix.setTranslate(SkIntToScalar(x), SkIntToScalar(y)); - SkShader* shader = gfx::CreateImageRepShader(image_rep, - SkShader::kRepeat_TileMode, matrix); + skia::RefPtr<SkShader> shader = gfx::CreateImageRepShader( + image_rep, + SkShader::kRepeat_TileMode, + matrix); SkPaint p(paint); - p.setShader(shader); - shader->unref(); + p.setShader(shader.get()); canvas_->drawPath(path, p); } @@ -465,14 +466,14 @@ void Canvas::TileImageInt(const gfx::ImageSkia& image, shader_scale.preTranslate(SkIntToScalar(-src_x), SkIntToScalar(-src_y)); shader_scale.postTranslate(SkIntToScalar(dest_x), SkIntToScalar(dest_y)); - SkShader* shader = gfx::CreateImageRepShader(image_rep, - SkShader::kRepeat_TileMode, - shader_scale); + skia::RefPtr<SkShader> shader = gfx::CreateImageRepShader( + image_rep, + SkShader::kRepeat_TileMode, + shader_scale); SkPaint paint; - paint.setShader(shader); + paint.setShader(shader.get()); paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); - shader->unref(); SkRect dest_rect = { SkIntToScalar(dest_x), SkIntToScalar(dest_y), diff --git a/ui/gfx/canvas.h b/ui/gfx/canvas.h index 75a19ca..7fee483 100644 --- a/ui/gfx/canvas.h +++ b/ui/gfx/canvas.h @@ -11,6 +11,7 @@ #include "base/memory/scoped_ptr.h" #include "base/string16.h" #include "skia/ext/platform_canvas.h" +#include "skia/ext/refptr.h" #include "ui/gfx/image/image_skia.h" #include "ui/gfx/native_widget_types.h" #include "ui/gfx/shadow_value.h" @@ -398,7 +399,7 @@ class UI_EXPORT Canvas { // Canvas::Scale() does not affect |scale_factor_|. ui::ScaleFactor scale_factor_; - scoped_ptr<skia::PlatformCanvas> owned_canvas_; + skia::RefPtr<skia::PlatformCanvas> owned_canvas_; SkCanvas* canvas_; DISALLOW_COPY_AND_ASSIGN(Canvas); diff --git a/ui/gfx/canvas_mac.mm b/ui/gfx/canvas_mac.mm index 2b8f39e..0a597a5 100644 --- a/ui/gfx/canvas_mac.mm +++ b/ui/gfx/canvas_mac.mm @@ -59,11 +59,11 @@ void Canvas::DrawStringWithShadows(const string16& text, const ShadowValues& shadows) { DLOG_IF(WARNING, !shadows.empty()) << "Text shadow not implemented."; - SkTypeface* typeface = SkTypeface::CreateFromName(font.GetFontName().c_str(), - FontTypefaceStyle(font)); + skia::RefPtr<SkTypeface> typeface = skia::AdoptRef( + SkTypeface::CreateFromName( + font.GetFontName().c_str(), FontTypefaceStyle(font))); SkPaint paint; - paint.setTypeface(typeface); - typeface->unref(); + paint.setTypeface(typeface.get()); paint.setColor(color); canvas_->drawText(text.c_str(), text.size() * sizeof(string16::value_type), diff --git a/ui/gfx/platform_font_pango.cc b/ui/gfx/platform_font_pango.cc index ebf71c6..6bb580b 100644 --- a/ui/gfx/platform_font_pango.cc +++ b/ui/gfx/platform_font_pango.cc @@ -174,10 +174,10 @@ Font PlatformFontPango::DeriveFont(int size_delta, int style) const { if (gfx::Font::ITALIC & style) skstyle |= SkTypeface::kItalic; - SkTypeface* typeface = SkTypeface::CreateFromName( - font_family_.c_str(), - static_cast<SkTypeface::Style>(skstyle)); - SkAutoUnref tf_helper(typeface); + skia::RefPtr<SkTypeface> typeface = skia::AdoptRef( + SkTypeface::CreateFromName( + font_family_.c_str(), + static_cast<SkTypeface::Style>(skstyle))); return Font(new PlatformFontPango(typeface, font_family_, @@ -252,7 +252,7 @@ NativeFont PlatformFontPango::GetNativeFont() const { //////////////////////////////////////////////////////////////////////////////// // PlatformFontPango, private: -PlatformFontPango::PlatformFontPango(SkTypeface* typeface, +PlatformFontPango::PlatformFontPango(const skia::RefPtr<SkTypeface>& typeface, const std::string& name, int size, int style) { @@ -266,19 +266,19 @@ void PlatformFontPango::InitWithNameAndSize(const std::string& font_name, DCHECK_GT(font_size, 0); std::string fallback; - SkTypeface* typeface = SkTypeface::CreateFromName( - font_name.c_str(), SkTypeface::kNormal); + skia::RefPtr<SkTypeface> typeface = skia::AdoptRef( + SkTypeface::CreateFromName(font_name.c_str(), SkTypeface::kNormal)); if (!typeface) { // A non-scalable font such as .pcf is specified. Falls back to a default // scalable font. - typeface = SkTypeface::CreateFromName( - kFallbackFontFamilyName, SkTypeface::kNormal); + typeface = skia::AdoptRef( + SkTypeface::CreateFromName( + kFallbackFontFamilyName, SkTypeface::kNormal)); CHECK(typeface) << "Could not find any font: " << font_name << ", " << kFallbackFontFamilyName; fallback = kFallbackFontFamilyName; } - SkAutoUnref typeface_helper(typeface); InitWithTypefaceNameSizeAndStyle(typeface, fallback.empty() ? font_name : fallback, @@ -287,13 +287,11 @@ void PlatformFontPango::InitWithNameAndSize(const std::string& font_name, } void PlatformFontPango::InitWithTypefaceNameSizeAndStyle( - SkTypeface* typeface, + const skia::RefPtr<SkTypeface>& typeface, const std::string& font_family, int font_size, int style) { - typeface_helper_.reset(new SkAutoUnref(typeface)); typeface_ = typeface; - typeface_->ref(); font_family_ = font_family; font_size_pixels_ = font_size; style_ = style; @@ -312,9 +310,7 @@ void PlatformFontPango::InitWithTypefaceNameSizeAndStyle( } void PlatformFontPango::InitFromPlatformFont(const PlatformFontPango* other) { - typeface_helper_.reset(new SkAutoUnref(other->typeface_)); typeface_ = other->typeface_; - typeface_->ref(); font_family_ = other->font_family_; font_size_pixels_ = other->font_size_pixels_; style_ = other->style_; @@ -330,7 +326,7 @@ void PlatformFontPango::PaintSetup(SkPaint* paint) const { paint->setAntiAlias(false); paint->setSubpixelText(false); paint->setTextSize(font_size_pixels_); - paint->setTypeface(typeface_); + paint->setTypeface(typeface_.get()); paint->setFakeBoldText((gfx::Font::BOLD & style_) && !typeface_->isBold()); paint->setTextSkewX((gfx::Font::ITALIC & style_) && !typeface_->isItalic() ? -SK_Scalar1/4 : 0); diff --git a/ui/gfx/platform_font_pango.h b/ui/gfx/platform_font_pango.h index cb93bf4..845c150 100644 --- a/ui/gfx/platform_font_pango.h +++ b/ui/gfx/platform_font_pango.h @@ -7,6 +7,7 @@ #include "base/compiler_specific.h" #include "base/memory/scoped_ptr.h" +#include "skia/ext/refptr.h" #include "third_party/skia/include/core/SkRefCnt.h" #include "ui/gfx/platform_font.h" @@ -52,7 +53,7 @@ class UI_EXPORT PlatformFontPango : public PlatformFont { private: // Create a new instance of this object with the specified properties. Called // from DeriveFont. - PlatformFontPango(SkTypeface* typeface, + PlatformFontPango(const skia::RefPtr<SkTypeface>& typeface, const std::string& name, int size, int style); @@ -60,10 +61,11 @@ class UI_EXPORT PlatformFontPango : public PlatformFont { // Initialize this object. void InitWithNameAndSize(const std::string& font_name, int font_size); - void InitWithTypefaceNameSizeAndStyle(SkTypeface* typeface, - const std::string& name, - int size, - int style); + void InitWithTypefaceNameSizeAndStyle( + const skia::RefPtr<SkTypeface>& typeface, + const std::string& name, + int size, + int style); void InitFromPlatformFont(const PlatformFontPango* other); // Potentially slow call to get pango metrics (average width, underline info). @@ -78,11 +80,7 @@ class UI_EXPORT PlatformFontPango : public PlatformFont { // The average width of a character, initialized and cached if needed. double GetAverageWidth() const; - // These two both point to the same SkTypeface. We use the SkAutoUnref to - // handle the reference counting, but without @typeface_ we would have to - // cast the SkRefCnt from @typeface_helper_ every time. - scoped_ptr<SkAutoUnref> typeface_helper_; - SkTypeface* typeface_; + skia::RefPtr<SkTypeface> typeface_; // Additional information about the face // Skia actually expects a family name and not a font name. diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc index 2cedd9d..a724f86 100644 --- a/ui/gfx/render_text.cc +++ b/ui/gfx/render_text.cc @@ -143,10 +143,10 @@ void AddFadeEffect(const gfx::Rect& text_rect, // Creates a SkShader to fade the text, with |left_part| specifying the left // fade effect, if any, and |right_part| specifying the right fade effect. -SkShader* CreateFadeShader(const gfx::Rect& text_rect, - const gfx::Rect& left_part, - const gfx::Rect& right_part, - SkColor color) { +skia::RefPtr<SkShader> CreateFadeShader(const gfx::Rect& text_rect, + const gfx::Rect& left_part, + const gfx::Rect& right_part, + SkColor color) { // Fade alpha of 51/255 corresponds to a fade of 0.2 of the original color. const SkColor fade_color = SkColorSetA(color, 51); std::vector<SkScalar> positions; @@ -170,8 +170,9 @@ SkShader* CreateFadeShader(const gfx::Rect& text_rect, points[0].iset(text_rect.x(), text_rect.y()); points[1].iset(text_rect.right(), text_rect.y()); - return SkGradientShader::CreateLinear(&points[0], &colors[0], &positions[0], - colors.size(), SkShader::kClamp_TileMode); + return skia::AdoptRef( + SkGradientShader::CreateLinear(&points[0], &colors[0], &positions[0], + colors.size(), SkShader::kClamp_TileMode)); } } // namespace @@ -237,11 +238,11 @@ void SkiaTextRenderer::SetFontFamilyWithStyle(const std::string& family, DCHECK(!family.empty()); SkTypeface::Style skia_style = ConvertFontStyleToSkiaTypefaceStyle(style); - SkTypeface* typeface = SkTypeface::CreateFromName(family.c_str(), skia_style); - SkAutoUnref auto_unref(typeface); + skia::RefPtr<SkTypeface> typeface = + skia::AdoptRef(SkTypeface::CreateFromName(family.c_str(), skia_style)); if (typeface) { // |paint_| adds its own ref. So don't |release()| it from the ref ptr here. - SetTypeface(typeface); + SetTypeface(typeface.get()); // Enable fake bold text if bold style is needed but new typeface does not // have it. @@ -916,18 +917,16 @@ void RenderText::ApplyFadeEffects(internal::SkiaTextRenderer* renderer) { text_rect.Inset(GetAlignmentOffset().x(), 0, 0, 0); const SkColor color = default_style().foreground; - SkShader* shader = CreateFadeShader(text_rect, left_part, right_part, color); - SkAutoUnref auto_unref(shader); - if (shader) { - // |renderer| adds its own ref. So don't |release()| it from the ref ptr. - renderer->SetShader(shader, display_rect()); - } + skia::RefPtr<SkShader> shader = + CreateFadeShader(text_rect, left_part, right_part, color); + if (shader) + renderer->SetShader(shader.get(), display_rect()); } void RenderText::ApplyTextShadows(internal::SkiaTextRenderer* renderer) { - SkDrawLooper* looper = gfx::CreateShadowDrawLooper(text_shadows_); - SkAutoUnref auto_unref(looper); - renderer->SetDrawLooper(looper); + skia::RefPtr<SkDrawLooper> looper = + gfx::CreateShadowDrawLooper(text_shadows_); + renderer->SetDrawLooper(looper.get()); } // static diff --git a/ui/gfx/skbitmap_operations.cc b/ui/gfx/skbitmap_operations.cc index 7e27506..80f91ca 100644 --- a/ui/gfx/skbitmap_operations.cc +++ b/ui/gfx/skbitmap_operations.cc @@ -8,6 +8,7 @@ #include <string.h> #include "base/logging.h" +#include "skia/ext/refptr.h" #include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkColorFilter.h" @@ -759,10 +760,10 @@ SkBitmap SkBitmapOperations::CreateColorMask(const SkBitmap& bitmap, SkCanvas canvas(color_mask); - SkColorFilter* color_filter = SkColorFilter::CreateModeFilter( - c, SkXfermode::kSrcIn_Mode); + skia::RefPtr<SkColorFilter> color_filter = skia::AdoptRef( + SkColorFilter::CreateModeFilter(c, SkXfermode::kSrcIn_Mode)); SkPaint paint; - paint.setColorFilter(color_filter)->unref(); + paint.setColorFilter(color_filter.get()); canvas.drawBitmap(bitmap, SkIntToScalar(0), SkIntToScalar(0), &paint); return color_mask; } @@ -795,9 +796,10 @@ SkBitmap SkBitmapOperations::CreateDropShadow( SkBitmap shadow_image = SkBitmapOperations::CreateColorMask(bitmap, shadow.color()); - paint.setImageFilter( - new SkBlurImageFilter(SkDoubleToScalar(shadow.blur()), - SkDoubleToScalar(shadow.blur())))->unref(); + skia::RefPtr<SkBlurImageFilter> filter = + skia::AdoptRef(new SkBlurImageFilter(SkDoubleToScalar(shadow.blur()), + SkDoubleToScalar(shadow.blur()))); + paint.setImageFilter(filter.get()); canvas.saveLayer(0, &paint); canvas.drawBitmap(shadow_image, diff --git a/ui/gfx/skia_util.cc b/ui/gfx/skia_util.cc index caa35e7..162a5ba 100644 --- a/ui/gfx/skia_util.cc +++ b/ui/gfx/skia_util.cc @@ -47,11 +47,11 @@ RectF SkRectToRectF(const SkRect& rect) { } -SkShader* CreateImageRepShader(const gfx::ImageSkiaRep& image_rep, - SkShader::TileMode tile_mode, - const SkMatrix& local_matrix) { - SkShader* shader = SkShader::CreateBitmapShader(image_rep.sk_bitmap(), - tile_mode, tile_mode); +skia::RefPtr<SkShader> CreateImageRepShader(const gfx::ImageSkiaRep& image_rep, + SkShader::TileMode tile_mode, + const SkMatrix& local_matrix) { + skia::RefPtr<SkShader> shader = skia::AdoptRef(SkShader::CreateBitmapShader( + image_rep.sk_bitmap(), tile_mode, tile_mode)); SkScalar scale_x = local_matrix.getScaleX(); SkScalar scale_y = local_matrix.getScaleY(); SkScalar bitmap_scale = SkFloatToScalar(image_rep.GetScale()); @@ -72,24 +72,26 @@ SkShader* CreateImageRepShader(const gfx::ImageSkiaRep& image_rep, return shader; } -SkShader* CreateGradientShader(int start_point, - int end_point, - SkColor start_color, - SkColor end_color) { +skia::RefPtr<SkShader> CreateGradientShader(int start_point, + int end_point, + SkColor start_color, + SkColor end_color) { SkColor grad_colors[2] = { start_color, end_color}; SkPoint grad_points[2]; grad_points[0].iset(0, start_point); grad_points[1].iset(0, end_point); - return SkGradientShader::CreateLinear( - grad_points, grad_colors, NULL, 2, SkShader::kRepeat_TileMode); + return skia::AdoptRef(SkGradientShader::CreateLinear( + grad_points, grad_colors, NULL, 2, SkShader::kRepeat_TileMode)); } -SkDrawLooper* CreateShadowDrawLooper(const std::vector<ShadowValue>& shadows) { +skia::RefPtr<SkDrawLooper> CreateShadowDrawLooper( + const std::vector<ShadowValue>& shadows) { if (shadows.empty()) - return NULL; + return skia::RefPtr<SkDrawLooper>(); - SkLayerDrawLooper* looper = new SkLayerDrawLooper; + skia::RefPtr<SkLayerDrawLooper> looper = + skia::AdoptRef(new SkLayerDrawLooper); looper->addLayer(); // top layer of the original. @@ -106,17 +108,17 @@ SkDrawLooper* CreateShadowDrawLooper(const std::vector<ShadowValue>& shadows) { // SkBlurMaskFilter's blur radius defines the range to extend the blur from // original mask, which is half of blur amount as defined in ShadowValue. - SkMaskFilter* blur_mask = SkBlurMaskFilter::Create( - SkDoubleToScalar(shadow.blur() / 2), - SkBlurMaskFilter::kNormal_BlurStyle, - SkBlurMaskFilter::kHighQuality_BlurFlag); - SkColorFilter* color_filter = SkColorFilter::CreateModeFilter( - shadow.color(), - SkXfermode::kSrcIn_Mode); + skia::RefPtr<SkMaskFilter> blur_mask = skia::AdoptRef( + SkBlurMaskFilter::Create(SkDoubleToScalar(shadow.blur() / 2), + SkBlurMaskFilter::kNormal_BlurStyle, + SkBlurMaskFilter::kHighQuality_BlurFlag)); + skia::RefPtr<SkColorFilter> color_filter = skia::AdoptRef( + SkColorFilter::CreateModeFilter(shadow.color(), + SkXfermode::kSrcIn_Mode)); SkPaint* paint = looper->addLayer(layer_info); - SkSafeUnref(paint->setMaskFilter(blur_mask)); - SkSafeUnref(paint->setColorFilter(color_filter)); + paint->setMaskFilter(blur_mask.get()); + paint->setColorFilter(color_filter.get()); } return looper; diff --git a/ui/gfx/skia_util.h b/ui/gfx/skia_util.h index 6682407..bd9478f 100644 --- a/ui/gfx/skia_util.h +++ b/ui/gfx/skia_util.h @@ -8,6 +8,7 @@ #include <string> #include <vector> +#include "skia/ext/refptr.h" #include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkRect.h" #include "third_party/skia/include/core/SkShader.h" @@ -36,33 +37,23 @@ UI_EXPORT RectF SkRectToRectF(const SkRect& rect); // The shader's local matrix should not be changed after the shader is created. // TODO(pkotwicz): Allow shader's local matrix to be changed after the shader // is created. -// Example usage to avoid leaks: -// SkSafeUnref(paint.setShader(gfx::CreateImageRepShader(image_rep, -// tile_mode, matrix))); // -// (The old shader in the paint, if any, needs to be freed, and SkSafeUnref will -// handle the NULL case.) -UI_EXPORT SkShader* CreateImageRepShader(const gfx::ImageSkiaRep& image_rep, - SkShader::TileMode tile_mode, - const SkMatrix& local_matrix); +UI_EXPORT skia::RefPtr<SkShader> CreateImageRepShader( + const gfx::ImageSkiaRep& image_rep, + SkShader::TileMode tile_mode, + const SkMatrix& local_matrix); // Creates a vertical gradient shader. The caller owns the shader. // Example usage to avoid leaks: -// SkSafeUnref(paint.setShader(gfx::CreateGradientShader(0, 10, red, blue))); -// -// (The old shader in the paint, if any, needs to be freed, and SkSafeUnref will -// handle the NULL case.) -UI_EXPORT SkShader* CreateGradientShader(int start_point, - int end_point, - SkColor start_color, - SkColor end_color); +UI_EXPORT skia::RefPtr<SkShader> CreateGradientShader(int start_point, + int end_point, + SkColor start_color, + SkColor end_color); // Creates a draw looper to generate |shadows|. The caller owns the draw looper. // NULL is returned if |shadows| is empty since no draw looper is needed in // this case. -// Example usage to avoid leaks: -// SkSafeUnref(paint.setDrawLooper(gfx::CreateShadowDrawLooper(shadows))); -UI_EXPORT SkDrawLooper* CreateShadowDrawLooper( +UI_EXPORT skia::RefPtr<SkDrawLooper> CreateShadowDrawLooper( const std::vector<ShadowValue>& shadows); // Returns true if the two bitmaps contain the same pixels. diff --git a/ui/native_theme/native_theme_base.cc b/ui/native_theme/native_theme_base.cc index fa6151f..91a5172 100644 --- a/ui/native_theme/native_theme_base.cc +++ b/ui/native_theme/native_theme_base.cc @@ -576,12 +576,12 @@ SkRect NativeThemeBase::PaintCheckboxRadioNewCommon( else /* kNormal */ startEndColors = kCheckboxGradientColors; SkColor colors[3] = {startEndColors[0], startEndColors[0], startEndColors[1]}; - SkShader* shader = SkGradientShader::CreateLinear( - gradient_bounds, colors, NULL, 3, SkShader::kClamp_TileMode, NULL); + skia::RefPtr<SkShader> shader = skia::AdoptRef( + SkGradientShader::CreateLinear( + gradient_bounds, colors, NULL, 3, SkShader::kClamp_TileMode, NULL)); SkPaint paint; paint.setAntiAlias(true); - paint.setShader(shader); - shader->unref(); + paint.setShader(shader.get()); paint.setStyle(SkPaint::kFill_Style); canvas->drawRoundRect(skrect, borderRadius, borderRadius, paint); paint.setShader(NULL); @@ -725,12 +725,12 @@ void NativeThemeBase::PaintButton(SkCanvas* canvas, colors[0] = light_color; colors[1] = base_color; - SkShader* shader = SkGradientShader::CreateLinear( - gradient_bounds, colors, NULL, 2, SkShader::kClamp_TileMode, NULL); + skia::RefPtr<SkShader> shader = skia::AdoptRef( + SkGradientShader::CreateLinear( + gradient_bounds, colors, NULL, 2, SkShader::kClamp_TileMode, NULL)); paint.setStyle(SkPaint::kFill_Style); paint.setAntiAlias(true); - paint.setShader(shader); - shader->unref(); + paint.setShader(shader.get()); canvas->drawRoundRect(skrect, SkIntToScalar(1), SkIntToScalar(1), paint); paint.setShader(NULL); diff --git a/ui/native_theme/native_theme_win.cc b/ui/native_theme/native_theme_win.cc index 27a00a5..7ede675 100644 --- a/ui/native_theme/native_theme_win.cc +++ b/ui/native_theme/native_theme_win.cc @@ -81,16 +81,16 @@ void SetCheckerboardShader(SkPaint* paint, const RECT& align_rect) { temp_bitmap.setPixels(buffer); SkBitmap bitmap; temp_bitmap.copyTo(&bitmap, temp_bitmap.config()); - SkShader* shader = SkShader::CreateBitmapShader(bitmap, - SkShader::kRepeat_TileMode, - SkShader::kRepeat_TileMode); + skia::RefPtr<SkShader> shader = skia::AdoptRef( + SkShader::CreateBitmapShader( + bitmap, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode)); // Align the pattern with the upper corner of |align_rect|. SkMatrix matrix; matrix.setTranslate(SkIntToScalar(align_rect.left), SkIntToScalar(align_rect.top)); shader->setLocalMatrix(matrix); - SkSafeUnref(paint->setShader(shader)); + paint->setShader(shader.get()); } // <-a-> @@ -509,11 +509,11 @@ void NativeThemeWin::PaintIndirect(SkCanvas* canvas, // keeping a cache of the resulting bitmaps. // Create an offscreen canvas that is backed by an HDC. - skia::BitmapPlatformDevice* device = skia::BitmapPlatformDevice::Create( - rect.width(), rect.height(), false, NULL); + skia::RefPtr<skia::BitmapPlatformDevice> device = skia::AdoptRef( + skia::BitmapPlatformDevice::Create( + rect.width(), rect.height(), false, NULL)); DCHECK(device); - SkCanvas offscreen_canvas(device); - device->unref(); + SkCanvas offscreen_canvas(device.get()); DCHECK(skia::SupportsPlatformPaint(&offscreen_canvas)); // Some of the Windows theme drawing operations do not write correct alpha diff --git a/ui/views/controls/glow_hover_controller.cc b/ui/views/controls/glow_hover_controller.cc index 71785f0..82a25b9 100644 --- a/ui/views/controls/glow_hover_controller.cc +++ b/ui/views/controls/glow_hover_controller.cc @@ -83,16 +83,17 @@ void GlowHoverController::Draw(gfx::Canvas* canvas, static_cast<int>(255 * kOpacityScale * animation_.GetCurrentValue()); colors[0] = SkColorSetARGB(hover_alpha, 255, 255, 255); colors[1] = SkColorSetARGB(0, 255, 255, 255); - SkShader* shader = SkGradientShader::CreateRadial(center_point, - SkIntToScalar(radius), colors, NULL, 2, SkShader::kClamp_TileMode); + skia::RefPtr<SkShader> shader = skia::AdoptRef( + SkGradientShader::CreateRadial( + center_point, SkIntToScalar(radius), colors, NULL, 2, + SkShader::kClamp_TileMode)); // Shader can end up null when radius = 0. // If so, this results in default full tab glow behavior. if (shader) { SkPaint paint; paint.setStyle(SkPaint::kFill_Style); paint.setAntiAlias(true); - paint.setShader(shader); - shader->unref(); + paint.setShader(shader.get()); hover_canvas.DrawRect(gfx::Rect(location_.x() - radius, location_.y() - radius, radius * 2, radius * 2), paint); diff --git a/ui/views/controls/menu/menu_image_util.cc b/ui/views/controls/menu/menu_image_util.cc index c4545087..c0527d9 100644 --- a/ui/views/controls/menu/menu_image_util.cc +++ b/ui/views/controls/menu/menu_image_util.cc @@ -51,14 +51,14 @@ class RadioButtonImageSource : public gfx::CanvasImageSource { static_cast<int>(kIndicatorSize * kGradientStop)); gradient_points[2].iset(0, kIndicatorSize); SkColor gradient_colors[3] = { kGradient0, kGradient1, kGradient2 }; - SkShader* shader = SkGradientShader::CreateLinear( - gradient_points, gradient_colors, NULL, arraysize(gradient_points), - SkShader::kClamp_TileMode, NULL); + skia::RefPtr<SkShader> shader = skia::AdoptRef( + SkGradientShader::CreateLinear( + gradient_points, gradient_colors, NULL, arraysize(gradient_points), + SkShader::kClamp_TileMode, NULL)); SkPaint paint; paint.setStyle(SkPaint::kFill_Style); paint.setAntiAlias(true); - paint.setShader(shader); - shader->unref(); + paint.setShader(shader.get()); int radius = kIndicatorSize / 2; canvas->sk_canvas()->drawCircle(radius, radius, radius, paint); paint.setStrokeWidth(SkIntToScalar(0)); @@ -73,11 +73,12 @@ class RadioButtonImageSource : public gfx::CanvasImageSource { selected_gradient_points[1].iset(0, kSelectedIndicatorSize); SkColor selected_gradient_colors[2] = { kRadioButtonIndicatorGradient0, kRadioButtonIndicatorGradient1 }; - shader = SkGradientShader::CreateLinear( - selected_gradient_points, selected_gradient_colors, NULL, - arraysize(selected_gradient_points), SkShader::kClamp_TileMode, NULL); - paint.setShader(shader); - shader->unref(); + shader = skia::AdoptRef( + SkGradientShader::CreateLinear( + selected_gradient_points, selected_gradient_colors, NULL, + arraysize(selected_gradient_points), + SkShader::kClamp_TileMode, NULL)); + paint.setShader(shader.get()); paint.setStyle(SkPaint::kFill_Style); canvas->sk_canvas()->drawCircle(radius, radius, kSelectedIndicatorSize / 2, paint); diff --git a/ui/views/controls/progress_bar.cc b/ui/views/controls/progress_bar.cc index 1d7ad9d..cab2991 100644 --- a/ui/views/controls/progress_bar.cc +++ b/ui/views/controls/progress_bar.cc @@ -70,11 +70,9 @@ void FillRoundRect(gfx::Canvas* canvas, } else { p[1].iset(x, y + h); } - SkShader* s = SkGradientShader::CreateLinear( - p, colors, points, count, SkShader::kClamp_TileMode, NULL); - paint.setShader(s); - // Need to unref shader, otherwise never deleted. - s->unref(); + skia::RefPtr<SkShader> s = skia::AdoptRef(SkGradientShader::CreateLinear( + p, colors, points, count, SkShader::kClamp_TileMode, NULL)); + paint.setShader(s.get()); canvas->DrawPath(path, paint); } diff --git a/ui/views/painter.cc b/ui/views/painter.cc index 99c537c..85468d1 100644 --- a/ui/views/painter.cc +++ b/ui/views/painter.cc @@ -48,12 +48,11 @@ class GradientPainter : public Painter { else p[1].iset(0, size.height()); - SkShader* s = SkGradientShader::CreateLinear(p, colors_.get(), pos_.get(), - count_, SkShader::kClamp_TileMode, NULL); + skia::RefPtr<SkShader> s = skia::AdoptRef(SkGradientShader::CreateLinear( + p, colors_.get(), pos_.get(), count_, SkShader::kClamp_TileMode, NULL)); paint.setStyle(SkPaint::kFill_Style); - paint.setShader(s); + paint.setShader(s.get()); // Need to unref shader, otherwise never deleted. - s->unref(); canvas->sk_canvas()->drawRectCoords(SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(size.width()), diff --git a/ui/views/touchui/touch_selection_controller_impl.cc b/ui/views/touchui/touch_selection_controller_impl.cc index 4b06e09..a6e151b 100644 --- a/ui/views/touchui/touch_selection_controller_impl.cc +++ b/ui/views/touchui/touch_selection_controller_impl.cc @@ -253,14 +253,15 @@ class TouchSelectionControllerImpl::TouchContextMenuView points[0].iset(0, 0); points[1].iset(0, height()); - SkShader* shader = SkGradientShader::CreateLinear(points, - kGradientColors, kGradientPoints, arraysize(kGradientPoints), - SkShader::kRepeat_TileMode); + skia::RefPtr<SkShader> shader = skia::AdoptRef( + SkGradientShader::CreateLinear( + points, kGradientColors, kGradientPoints, + arraysize(kGradientPoints), + SkShader::kRepeat_TileMode)); DCHECK(shader); SkPaint paint; - paint.setShader(shader); - shader->unref(); + paint.setShader(shader.get()); paint.setStyle(SkPaint::kFill_Style); paint.setXfermodeMode(SkXfermode::kSrc_Mode); |