Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(870)

Side by Side Diff: cc/tiles/software_image_decode_controller.cc

Issue 2286583002: Make cc::SoftwareImageDecodeController, cc::ResourcePool, and cc::StagingBufferPoo… (Closed)
Patch Set: WIP Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "cc/tiles/software_image_decode_controller.h" 5 #include "cc/tiles/software_image_decode_controller.h"
6 6
7 #include <inttypes.h> 7 #include <inttypes.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
11 #include <functional> 11 #include <functional>
12 12
13 #include "base/format_macros.h" 13 #include "base/format_macros.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/discardable_memory.h" 15 #include "base/memory/discardable_memory.h"
16 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
17 #include "base/metrics/histogram_macros.h" 17 #include "base/metrics/histogram_macros.h"
18 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
19 #include "base/threading/thread_task_runner_handle.h" 19 #include "base/threading/thread_task_runner_handle.h"
20 #include "base/trace_event/memory_dump_manager.h" 20 #include "base/trace_event/memory_dump_manager.h"
21 #include "cc/debug/devtools_instrumentation.h" 21 #include "cc/debug/devtools_instrumentation.h"
22 #include "cc/raster/tile_task.h" 22 #include "cc/raster/tile_task.h"
23 #include "cc/resources/resource_format_utils.h" 23 #include "cc/resources/resource_format_utils.h"
24 #include "cc/tiles/mipmap_util.h" 24 #include "cc/tiles/mipmap_util.h"
25 #include "components/memory_coordinator/common/client_registry.h"
25 #include "third_party/skia/include/core/SkCanvas.h" 26 #include "third_party/skia/include/core/SkCanvas.h"
26 #include "third_party/skia/include/core/SkImage.h" 27 #include "third_party/skia/include/core/SkImage.h"
27 #include "third_party/skia/include/core/SkPixmap.h" 28 #include "third_party/skia/include/core/SkPixmap.h"
28 #include "ui/gfx/skia_util.h" 29 #include "ui/gfx/skia_util.h"
29 30
30 namespace cc { 31 namespace cc {
31 namespace { 32 namespace {
32 33
33 // The largest single high quality image to try and process. Images above this 34 // The largest single high quality image to try and process. Images above this
34 // size will drop down to medium quality. 35 // size will drop down to medium quality.
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 at_raster_decoded_images_(ImageMRUCache::NO_AUTO_EVICT), 174 at_raster_decoded_images_(ImageMRUCache::NO_AUTO_EVICT),
174 locked_images_budget_(locked_memory_limit_bytes), 175 locked_images_budget_(locked_memory_limit_bytes),
175 format_(format) { 176 format_(format) {
176 // In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview). 177 // In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview).
177 // Don't register a dump provider in these cases. 178 // Don't register a dump provider in these cases.
178 if (base::ThreadTaskRunnerHandle::IsSet()) { 179 if (base::ThreadTaskRunnerHandle::IsSet()) {
179 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( 180 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
180 this, "cc::SoftwareImageDecodeController", 181 this, "cc::SoftwareImageDecodeController",
181 base::ThreadTaskRunnerHandle::Get()); 182 base::ThreadTaskRunnerHandle::Get());
182 } 183 }
184 // Register this component with memory_coordinator::ClientRegistry.
185 memory_coordinator::ClientRegistry* registry =
186 memory_coordinator::ClientRegistry::GetInstance();
187 if (registry)
188 registry->RegisterClient(this);
183 } 189 }
184 190
185 SoftwareImageDecodeController::~SoftwareImageDecodeController() { 191 SoftwareImageDecodeController::~SoftwareImageDecodeController() {
186 DCHECK_EQ(0u, decoded_images_ref_counts_.size()); 192 DCHECK_EQ(0u, decoded_images_ref_counts_.size());
187 DCHECK_EQ(0u, at_raster_decoded_images_ref_counts_.size()); 193 DCHECK_EQ(0u, at_raster_decoded_images_ref_counts_.size());
188 194
189 // It is safe to unregister, even if we didn't register in the constructor. 195 // It is safe to unregister, even if we didn't register in the constructor.
190 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( 196 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
191 this); 197 this);
198 // Unregister this component with memory_coordinator::ClientRegistry.
199 memory_coordinator::ClientRegistry* registry =
200 memory_coordinator::ClientRegistry::GetInstance();
201 if (registry)
202 registry->UnregisterClient(this);
192 } 203 }
193 204
194 bool SoftwareImageDecodeController::GetTaskForImageAndRef( 205 bool SoftwareImageDecodeController::GetTaskForImageAndRef(
195 const DrawImage& image, 206 const DrawImage& image,
196 const TracingInfo& tracing_info, 207 const TracingInfo& tracing_info,
197 scoped_refptr<TileTask>* task) { 208 scoped_refptr<TileTask>* task) {
198 // If the image already exists or if we're going to create a task for it, then 209 // If the image already exists or if we're going to create a task for it, then
199 // we'll likely need to ref this image (the exception is if we're prerolling 210 // we'll likely need to ref this image (the exception is if we're prerolling
200 // the image only). That means the image is or will be in the cache. When the 211 // the image only). That means the image is or will be in the cache. When the
201 // ref goes to 0, it will be unpinned but will remain in the cache. If the 212 // ref goes to 0, it will be unpinned but will remain in the cache. If the
(...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 1082
1072 void SoftwareImageDecodeController::MemoryBudget::ResetUsage() { 1083 void SoftwareImageDecodeController::MemoryBudget::ResetUsage() {
1073 current_usage_bytes_ = 0; 1084 current_usage_bytes_ = 0;
1074 } 1085 }
1075 1086
1076 size_t SoftwareImageDecodeController::MemoryBudget::GetCurrentUsageSafe() 1087 size_t SoftwareImageDecodeController::MemoryBudget::GetCurrentUsageSafe()
1077 const { 1088 const {
1078 return current_usage_bytes_.ValueOrDie(); 1089 return current_usage_bytes_.ValueOrDie();
1079 } 1090 }
1080 1091
1092 void SoftwareImageDecodeController::OnMemoryStateChange(
1093 memory_coordinator::mojom::MemoryState state) {
1094 switch (state) {
1095 case memory_coordinator::mojom::MemoryState::NORMAL:
1096 // TODO(tasak): go back to normal state.
1097 break;
1098 case memory_coordinator::mojom::MemoryState::THROTTLED:
1099 // TODO(tasak): make the limits of this component's caches smaller to
1100 // save memory usage.
1101 break;
1102 case memory_coordinator::mojom::MemoryState::SUSPENDED:
1103 // TODO(tasak): free this component's caches as much as possible before
1104 // suspending renderer.
1105 break;
1106 default:
1107 // NOT_REACHED.
1108 break;
1109 }
1110 }
1111
1081 } // namespace cc 1112 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698