| 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" | |
| 14 #include "ui/gfx/ozone/surface_ozone_canvas.h" | |
| 15 #include "ui/gfx/size.h" | 13 #include "ui/gfx/size.h" |
| 16 #include "ui/gfx/skia_util.h" | 14 #include "ui/gfx/skia_util.h" |
| 17 #include "ui/gfx/vsync_provider.h" | 15 #include "ui/gfx/vsync_provider.h" |
| 18 #include "ui/gl/gl_implementation.h" | 16 #include "ui/gl/gl_implementation.h" |
| 17 #include "ui/ozone/public/surface_factory_ozone.h" |
| 18 #include "ui/ozone/public/surface_ozone_canvas.h" |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 class MockSurfaceOzone : public gfx::SurfaceOzoneCanvas { | 22 class MockSurfaceOzone : public ui::SurfaceOzoneCanvas { |
| 23 public: | 23 public: |
| 24 MockSurfaceOzone() {} | 24 MockSurfaceOzone() {} |
| 25 virtual ~MockSurfaceOzone() {} | 25 virtual ~MockSurfaceOzone() {} |
| 26 | 26 |
| 27 // gfx::SurfaceOzoneCanvas overrides: | 27 // ui::SurfaceOzoneCanvas overrides: |
| 28 virtual void 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 } | 31 } |
| 32 virtual skia::RefPtr<SkCanvas> GetCanvas() OVERRIDE { | 32 virtual skia::RefPtr<SkCanvas> GetCanvas() OVERRIDE { |
| 33 return skia::SharePtr(surface_->getCanvas()); | 33 return skia::SharePtr(surface_->getCanvas()); |
| 34 } | 34 } |
| 35 virtual void PresentCanvas(const gfx::Rect& damage) OVERRIDE {} | 35 virtual void PresentCanvas(const gfx::Rect& damage) OVERRIDE {} |
| 36 virtual scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() OVERRIDE { | 36 virtual scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() OVERRIDE { |
| 37 return scoped_ptr<gfx::VSyncProvider>(); | 37 return scoped_ptr<gfx::VSyncProvider>(); |
| 38 } | 38 } |
| 39 | 39 |
| 40 private: | 40 private: |
| 41 skia::RefPtr<SkSurface> surface_; | 41 skia::RefPtr<SkSurface> surface_; |
| 42 | 42 |
| 43 DISALLOW_COPY_AND_ASSIGN(MockSurfaceOzone); | 43 DISALLOW_COPY_AND_ASSIGN(MockSurfaceOzone); |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 class MockSurfaceFactoryOzone : public gfx::SurfaceFactoryOzone { | 46 class MockSurfaceFactoryOzone : public ui::SurfaceFactoryOzone { |
| 47 public: | 47 public: |
| 48 MockSurfaceFactoryOzone() {} | 48 MockSurfaceFactoryOzone() {} |
| 49 virtual ~MockSurfaceFactoryOzone() {} | 49 virtual ~MockSurfaceFactoryOzone() {} |
| 50 | 50 |
| 51 virtual HardwareState InitializeHardware() OVERRIDE { | 51 virtual HardwareState InitializeHardware() OVERRIDE { |
| 52 return SurfaceFactoryOzone::INITIALIZED; | 52 return SurfaceFactoryOzone::INITIALIZED; |
| 53 } | 53 } |
| 54 | 54 |
| 55 virtual void ShutdownHardware() OVERRIDE {} | 55 virtual void ShutdownHardware() OVERRIDE {} |
| 56 virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE { return 1; } | 56 virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE { return 1; } |
| 57 virtual bool LoadEGLGLES2Bindings( | 57 virtual bool LoadEGLGLES2Bindings( |
| 58 AddGLLibraryCallback add_gl_library, | 58 AddGLLibraryCallback add_gl_library, |
| 59 SetGLGetProcAddressProcCallback set_gl_get_proc_address) OVERRIDE { | 59 SetGLGetProcAddressProcCallback set_gl_get_proc_address) OVERRIDE { |
| 60 return false; | 60 return false; |
| 61 } | 61 } |
| 62 virtual scoped_ptr<gfx::SurfaceOzoneCanvas> CreateCanvasForWidget( | 62 virtual scoped_ptr<ui::SurfaceOzoneCanvas> CreateCanvasForWidget( |
| 63 gfx::AcceleratedWidget widget) OVERRIDE { | 63 gfx::AcceleratedWidget widget) OVERRIDE { |
| 64 return make_scoped_ptr<gfx::SurfaceOzoneCanvas>(new MockSurfaceOzone()); | 64 return make_scoped_ptr<ui::SurfaceOzoneCanvas>(new MockSurfaceOzone()); |
| 65 } | 65 } |
| 66 | 66 |
| 67 private: | 67 private: |
| 68 DISALLOW_COPY_AND_ASSIGN(MockSurfaceFactoryOzone); | 68 DISALLOW_COPY_AND_ASSIGN(MockSurfaceFactoryOzone); |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 } // namespace | 71 } // namespace |
| 72 | 72 |
| 73 class SoftwareOutputDeviceOzoneTest : public testing::Test { | 73 class SoftwareOutputDeviceOzoneTest : public testing::Test { |
| 74 public: | 74 public: |
| 75 SoftwareOutputDeviceOzoneTest(); | 75 SoftwareOutputDeviceOzoneTest(); |
| 76 virtual ~SoftwareOutputDeviceOzoneTest(); | 76 virtual ~SoftwareOutputDeviceOzoneTest(); |
| 77 | 77 |
| 78 virtual void SetUp() OVERRIDE; | 78 virtual void SetUp() OVERRIDE; |
| 79 virtual void TearDown() OVERRIDE; | 79 virtual void TearDown() OVERRIDE; |
| 80 | 80 |
| 81 protected: | 81 protected: |
| 82 scoped_ptr<content::SoftwareOutputDeviceOzone> output_device_; | 82 scoped_ptr<content::SoftwareOutputDeviceOzone> output_device_; |
| 83 bool enable_pixel_output_; | 83 bool enable_pixel_output_; |
| 84 | 84 |
| 85 private: | 85 private: |
| 86 scoped_ptr<ui::Compositor> compositor_; | 86 scoped_ptr<ui::Compositor> compositor_; |
| 87 scoped_ptr<base::MessageLoop> message_loop_; | 87 scoped_ptr<base::MessageLoop> message_loop_; |
| 88 scoped_ptr<gfx::SurfaceFactoryOzone> surface_factory_; | 88 scoped_ptr<ui::SurfaceFactoryOzone> surface_factory_; |
| 89 | 89 |
| 90 DISALLOW_COPY_AND_ASSIGN(SoftwareOutputDeviceOzoneTest); | 90 DISALLOW_COPY_AND_ASSIGN(SoftwareOutputDeviceOzoneTest); |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 SoftwareOutputDeviceOzoneTest::SoftwareOutputDeviceOzoneTest() | 93 SoftwareOutputDeviceOzoneTest::SoftwareOutputDeviceOzoneTest() |
| 94 : enable_pixel_output_(false) { | 94 : enable_pixel_output_(false) { |
| 95 message_loop_.reset(new base::MessageLoopForUI); | 95 message_loop_.reset(new base::MessageLoopForUI); |
| 96 } | 96 } |
| 97 | 97 |
| 98 SoftwareOutputDeviceOzoneTest::~SoftwareOutputDeviceOzoneTest() { | 98 SoftwareOutputDeviceOzoneTest::~SoftwareOutputDeviceOzoneTest() { |
| 99 } | 99 } |
| 100 | 100 |
| 101 void SoftwareOutputDeviceOzoneTest::SetUp() { | 101 void SoftwareOutputDeviceOzoneTest::SetUp() { |
| 102 ui::ContextFactory* context_factory = | 102 ui::ContextFactory* context_factory = |
| 103 ui::InitializeContextFactoryForTests(enable_pixel_output_); | 103 ui::InitializeContextFactoryForTests(enable_pixel_output_); |
| 104 | 104 |
| 105 surface_factory_.reset(new MockSurfaceFactoryOzone()); | 105 surface_factory_.reset(new MockSurfaceFactoryOzone()); |
| 106 | 106 |
| 107 const gfx::Size size(500, 400); | 107 const gfx::Size size(500, 400); |
| 108 compositor_.reset(new ui::Compositor( | 108 compositor_.reset(new ui::Compositor( |
| 109 gfx::SurfaceFactoryOzone::GetInstance()->GetAcceleratedWidget(), | 109 ui::SurfaceFactoryOzone::GetInstance()->GetAcceleratedWidget(), |
| 110 context_factory)); | 110 context_factory)); |
| 111 compositor_->SetScaleAndSize(1.0f, size); | 111 compositor_->SetScaleAndSize(1.0f, size); |
| 112 | 112 |
| 113 output_device_.reset(new content::SoftwareOutputDeviceOzone( | 113 output_device_.reset(new content::SoftwareOutputDeviceOzone( |
| 114 compositor_.get())); | 114 compositor_.get())); |
| 115 output_device_->Resize(size, 1.f); | 115 output_device_->Resize(size, 1.f); |
| 116 } | 116 } |
| 117 | 117 |
| 118 void SoftwareOutputDeviceOzoneTest::TearDown() { | 118 void SoftwareOutputDeviceOzoneTest::TearDown() { |
| 119 output_device_.reset(); | 119 output_device_.reset(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 const SkPMColor black = SkPreMultiplyColor(SK_ColorBLACK); | 186 const SkPMColor black = SkPreMultiplyColor(SK_ColorBLACK); |
| 187 for (int i = 0; i < area.height(); ++i) { | 187 for (int i = 0; i < area.height(); ++i) { |
| 188 for (int j = 0; j < area.width(); ++j) { | 188 for (int j = 0; j < area.width(); ++j) { |
| 189 if (j < damage.width() && i < damage.height()) | 189 if (j < damage.width() && i < damage.height()) |
| 190 EXPECT_EQ(white, pixels[i * area.width() + j]); | 190 EXPECT_EQ(white, pixels[i * area.width() + j]); |
| 191 else | 191 else |
| 192 EXPECT_EQ(black, pixels[i * area.width() + j]); | 192 EXPECT_EQ(black, pixels[i * area.width() + j]); |
| 193 } | 193 } |
| 194 } | 194 } |
| 195 } | 195 } |
| OLD | NEW |