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" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 | 103 |
104 surface_factory_.reset(new MockSurfaceFactoryOzone()); | 104 surface_factory_.reset(new MockSurfaceFactoryOzone()); |
105 | 105 |
106 const gfx::Size size(500, 400); | 106 const gfx::Size size(500, 400); |
107 compositor_.reset(new ui::Compositor( | 107 compositor_.reset(new ui::Compositor( |
108 gfx::SurfaceFactoryOzone::GetInstance()->GetAcceleratedWidget())); | 108 gfx::SurfaceFactoryOzone::GetInstance()->GetAcceleratedWidget())); |
109 compositor_->SetScaleAndSize(1.0f, size); | 109 compositor_->SetScaleAndSize(1.0f, size); |
110 | 110 |
111 output_device_.reset(new content::SoftwareOutputDeviceOzone( | 111 output_device_.reset(new content::SoftwareOutputDeviceOzone( |
112 compositor_.get())); | 112 compositor_.get())); |
113 output_device_->Resize(size); | 113 output_device_->Resize(size, 1.f); |
114 } | 114 } |
115 | 115 |
116 void SoftwareOutputDeviceOzoneTest::TearDown() { | 116 void SoftwareOutputDeviceOzoneTest::TearDown() { |
117 output_device_.reset(); | 117 output_device_.reset(); |
118 compositor_.reset(); | 118 compositor_.reset(); |
119 surface_factory_.reset(); | 119 surface_factory_.reset(); |
120 ui::TerminateContextFactoryForTests(); | 120 ui::TerminateContextFactoryForTests(); |
121 } | 121 } |
122 | 122 |
123 class SoftwareOutputDeviceOzonePixelTest | 123 class SoftwareOutputDeviceOzonePixelTest |
124 : public SoftwareOutputDeviceOzoneTest { | 124 : public SoftwareOutputDeviceOzoneTest { |
125 protected: | 125 protected: |
126 virtual void SetUp() OVERRIDE; | 126 virtual void SetUp() OVERRIDE; |
127 }; | 127 }; |
128 | 128 |
129 void SoftwareOutputDeviceOzonePixelTest::SetUp() { | 129 void SoftwareOutputDeviceOzonePixelTest::SetUp() { |
130 enable_pixel_output_ = true; | 130 enable_pixel_output_ = true; |
131 SoftwareOutputDeviceOzoneTest::SetUp(); | 131 SoftwareOutputDeviceOzoneTest::SetUp(); |
132 } | 132 } |
133 | 133 |
134 TEST_F(SoftwareOutputDeviceOzoneTest, CheckCorrectResizeBehavior) { | 134 TEST_F(SoftwareOutputDeviceOzoneTest, CheckCorrectResizeBehavior) { |
135 gfx::Rect damage(0, 0, 100, 100); | 135 gfx::Rect damage(0, 0, 100, 100); |
136 gfx::Size size(200, 100); | 136 gfx::Size size(200, 100); |
137 // Reduce size. | 137 // Reduce size. |
138 output_device_->Resize(size); | 138 output_device_->Resize(size, 1.f); |
139 | 139 |
140 SkCanvas* canvas = output_device_->BeginPaint(damage); | 140 SkCanvas* canvas = output_device_->BeginPaint(damage); |
141 gfx::Size canvas_size(canvas->getDeviceSize().width(), | 141 gfx::Size canvas_size(canvas->getDeviceSize().width(), |
142 canvas->getDeviceSize().height()); | 142 canvas->getDeviceSize().height()); |
143 EXPECT_EQ(size.ToString(), canvas_size.ToString()); | 143 EXPECT_EQ(size.ToString(), canvas_size.ToString()); |
144 | 144 |
145 size.SetSize(1000, 500); | 145 size.SetSize(1000, 500); |
146 // Increase size. | 146 // Increase size. |
147 output_device_->Resize(size); | 147 output_device_->Resize(size, 1.f); |
148 | 148 |
149 canvas = output_device_->BeginPaint(damage); | 149 canvas = output_device_->BeginPaint(damage); |
150 canvas_size.SetSize(canvas->getDeviceSize().width(), | 150 canvas_size.SetSize(canvas->getDeviceSize().width(), |
151 canvas->getDeviceSize().height()); | 151 canvas->getDeviceSize().height()); |
152 EXPECT_EQ(size.ToString(), canvas_size.ToString()); | 152 EXPECT_EQ(size.ToString(), canvas_size.ToString()); |
153 | 153 |
154 } | 154 } |
155 | 155 |
156 TEST_F(SoftwareOutputDeviceOzonePixelTest, CheckCopyToBitmap) { | 156 TEST_F(SoftwareOutputDeviceOzonePixelTest, CheckCopyToBitmap) { |
157 const int width = 6; | 157 const int width = 6; |
158 const int height = 4; | 158 const int height = 4; |
159 const gfx::Rect area(width, height); | 159 const gfx::Rect area(width, height); |
160 output_device_->Resize(area.size()); | 160 output_device_->Resize(area.size(), 1.f); |
161 SkCanvas* canvas = output_device_->BeginPaint(area); | 161 SkCanvas* canvas = output_device_->BeginPaint(area); |
162 | 162 |
163 // Clear the background to black. | 163 // Clear the background to black. |
164 canvas->drawColor(SK_ColorBLACK); | 164 canvas->drawColor(SK_ColorBLACK); |
165 | 165 |
166 cc::SoftwareFrameData frame; | 166 cc::SoftwareFrameData frame; |
167 output_device_->EndPaint(&frame); | 167 output_device_->EndPaint(&frame); |
168 | 168 |
169 // Draw a white rectangle. | 169 // Draw a white rectangle. |
170 gfx::Rect damage(area.width() / 2, area.height() / 2); | 170 gfx::Rect damage(area.width() / 2, area.height() / 2); |
(...skipping 13 matching lines...) Expand all Loading... |
184 const SkPMColor black = SkPreMultiplyColor(SK_ColorBLACK); | 184 const SkPMColor black = SkPreMultiplyColor(SK_ColorBLACK); |
185 for (int i = 0; i < area.height(); ++i) { | 185 for (int i = 0; i < area.height(); ++i) { |
186 for (int j = 0; j < area.width(); ++j) { | 186 for (int j = 0; j < area.width(); ++j) { |
187 if (j < damage.width() && i < damage.height()) | 187 if (j < damage.width() && i < damage.height()) |
188 EXPECT_EQ(white, pixels[i * area.width() + j]); | 188 EXPECT_EQ(white, pixels[i * area.width() + j]); |
189 else | 189 else |
190 EXPECT_EQ(black, pixels[i * area.width() + j]); | 190 EXPECT_EQ(black, pixels[i * area.width() + j]); |
191 } | 191 } |
192 } | 192 } |
193 } | 193 } |
OLD | NEW |