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

Side by Side Diff: ui/gfx/image/image_unittest.cc

Issue 10245003: Makes ImageSkia more like SkBitmap (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated comment Created 8 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/gfx/image/image_skia.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "third_party/skia/include/core/SkBitmap.h" 6 #include "third_party/skia/include/core/SkBitmap.h"
7 #include "ui/gfx/image/image.h" 7 #include "ui/gfx/image/image.h"
8 #include "ui/gfx/image/image_skia.h" 8 #include "ui/gfx/image/image_skia.h"
9 #include "ui/gfx/image/image_unittest_util.h" 9 #include "ui/gfx/image/image_unittest_util.h"
10 10
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 EXPECT_TRUE(bitmap); 60 EXPECT_TRUE(bitmap);
61 EXPECT_FALSE(bitmap->isNull()); 61 EXPECT_FALSE(bitmap->isNull());
62 EXPECT_EQ(1U, image.RepresentationCount()); 62 EXPECT_EQ(1U, image.RepresentationCount());
63 63
64 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia)); 64 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia));
65 if (!kUsesSkiaNatively) 65 if (!kUsesSkiaNatively)
66 EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType())); 66 EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType()));
67 } 67 }
68 68
69 TEST_F(ImageTest, SkiaRefToSkia) { 69 TEST_F(ImageTest, SkiaRefToSkia) {
70 SkBitmap originalBitmap(gt::CreateBitmap(25, 25)); 70 gfx::Image image(gt::CreateBitmap(25, 25));
71 gfx::Image image(originalBitmap);
72 const SkBitmap* bitmap = image.ToSkBitmap(); 71 const SkBitmap* bitmap = image.ToSkBitmap();
73 EXPECT_TRUE(bitmap); 72 EXPECT_TRUE(bitmap);
74 EXPECT_FALSE(bitmap->isNull()); 73 EXPECT_FALSE(bitmap->isNull());
75 EXPECT_EQ(1U, image.RepresentationCount()); 74 EXPECT_EQ(1U, image.RepresentationCount());
76 75
77 EXPECT_EQ(bitmap, image.ToSkBitmap()); 76 EXPECT_EQ(bitmap, image.ToSkBitmap());
78 if (!kUsesSkiaNatively) 77 if (!kUsesSkiaNatively)
79 EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType())); 78 EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType()));
80 } 79 }
81 80
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 243
245 TEST_F(ImageTest, Assign) { 244 TEST_F(ImageTest, Assign) {
246 gfx::Image image1(gt::CreatePlatformImage()); 245 gfx::Image image1(gt::CreatePlatformImage());
247 gfx::Image image2 = image1; 246 gfx::Image image2 = image1;
248 247
249 EXPECT_EQ(1U, image1.RepresentationCount()); 248 EXPECT_EQ(1U, image1.RepresentationCount());
250 EXPECT_EQ(1U, image2.RepresentationCount()); 249 EXPECT_EQ(1U, image2.RepresentationCount());
251 EXPECT_EQ(image1.ToSkBitmap(), image2.ToSkBitmap()); 250 EXPECT_EQ(image1.ToSkBitmap(), image2.ToSkBitmap());
252 } 251 }
253 252
254 TEST_F(ImageTest, MultiResolutionSkBitmap) { 253 TEST_F(ImageTest, MultiResolutionImage) {
255 const int width1 = 10; 254 const int width1x = 10;
256 const int height1 = 12; 255 const int height1x = 12;
257 const int width2 = 20; 256 const int width2x = 20;
258 const int height2 = 24; 257 const int height2x = 24;
259 258
260 std::vector<const SkBitmap*> bitmaps; 259 gfx::ImageSkia image_skia;
261 bitmaps.push_back(new SkBitmap(gt::CreateBitmap(width1, height1))); 260 image_skia.AddBitmapForScale(gt::CreateBitmap(width1x, height1x), 1.0f);
262 bitmaps.push_back(new SkBitmap(gt::CreateBitmap(width2, height2))); 261 image_skia.AddBitmapForScale(gt::CreateBitmap(width2x, height2x), 2.0f);
263 gfx::Image image(bitmaps);
264 262
263 EXPECT_EQ(2u, image_skia.bitmaps().size());
264
265 float scale_factor;
266 const SkBitmap& bitmap1x = image_skia.GetBitmapForScale(1.0f, 1.0f,
267 &scale_factor);
268 EXPECT_TRUE(!bitmap1x.isNull());
269 EXPECT_EQ(1.0f, scale_factor);
270 EXPECT_EQ(width1x, bitmap1x.width());
271 EXPECT_EQ(height1x, bitmap1x.height());
272
273 const SkBitmap& bitmap2x = image_skia.GetBitmapForScale(2.0f, 2.0f,
274 &scale_factor);
275 EXPECT_TRUE(!bitmap2x.isNull());
276 EXPECT_EQ(2.0f, scale_factor);
277 EXPECT_EQ(width2x, bitmap2x.width());
278 EXPECT_EQ(height2x, bitmap2x.height());
279
280 // Check that the image has a single representation.
281 gfx::Image image(image_skia);
265 EXPECT_EQ(1u, image.RepresentationCount()); 282 EXPECT_EQ(1u, image.RepresentationCount());
266 const std::vector<const SkBitmap*>& image_bitmaps = 283 }
267 image.ToImageSkia()->bitmaps();
268 EXPECT_EQ(2u, image_bitmaps.size());
269 284
270 const SkBitmap* bitmap1 = image_bitmaps[0]; 285 // Tests that gfx::Image does indeed take ownership of the SkBitmap it is
271 EXPECT_TRUE(bitmap1); 286 // passed.
272 const SkBitmap* bitmap2 = image_bitmaps[1]; 287 TEST_F(ImageTest, OwnershipTest) {
273 EXPECT_TRUE(bitmap2); 288 gfx::Image image;
274 289 {
275 if (bitmap1->width() == width1) { 290 SkBitmap bitmap = gt::CreateBitmap(10, 10);
276 EXPECT_EQ(bitmap1->height(), height1); 291 EXPECT_TRUE(!bitmap.isNull());
277 EXPECT_EQ(bitmap2->width(), width2); 292 image = gfx::Image(bitmap);
278 EXPECT_EQ(bitmap2->height(), height2);
279 } else {
280 EXPECT_EQ(bitmap1->width(), width2);
281 EXPECT_EQ(bitmap1->height(), height2);
282 EXPECT_EQ(bitmap2->width(), width1);
283 EXPECT_EQ(bitmap2->height(), height1);
284 } 293 }
285 294 EXPECT_TRUE(!image.ToSkBitmap()->isNull());
286 // Sanity check.
287 EXPECT_EQ(1u, image.RepresentationCount());
288 EXPECT_EQ(2u, image.ToImageSkia()->bitmaps().size());
289 } 295 }
290 296
291 // Integration tests with UI toolkit frameworks require linking against the 297 // Integration tests with UI toolkit frameworks require linking against the
292 // Views library and cannot be here (gfx_unittests doesn't include it). They 298 // Views library and cannot be here (gfx_unittests doesn't include it). They
293 // instead live in /chrome/browser/ui/tests/ui_gfx_image_unittest.cc. 299 // instead live in /chrome/browser/ui/tests/ui_gfx_image_unittest.cc.
294 300
295 } // namespace 301 } // namespace
OLDNEW
« no previous file with comments | « ui/gfx/image/image_skia.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698