| 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_CONTROLLER_H_ | 5 #ifndef CC_TILES_IMAGE_DECODE_CACHE_H_ |
| 6 #define CC_TILES_IMAGE_DECODE_CONTROLLER_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/playback/decoded_draw_image.h" | 9 #include "cc/playback/decoded_draw_image.h" |
| 10 #include "cc/playback/draw_image.h" | 10 #include "cc/playback/draw_image.h" |
| 11 #include "cc/tiles/tile_priority.h" | 11 #include "cc/tiles/tile_priority.h" |
| 12 | 12 |
| 13 namespace cc { | 13 namespace cc { |
| 14 | 14 |
| 15 class TileTask; | 15 class TileTask; |
| 16 | 16 |
| 17 // ImageDecodeController is responsible for generating decode tasks, decoding | 17 // ImageDecodeCache is responsible for generating decode tasks, decoding |
| 18 // images, storing images in cache, and being able to return the decoded images | 18 // images, storing images in cache, and being able to return the decoded images |
| 19 // when requested. | 19 // when requested. |
| 20 | 20 |
| 21 // ImageDecodeController is responsible for the following things: | 21 // ImageDecodeCache is responsible for the following things: |
| 22 // 1. Given a DrawImage, it can return an TileTask which when run will | 22 // 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 | 23 // 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 | 24 // 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 | 25 // function indicates whether the image was or is going to be locked, so an |
| 26 // unlock will be required. | 26 // unlock will be required. |
| 27 // 2. Given a cache key and a DrawImage, it can decode the image and store it in | 27 // 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 | 28 // the cache. Note that it is important that this function is only accessed |
| 29 // via an image decode task. | 29 // via an image decode task. |
| 30 // 3. Given a DrawImage, it can return a DecodedDrawImage, which represented the | 30 // 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 | 31 // 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 | 32 // 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 | 33 // getting the image. As such, this should only be accessed from a raster |
| 34 // thread. | 34 // thread. |
| 35 class CC_EXPORT ImageDecodeController { | 35 class CC_EXPORT ImageDecodeCache { |
| 36 public: | 36 public: |
| 37 // This information should be used strictly in tracing, UMA, and any other | 37 // This information should be used strictly in tracing, UMA, and any other |
| 38 // reporting systems. | 38 // reporting systems. |
| 39 struct TracingInfo { | 39 struct TracingInfo { |
| 40 TracingInfo(uint64_t prepare_tiles_id, | 40 TracingInfo(uint64_t prepare_tiles_id, |
| 41 TilePriority::PriorityBin requesting_tile_bin) | 41 TilePriority::PriorityBin requesting_tile_bin) |
| 42 : prepare_tiles_id(prepare_tiles_id), | 42 : prepare_tiles_id(prepare_tiles_id), |
| 43 requesting_tile_bin(requesting_tile_bin) {} | 43 requesting_tile_bin(requesting_tile_bin) {} |
| 44 TracingInfo() : TracingInfo(0, TilePriority::NOW) {} | 44 TracingInfo() : TracingInfo(0, TilePriority::NOW) {} |
| 45 | 45 |
| 46 // ID for the current prepare tiles call. | 46 // ID for the current prepare tiles call. |
| 47 const uint64_t prepare_tiles_id; | 47 const uint64_t prepare_tiles_id; |
| 48 | 48 |
| 49 // The bin of the tile that caused this image to be requested. | 49 // The bin of the tile that caused this image to be requested. |
| 50 const TilePriority::PriorityBin requesting_tile_bin; | 50 const TilePriority::PriorityBin requesting_tile_bin; |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 virtual ~ImageDecodeController() {} | 53 virtual ~ImageDecodeCache() {} |
| 54 | 54 |
| 55 // Fill in an TileTask which will decode the given image when run. In | 55 // 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 | 56 // 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. | 57 // image needs to be unreffed when the caller is finished with it. |
| 58 // | 58 // |
| 59 // This is called by the tile manager (on the compositor thread) when creating | 59 // This is called by the tile manager (on the compositor thread) when creating |
| 60 // a raster task. | 60 // a raster task. |
| 61 virtual bool GetTaskForImageAndRef(const DrawImage& image, | 61 virtual bool GetTaskForImageAndRef(const DrawImage& image, |
| 62 const TracingInfo& tracing_info, | 62 const TracingInfo& tracing_info, |
| 63 scoped_refptr<TileTask>* task) = 0; | 63 scoped_refptr<TileTask>* task) = 0; |
| 64 // Unrefs an image. When the tile is finished, this should be called for every | 64 // Unrefs an image. When the tile is finished, this should be called for every |
| 65 // GetTaskForImageAndRef call that returned true. | 65 // GetTaskForImageAndRef call that returned true. |
| 66 virtual void UnrefImage(const DrawImage& image) = 0; | 66 virtual void UnrefImage(const DrawImage& image) = 0; |
| 67 | 67 |
| 68 // Returns a decoded draw image. This may cause a decode if the image was not | 68 // Returns a decoded draw image. This may cause a decode if the image was not |
| 69 // predecoded. | 69 // predecoded. |
| 70 // | 70 // |
| 71 // This is called by a raster task (on a worker thread) when an image is | 71 // This is called by a raster task (on a worker thread) when an image is |
| 72 // required. | 72 // required. |
| 73 virtual DecodedDrawImage GetDecodedImageForDraw(const DrawImage& image) = 0; | 73 virtual DecodedDrawImage GetDecodedImageForDraw(const DrawImage& image) = 0; |
| 74 // Unrefs an image. This should be called for every GetDecodedImageForDraw | 74 // Unrefs an image. This should be called for every GetDecodedImageForDraw |
| 75 // when the draw with the image is finished. | 75 // when the draw with the image is finished. |
| 76 virtual void DrawWithImageFinished(const DrawImage& image, | 76 virtual void DrawWithImageFinished(const DrawImage& image, |
| 77 const DecodedDrawImage& decoded_image) = 0; | 77 const DecodedDrawImage& decoded_image) = 0; |
| 78 | 78 |
| 79 // This function informs the controller that now is a good time to clean up | 79 // This function informs the cache that now is a good time to clean up |
| 80 // memory. This is called periodically from the compositor thread. | 80 // memory. This is called periodically from the compositor thread. |
| 81 virtual void ReduceCacheUsage() = 0; | 81 virtual void ReduceCacheUsage() = 0; |
| 82 | 82 |
| 83 // This function informs the controller that we are hidden and should not be | 83 // This function informs the cache that we are hidden and should not be |
| 84 // retaining cached resources longer than needed. | 84 // retaining cached resources longer than needed. |
| 85 virtual void SetShouldAggressivelyFreeResources( | 85 virtual void SetShouldAggressivelyFreeResources( |
| 86 bool aggressively_free_resources) = 0; | 86 bool aggressively_free_resources) = 0; |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 } // namespace cc | 89 } // namespace cc |
| 90 | 90 |
| 91 #endif // CC_TILES_IMAGE_DECODE_CONTROLLER_H_ | 91 #endif // CC_TILES_IMAGE_DECODE_CACHE_H_ |
| OLD | NEW |