From a59147554aaa82da73512da5f9d61e9265d54bc0 Mon Sep 17 00:00:00 2001 From: danakj Date: Tue, 7 Apr 2015 11:10:33 -0700 Subject: [PATCH] ash: Access the Canvas for painting through PaintRecorder. The PaintContext will not be backed by a Canvas in the future, so do not grab the canvas from it directly. Instead use a PaintRecorder. R=oshima BUG=466426 Review URL: https://codereview.chromium.org/1062003003 Cr-Commit-Position: refs/heads/master@{#324071} --- ash/utility/partial_screenshot_controller.cc | 7 +++--- ash/wm/boot_splash_screen_chromeos.cc | 4 +++- ash/wm/dock/docked_window_layout_manager.cc | 36 ++++++++++------------------ 3 files changed, 19 insertions(+), 28 deletions(-) diff --git a/ash/utility/partial_screenshot_controller.cc b/ash/utility/partial_screenshot_controller.cc index 466432c57a31..661d40565411 100644 --- a/ash/utility/partial_screenshot_controller.cc +++ b/ash/utility/partial_screenshot_controller.cc @@ -11,6 +11,7 @@ #include "ash/shell_window_ids.h" #include "base/stl_util.h" #include "ui/compositor/paint_context.h" +#include "ui/compositor/paint_recorder.h" #include "ui/events/event_handler.h" #include "ui/gfx/canvas.h" #include "ui/wm/core/cursor_manager.h" @@ -61,15 +62,15 @@ class PartialScreenshotController::PartialScreenshotLayer if (region_.IsEmpty()) return; - gfx::Canvas* canvas = context.canvas(); // Screenshot area representation: black rectangle with white // rectangle inside. To avoid capturing these rectangles when mouse // release, they should be outside of the actual capturing area. + ui::PaintRecorder recorder(context); gfx::Rect rect(region_); rect.Inset(-1, -1); - canvas->DrawRect(rect, SK_ColorWHITE); + recorder.canvas()->DrawRect(rect, SK_ColorWHITE); rect.Inset(-1, -1); - canvas->DrawRect(rect, SK_ColorBLACK); + recorder.canvas()->DrawRect(rect, SK_ColorBLACK); } void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} diff --git a/ash/wm/boot_splash_screen_chromeos.cc b/ash/wm/boot_splash_screen_chromeos.cc index 04d66c301411..0c3cb541c5f0 100644 --- a/ash/wm/boot_splash_screen_chromeos.cc +++ b/ash/wm/boot_splash_screen_chromeos.cc @@ -11,6 +11,7 @@ #include "ui/compositor/layer.h" #include "ui/compositor/layer_type.h" #include "ui/compositor/paint_context.h" +#include "ui/compositor/paint_recorder.h" #include "ui/compositor/scoped_layer_animation_settings.h" #include "ui/gfx/canvas.h" @@ -36,8 +37,9 @@ class BootSplashScreen::CopyHostContentLayerDelegate // to create a zero-copy texture (when possible): // https://codereview.chromium.org/10543125 #if defined(USE_X11) + ui::PaintRecorder recorder(context); ui::CopyAreaToCanvas(host_->GetAcceleratedWidget(), host_->GetBounds(), - gfx::Point(), context.canvas()); + gfx::Point(), recorder.canvas()); #else // TODO(spang): Figure out what to do here. NOTIMPLEMENTED(); diff --git a/ash/wm/dock/docked_window_layout_manager.cc b/ash/wm/dock/docked_window_layout_manager.cc index 9945fa57556e..684519597895 100644 --- a/ash/wm/dock/docked_window_layout_manager.cc +++ b/ash/wm/dock/docked_window_layout_manager.cc @@ -32,6 +32,7 @@ #include "ui/aura/window_event_dispatcher.h" #include "ui/base/resource/resource_bundle.h" #include "ui/compositor/paint_context.h" +#include "ui/compositor/paint_recorder.h" #include "ui/compositor/scoped_layer_animation_settings.h" #include "ui/gfx/canvas.h" #include "ui/gfx/geometry/rect.h" @@ -94,38 +95,25 @@ class DockedBackgroundWidget : public views::Widget, } void OnNativeWidgetPaint(const ui::PaintContext& context) override { - gfx::Canvas* canvas = context.canvas(); + ui::PaintRecorder recorder(context); const gfx::ImageSkia& shelf_background( alignment_ == DOCKED_ALIGNMENT_LEFT ? shelf_background_left_ : shelf_background_right_); gfx::Rect rect = gfx::Rect(GetWindowBoundsInScreen().size()); SkPaint paint; paint.setAlpha(alpha_); - canvas->DrawImageInt(shelf_background, - 0, - 0, - shelf_background.width(), - shelf_background.height(), - alignment_ == DOCKED_ALIGNMENT_LEFT - ? rect.width() - shelf_background.width() - : 0, - 0, - shelf_background.width(), - rect.height(), - false, - paint); - canvas->DrawImageInt( + recorder.canvas()->DrawImageInt( + shelf_background, 0, 0, shelf_background.width(), + shelf_background.height(), alignment_ == DOCKED_ALIGNMENT_LEFT + ? rect.width() - shelf_background.width() + : 0, + 0, shelf_background.width(), rect.height(), false, paint); + recorder.canvas()->DrawImageInt( shelf_background, alignment_ == DOCKED_ALIGNMENT_LEFT ? 0 : shelf_background.width() - 1, - 0, - 1, - shelf_background.height(), - alignment_ == DOCKED_ALIGNMENT_LEFT ? 0 : shelf_background.width(), - 0, - rect.width() - shelf_background.width(), - rect.height(), - false, - paint); + 0, 1, shelf_background.height(), + alignment_ == DOCKED_ALIGNMENT_LEFT ? 0 : shelf_background.width(), 0, + rect.width() - shelf_background.width(), rect.height(), false, paint); } // BackgroundAnimatorDelegate: -- 2.11.4.GIT