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_TILES_IMAGE_DECODE_CACHE_H_ | 5 #ifndef CC_TILES_IMAGE_DECODE_CACHE_H_ |
| 6 #define CC_TILES_IMAGE_DECODE_CACHE_H_ | 6 #define CC_TILES_IMAGE_DECODE_CACHE_H_ |
| 7 | 7 |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "cc/base/devtools_instrumentation.h" | |
| 9 #include "cc/paint/draw_image.h" | 10 #include "cc/paint/draw_image.h" |
| 10 #include "cc/tiles/decoded_draw_image.h" | 11 #include "cc/tiles/decoded_draw_image.h" |
| 11 #include "cc/tiles/tile_priority.h" | 12 #include "cc/tiles/tile_priority.h" |
| 12 | 13 |
| 13 namespace cc { | 14 namespace cc { |
| 14 | 15 |
| 15 class TileTask; | 16 class TileTask; |
| 16 | 17 |
| 17 // ImageDecodeCache is responsible for generating decode tasks, decoding | 18 // ImageDecodeCache is responsible for generating decode tasks, decoding |
| 18 // images, storing images in cache, and being able to return the decoded images | 19 // images, storing images in cache, and being able to return the decoded images |
| 19 // when requested. | 20 // when requested. |
| 20 | 21 |
| 21 // ImageDecodeCache is responsible for the following things: | 22 // ImageDecodeCache is responsible for the following things: |
| 22 // 1. Given a DrawImage, it can return an TileTask which when run will | 23 // 1. Given a DrawImage, it can return an TileTask which when run will |
| 23 // decode and cache the resulting image. If the image does not need a task to | 24 // decode and cache the resulting image. If the image does not need a task to |
| 24 // be decoded, then nullptr will be returned. The return value of the | 25 // be decoded, then nullptr will be returned. The return value of the |
| 25 // function indicates whether the image was or is going to be locked, so an | 26 // function indicates whether the image was or is going to be locked, so an |
| 26 // unlock will be required. | 27 // unlock will be required. |
| 27 // 2. Given a cache key and a DrawImage, it can decode the image and store it in | 28 // 2. Given a cache key and a DrawImage, it can decode the image and store it in |
| 28 // the cache. Note that it is important that this function is only accessed | 29 // the cache. Note that it is important that this function is only accessed |
| 29 // via an image decode task. | 30 // via an image decode task. |
| 30 // 3. Given a DrawImage, it can return a DecodedDrawImage, which represented the | 31 // 3. Given a DrawImage, it can return a DecodedDrawImage, which represented the |
| 31 // decoded version of the image. Note that if the image is not in the cache | 32 // decoded version of the image. Note that if the image is not in the cache |
| 32 // and it needs to be scaled/decoded, then this decode will happen as part of | 33 // and it needs to be scaled/decoded, then this decode will happen as part of |
| 33 // getting the image. As such, this should only be accessed from a raster | 34 // getting the image. As such, this should only be accessed from a raster |
| 34 // thread. | 35 // thread. |
| 35 class CC_EXPORT ImageDecodeCache { | 36 class CC_EXPORT ImageDecodeCache { |
| 36 public: | 37 public: |
| 38 enum class ImageDecodeType { | |
| 39 IN_RASTER, | |
|
danakj
2017/05/26 22:36:23
enums should be kFoo style now
Khushal
2017/05/26 23:17:35
Done.
| |
| 40 OUT_OF_RASTER_CHECKER_IMAGING, | |
| 41 OUT_OF_RASTER_JS_DECODE | |
| 42 }; | |
| 43 | |
| 44 static devtools_instrumentation::ScopedImageDecodeTask::DecodeTaskType | |
| 45 ToScopedDecodeTaskType(ImageDecodeType decode_type) { | |
| 46 using ScopedTaskType = | |
| 47 devtools_instrumentation::ScopedImageDecodeTask::DecodeTaskType; | |
| 48 switch (decode_type) { | |
| 49 case ImageDecodeType::IN_RASTER: | |
| 50 return ScopedTaskType::IN_RASTER; | |
| 51 case ImageDecodeType::OUT_OF_RASTER_CHECKER_IMAGING: | |
| 52 return ScopedTaskType::CHECKER_IMAGING; | |
|
danakj
2017/05/26 22:36:23
I think itd be less confusing if these names match
Khushal
2017/05/26 23:17:35
Done.
| |
| 53 case ImageDecodeType::OUT_OF_RASTER_JS_DECODE: | |
| 54 return ScopedTaskType::JS_DECODE_API; | |
| 55 } | |
| 56 NOTREACHED(); | |
| 57 return ScopedTaskType::IN_RASTER; | |
| 58 } | |
| 59 | |
| 37 // This information should be used strictly in tracing, UMA, and any other | 60 // This information should be used strictly in tracing, UMA, and any other |
| 38 // reporting systems. | 61 // reporting systems. |
| 39 struct TracingInfo { | 62 struct TracingInfo { |
|
danakj
2017/05/26 22:36:23
With these changes, this struct now has 4 construc
Khushal
2017/05/26 23:17:35
I just removed both.
| |
| 40 TracingInfo(uint64_t prepare_tiles_id, | 63 TracingInfo(uint64_t prepare_tiles_id, |
| 41 TilePriority::PriorityBin requesting_tile_bin) | 64 TilePriority::PriorityBin requesting_tile_bin, |
| 65 ImageDecodeType type = ImageDecodeType::IN_RASTER) | |
| 42 : prepare_tiles_id(prepare_tiles_id), | 66 : prepare_tiles_id(prepare_tiles_id), |
| 43 requesting_tile_bin(requesting_tile_bin) {} | 67 requesting_tile_bin(requesting_tile_bin), |
| 68 type(type) {} | |
| 44 TracingInfo() : TracingInfo(0, TilePriority::NOW) {} | 69 TracingInfo() : TracingInfo(0, TilePriority::NOW) {} |
| 70 explicit TracingInfo(ImageDecodeType type) | |
| 71 : TracingInfo(0, TilePriority::NOW, type) {} | |
| 45 | 72 |
| 46 // ID for the current prepare tiles call. | 73 // ID for the current prepare tiles call. |
| 47 const uint64_t prepare_tiles_id; | 74 const uint64_t prepare_tiles_id; |
| 48 | 75 |
| 49 // The bin of the tile that caused this image to be requested. | 76 // The bin of the tile that caused this image to be requested. |
| 50 const TilePriority::PriorityBin requesting_tile_bin; | 77 const TilePriority::PriorityBin requesting_tile_bin; |
| 78 | |
| 79 // The task type for in-raster and out of raster decode tasks. | |
| 80 const ImageDecodeType type; | |
| 51 }; | 81 }; |
| 52 | 82 |
| 53 virtual ~ImageDecodeCache() {} | 83 virtual ~ImageDecodeCache() {} |
| 54 | 84 |
| 55 // Fill in an TileTask which will decode the given image when run. In | 85 // Fill in an TileTask which will decode the given image when run. In |
| 56 // case the image is already cached, fills in nullptr. Returns true if the | 86 // case the image is already cached, fills in nullptr. Returns true if the |
| 57 // image needs to be unreffed when the caller is finished with it. | 87 // image needs to be unreffed when the caller is finished with it. |
| 58 // | 88 // |
| 59 // This is called by the tile manager (on the compositor thread) when creating | 89 // This is called by the tile manager (on the compositor thread) when creating |
| 60 // a raster task. | 90 // a raster task. |
| 61 virtual bool GetTaskForImageAndRef(const DrawImage& image, | 91 virtual bool GetTaskForImageAndRef(const DrawImage& image, |
| 62 const TracingInfo& tracing_info, | 92 const TracingInfo& tracing_info, |
| 63 scoped_refptr<TileTask>* task) = 0; | 93 scoped_refptr<TileTask>* task) = 0; |
| 64 // Similar to GetTaskForImageAndRef, except that it returns tasks that are not | 94 // Similar to GetTaskForImageAndRef, except that it returns tasks that are not |
| 65 // meant to be run as part of raster. That is, this is part of a predecode | 95 // meant to be run as part of raster. That is, this is part of a predecode |
| 66 // API. Note that this should only return a task responsible for decoding (and | 96 // API. Note that this should only return a task responsible for decoding (and |
| 67 // not uploading), since it will be run on a worker thread which may not have | 97 // not uploading), since it will be run on a worker thread which may not have |
| 68 // the right GPU context for upload. | 98 // the right GPU context for upload. |
| 69 virtual bool GetOutOfRasterDecodeTaskForImageAndRef( | 99 virtual bool GetOutOfRasterDecodeTaskForImageAndRef( |
| 70 const DrawImage& image, | 100 const DrawImage& image, |
| 101 ImageDecodeType decode_type, | |
| 71 scoped_refptr<TileTask>* task) = 0; | 102 scoped_refptr<TileTask>* task) = 0; |
| 72 | 103 |
| 73 // Unrefs an image. When the tile is finished, this should be called for every | 104 // Unrefs an image. When the tile is finished, this should be called for every |
| 74 // GetTaskForImageAndRef call that returned true. | 105 // GetTaskForImageAndRef call that returned true. |
| 75 virtual void UnrefImage(const DrawImage& image) = 0; | 106 virtual void UnrefImage(const DrawImage& image) = 0; |
| 76 | 107 |
| 77 // Returns a decoded draw image. This may cause a decode if the image was not | 108 // Returns a decoded draw image. This may cause a decode if the image was not |
| 78 // predecoded. | 109 // predecoded. |
| 79 // | 110 // |
| 80 // This is called by a raster task (on a worker thread) when an image is | 111 // This is called by a raster task (on a worker thread) when an image is |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 100 // Returns the maximum amount of memory we would be able to lock. This ignores | 131 // Returns the maximum amount of memory we would be able to lock. This ignores |
| 101 // any temporary states, such as throttled, and return the maximum possible | 132 // any temporary states, such as throttled, and return the maximum possible |
| 102 // memory. It is used as an esimate of whether an image can fit into the | 133 // memory. It is used as an esimate of whether an image can fit into the |
| 103 // locked budget before creating a task. | 134 // locked budget before creating a task. |
| 104 virtual size_t GetMaximumMemoryLimitBytes() const = 0; | 135 virtual size_t GetMaximumMemoryLimitBytes() const = 0; |
| 105 }; | 136 }; |
| 106 | 137 |
| 107 } // namespace cc | 138 } // namespace cc |
| 108 | 139 |
| 109 #endif // CC_TILES_IMAGE_DECODE_CACHE_H_ | 140 #endif // CC_TILES_IMAGE_DECODE_CACHE_H_ |
| OLD | NEW |