diff options
author | reed@google.com <reed@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-14 13:46:56 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-14 13:46:56 +0000 |
commit | 9d611ca0375cf3594423fa8571a30ed356e568f6 (patch) | |
tree | 6e04e592faf658dd786ea2cb1115af7ac7247124 /ui/gfx | |
parent | bd3db410a3334cbcbd50247306d286326003eb2c (diff) | |
download | chromium_src-9d611ca0375cf3594423fa8571a30ed356e568f6.zip chromium_src-9d611ca0375cf3594423fa8571a30ed356e568f6.tar.gz chromium_src-9d611ca0375cf3594423fa8571a30ed356e568f6.tar.bz2 |
Simplify platform_canvas.h by recognizing that PlatformCanvas does not actually extend
SkCanvas in any way, other than provide a host of constructors (and delayed constructors
in the form of 'initialize' methods).
These late initializers are a problem, as SkCanvas is deprecating its setDevice() call,
moving to model where the backingstore/device for the canvas must be created before the
canvas is created. This is necessary to allow skia to continue to extend SkCanvas for
its backends (e.g. GPU, PDF, Picture, Pipe, etc.).
The practical change in this CL is to make PlatformCanvas just a typedef for SkCanvas,
and change the call-sites that want to call initialize() to instead create the canvas
using one of the provided Factory functions (e.g. CreatePlatformCanvas). The modifier
Platform is maintained, to document that this canvas may be backed by platform-specific
pixels (e.g. allocated by GDI or cairo).
Review URL: https://codereview.chromium.org/11138024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@167669 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx')
-rw-r--r-- | ui/gfx/blit_unittest.cc | 48 | ||||
-rw-r--r-- | ui/gfx/canvas.cc | 16 | ||||
-rw-r--r-- | ui/gfx/canvas_paint_gtk.cc | 9 | ||||
-rw-r--r-- | ui/gfx/canvas_paint_win.h | 12 | ||||
-rw-r--r-- | ui/gfx/image/image_skia_operations.cc | 10 |
5 files changed, 49 insertions, 46 deletions
diff --git a/ui/gfx/blit_unittest.cc b/ui/gfx/blit_unittest.cc index a0c4de9..1d59d9b 100644 --- a/ui/gfx/blit_unittest.cc +++ b/ui/gfx/blit_unittest.cc @@ -61,78 +61,78 @@ void VerifyCanvasValues(skia::PlatformCanvas* canvas, uint8 values[h][w]) { TEST(Blit, ScrollCanvas) { static const int kCanvasWidth = 5; static const int kCanvasHeight = 5; - skia::PlatformCanvas canvas(kCanvasWidth, kCanvasHeight, true); + skia::ScopedPlatformCanvas canvas(kCanvasWidth, kCanvasHeight, true); uint8 initial_values[kCanvasHeight][kCanvasWidth] = { { 0x00, 0x01, 0x02, 0x03, 0x04 }, { 0x10, 0x11, 0x12, 0x13, 0x14 }, { 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, initial_values); // Sanity check on input. - VerifyCanvasValues<5, 5>(&canvas, initial_values); + VerifyCanvasValues<5, 5>(canvas, initial_values); // Scroll none and make sure it's a NOP. - gfx::ScrollCanvas(&canvas, + gfx::ScrollCanvas(canvas, gfx::Rect(0, 0, kCanvasWidth, kCanvasHeight), gfx::Vector2d(0, 0)); - VerifyCanvasValues<5, 5>(&canvas, initial_values); + VerifyCanvasValues<5, 5>(canvas, initial_values); // Scroll the center 3 pixels up one. gfx::Rect center_three(1, 1, 3, 3); - gfx::ScrollCanvas(&canvas, center_three, gfx::Vector2d(0, -1)); + gfx::ScrollCanvas(canvas, center_three, gfx::Vector2d(0, -1)); uint8 scroll_up_expected[kCanvasHeight][kCanvasWidth] = { { 0x00, 0x01, 0x02, 0x03, 0x04 }, { 0x10, 0x21, 0x22, 0x23, 0x14 }, { 0x20, 0x31, 0x32, 0x33, 0x24 }, { 0x30, 0x31, 0x32, 0x33, 0x34 }, { 0x40, 0x41, 0x42, 0x43, 0x44 }}; - VerifyCanvasValues<5, 5>(&canvas, scroll_up_expected); + VerifyCanvasValues<5, 5>(canvas, scroll_up_expected); // Reset and scroll the center 3 pixels down one. - SetToCanvas<5, 5>(&canvas, initial_values); - gfx::ScrollCanvas(&canvas, center_three, gfx::Vector2d(0, 1)); + SetToCanvas<5, 5>(canvas, initial_values); + gfx::ScrollCanvas(canvas, center_three, gfx::Vector2d(0, 1)); uint8 scroll_down_expected[kCanvasHeight][kCanvasWidth] = { { 0x00, 0x01, 0x02, 0x03, 0x04 }, { 0x10, 0x11, 0x12, 0x13, 0x14 }, { 0x20, 0x11, 0x12, 0x13, 0x24 }, { 0x30, 0x21, 0x22, 0x23, 0x34 }, { 0x40, 0x41, 0x42, 0x43, 0x44 }}; - VerifyCanvasValues<5, 5>(&canvas, scroll_down_expected); + VerifyCanvasValues<5, 5>(canvas, scroll_down_expected); // Reset and scroll the center 3 pixels right one. - SetToCanvas<5, 5>(&canvas, initial_values); - gfx::ScrollCanvas(&canvas, center_three, gfx::Vector2d(1, 0)); + SetToCanvas<5, 5>(canvas, initial_values); + gfx::ScrollCanvas(canvas, center_three, gfx::Vector2d(1, 0)); uint8 scroll_right_expected[kCanvasHeight][kCanvasWidth] = { { 0x00, 0x01, 0x02, 0x03, 0x04 }, { 0x10, 0x11, 0x11, 0x12, 0x14 }, { 0x20, 0x21, 0x21, 0x22, 0x24 }, { 0x30, 0x31, 0x31, 0x32, 0x34 }, { 0x40, 0x41, 0x42, 0x43, 0x44 }}; - VerifyCanvasValues<5, 5>(&canvas, scroll_right_expected); + VerifyCanvasValues<5, 5>(canvas, scroll_right_expected); // Reset and scroll the center 3 pixels left one. - SetToCanvas<5, 5>(&canvas, initial_values); - gfx::ScrollCanvas(&canvas, center_three, gfx::Vector2d(-1, 0)); + SetToCanvas<5, 5>(canvas, initial_values); + gfx::ScrollCanvas(canvas, center_three, gfx::Vector2d(-1, 0)); uint8 scroll_left_expected[kCanvasHeight][kCanvasWidth] = { { 0x00, 0x01, 0x02, 0x03, 0x04 }, { 0x10, 0x12, 0x13, 0x13, 0x14 }, { 0x20, 0x22, 0x23, 0x23, 0x24 }, { 0x30, 0x32, 0x33, 0x33, 0x34 }, { 0x40, 0x41, 0x42, 0x43, 0x44 }}; - VerifyCanvasValues<5, 5>(&canvas, scroll_left_expected); + VerifyCanvasValues<5, 5>(canvas, scroll_left_expected); // Diagonal scroll. - SetToCanvas<5, 5>(&canvas, initial_values); - gfx::ScrollCanvas(&canvas, center_three, gfx::Vector2d(2, 2)); + SetToCanvas<5, 5>(canvas, initial_values); + gfx::ScrollCanvas(canvas, center_three, gfx::Vector2d(2, 2)); uint8 scroll_diagonal_expected[kCanvasHeight][kCanvasWidth] = { { 0x00, 0x01, 0x02, 0x03, 0x04 }, { 0x10, 0x11, 0x12, 0x13, 0x14 }, { 0x20, 0x21, 0x22, 0x23, 0x24 }, { 0x30, 0x31, 0x32, 0x11, 0x34 }, { 0x40, 0x41, 0x42, 0x43, 0x44 }}; - VerifyCanvasValues<5, 5>(&canvas, scroll_diagonal_expected); + VerifyCanvasValues<5, 5>(canvas, scroll_diagonal_expected); } #if defined(OS_WIN) @@ -140,11 +140,13 @@ TEST(Blit, ScrollCanvas) { TEST(Blit, WithSharedMemory) { const int kCanvasWidth = 5; const int kCanvasHeight = 5; - skia::PlatformCanvas canvas; base::SharedMemory shared_mem; ASSERT_TRUE(shared_mem.CreateAnonymous(kCanvasWidth * kCanvasHeight)); base::SharedMemoryHandle section = shared_mem.handle(); - ASSERT_TRUE(canvas.initialize(kCanvasWidth, kCanvasHeight, true, section)); + SkCanvas* canvas = skia::CreatePlatformCanvas(kCanvasWidth, kCanvasHeight, + true, section, skia::RETURN_NULL_ON_FAILURE); + ASSERT_TRUE(NULL != canvas); + SkAutoUnref aur(canvas); shared_mem.Close(); uint8 initial_values[kCanvasHeight][kCanvasWidth] = { @@ -153,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, initial_values); // Sanity check on input. - VerifyCanvasValues<5, 5>(&canvas, initial_values); + VerifyCanvasValues<5, 5>(canvas, initial_values); } #endif diff --git a/ui/gfx/canvas.cc b/ui/gfx/canvas.cc index eb11b37..831f4fc 100644 --- a/ui/gfx/canvas.cc +++ b/ui/gfx/canvas.cc @@ -31,9 +31,9 @@ Canvas::Canvas(const gfx::Size& size, canvas_(NULL) { gfx::Size pixel_size = gfx::ToFlooredSize( gfx::ScaleSize(size, ui::GetScaleFactorScale(scale_factor))); - owned_canvas_.reset(new skia::PlatformCanvas(pixel_size.width(), - pixel_size.height(), - is_opaque)); + owned_canvas_.reset(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,7 +48,7 @@ Canvas::Canvas(const gfx::Size& size, Canvas::Canvas(const gfx::ImageSkiaRep& image_rep, bool is_opaque) : scale_factor_(image_rep.scale_factor()), - owned_canvas_(new skia::PlatformCanvas(image_rep.pixel_width(), + owned_canvas_(skia::CreatePlatformCanvas(image_rep.pixel_width(), image_rep.pixel_height(), is_opaque)), canvas_(owned_canvas_.get()) { @@ -59,7 +59,7 @@ Canvas::Canvas(const gfx::ImageSkiaRep& image_rep, bool is_opaque) Canvas::Canvas() : scale_factor_(ui::SCALE_FACTOR_100P), - owned_canvas_(new skia::PlatformCanvas()), + owned_canvas_(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(new skia::PlatformCanvas(pixel_size.width(), - pixel_size.height(), - is_opaque)); + owned_canvas_.reset(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); diff --git a/ui/gfx/canvas_paint_gtk.cc b/ui/gfx/canvas_paint_gtk.cc index ded981b..4c185c0 100644 --- a/ui/gfx/canvas_paint_gtk.cc +++ b/ui/gfx/canvas_paint_gtk.cc @@ -52,13 +52,10 @@ CanvasSkiaPaint::~CanvasSkiaPaint() { void CanvasSkiaPaint::Init(bool opaque) { GdkRectangle bounds = rectangle(); + RecreateBackingCanvas(gfx::Size(bounds.width, bounds.height), + ui::SCALE_FACTOR_100P, opaque); + skia::PlatformCanvas* canvas = platform_canvas(); - if (!canvas->initialize(bounds.width, bounds.height, opaque, NULL)) { - // Cause a deliberate crash; - CHECK(false); - } - // No need to clear the canvas, because cairo automatically performs the - // clear. // Need to translate so that the dirty region appears at the origin of the // surface. diff --git a/ui/gfx/canvas_paint_win.h b/ui/gfx/canvas_paint_win.h index 8a146e1..1316b96 100644 --- a/ui/gfx/canvas_paint_win.h +++ b/ui/gfx/canvas_paint_win.h @@ -8,6 +8,7 @@ #include "skia/ext/platform_canvas.h" #include "ui/gfx/canvas.h" #include "ui/gfx/canvas_paint.h" +#include "ui/gfx/size.h" namespace gfx { @@ -102,18 +103,17 @@ class UI_EXPORT CanvasSkiaPaint : public Canvas { } void init(bool opaque) { - skia::PlatformCanvas* canvas = platform_canvas(); // FIXME(brettw) for ClearType, we probably want to expand the bounds of // painting by one pixel so that the boundaries will be correct (ClearType // text can depend on the adjacent pixel). Then we would paint just the // inset pixels to the screen. const int width = ps_.rcPaint.right - ps_.rcPaint.left; const int height = ps_.rcPaint.bottom - ps_.rcPaint.top; - if (!canvas->initialize(width, height, opaque, NULL)) { - // Cause a deliberate crash; - __debugbreak(); - _exit(1); - } + + RecreateBackingCanvas(gfx::Size(width, height), ui::SCALE_FACTOR_100P, + opaque); + skia::PlatformCanvas* canvas = platform_canvas(); + canvas->clear(SkColorSetARGB(0, 0, 0, 0)); // This will bring the canvas into the screen coordinate system for the diff --git a/ui/gfx/image/image_skia_operations.cc b/ui/gfx/image/image_skia_operations.cc index 878d9d2..db80e0b 100644 --- a/ui/gfx/image/image_skia_operations.cc +++ b/ui/gfx/image/image_skia_operations.cc @@ -7,7 +7,6 @@ #include "base/command_line.h" #include "base/logging.h" #include "skia/ext/image_operations.h" -#include "skia/ext/platform_canvas.h" #include "ui/base/layout.h" #include "ui/gfx/canvas.h" #include "ui/gfx/image/canvas_image_source.h" @@ -35,10 +34,15 @@ bool ScalingEnabled() { // Creates 2x scaled image of the give |source|. ImageSkiaRep Create2XImageSkiaRep(const ImageSkiaRep& source) { gfx::Size size(source.GetWidth() * 2.0f, source.GetHeight() * 2.0f); - skia::PlatformCanvas canvas(size.width(), size.height(), false); + + SkBitmap resized_bitmap; + resized_bitmap.setConfig(SkBitmap::kARGB_8888_Config, size.width(), + size.height()); + if (!resized_bitmap.allocPixels()) + SK_CRASH(); + SkCanvas canvas(resized_bitmap); SkRect resized_bounds = RectToSkRect(gfx::Rect(size)); canvas.drawBitmapRect(source.sk_bitmap(), NULL, resized_bounds); - SkBitmap resized_bitmap = canvas.getDevice()->accessBitmap(false); return ImageSkiaRep(resized_bitmap, ui::SCALE_FACTOR_200P); } |