-TEST_F(DriSurfaceTest, CheckCorrectBufferSync) {
- EXPECT_TRUE(surface_->Initialize());
-
- SkCanvas* canvas = surface_->GetDrawableForWidget();
- SkRect clip;
- // Modify part of the canvas.
- clip.set(0, 0,
- canvas->getDeviceSize().width() / 2,
- canvas->getDeviceSize().height() / 2);
- canvas->clipRect(clip, SkRegion::kReplace_Op);
-
- canvas->drawColor(SK_ColorWHITE);
-
- surface_->SwapBuffers();
-
- // Verify that the modified contents have been copied over on swap (make sure
- // the 2 buffers have the same content).
- for (int i = 0; i < canvas->getDeviceSize().height(); ++i) {
- for (int j = 0; j < canvas->getDeviceSize().width(); ++j) {
- if (i < clip.height() && j < clip.width())
- EXPECT_EQ(SK_ColorWHITE,
- canvas->getDevice()->accessBitmap(false).getColor(j, i));
+TEST_F(DriSurfaceTest, CheckSurfaceContents) {
+ SkPaint paint;
+ paint.setColor(SK_ColorWHITE);
+ SkRect rect = SkRect::MakeWH(kDefaultMode.hdisplay / 2,
+ kDefaultMode.vdisplay / 2);
+ surface_->GetCanvas()->drawRect(rect, paint);
+ surface_->PresentCanvas(
+ gfx::Rect(0, 0, kDefaultMode.hdisplay / 2, kDefaultMode.vdisplay / 2));
+
+ SkBitmap image;
+ // Buffer 0 is the buffer used in SetUp for modesetting and buffer 1 is the
+ // frontbuffer.
+ // Buffer 2 is the backbuffer we just painted in, so we want to make sure its
+ // contents are correct.
+ image.setInfo(drm_->buffers()[2]->getCanvas()->imageInfo());
+ EXPECT_TRUE(drm_->buffers()[2]->getCanvas()->readPixels(&image, 0, 0));
+
+ EXPECT_EQ(kDefaultMode.hdisplay, image.width());
+ EXPECT_EQ(kDefaultMode.vdisplay, image.height());
+
+ // Make sure the updates are correctly propagated to the native surface.
+ for (int i = 0; i < image.height(); ++i) {
+ for (int j = 0; j < image.width(); ++j) {
+ if (j < kDefaultMode.hdisplay / 2 && i < kDefaultMode.vdisplay / 2)
+ EXPECT_EQ(SK_ColorWHITE, image.getColor(j, i));