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 #ifndef CC_PLAYBACK_DISCARDABLE_IMAGE_MAP_H_ | 5 #ifndef CC_PLAYBACK_DISCARDABLE_IMAGE_MAP_H_ |
| 6 #define CC_PLAYBACK_DISCARDABLE_IMAGE_MAP_H_ | 6 #define CC_PLAYBACK_DISCARDABLE_IMAGE_MAP_H_ |
| 7 | 7 |
| 8 #include <unordered_map> | |
| 8 #include <utility> | 9 #include <utility> |
| 9 #include <vector> | 10 #include <vector> |
| 10 | 11 |
| 11 #include "cc/base/cc_export.h" | 12 #include "cc/base/cc_export.h" |
| 13 #include "cc/base/region.h" | |
| 12 #include "cc/base/rtree.h" | 14 #include "cc/base/rtree.h" |
| 13 #include "cc/playback/draw_image.h" | 15 #include "cc/playback/draw_image.h" |
| 14 #include "third_party/skia/include/core/SkCanvas.h" | 16 #include "third_party/skia/include/core/SkCanvas.h" |
| 15 #include "third_party/skia/include/core/SkRefCnt.h" | 17 #include "third_party/skia/include/core/SkRefCnt.h" |
| 16 #include "ui/gfx/geometry/rect.h" | 18 #include "ui/gfx/geometry/rect.h" |
| 17 #include "ui/gfx/geometry/size.h" | 19 #include "ui/gfx/geometry/size.h" |
| 18 | 20 |
| 19 namespace cc { | 21 namespace cc { |
| 20 | 22 |
| 23 // A map of SkImage id to the region for this image. | |
| 24 using ImageToRegionMap = std::unordered_map<uint32_t, Region>; | |
|
vmpstr
2016/11/15 18:57:54
Can you put this as a member of DiscardableImageMa
Khushal
2016/11/16 05:01:58
Done.
| |
| 25 | |
| 21 // Helper function to apply the matrix to the rect and return the result. | 26 // Helper function to apply the matrix to the rect and return the result. |
| 22 SkRect MapRect(const SkMatrix& matrix, const SkRect& src); | 27 SkRect MapRect(const SkMatrix& matrix, const SkRect& src); |
| 23 | 28 |
| 24 // This class is used for generating discardable images data (see DrawImage | 29 // This class is used for generating discardable images data (see DrawImage |
| 25 // for the type of data it stores). It allows the client to query a particular | 30 // for the type of data it stores). It allows the client to query a particular |
| 26 // rect and get back a list of DrawImages in that rect. | 31 // rect and get back a list of DrawImages in that rect. |
| 27 class CC_EXPORT DiscardableImageMap { | 32 class CC_EXPORT DiscardableImageMap { |
| 28 public: | 33 public: |
| 29 class CC_EXPORT ScopedMetadataGenerator { | 34 class CC_EXPORT ScopedMetadataGenerator { |
| 30 public: | 35 public: |
| 31 ScopedMetadataGenerator(DiscardableImageMap* image_map, | 36 ScopedMetadataGenerator(DiscardableImageMap* image_map, |
| 32 const gfx::Size& bounds); | 37 const gfx::Size& bounds); |
| 33 ~ScopedMetadataGenerator(); | 38 ~ScopedMetadataGenerator(); |
| 34 | 39 |
| 35 SkCanvas* canvas() { return metadata_canvas_.get(); } | 40 SkCanvas* canvas() { return metadata_canvas_.get(); } |
| 36 | 41 |
| 37 private: | 42 private: |
| 38 DiscardableImageMap* image_map_; | 43 DiscardableImageMap* image_map_; |
| 39 sk_sp<SkCanvas> metadata_canvas_; | 44 sk_sp<SkCanvas> metadata_canvas_; |
| 40 }; | 45 }; |
| 41 | 46 |
| 42 DiscardableImageMap(); | 47 DiscardableImageMap(); |
| 43 ~DiscardableImageMap(); | 48 ~DiscardableImageMap(); |
| 44 | 49 |
| 45 bool empty() const { return all_images_.empty(); } | 50 bool empty() const { return all_images_.empty(); } |
| 46 void GetDiscardableImagesInRect(const gfx::Rect& rect, | 51 void GetDiscardableImagesInRect(const gfx::Rect& rect, |
| 47 const gfx::SizeF& raster_scales, | 52 const gfx::SizeF& raster_scales, |
| 48 std::vector<DrawImage>* images) const; | 53 std::vector<DrawImage>* images) const; |
| 54 Region GetRegionForImage(const SkImage* image) const; | |
| 49 | 55 |
| 50 private: | 56 private: |
| 51 friend class ScopedMetadataGenerator; | 57 friend class ScopedMetadataGenerator; |
| 52 friend class DiscardableImageMapTest; | 58 friend class DiscardableImageMapTest; |
| 53 | 59 |
| 54 sk_sp<SkCanvas> BeginGeneratingMetadata(const gfx::Size& bounds); | 60 sk_sp<SkCanvas> BeginGeneratingMetadata(const gfx::Size& bounds); |
| 55 void EndGeneratingMetadata(); | 61 void EndGeneratingMetadata(); |
| 56 | 62 |
| 57 std::vector<std::pair<DrawImage, gfx::Rect>> all_images_; | 63 std::vector<std::pair<DrawImage, gfx::Rect>> all_images_; |
| 64 ImageToRegionMap image_to_region_; | |
|
vmpstr
2016/11/15 18:57:54
nit: image_id_to_region_map_
Khushal
2016/11/16 05:01:58
Done.
| |
| 65 | |
| 58 RTree images_rtree_; | 66 RTree images_rtree_; |
| 59 }; | 67 }; |
| 60 | 68 |
| 61 } // namespace cc | 69 } // namespace cc |
| 62 | 70 |
| 63 #endif // CC_PLAYBACK_DISCARDABLE_IMAGE_MAP_H_ | 71 #endif // CC_PLAYBACK_DISCARDABLE_IMAGE_MAP_H_ |
| OLD | NEW |