| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/gpu_image_decode_controller.h" | 5 #include "cc/tiles/gpu_image_decode_controller.h" |
| 6 | 6 |
| 7 #include "base/memory/discardable_memory_allocator.h" | 7 #include "base/memory/discardable_memory_allocator.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/numerics/safe_math.h" | 9 #include "base/numerics/safe_math.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "base/threading/thread_task_runner_handle.h" | 11 #include "base/threading/thread_task_runner_handle.h" |
| 12 #include "cc/debug/devtools_instrumentation.h" | 12 #include "cc/debug/devtools_instrumentation.h" |
| 13 #include "cc/output/context_provider.h" | 13 #include "cc/output/context_provider.h" |
| 14 #include "cc/raster/tile_task.h" | 14 #include "cc/raster/tile_task.h" |
| 15 #include "gpu/command_buffer/client/context_support.h" | 15 #include "gpu/command_buffer/client/context_support.h" |
| 16 #include "gpu/command_buffer/client/gles2_interface.h" | 16 #include "gpu/command_buffer/client/gles2_interface.h" |
| 17 #include "gpu_image_decode_controller.h" | 17 #include "gpu_image_decode_controller.h" |
| 18 #include "skia/ext/texture_handle.h" | 18 #include "skia/ext/texture_handle.h" |
| 19 #include "third_party/skia/include/core/SkCanvas.h" | 19 #include "third_party/skia/include/core/SkCanvas.h" |
| 20 #include "third_party/skia/include/core/SkRefCnt.h" | 20 #include "third_party/skia/include/core/SkRefCnt.h" |
| 21 #include "third_party/skia/include/core/SkSurface.h" | 21 #include "third_party/skia/include/core/SkSurface.h" |
| 22 #include "third_party/skia/include/gpu/GrContext.h" | 22 #include "third_party/skia/include/gpu/GrContext.h" |
| 23 #include "third_party/skia/include/gpu/GrTexture.h" | 23 #include "third_party/skia/include/gpu/GrTexture.h" |
| 24 #include "ui/gfx/skia_util.h" | 24 #include "ui/gfx/skia_util.h" |
| 25 #include "ui/gl/trace_util.h" | 25 #include "ui/gl/trace_util.h" |
| 26 | 26 |
| 27 namespace cc { | 27 namespace cc { |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 static const int kMaxGpuImageBytes = 1024 * 1024 * 96; | |
| 31 static const int kMaxDiscardableItems = 2000; | 30 static const int kMaxDiscardableItems = 2000; |
| 32 | 31 |
| 33 // Returns true if an image would not be drawn and should therefore be | 32 // Returns true if an image would not be drawn and should therefore be |
| 34 // skipped rather than decoded. | 33 // skipped rather than decoded. |
| 35 bool SkipImage(const DrawImage& draw_image) { | 34 bool SkipImage(const DrawImage& draw_image) { |
| 36 if (!SkIRect::Intersects(draw_image.src_rect(), draw_image.image()->bounds())) | 35 if (!SkIRect::Intersects(draw_image.src_rect(), draw_image.image()->bounds())) |
| 37 return true; | 36 return true; |
| 38 if (std::abs(draw_image.scale().width()) < | 37 if (std::abs(draw_image.scale().width()) < |
| 39 std::numeric_limits<float>::epsilon() || | 38 std::numeric_limits<float>::epsilon() || |
| 40 std::abs(draw_image.scale().height()) < | 39 std::abs(draw_image.scale().height()) < |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 | 145 |
| 147 GpuImageDecodeController::UploadedImageData::~UploadedImageData() = default; | 146 GpuImageDecodeController::UploadedImageData::~UploadedImageData() = default; |
| 148 | 147 |
| 149 GpuImageDecodeController::ImageData::ImageData(DecodedDataMode mode, | 148 GpuImageDecodeController::ImageData::ImageData(DecodedDataMode mode, |
| 150 size_t size) | 149 size_t size) |
| 151 : mode(mode), size(size), is_at_raster(false) {} | 150 : mode(mode), size(size), is_at_raster(false) {} |
| 152 | 151 |
| 153 GpuImageDecodeController::ImageData::~ImageData() = default; | 152 GpuImageDecodeController::ImageData::~ImageData() = default; |
| 154 | 153 |
| 155 GpuImageDecodeController::GpuImageDecodeController(ContextProvider* context, | 154 GpuImageDecodeController::GpuImageDecodeController(ContextProvider* context, |
| 156 ResourceFormat decode_format) | 155 ResourceFormat decode_format, |
| 156 size_t max_gpu_image_bytes) |
| 157 : format_(decode_format), | 157 : format_(decode_format), |
| 158 context_(context), | 158 context_(context), |
| 159 image_data_(ImageDataMRUCache::NO_AUTO_EVICT), | 159 image_data_(ImageDataMRUCache::NO_AUTO_EVICT), |
| 160 cached_items_limit_(kMaxDiscardableItems), | 160 cached_items_limit_(kMaxDiscardableItems), |
| 161 cached_bytes_limit_(kMaxGpuImageBytes), | 161 cached_bytes_limit_(max_gpu_image_bytes), |
| 162 bytes_used_(0) { | 162 bytes_used_(0), |
| 163 max_gpu_image_bytes_(max_gpu_image_bytes) { |
| 163 // Acquire the context_lock so that we can safely retrieve the | 164 // Acquire the context_lock so that we can safely retrieve the |
| 164 // GrContextThreadSafeProxy. This proxy can then be used with no lock held. | 165 // GrContextThreadSafeProxy. This proxy can then be used with no lock held. |
| 165 { | 166 { |
| 166 ContextProvider::ScopedContextLock context_lock(context_); | 167 ContextProvider::ScopedContextLock context_lock(context_); |
| 167 context_threadsafe_proxy_ = sk_sp<GrContextThreadSafeProxy>( | 168 context_threadsafe_proxy_ = sk_sp<GrContextThreadSafeProxy>( |
| 168 context->GrContext()->threadSafeProxy()); | 169 context->GrContext()->threadSafeProxy()); |
| 169 } | 170 } |
| 170 | 171 |
| 171 // In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview). | 172 // In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview). |
| 172 // Don't register a dump provider in these cases. | 173 // Don't register a dump provider in these cases. |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 // We want to keep as little in our cache as possible. Set our memory limit | 357 // We want to keep as little in our cache as possible. Set our memory limit |
| 357 // to zero and EnsureCapacity to clean up memory. | 358 // to zero and EnsureCapacity to clean up memory. |
| 358 cached_bytes_limit_ = 0; | 359 cached_bytes_limit_ = 0; |
| 359 EnsureCapacity(0); | 360 EnsureCapacity(0); |
| 360 | 361 |
| 361 // We are holding the context lock, so finish cleaning up deleted images | 362 // We are holding the context lock, so finish cleaning up deleted images |
| 362 // now. | 363 // now. |
| 363 DeletePendingImages(); | 364 DeletePendingImages(); |
| 364 } else { | 365 } else { |
| 365 base::AutoLock lock(lock_); | 366 base::AutoLock lock(lock_); |
| 366 cached_bytes_limit_ = kMaxGpuImageBytes; | 367 cached_bytes_limit_ = max_gpu_image_bytes_; |
| 367 } | 368 } |
| 368 } | 369 } |
| 369 | 370 |
| 370 bool GpuImageDecodeController::OnMemoryDump( | 371 bool GpuImageDecodeController::OnMemoryDump( |
| 371 const base::trace_event::MemoryDumpArgs& args, | 372 const base::trace_event::MemoryDumpArgs& args, |
| 372 base::trace_event::ProcessMemoryDump* pmd) { | 373 base::trace_event::ProcessMemoryDump* pmd) { |
| 373 for (const auto& image_pair : image_data_) { | 374 for (const auto& image_pair : image_data_) { |
| 374 const ImageData* image_data = image_pair.second.get(); | 375 const ImageData* image_data = image_pair.second.get(); |
| 375 const uint32_t image_id = image_pair.first; | 376 const uint32_t image_id = image_pair.first; |
| 376 | 377 |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 857 bool GpuImageDecodeController::DiscardableIsLockedForTesting( | 858 bool GpuImageDecodeController::DiscardableIsLockedForTesting( |
| 858 const DrawImage& image) { | 859 const DrawImage& image) { |
| 859 base::AutoLock lock(lock_); | 860 base::AutoLock lock(lock_); |
| 860 auto found = image_data_.Peek(image.image()->uniqueID()); | 861 auto found = image_data_.Peek(image.image()->uniqueID()); |
| 861 DCHECK(found != image_data_.end()); | 862 DCHECK(found != image_data_.end()); |
| 862 ImageData* image_data = found->second.get(); | 863 ImageData* image_data = found->second.get(); |
| 863 return image_data->decode.is_locked; | 864 return image_data->decode.is_locked; |
| 864 } | 865 } |
| 865 | 866 |
| 866 } // namespace cc | 867 } // namespace cc |
| OLD | NEW |