| 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 <inttypes.h> | 7 #include <inttypes.h> |
| 8 | 8 |
| 9 #include "base/memory/discardable_memory_allocator.h" | 9 #include "base/memory/discardable_memory_allocator.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 return false; | 49 return false; |
| 50 } | 50 } |
| 51 | 51 |
| 52 // Returns the filter quality to use for scaling the image to upload scale. For | 52 // Returns the filter quality to use for scaling the image to upload scale. For |
| 53 // GPU raster, medium and high filter quality are identical for downscales. | 53 // GPU raster, medium and high filter quality are identical for downscales. |
| 54 // Upload scaling is always a downscale, so cap our filter quality to medium. | 54 // Upload scaling is always a downscale, so cap our filter quality to medium. |
| 55 SkFilterQuality CalculateUploadScaleFilterQuality(const DrawImage& draw_image) { | 55 SkFilterQuality CalculateUploadScaleFilterQuality(const DrawImage& draw_image) { |
| 56 return std::min(kMedium_SkFilterQuality, draw_image.filter_quality()); | 56 return std::min(kMedium_SkFilterQuality, draw_image.filter_quality()); |
| 57 } | 57 } |
| 58 | 58 |
| 59 SkImage::DeferredTextureImageUsageParams ParamsFromDrawImage( | |
| 60 const DrawImage& draw_image, | |
| 61 int upload_scale_mip_level) { | |
| 62 SkImage::DeferredTextureImageUsageParams params; | |
| 63 params.fMatrix = draw_image.matrix(); | |
| 64 params.fQuality = draw_image.filter_quality(); | |
| 65 params.fPreScaleMipLevel = upload_scale_mip_level; | |
| 66 | |
| 67 return params; | |
| 68 } | |
| 69 | |
| 70 // Calculate the mip level to upload-scale the image to before uploading. We use | 59 // Calculate the mip level to upload-scale the image to before uploading. We use |
| 71 // mip levels rather than exact scales to increase re-use of scaled images. | 60 // mip levels rather than exact scales to increase re-use of scaled images. |
| 72 int CalculateUploadScaleMipLevel(const DrawImage& draw_image) { | 61 int CalculateUploadScaleMipLevel(const DrawImage& draw_image) { |
| 73 // Images which are being clipped will have color-bleeding if scaled. | 62 // Images which are being clipped will have color-bleeding if scaled. |
| 74 // TODO(ericrk): Investigate uploading clipped images to handle this case and | 63 // TODO(ericrk): Investigate uploading clipped images to handle this case and |
| 75 // provide further optimization. crbug.com/620899 | 64 // provide further optimization. crbug.com/620899 |
| 76 if (draw_image.src_rect() != draw_image.image()->bounds()) | 65 if (draw_image.src_rect() != draw_image.image()->bounds()) |
| 77 return 0; | 66 return 0; |
| 78 | 67 |
| 79 gfx::Size base_size(draw_image.image()->width(), | 68 gfx::Size base_size(draw_image.image()->width(), |
| (...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 936 image_pixmap, CalculateUploadScaleFilterQuality(draw_image), | 925 image_pixmap, CalculateUploadScaleFilterQuality(draw_image), |
| 937 SkImage::kDisallow_CachingHint)) { | 926 SkImage::kDisallow_CachingHint)) { |
| 938 backing_memory.reset(); | 927 backing_memory.reset(); |
| 939 } | 928 } |
| 940 break; | 929 break; |
| 941 } | 930 } |
| 942 case DecodedDataMode::GPU: { | 931 case DecodedDataMode::GPU: { |
| 943 backing_memory = | 932 backing_memory = |
| 944 base::DiscardableMemoryAllocator::GetInstance() | 933 base::DiscardableMemoryAllocator::GetInstance() |
| 945 ->AllocateLockedDiscardableMemory(image_data->size); | 934 ->AllocateLockedDiscardableMemory(image_data->size); |
| 946 auto params = | 935 auto params = SkImage::DeferredTextureImageUsageParams( |
| 947 ParamsFromDrawImage(draw_image, image_data->upload_scale_mip_level); | 936 draw_image.matrix(), draw_image.filter_quality(), |
| 937 image_data->upload_scale_mip_level); |
| 948 if (!draw_image.image()->getDeferredTextureImageData( | 938 if (!draw_image.image()->getDeferredTextureImageData( |
| 949 *context_threadsafe_proxy_.get(), ¶ms, 1, | 939 *context_threadsafe_proxy_.get(), ¶ms, 1, |
| 950 backing_memory->data())) { | 940 backing_memory->data())) { |
| 951 backing_memory.reset(); | 941 backing_memory.reset(); |
| 952 } | 942 } |
| 953 break; | 943 break; |
| 954 } | 944 } |
| 955 } | 945 } |
| 956 } | 946 } |
| 957 | 947 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1024 if (!image_data->upload.image()) | 1014 if (!image_data->upload.image()) |
| 1025 image_data->upload.SetImage(std::move(uploaded_image)); | 1015 image_data->upload.SetImage(std::move(uploaded_image)); |
| 1026 } | 1016 } |
| 1027 | 1017 |
| 1028 scoped_refptr<GpuImageDecodeController::ImageData> | 1018 scoped_refptr<GpuImageDecodeController::ImageData> |
| 1029 GpuImageDecodeController::CreateImageData(const DrawImage& draw_image) { | 1019 GpuImageDecodeController::CreateImageData(const DrawImage& draw_image) { |
| 1030 lock_.AssertAcquired(); | 1020 lock_.AssertAcquired(); |
| 1031 | 1021 |
| 1032 DecodedDataMode mode; | 1022 DecodedDataMode mode; |
| 1033 int upload_scale_mip_level = CalculateUploadScaleMipLevel(draw_image); | 1023 int upload_scale_mip_level = CalculateUploadScaleMipLevel(draw_image); |
| 1034 SkImage::DeferredTextureImageUsageParams params = | 1024 auto params = SkImage::DeferredTextureImageUsageParams( |
| 1035 ParamsFromDrawImage(draw_image, upload_scale_mip_level); | 1025 draw_image.matrix(), draw_image.filter_quality(), upload_scale_mip_level); |
| 1036 size_t data_size = draw_image.image()->getDeferredTextureImageData( | 1026 size_t data_size = draw_image.image()->getDeferredTextureImageData( |
| 1037 *context_threadsafe_proxy_.get(), ¶ms, 1, nullptr); | 1027 *context_threadsafe_proxy_.get(), ¶ms, 1, nullptr); |
| 1038 | 1028 |
| 1039 if (data_size == 0) { | 1029 if (data_size == 0) { |
| 1040 // Can't upload image, too large or other failure. Try to use SW fallback. | 1030 // Can't upload image, too large or other failure. Try to use SW fallback. |
| 1041 SkImageInfo image_info = | 1031 SkImageInfo image_info = |
| 1042 CreateImageInfoForDrawImage(draw_image, upload_scale_mip_level); | 1032 CreateImageInfoForDrawImage(draw_image, upload_scale_mip_level); |
| 1043 data_size = image_info.getSafeSize(image_info.minRowBytes()); | 1033 data_size = image_info.getSafeSize(image_info.minRowBytes()); |
| 1044 mode = DecodedDataMode::CPU; | 1034 mode = DecodedDataMode::CPU; |
| 1045 } else { | 1035 } else { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1129 bool GpuImageDecodeController::DiscardableIsLockedForTesting( | 1119 bool GpuImageDecodeController::DiscardableIsLockedForTesting( |
| 1130 const DrawImage& image) { | 1120 const DrawImage& image) { |
| 1131 base::AutoLock lock(lock_); | 1121 base::AutoLock lock(lock_); |
| 1132 auto found = persistent_cache_.Peek(image.image()->uniqueID()); | 1122 auto found = persistent_cache_.Peek(image.image()->uniqueID()); |
| 1133 DCHECK(found != persistent_cache_.end()); | 1123 DCHECK(found != persistent_cache_.end()); |
| 1134 ImageData* image_data = found->second.get(); | 1124 ImageData* image_data = found->second.get(); |
| 1135 return image_data->decode.is_locked(); | 1125 return image_data->decode.is_locked(); |
| 1136 } | 1126 } |
| 1137 | 1127 |
| 1138 } // namespace cc | 1128 } // namespace cc |
| OLD | NEW |