| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
| 7 #include "cc/output/software_frame_data.h" | 7 #include "cc/output/software_frame_data.h" |
| 8 #include "content/browser/compositor/software_output_device_ozone.h" | 8 #include "content/browser/compositor/software_output_device_ozone.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "third_party/skia/include/core/SkSurface.h" | 10 #include "third_party/skia/include/core/SkSurface.h" |
| 11 #include "ui/compositor/compositor.h" | 11 #include "ui/compositor/compositor.h" |
| 12 #include "ui/compositor/test/context_factories_for_test.h" | 12 #include "ui/compositor/test/context_factories_for_test.h" |
| 13 #include "ui/gfx/ozone/surface_factory_ozone.h" | 13 #include "ui/gfx/ozone/surface_factory_ozone.h" |
| 14 #include "ui/gfx/ozone/surface_ozone_canvas.h" | 14 #include "ui/gfx/ozone/surface_ozone_canvas.h" |
| 15 #include "ui/gfx/size.h" | 15 #include "ui/gfx/size.h" |
| 16 #include "ui/gfx/skia_util.h" | 16 #include "ui/gfx/skia_util.h" |
| 17 #include "ui/gfx/vsync_provider.h" | 17 #include "ui/gfx/vsync_provider.h" |
| 18 #include "ui/gl/gl_implementation.h" | 18 #include "ui/gl/gl_implementation.h" |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 class MockSurfaceOzone : public gfx::SurfaceOzoneCanvas { | 22 class MockSurfaceOzone : public gfx::SurfaceOzoneCanvas { |
| 23 public: | 23 public: |
| 24 MockSurfaceOzone() {} | 24 MockSurfaceOzone() {} |
| 25 virtual ~MockSurfaceOzone() {} | 25 virtual ~MockSurfaceOzone() {} |
| 26 | 26 |
| 27 // gfx::SurfaceOzoneCanvas overrides: | 27 // gfx::SurfaceOzoneCanvas overrides: |
| 28 virtual bool ResizeCanvas(const gfx::Size& size) OVERRIDE { | 28 virtual void ResizeCanvas(const gfx::Size& size) OVERRIDE { |
| 29 surface_ = skia::AdoptRef(SkSurface::NewRaster( | 29 surface_ = skia::AdoptRef(SkSurface::NewRaster( |
| 30 SkImageInfo::MakeN32Premul(size.width(), size.height()))); | 30 SkImageInfo::MakeN32Premul(size.width(), size.height()))); |
| 31 return true; | |
| 32 } | 31 } |
| 33 virtual skia::RefPtr<SkCanvas> GetCanvas() OVERRIDE { | 32 virtual skia::RefPtr<SkCanvas> GetCanvas() OVERRIDE { |
| 34 return skia::SharePtr(surface_->getCanvas()); | 33 return skia::SharePtr(surface_->getCanvas()); |
| 35 } | 34 } |
| 36 virtual bool PresentCanvas() OVERRIDE { | 35 virtual void PresentCanvas(const gfx::Rect& damage) OVERRIDE {} |
| 37 NOTIMPLEMENTED(); | |
| 38 return true; | |
| 39 } | |
| 40 virtual scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() OVERRIDE { | 36 virtual scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() OVERRIDE { |
| 41 return scoped_ptr<gfx::VSyncProvider>(); | 37 return scoped_ptr<gfx::VSyncProvider>(); |
| 42 } | 38 } |
| 43 | 39 |
| 44 private: | 40 private: |
| 45 skia::RefPtr<SkSurface> surface_; | 41 skia::RefPtr<SkSurface> surface_; |
| 46 | 42 |
| 47 DISALLOW_COPY_AND_ASSIGN(MockSurfaceOzone); | 43 DISALLOW_COPY_AND_ASSIGN(MockSurfaceOzone); |
| 48 }; | 44 }; |
| 49 | 45 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 : public SoftwareOutputDeviceOzoneTest { | 127 : public SoftwareOutputDeviceOzoneTest { |
| 132 protected: | 128 protected: |
| 133 virtual void SetUp() OVERRIDE; | 129 virtual void SetUp() OVERRIDE; |
| 134 }; | 130 }; |
| 135 | 131 |
| 136 void SoftwareOutputDeviceOzonePixelTest::SetUp() { | 132 void SoftwareOutputDeviceOzonePixelTest::SetUp() { |
| 137 enable_pixel_output_ = true; | 133 enable_pixel_output_ = true; |
| 138 SoftwareOutputDeviceOzoneTest::SetUp(); | 134 SoftwareOutputDeviceOzoneTest::SetUp(); |
| 139 } | 135 } |
| 140 | 136 |
| 141 TEST_F(SoftwareOutputDeviceOzoneTest, CheckClipAfterBeginPaint) { | |
| 142 gfx::Rect damage(10, 10, 100, 100); | |
| 143 SkCanvas* canvas = output_device_->BeginPaint(damage); | |
| 144 | |
| 145 SkIRect sk_bounds; | |
| 146 canvas->getClipDeviceBounds(&sk_bounds); | |
| 147 | |
| 148 EXPECT_EQ(damage.ToString(), gfx::SkIRectToRect(sk_bounds).ToString()); | |
| 149 } | |
| 150 | |
| 151 TEST_F(SoftwareOutputDeviceOzoneTest, CheckClipAfterSecondBeginPaint) { | |
| 152 gfx::Rect damage(10, 10, 100, 100); | |
| 153 SkCanvas* canvas = output_device_->BeginPaint(damage); | |
| 154 | |
| 155 cc::SoftwareFrameData frame; | |
| 156 output_device_->EndPaint(&frame); | |
| 157 | |
| 158 damage = gfx::Rect(100, 100, 100, 100); | |
| 159 canvas = output_device_->BeginPaint(damage); | |
| 160 SkIRect sk_bounds; | |
| 161 canvas->getClipDeviceBounds(&sk_bounds); | |
| 162 | |
| 163 EXPECT_EQ(damage.ToString(), gfx::SkIRectToRect(sk_bounds).ToString()); | |
| 164 } | |
| 165 | |
| 166 TEST_F(SoftwareOutputDeviceOzoneTest, CheckCorrectResizeBehavior) { | 137 TEST_F(SoftwareOutputDeviceOzoneTest, CheckCorrectResizeBehavior) { |
| 167 gfx::Rect damage(0, 0, 100, 100); | 138 gfx::Rect damage(0, 0, 100, 100); |
| 168 gfx::Size size(200, 100); | 139 gfx::Size size(200, 100); |
| 169 // Reduce size. | 140 // Reduce size. |
| 170 output_device_->Resize(size); | 141 output_device_->Resize(size); |
| 171 | 142 |
| 172 SkCanvas* canvas = output_device_->BeginPaint(damage); | 143 SkCanvas* canvas = output_device_->BeginPaint(damage); |
| 173 gfx::Size canvas_size(canvas->getDeviceSize().width(), | 144 gfx::Size canvas_size(canvas->getDeviceSize().width(), |
| 174 canvas->getDeviceSize().height()); | 145 canvas->getDeviceSize().height()); |
| 175 EXPECT_EQ(size.ToString(), canvas_size.ToString()); | 146 EXPECT_EQ(size.ToString(), canvas_size.ToString()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 194 | 165 |
| 195 // Clear the background to black. | 166 // Clear the background to black. |
| 196 canvas->drawColor(SK_ColorBLACK); | 167 canvas->drawColor(SK_ColorBLACK); |
| 197 | 168 |
| 198 cc::SoftwareFrameData frame; | 169 cc::SoftwareFrameData frame; |
| 199 output_device_->EndPaint(&frame); | 170 output_device_->EndPaint(&frame); |
| 200 | 171 |
| 201 // Draw a white rectangle. | 172 // Draw a white rectangle. |
| 202 gfx::Rect damage(area.width() / 2, area.height() / 2); | 173 gfx::Rect damage(area.width() / 2, area.height() / 2); |
| 203 canvas = output_device_->BeginPaint(damage); | 174 canvas = output_device_->BeginPaint(damage); |
| 175 canvas->clipRect(gfx::RectToSkRect(damage), SkRegion::kReplace_Op); |
| 204 | 176 |
| 205 canvas->drawColor(SK_ColorWHITE); | 177 canvas->drawColor(SK_ColorWHITE); |
| 206 | 178 |
| 207 output_device_->EndPaint(&frame); | 179 output_device_->EndPaint(&frame); |
| 208 | 180 |
| 209 SkPMColor pixels[width * height]; | 181 SkPMColor pixels[width * height]; |
| 210 output_device_->CopyToPixels(area, pixels); | 182 output_device_->CopyToPixels(area, pixels); |
| 211 | 183 |
| 212 // Check that the copied bitmap contains the same pixel values as what we | 184 // Check that the copied bitmap contains the same pixel values as what we |
| 213 // painted. | 185 // painted. |
| 214 const SkPMColor white = SkPreMultiplyColor(SK_ColorWHITE); | 186 const SkPMColor white = SkPreMultiplyColor(SK_ColorWHITE); |
| 215 const SkPMColor black = SkPreMultiplyColor(SK_ColorBLACK); | 187 const SkPMColor black = SkPreMultiplyColor(SK_ColorBLACK); |
| 216 for (int i = 0; i < area.height(); ++i) { | 188 for (int i = 0; i < area.height(); ++i) { |
| 217 for (int j = 0; j < area.width(); ++j) { | 189 for (int j = 0; j < area.width(); ++j) { |
| 218 if (j < damage.width() && i < damage.height()) | 190 if (j < damage.width() && i < damage.height()) |
| 219 EXPECT_EQ(white, pixels[i * area.width() + j]); | 191 EXPECT_EQ(white, pixels[i * area.width() + j]); |
| 220 else | 192 else |
| 221 EXPECT_EQ(black, pixels[i * area.width() + j]); | 193 EXPECT_EQ(black, pixels[i * area.width() + j]); |
| 222 } | 194 } |
| 223 } | 195 } |
| 224 } | 196 } |
| OLD | NEW |