| 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_PAINT_DISCARDABLE_IMAGE_MAP_H_ | 5 #ifndef CC_PAINT_DISCARDABLE_IMAGE_MAP_H_ |
| 6 #define CC_PAINT_DISCARDABLE_IMAGE_MAP_H_ | 6 #define CC_PAINT_DISCARDABLE_IMAGE_MAP_H_ |
| 7 | 7 |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/containers/flat_map.h" | 11 #include "base/containers/flat_map.h" |
| 12 #include "cc/base/rtree.h" | 12 #include "cc/base/rtree.h" |
| 13 #include "cc/paint/draw_image.h" | 13 #include "cc/paint/draw_image.h" |
| 14 #include "cc/paint/image_id.h" | 14 #include "cc/paint/image_id.h" |
| 15 #include "cc/paint/paint_export.h" | 15 #include "cc/paint/paint_export.h" |
| 16 #include "cc/paint/paint_flags.h" |
| 17 #include "cc/paint/paint_image.h" |
| 16 #include "third_party/skia/include/core/SkCanvas.h" | 18 #include "third_party/skia/include/core/SkCanvas.h" |
| 17 #include "third_party/skia/include/core/SkRefCnt.h" | 19 #include "third_party/skia/include/core/SkRefCnt.h" |
| 18 #include "ui/gfx/geometry/rect.h" | 20 #include "ui/gfx/geometry/rect.h" |
| 19 #include "ui/gfx/geometry/size.h" | 21 #include "ui/gfx/geometry/size.h" |
| 20 | 22 |
| 21 namespace cc { | 23 namespace cc { |
| 22 | 24 class DiscardableImageStore; |
| 23 // Helper function to apply the matrix to the rect and return the result. | |
| 24 SkRect MapRect(const SkMatrix& matrix, const SkRect& src); | |
| 25 | 25 |
| 26 // This class is used for generating discardable images data (see DrawImage | 26 // This class is used for generating discardable images data (see DrawImage |
| 27 // for the type of data it stores). It allows the client to query a particular | 27 // for the type of data it stores). It allows the client to query a particular |
| 28 // rect and get back a list of DrawImages in that rect. | 28 // rect and get back a list of DrawImages in that rect. |
| 29 class CC_PAINT_EXPORT DiscardableImageMap { | 29 class CC_PAINT_EXPORT DiscardableImageMap { |
| 30 public: | 30 public: |
| 31 class CC_PAINT_EXPORT ScopedMetadataGenerator { | 31 class CC_PAINT_EXPORT ScopedMetadataGenerator { |
| 32 public: | 32 public: |
| 33 ScopedMetadataGenerator(DiscardableImageMap* image_map, | 33 ScopedMetadataGenerator(DiscardableImageMap* image_map, |
| 34 const gfx::Size& bounds); | 34 const gfx::Size& bounds); |
| 35 ~ScopedMetadataGenerator(); | 35 ~ScopedMetadataGenerator(); |
| 36 | 36 |
| 37 SkCanvas* canvas() { return metadata_canvas_.get(); } | 37 DiscardableImageStore* image_store() { return image_store_.get(); } |
| 38 | 38 |
| 39 private: | 39 private: |
| 40 DiscardableImageMap* image_map_; | 40 DiscardableImageMap* image_map_; |
| 41 std::unique_ptr<SkCanvas> metadata_canvas_; | 41 std::unique_ptr<DiscardableImageStore> image_store_; |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 DiscardableImageMap(); | 44 DiscardableImageMap(); |
| 45 ~DiscardableImageMap(); | 45 ~DiscardableImageMap(); |
| 46 | 46 |
| 47 bool empty() const { return all_images_.empty(); } | 47 bool empty() const { return all_images_.empty(); } |
| 48 void GetDiscardableImagesInRect(const gfx::Rect& rect, | 48 void GetDiscardableImagesInRect(const gfx::Rect& rect, |
| 49 float contents_scale, | 49 float contents_scale, |
| 50 const gfx::ColorSpace& target_color_space, | 50 const gfx::ColorSpace& target_color_space, |
| 51 std::vector<DrawImage>* images) const; | 51 std::vector<DrawImage>* images) const; |
| 52 gfx::Rect GetRectForImage(ImageId image_id) const; | 52 gfx::Rect GetRectForImage(ImageId image_id) const; |
| 53 | 53 |
| 54 private: | 54 private: |
| 55 friend class ScopedMetadataGenerator; | 55 friend class ScopedMetadataGenerator; |
| 56 friend class DiscardableImageMapTest; | 56 friend class DiscardableImageMapTest; |
| 57 | 57 |
| 58 std::unique_ptr<SkCanvas> BeginGeneratingMetadata(const gfx::Size& bounds); | 58 std::unique_ptr<DiscardableImageStore> BeginGeneratingMetadata( |
| 59 const gfx::Size& bounds); |
| 59 void EndGeneratingMetadata(); | 60 void EndGeneratingMetadata(); |
| 60 | 61 |
| 61 std::vector<std::pair<DrawImage, gfx::Rect>> all_images_; | 62 std::vector<std::pair<DrawImage, gfx::Rect>> all_images_; |
| 62 base::flat_map<ImageId, gfx::Rect> image_id_to_rect_; | 63 base::flat_map<ImageId, gfx::Rect> image_id_to_rect_; |
| 63 | 64 |
| 64 RTree images_rtree_; | 65 RTree images_rtree_; |
| 65 }; | 66 }; |
| 66 | 67 |
| 67 } // namespace cc | 68 } // namespace cc |
| 68 | 69 |
| 69 #endif // CC_PAINT_DISCARDABLE_IMAGE_MAP_H_ | 70 #endif // CC_PAINT_DISCARDABLE_IMAGE_MAP_H_ |
| OLD | NEW |