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

Side by Side Diff: skia/ext/platform_canvas_unittest.cc

Issue 1396613006: Remove skia::PlatformBitmap. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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
« no previous file with comments | « skia/ext/platform_canvas.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 // TODO(awalker): clean up the const/non-const reference handling in this test 5 // TODO(awalker): clean up the const/non-const reference handling in this test
6 6
7 #include "skia/ext/platform_canvas.h" 7 #include "skia/ext/platform_canvas.h"
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 #endif 390 #endif
391 } 391 }
392 canvas->restore(); 392 canvas->restore();
393 EXPECT_TRUE(VerifyRoundedRect(*canvas, SK_ColorWHITE, SK_ColorBLACK, 393 EXPECT_TRUE(VerifyRoundedRect(*canvas, SK_ColorWHITE, SK_ColorBLACK,
394 kInnerX + 1, kInnerY + 1, kInnerW, kInnerH)); 394 kInnerX + 1, kInnerY + 1, kInnerW, kInnerH));
395 #endif 395 #endif
396 } 396 }
397 397
398 #endif // #if !defined(USE_AURA) 398 #endif // #if !defined(USE_AURA)
399 399
400 TEST(PlatformBitmapTest, PlatformBitmap) {
401 const int kWidth = 400;
402 const int kHeight = 300;
403 scoped_ptr<PlatformBitmap> platform_bitmap(new PlatformBitmap);
404
405 EXPECT_TRUE(0 == platform_bitmap->GetSurface());
406 EXPECT_TRUE(platform_bitmap->GetBitmap().empty());
407 EXPECT_TRUE(platform_bitmap->GetBitmap().isNull());
408
409 EXPECT_TRUE(platform_bitmap->Allocate(kWidth, kHeight, /*is_opaque=*/false));
410
411 EXPECT_TRUE(0 != platform_bitmap->GetSurface());
412 EXPECT_FALSE(platform_bitmap->GetBitmap().empty());
413 EXPECT_FALSE(platform_bitmap->GetBitmap().isNull());
414 EXPECT_EQ(kWidth, platform_bitmap->GetBitmap().width());
415 EXPECT_EQ(kHeight, platform_bitmap->GetBitmap().height());
416 EXPECT_LE(static_cast<size_t>(platform_bitmap->GetBitmap().width()*4),
417 platform_bitmap->GetBitmap().rowBytes());
418 EXPECT_EQ(kN32_SkColorType, // Same for all platforms.
419 platform_bitmap->GetBitmap().colorType());
420 EXPECT_TRUE(platform_bitmap->GetBitmap().lockPixelsAreWritable());
421 #if defined(SK_DEBUG)
422 EXPECT_TRUE(platform_bitmap->GetBitmap().pixelRef()->isLocked());
423 #endif
424 EXPECT_TRUE(platform_bitmap->GetBitmap().pixelRef()->unique());
425
426 *(platform_bitmap->GetBitmap().getAddr32(10, 20)) = 0xDEED1020;
427 *(platform_bitmap->GetBitmap().getAddr32(20, 30)) = 0xDEED2030;
428
429 SkBitmap sk_bitmap = platform_bitmap->GetBitmap();
430 sk_bitmap.lockPixels();
431
432 EXPECT_FALSE(platform_bitmap->GetBitmap().pixelRef()->unique());
433 EXPECT_FALSE(sk_bitmap.pixelRef()->unique());
434
435 EXPECT_EQ(0xDEED1020, *sk_bitmap.getAddr32(10, 20));
436 EXPECT_EQ(0xDEED2030, *sk_bitmap.getAddr32(20, 30));
437
438 *(platform_bitmap->GetBitmap().getAddr32(30, 40)) = 0xDEED3040;
439
440 // The SkBitmaps derived from a PlatformBitmap must be capable of outliving
441 // the PlatformBitmap.
442 platform_bitmap.reset();
443
444 EXPECT_TRUE(sk_bitmap.pixelRef()->unique());
445
446 EXPECT_EQ(0xDEED1020, *sk_bitmap.getAddr32(10, 20));
447 EXPECT_EQ(0xDEED2030, *sk_bitmap.getAddr32(20, 30));
448 EXPECT_EQ(0xDEED3040, *sk_bitmap.getAddr32(30, 40));
449 sk_bitmap.unlockPixels();
450
451 EXPECT_EQ(NULL, sk_bitmap.getPixels());
452
453 sk_bitmap.lockPixels();
454 EXPECT_EQ(0xDEED1020, *sk_bitmap.getAddr32(10, 20));
455 EXPECT_EQ(0xDEED2030, *sk_bitmap.getAddr32(20, 30));
456 EXPECT_EQ(0xDEED3040, *sk_bitmap.getAddr32(30, 40));
457 sk_bitmap.unlockPixels();
458 }
459
460
461 } // namespace skia 400 } // namespace skia
OLDNEW
« no previous file with comments | « skia/ext/platform_canvas.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698