Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(477)

Unified Diff: cc/playback/display_list_raster_source_unittest.cc

Issue 1673193002: HBitmap can't be immutable Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | cc/test/fake_content_layer_client.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/playback/display_list_raster_source_unittest.cc
diff --git a/cc/playback/display_list_raster_source_unittest.cc b/cc/playback/display_list_raster_source_unittest.cc
index 2cf6f0694b43d3134840a732a96c9045e77572d8..c32e016afeda40034dced551933aaa7c919e2c8b 100644
--- a/cc/playback/display_list_raster_source_unittest.cc
+++ b/cc/playback/display_list_raster_source_unittest.cc
@@ -8,6 +8,7 @@
#include "cc/playback/display_list_raster_source.h"
#include "cc/test/fake_display_list_recording_source.h"
#include "cc/test/skia_common.h"
+#include "skia/ext/platform_canvas.h"
#include "skia/ext/refptr.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkPixelRef.h"
@@ -544,5 +545,74 @@ TEST(DisplayListRasterSourceTest,
EXPECT_LT(total_memory_usage, 2 * kReportedMemoryUsageInBytes);
}
+class BadPainter : public FakeOnPaintDelegate {
+ public:
+ BadPainter() {}
+ void OnPaint(SkCanvas* canvas,
+ const gfx::Rect& invalidation) override {
+ skia::RefPtr<SkCanvas> temp_canvas =
+ skia::AdoptRef(
+ skia::CreatePlatformCanvas(invalidation.width(),
+ invalidation.height(),
+ false));
+ SkPaint bkgnd_paint;
+ bkgnd_paint.setColor(SK_ColorBLACK);
+ SkRect rect = gfx::RectToSkRect(invalidation);
+ temp_canvas->drawRect(rect, bkgnd_paint);
+ SkPixmap pixmap;
+ skia::GetWritablePixels(temp_canvas.get(), &pixmap);
+
+ bool is_odd = false;
+ for (int cur_y = 0; cur_y < pixmap.height(); cur_y++) {
+ uint32_t* text_row = pixmap.writable_addr32(0, cur_y);
+ for (int cur_x = 0; cur_x < pixmap.width(); cur_x++) {
+ if (is_odd)
+ text_row[cur_x] = SK_ColorRED;
+ is_odd = !is_odd;
+ }
+ }
+
+ SkBitmap bitmap;
+ bitmap.installPixels(pixmap.info(),
+ pixmap.writable_addr(),
+ pixmap.rowBytes());
+ // HBitmap can't be immutable!
+ // bitmap.setImmutable();
+ canvas->drawBitmap(bitmap, 0, 0);
+ }
+};
+
+TEST(DisplayListRasterSourceTest, TemporaryBitmapRaster) {
+ gfx::Size layer_bounds(10, 10);
+
+ scoped_ptr<FakeDisplayListRecordingSource> recording_source =
+ FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds);
+ recording_source->SetBackgroundColor(SK_ColorTRANSPARENT);
+ recording_source->SetRequiresClear(true);
+ recording_source->SetClearCanvasWithDebugColor(false);
+ recording_source->set_on_paint_delegate(make_scoped_ptr(new BadPainter));
+ recording_source->Rerecord();
+
+ scoped_refptr<DisplayListRasterSource> raster =
+ DisplayListRasterSource::CreateFromDisplayListRecordingSource(
+ recording_source.get(), false);
+
+ SkBitmap bitmap;
+ bitmap.allocN32Pixels(layer_bounds.width(), layer_bounds.height());
+ SkCanvas canvas(bitmap);
+
+ gfx::Rect canvas_rect(layer_bounds);
+ raster->PlaybackToCanvas(&canvas, canvas_rect, canvas_rect, 1.0f);
+
+ SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels());
+ int num_pixels = bitmap.width() * bitmap.height();
+ for (int i = 0; i < num_pixels; ++i) {
+ if (i % 2 == 0)
+ EXPECT_EQ(SK_ColorBLACK, pixels[i]);
+ else
+ EXPECT_EQ(SK_ColorRED, pixels[i]);
+ }
+}
+
} // namespace
} // namespace cc
« no previous file with comments | « no previous file | cc/test/fake_content_layer_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698