| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "skia/ext/bitmap_platform_device_mac.h" | 5 #include "skia/ext/bitmap_platform_device_mac.h" |
| 6 | 6 |
| 7 #include "base/scoped_ptr.h" | 7 #include "base/scoped_ptr.h" |
| 8 #include "skia/ext/skia_utils_mac.h" | 8 #include "skia/ext/skia_utils_mac.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "third_party/skia/include/core/SkMatrix.h" | 10 #include "third_party/skia/include/core/SkMatrix.h" |
| 11 #include "third_party/skia/include/core/SkRegion.h" | 11 #include "third_party/skia/include/core/SkRegion.h" |
| 12 #include "third_party/skia/include/core/SkClipStack.h" |
| 12 | 13 |
| 13 namespace skia { | 14 namespace skia { |
| 14 | 15 |
| 15 const int kWidth = 400; | 16 const int kWidth = 400; |
| 16 const int kHeight = 300; | 17 const int kHeight = 300; |
| 17 | 18 |
| 18 class BitmapPlatformDeviceMacTest : public testing::Test { | 19 class BitmapPlatformDeviceMacTest : public testing::Test { |
| 19 public: | 20 public: |
| 20 BitmapPlatformDeviceMacTest() { | 21 BitmapPlatformDeviceMacTest() { |
| 21 bitmap_.reset(BitmapPlatformDevice::Create( | 22 bitmap_.reset(BitmapPlatformDevice::Create( |
| 22 NULL, kWidth, kHeight, /*is_opaque=*/true)); | 23 NULL, kWidth, kHeight, /*is_opaque=*/true)); |
| 23 } | 24 } |
| 24 | 25 |
| 25 scoped_ptr<BitmapPlatformDevice> bitmap_; | 26 scoped_ptr<BitmapPlatformDevice> bitmap_; |
| 26 }; | 27 }; |
| 27 | 28 |
| 28 TEST_F(BitmapPlatformDeviceMacTest, ClipRectTransformWithTranslate) { | 29 TEST_F(BitmapPlatformDeviceMacTest, ClipRectTransformWithTranslate) { |
| 29 SkMatrix transform; | 30 SkMatrix transform; |
| 30 transform.setTranslate(50, 140); | 31 transform.setTranslate(50, 140); |
| 31 | 32 |
| 33 SkClipStack ignore; |
| 32 SkRegion clip_region; | 34 SkRegion clip_region; |
| 33 SkIRect rect; | 35 SkIRect rect; |
| 34 rect.set(0, 0, kWidth, kHeight); | 36 rect.set(0, 0, kWidth, kHeight); |
| 35 clip_region.setRect(rect); | 37 clip_region.setRect(rect); |
| 36 bitmap_->setMatrixClip(transform, clip_region); | 38 bitmap_->setMatrixClip(transform, clip_region, ignore); |
| 37 | 39 |
| 38 CGContextRef context = bitmap_->GetBitmapContext(); | 40 CGContextRef context = bitmap_->GetBitmapContext(); |
| 39 SkRect clip_rect = gfx::CGRectToSkRect(CGContextGetClipBoundingBox(context)); | 41 SkRect clip_rect = gfx::CGRectToSkRect(CGContextGetClipBoundingBox(context)); |
| 40 transform.mapRect(&clip_rect); | 42 transform.mapRect(&clip_rect); |
| 41 EXPECT_EQ(0, clip_rect.fLeft); | 43 EXPECT_EQ(0, clip_rect.fLeft); |
| 42 EXPECT_EQ(0, clip_rect.fTop); | 44 EXPECT_EQ(0, clip_rect.fTop); |
| 43 EXPECT_EQ(kWidth, clip_rect.width()); | 45 EXPECT_EQ(kWidth, clip_rect.width()); |
| 44 EXPECT_EQ(kHeight, clip_rect.height()); | 46 EXPECT_EQ(kHeight, clip_rect.height()); |
| 45 } | 47 } |
| 46 | 48 |
| 47 TEST_F(BitmapPlatformDeviceMacTest, ClipRectTransformWithScale) { | 49 TEST_F(BitmapPlatformDeviceMacTest, ClipRectTransformWithScale) { |
| 48 SkMatrix transform; | 50 SkMatrix transform; |
| 49 transform.setScale(0.5, 0.5); | 51 transform.setScale(0.5, 0.5); |
| 50 | 52 |
| 53 SkClipStack unused; |
| 51 SkRegion clip_region; | 54 SkRegion clip_region; |
| 52 SkIRect rect; | 55 SkIRect rect; |
| 53 rect.set(0, 0, kWidth, kHeight); | 56 rect.set(0, 0, kWidth, kHeight); |
| 54 clip_region.setRect(rect); | 57 clip_region.setRect(rect); |
| 55 bitmap_->setMatrixClip(transform, clip_region); | 58 bitmap_->setMatrixClip(transform, clip_region, unused); |
| 56 | 59 |
| 57 CGContextRef context = bitmap_->GetBitmapContext(); | 60 CGContextRef context = bitmap_->GetBitmapContext(); |
| 58 SkRect clip_rect = gfx::CGRectToSkRect(CGContextGetClipBoundingBox(context)); | 61 SkRect clip_rect = gfx::CGRectToSkRect(CGContextGetClipBoundingBox(context)); |
| 59 transform.mapRect(&clip_rect); | 62 transform.mapRect(&clip_rect); |
| 60 EXPECT_EQ(0, clip_rect.fLeft); | 63 EXPECT_EQ(0, clip_rect.fLeft); |
| 61 EXPECT_EQ(0, clip_rect.fTop); | 64 EXPECT_EQ(0, clip_rect.fTop); |
| 62 EXPECT_EQ(kWidth, clip_rect.width()); | 65 EXPECT_EQ(kWidth, clip_rect.width()); |
| 63 EXPECT_EQ(kHeight, clip_rect.height()); | 66 EXPECT_EQ(kHeight, clip_rect.height()); |
| 64 } | 67 } |
| 65 | 68 |
| 66 } // namespace skia | 69 } // namespace skia |
| OLD | NEW |