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