| OLD | NEW |
| 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 "ui/gfx/image/image_skia.h" | 5 #include "ui/gfx/image/image_skia.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/threading/simple_thread.h" | 9 #include "base/threading/simple_thread.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #endif | 23 #endif |
| 24 | 24 |
| 25 namespace gfx { | 25 namespace gfx { |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 class FixedSource : public ImageSkiaSource { | 29 class FixedSource : public ImageSkiaSource { |
| 30 public: | 30 public: |
| 31 explicit FixedSource(const ImageSkiaRep& image) : image_(image) {} | 31 explicit FixedSource(const ImageSkiaRep& image) : image_(image) {} |
| 32 | 32 |
| 33 virtual ~FixedSource() { | 33 ~FixedSource() override {} |
| 34 } | |
| 35 | 34 |
| 36 virtual ImageSkiaRep GetImageForScale(float scale) override { | 35 ImageSkiaRep GetImageForScale(float scale) override { return image_; } |
| 37 return image_; | |
| 38 } | |
| 39 | 36 |
| 40 private: | 37 private: |
| 41 ImageSkiaRep image_; | 38 ImageSkiaRep image_; |
| 42 | 39 |
| 43 DISALLOW_COPY_AND_ASSIGN(FixedSource); | 40 DISALLOW_COPY_AND_ASSIGN(FixedSource); |
| 44 }; | 41 }; |
| 45 | 42 |
| 46 class FixedScaleSource : public ImageSkiaSource { | 43 class FixedScaleSource : public ImageSkiaSource { |
| 47 public: | 44 public: |
| 48 explicit FixedScaleSource(const ImageSkiaRep& image) : image_(image) {} | 45 explicit FixedScaleSource(const ImageSkiaRep& image) : image_(image) {} |
| 49 | 46 |
| 50 virtual ~FixedScaleSource() { | 47 ~FixedScaleSource() override {} |
| 51 } | |
| 52 | 48 |
| 53 virtual ImageSkiaRep GetImageForScale(float scale) override { | 49 ImageSkiaRep GetImageForScale(float scale) override { |
| 54 if (!image_.unscaled() && image_.scale() != scale) | 50 if (!image_.unscaled() && image_.scale() != scale) |
| 55 return ImageSkiaRep(); | 51 return ImageSkiaRep(); |
| 56 return image_; | 52 return image_; |
| 57 } | 53 } |
| 58 | 54 |
| 59 private: | 55 private: |
| 60 ImageSkiaRep image_; | 56 ImageSkiaRep image_; |
| 61 | 57 |
| 62 DISALLOW_COPY_AND_ASSIGN(FixedScaleSource); | 58 DISALLOW_COPY_AND_ASSIGN(FixedScaleSource); |
| 63 }; | 59 }; |
| 64 | 60 |
| 65 class DynamicSource : public ImageSkiaSource { | 61 class DynamicSource : public ImageSkiaSource { |
| 66 public: | 62 public: |
| 67 explicit DynamicSource(const gfx::Size& size) | 63 explicit DynamicSource(const gfx::Size& size) |
| 68 : size_(size), | 64 : size_(size), |
| 69 last_requested_scale_(0.0f) {} | 65 last_requested_scale_(0.0f) {} |
| 70 | 66 |
| 71 virtual ~DynamicSource() { | 67 ~DynamicSource() override {} |
| 72 } | |
| 73 | 68 |
| 74 virtual ImageSkiaRep GetImageForScale(float scale) override { | 69 ImageSkiaRep GetImageForScale(float scale) override { |
| 75 last_requested_scale_ = scale; | 70 last_requested_scale_ = scale; |
| 76 return gfx::ImageSkiaRep(size_, scale); | 71 return gfx::ImageSkiaRep(size_, scale); |
| 77 } | 72 } |
| 78 | 73 |
| 79 float GetLastRequestedScaleAndReset() { | 74 float GetLastRequestedScaleAndReset() { |
| 80 float result = last_requested_scale_; | 75 float result = last_requested_scale_; |
| 81 last_requested_scale_ = 0.0f; | 76 last_requested_scale_ = 0.0f; |
| 82 return result; | 77 return result; |
| 83 } | 78 } |
| 84 | 79 |
| 85 private: | 80 private: |
| 86 gfx::Size size_; | 81 gfx::Size size_; |
| 87 float last_requested_scale_; | 82 float last_requested_scale_; |
| 88 | 83 |
| 89 DISALLOW_COPY_AND_ASSIGN(DynamicSource); | 84 DISALLOW_COPY_AND_ASSIGN(DynamicSource); |
| 90 }; | 85 }; |
| 91 | 86 |
| 92 class NullSource: public ImageSkiaSource { | 87 class NullSource: public ImageSkiaSource { |
| 93 public: | 88 public: |
| 94 NullSource() { | 89 NullSource() { |
| 95 } | 90 } |
| 96 | 91 |
| 97 virtual ~NullSource() { | 92 ~NullSource() override {} |
| 98 } | |
| 99 | 93 |
| 100 virtual ImageSkiaRep GetImageForScale(float scale) override { | 94 ImageSkiaRep GetImageForScale(float scale) override { |
| 101 return gfx::ImageSkiaRep(); | 95 return gfx::ImageSkiaRep(); |
| 102 } | 96 } |
| 103 | 97 |
| 104 private: | 98 private: |
| 105 DISALLOW_COPY_AND_ASSIGN(NullSource); | 99 DISALLOW_COPY_AND_ASSIGN(NullSource); |
| 106 }; | 100 }; |
| 107 | 101 |
| 108 } // namespace | 102 } // namespace |
| 109 | 103 |
| 110 namespace test { | 104 namespace test { |
| 111 class TestOnThread : public base::SimpleThread { | 105 class TestOnThread : public base::SimpleThread { |
| 112 public: | 106 public: |
| 113 explicit TestOnThread(ImageSkia* image_skia) | 107 explicit TestOnThread(ImageSkia* image_skia) |
| 114 : SimpleThread("image_skia_on_thread"), | 108 : SimpleThread("image_skia_on_thread"), |
| 115 image_skia_(image_skia), | 109 image_skia_(image_skia), |
| 116 can_read_(false), | 110 can_read_(false), |
| 117 can_modify_(false) { | 111 can_modify_(false) { |
| 118 } | 112 } |
| 119 | 113 |
| 120 virtual void Run() override { | 114 void Run() override { |
| 121 can_read_ = image_skia_->CanRead(); | 115 can_read_ = image_skia_->CanRead(); |
| 122 can_modify_ = image_skia_->CanModify(); | 116 can_modify_ = image_skia_->CanModify(); |
| 123 if (can_read_) | 117 if (can_read_) |
| 124 image_skia_->image_reps(); | 118 image_skia_->image_reps(); |
| 125 } | 119 } |
| 126 | 120 |
| 127 void StartAndJoin() { | 121 void StartAndJoin() { |
| 128 Start(); | 122 Start(); |
| 129 Join(); | 123 Join(); |
| 130 } | 124 } |
| (...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 EXPECT_EQ(1U, image.image_reps().size()); | 612 EXPECT_EQ(1U, image.image_reps().size()); |
| 619 | 613 |
| 620 const ImageSkiaRep& rep12 = image.GetRepresentation(1.2f); | 614 const ImageSkiaRep& rep12 = image.GetRepresentation(1.2f); |
| 621 EXPECT_EQ(1.0f, rep12.scale()); | 615 EXPECT_EQ(1.0f, rep12.scale()); |
| 622 EXPECT_EQ("100x200", rep12.pixel_size().ToString()); | 616 EXPECT_EQ("100x200", rep12.pixel_size().ToString()); |
| 623 EXPECT_TRUE(rep12.unscaled()); | 617 EXPECT_TRUE(rep12.unscaled()); |
| 624 EXPECT_EQ(1U, image.image_reps().size()); | 618 EXPECT_EQ(1U, image.image_reps().size()); |
| 625 } | 619 } |
| 626 | 620 |
| 627 } // namespace gfx | 621 } // namespace gfx |
| OLD | NEW |