Commit 80f046dd authored by vmpstr's avatar vmpstr Committed by Commit bot

This patch removes readPixels from PaintCanvas.

Most of the changes replace canvas read pixels call in favor
of first getting the bitmap, and then doing a readpixels on that.

CQ_INCLUDE_TRYBOTS=master.tryserver.blink:linux_trusty_blink_rel

Review-Url: https://codereview.chromium.org/2792133002
Cr-Commit-Position: refs/heads/master@{#462984}
parent 24d1d608
...@@ -165,18 +165,15 @@ class WallpaperControllerTest : public test::AshTestBase { ...@@ -165,18 +165,15 @@ class WallpaperControllerTest : public test::AshTestBase {
gfx::Canvas canvas(size, device_scale_factor, true); gfx::Canvas canvas(size, device_scale_factor, true);
view->OnPaint(&canvas); view->OnPaint(&canvas);
int canvas_width = canvas.sk_canvas()->imageInfo().width(); SkBitmap bitmap = canvas.GetBitmap();
int canvas_height = canvas.sk_canvas()->imageInfo().height(); int bitmap_width = bitmap.width();
SkBitmap bitmap; int bitmap_height = bitmap.height();
bitmap.allocN32Pixels(canvas_width, canvas_height); for (int i = 0; i < bitmap_width; i++) {
canvas.sk_canvas()->readPixels(&bitmap, 0, 0); for (int j = 0; j < bitmap_height; j++) {
if (i >= (bitmap_width - image_width) / 2 &&
for (int i = 0; i < canvas_width; i++) { i < (bitmap_width + image_width) / 2 &&
for (int j = 0; j < canvas_height; j++) { j >= (bitmap_height - image_height) / 2 &&
if (i >= (canvas_width - image_width) / 2 && j < (bitmap_height + image_height) / 2) {
i < (canvas_width + image_width) / 2 &&
j >= (canvas_height - image_height) / 2 &&
j < (canvas_height + image_height) / 2) {
EXPECT_EQ(color, bitmap.getColor(i, j)); EXPECT_EQ(color, bitmap.getColor(i, j));
} else { } else {
EXPECT_EQ(SK_ColorBLACK, bitmap.getColor(i, j)); EXPECT_EQ(SK_ColorBLACK, bitmap.getColor(i, j));
......
...@@ -568,7 +568,7 @@ void LaserPointerView::UpdateBuffer() { ...@@ -568,7 +568,7 @@ void LaserPointerView::UpdateBuffer() {
gfx::ScaleToEnclosingRect(update_rect, scale_factor_); gfx::ScaleToEnclosingRect(update_rect, scale_factor_);
uint8_t* data = static_cast<uint8_t*>(gpu_memory_buffer_->memory(0)); uint8_t* data = static_cast<uint8_t*>(gpu_memory_buffer_->memory(0));
int stride = gpu_memory_buffer_->stride(0); int stride = gpu_memory_buffer_->stride(0);
canvas.sk_canvas()->readPixels( canvas.GetBitmap().readPixels(
SkImageInfo::MakeN32Premul(pixel_rect.width(), pixel_rect.height()), SkImageInfo::MakeN32Premul(pixel_rect.width(), pixel_rect.height()),
data + pixel_rect.y() * stride + pixel_rect.x() * 4, stride, 0, 0); data + pixel_rect.y() * stride + pixel_rect.x() * 4, stride, 0, 0);
} }
......
...@@ -34,13 +34,6 @@ class CC_PAINT_EXPORT PaintCanvas { ...@@ -34,13 +34,6 @@ class CC_PAINT_EXPORT PaintCanvas {
virtual void flush() = 0; virtual void flush() = 0;
virtual SkISize getBaseLayerSize() const = 0; virtual SkISize getBaseLayerSize() const = 0;
virtual bool readPixels(const SkImageInfo& dest_info,
void* dest_pixels,
size_t dest_row_bytes,
int src_x,
int src_y) = 0;
virtual bool readPixels(SkBitmap* bitmap, int src_x, int src_y) = 0;
virtual bool readPixels(const SkIRect& srcRect, SkBitmap* bitmap) = 0;
virtual bool writePixels(const SkImageInfo& info, virtual bool writePixels(const SkImageInfo& info,
const void* pixels, const void* pixels,
size_t row_bytes, size_t row_bytes,
......
...@@ -42,23 +42,6 @@ SkISize SkiaPaintCanvas::getBaseLayerSize() const { ...@@ -42,23 +42,6 @@ SkISize SkiaPaintCanvas::getBaseLayerSize() const {
return canvas_->getBaseLayerSize(); return canvas_->getBaseLayerSize();
} }
bool SkiaPaintCanvas::readPixels(const SkImageInfo& dest_info,
void* dest_pixels,
size_t dest_row_bytes,
int src_x,
int src_y) {
return canvas_->readPixels(dest_info, dest_pixels, dest_row_bytes, src_x,
src_y);
}
bool SkiaPaintCanvas::readPixels(SkBitmap* bitmap, int src_x, int src_y) {
return canvas_->readPixels(bitmap, src_x, src_y);
}
bool SkiaPaintCanvas::readPixels(const SkIRect& srcRect, SkBitmap* bitmap) {
return canvas_->readPixels(srcRect, bitmap);
}
bool SkiaPaintCanvas::writePixels(const SkImageInfo& info, bool SkiaPaintCanvas::writePixels(const SkImageInfo& info,
const void* pixels, const void* pixels,
size_t row_bytes, size_t row_bytes,
......
...@@ -39,13 +39,6 @@ class CC_PAINT_EXPORT SkiaPaintCanvas final : public PaintCanvas { ...@@ -39,13 +39,6 @@ class CC_PAINT_EXPORT SkiaPaintCanvas final : public PaintCanvas {
void flush() override; void flush() override;
SkISize getBaseLayerSize() const override; SkISize getBaseLayerSize() const override;
bool readPixels(const SkImageInfo& dest_info,
void* dest_pixels,
size_t dest_row_bytes,
int src_x,
int src_y) override;
bool readPixels(SkBitmap* bitmap, int src_x, int src_y) override;
bool readPixels(const SkIRect& srcRect, SkBitmap* bitmap) override;
bool writePixels(const SkImageInfo& info, bool writePixels(const SkImageInfo& info,
const void* pixels, const void* pixels,
size_t row_bytes, size_t row_bytes,
......
...@@ -104,15 +104,14 @@ int Canvas::DefaultCanvasTextAlignment() { ...@@ -104,15 +104,14 @@ int Canvas::DefaultCanvasTextAlignment() {
} }
ImageSkiaRep Canvas::ExtractImageRep() const { ImageSkiaRep Canvas::ExtractImageRep() const {
// Make a bitmap to return, and a canvas to draw into it. We don't just want DCHECK(bitmap_);
// to call extractSubset or the copy constructor, since we want an actual copy SkBitmap bitmap_copy;
// of the bitmap. // copyTo() will perform a deep copy, which is what we want.
const SkISize size = canvas_->getBaseLayerSize(); bool result = bitmap_->copyTo(&bitmap_copy);
SkBitmap result; // This should succeed since the destination bitmap is empty to begin with.
result.allocN32Pixels(size.width(), size.height()); // The only failure is an allocation failure, which we want to DCHECK anyway.
DCHECK(result);
canvas_->readPixels(&result, 0, 0); return ImageSkiaRep(bitmap_copy, image_scale_);
return ImageSkiaRep(result, image_scale_);
} }
void Canvas::DrawDashedRect(const Rect& rect, SkColor color) { void Canvas::DrawDashedRect(const Rect& rect, SkColor color) {
......
...@@ -132,10 +132,7 @@ class NotificationViewTest : public views::ViewsTestBase, ...@@ -132,10 +132,7 @@ class NotificationViewTest : public views::ViewsTestBase,
canvas.DrawColor(SK_ColorBLACK); canvas.DrawColor(SK_ColorBLACK);
view->OnPaint(&canvas); view->OnPaint(&canvas);
SkBitmap bitmap; SkBitmap bitmap = canvas.GetBitmap();
bitmap.allocN32Pixels(canvas_size.width(), canvas_size.height());
canvas.sk_canvas()->readPixels(&bitmap, 0, 0);
// Incrementally inset each edge at its midpoint to find the bounds of the // Incrementally inset each edge at its midpoint to find the bounds of the
// rect containing the image's color. This assumes that the image is // rect containing the image's color. This assumes that the image is
// centered in the canvas. // centered in the canvas.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment