Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "cc/playback/discardable_image_map.h" | 5 #include "cc/playback/discardable_image_map.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <limits> | 10 #include <limits> |
| 11 | 11 |
| 12 #include "base/containers/adapters.h" | 12 #include "base/containers/adapters.h" |
| 13 #include "cc/base/math_util.h" | 13 #include "cc/base/math_util.h" |
| 14 #include "cc/playback/display_item_list.h" | 14 #include "cc/playback/display_item_list.h" |
| 15 #include "third_party/skia/include/utils/SkNWayCanvas.h" | 15 #include "third_party/skia/include/utils/SkNWayCanvas.h" |
| 16 #include "ui/gfx/geometry/rect_conversions.h" | 16 #include "ui/gfx/geometry/rect_conversions.h" |
| 17 #include "ui/gfx/skia_util.h" | 17 #include "ui/gfx/skia_util.h" |
| 18 | 18 |
| 19 namespace cc { | 19 namespace cc { |
| 20 | 20 |
| 21 SkRect MapRect(const SkMatrix& matrix, const SkRect& src) { | 21 SkRect MapRect(const SkMatrix& matrix, const SkRect& src) { |
| 22 SkRect dst; | 22 SkRect dst; |
| 23 matrix.mapRect(&dst, src); | 23 matrix.mapRect(&dst, src); |
| 24 return dst; | 24 return dst; |
| 25 } | 25 } |
| 26 | 26 |
| 27 gfx::Rect SafeIntersectRects(const SkRect& paint_rect, | |
| 28 const gfx::Rect& max_bounds) { | |
| 29 DCHECK_EQ(0, max_bounds.x()); | |
|
enne (OOO)
2016/08/08 21:54:01
How about just passing a gfx::Size? If that makes
vmpstr
2016/08/08 22:25:14
Done.
| |
| 30 DCHECK_EQ(0, max_bounds.y()); | |
| 31 | |
| 32 // bounds_rect.x() + bounds_rect.width() (aka bounds_rect.right()) might | |
| 33 // overflow integer bounds, so do custom intersect, since gfx::Rect::Intersect | |
| 34 // uses bounds_rect.right(). | |
| 35 gfx::RectF bounds_rect = gfx::SkRectToRectF(paint_rect); | |
| 36 bounds_rect.set_x(std::max(0.f, bounds_rect.x())); | |
| 37 bounds_rect.set_y(std::max(0.f, bounds_rect.y())); | |
| 38 bounds_rect.set_width( | |
| 39 std::min(bounds_rect.width(), max_bounds.width() - bounds_rect.x())); | |
|
enne (OOO)
2016/08/08 21:54:01
Can this be negative if the paint offset is outsid
vmpstr
2016/08/08 22:25:14
That shouldn't be possible since there's an early
| |
| 40 bounds_rect.set_height( | |
| 41 std::min(bounds_rect.height(), max_bounds.height() - bounds_rect.y())); | |
| 42 return gfx::ToEnclosingRect(bounds_rect); | |
| 43 } | |
| 44 | |
| 27 namespace { | 45 namespace { |
| 28 | 46 |
| 29 // We're using an NWay canvas with no added canvases, so in effect | 47 // We're using an NWay canvas with no added canvases, so in effect |
| 30 // non-overridden functions are no-ops. | 48 // non-overridden functions are no-ops. |
| 31 class DiscardableImagesMetadataCanvas : public SkNWayCanvas { | 49 class DiscardableImagesMetadataCanvas : public SkNWayCanvas { |
| 32 public: | 50 public: |
| 33 DiscardableImagesMetadataCanvas( | 51 DiscardableImagesMetadataCanvas( |
| 34 int width, | 52 int width, |
| 35 int height, | 53 int height, |
| 36 std::vector<std::pair<DrawImage, gfx::Rect>>* image_set) | 54 std::vector<std::pair<DrawImage, gfx::Rect>>* image_set) |
| 37 : SkNWayCanvas(width, height), | 55 : SkNWayCanvas(width, height), |
| 38 image_set_(image_set), | 56 image_set_(image_set), |
| 39 canvas_bounds_(SkRect::MakeIWH(width, height)) {} | 57 canvas_bounds_(SkRect::MakeIWH(width, height)), |
| 58 int_canvas_bounds_( | |
| 59 gfx::ToEnclosingRect(gfx::SkRectToRectF(canvas_bounds_))) {} | |
| 40 | 60 |
| 41 protected: | 61 protected: |
| 42 // we need to "undo" the behavior of SkNWayCanvas, which will try to forward | 62 // we need to "undo" the behavior of SkNWayCanvas, which will try to forward |
| 43 // it. | 63 // it. |
| 44 void onDrawPicture(const SkPicture* picture, | 64 void onDrawPicture(const SkPicture* picture, |
| 45 const SkMatrix* matrix, | 65 const SkMatrix* matrix, |
| 46 const SkPaint* paint) override { | 66 const SkPaint* paint) override { |
| 47 SkCanvas::onDrawPicture(picture, matrix, paint); | 67 SkCanvas::onDrawPicture(picture, matrix, paint); |
| 48 } | 68 } |
| 49 | 69 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 | 159 |
| 140 SkFilterQuality filter_quality = kNone_SkFilterQuality; | 160 SkFilterQuality filter_quality = kNone_SkFilterQuality; |
| 141 if (paint) { | 161 if (paint) { |
| 142 filter_quality = paint->getFilterQuality(); | 162 filter_quality = paint->getFilterQuality(); |
| 143 } | 163 } |
| 144 | 164 |
| 145 SkIRect src_irect; | 165 SkIRect src_irect; |
| 146 src_rect.roundOut(&src_irect); | 166 src_rect.roundOut(&src_irect); |
| 147 image_set_->push_back(std::make_pair( | 167 image_set_->push_back(std::make_pair( |
| 148 DrawImage(std::move(image), src_irect, filter_quality, matrix), | 168 DrawImage(std::move(image), src_irect, filter_quality, matrix), |
| 149 gfx::ToEnclosingRect(gfx::SkRectToRectF(paint_rect)))); | 169 SafeIntersectRects(paint_rect, int_canvas_bounds_))); |
| 150 } | 170 } |
| 151 | 171 |
| 152 std::vector<std::pair<DrawImage, gfx::Rect>>* image_set_; | 172 std::vector<std::pair<DrawImage, gfx::Rect>>* image_set_; |
| 153 const SkRect canvas_bounds_; | 173 const SkRect canvas_bounds_; |
| 174 const gfx::Rect int_canvas_bounds_; | |
| 154 std::vector<SkPaint> saved_paints_; | 175 std::vector<SkPaint> saved_paints_; |
| 155 }; | 176 }; |
| 156 | 177 |
| 157 } // namespace | 178 } // namespace |
| 158 | 179 |
| 159 DiscardableImageMap::DiscardableImageMap() {} | 180 DiscardableImageMap::DiscardableImageMap() {} |
| 160 | 181 |
| 161 DiscardableImageMap::~DiscardableImageMap() {} | 182 DiscardableImageMap::~DiscardableImageMap() {} |
| 162 | 183 |
| 163 sk_sp<SkCanvas> DiscardableImageMap::BeginGeneratingMetadata( | 184 sk_sp<SkCanvas> DiscardableImageMap::BeginGeneratingMetadata( |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 188 DiscardableImageMap* image_map, | 209 DiscardableImageMap* image_map, |
| 189 const gfx::Size& bounds) | 210 const gfx::Size& bounds) |
| 190 : image_map_(image_map), | 211 : image_map_(image_map), |
| 191 metadata_canvas_(image_map->BeginGeneratingMetadata(bounds)) {} | 212 metadata_canvas_(image_map->BeginGeneratingMetadata(bounds)) {} |
| 192 | 213 |
| 193 DiscardableImageMap::ScopedMetadataGenerator::~ScopedMetadataGenerator() { | 214 DiscardableImageMap::ScopedMetadataGenerator::~ScopedMetadataGenerator() { |
| 194 image_map_->EndGeneratingMetadata(); | 215 image_map_->EndGeneratingMetadata(); |
| 195 } | 216 } |
| 196 | 217 |
| 197 } // namespace cc | 218 } // namespace cc |
| OLD | NEW |