summaryrefslogtreecommitdiffstats
path: root/cc/tiles/image_decode_controller.h
blob: f07892c13f5cc683b2a6df4acb9365c355ccb296 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CC_TILES_IMAGE_DECODE_CONTROLLER_H_
#define CC_TILES_IMAGE_DECODE_CONTROLLER_H_

#include "base/containers/hash_tables.h"
#include "base/memory/ref_counted.h"
#include "cc/base/cc_export.h"
#include "cc/playback/discardable_image_map.h"
#include "cc/raster/tile_task_runner.h"
#include "skia/ext/refptr.h"

namespace cc {

class ImageDecodeController {
 public:
  ImageDecodeController();
  ~ImageDecodeController();

  scoped_refptr<ImageDecodeTask> GetTaskForImage(const DrawImage& image,
                                                 int layer_id,
                                                 uint64_t prepare_tiles_id);

  // Note that this function has to remain thread safe.
  void DecodeImage(const SkImage* image);

  // TODO(vmpstr): This should go away once the controller is decoding images
  // based on priority and memory.
  void AddLayerUsedCount(int layer_id);
  void SubtractLayerUsedCount(int layer_id);

  void OnImageDecodeTaskCompleted(int layer_id,
                                  const SkImage* image,
                                  bool was_canceled);

 private:
  scoped_refptr<ImageDecodeTask> CreateTaskForImage(const SkImage* image,
                                                    int layer_id,
                                                    uint64_t prepare_tiles_id);

  using ImageTaskMap = base::hash_map<uint32_t, scoped_refptr<ImageDecodeTask>>;
  using LayerImageTaskMap = base::hash_map<int, ImageTaskMap>;
  LayerImageTaskMap image_decode_tasks_;

  using LayerCountMap = base::hash_map<int, int>;
  LayerCountMap used_layer_counts_;
};

}  // namespace cc

#endif  // CC_TILES_IMAGE_DECODE_CONTROLLER_H_