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