Commit a599a458 authored by Vladimir Levin's avatar Vladimir Levin Committed by Commit Bot

Revert software image cache rework patches.

This patch reverts two commits:
Revert "Reland "cc: Rework software image decode cache.""
  This reverts commit 0a6f9bcd.
Revert "cc/images: Resuse the closest available decode for scaling sw images."
  This reverts commit 7a28b96c.

The reason is that the rework missed a few cases that are causing DCHECKs
or incorrect behavior in release builds. Since these are not currently
blocking any work, I will reland them with the proper fixes.

TBR=khushalsagar@chromium.org, ericrk@chromium.org

Bug: 786285
Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.android:android_optional_gpu_tests_rel
Change-Id: I7fc81026e162d0854fc828bdd4457a3212b27db9
Reviewed-on: https://chromium-review.googlesource.com/779939
Commit-Queue: vmpstr <vmpstr@chromium.org>
Reviewed-by: default avatarEric Karl <ericrk@chromium.org>
Reviewed-by: default avatarvmpstr <vmpstr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#517920}
parent e65fda39
...@@ -142,6 +142,13 @@ SkISize PaintImage::GetSupportedDecodeSize( ...@@ -142,6 +142,13 @@ SkISize PaintImage::GetSupportedDecodeSize(
return SkISize::Make(width(), height()); return SkISize::Make(width(), height());
} }
SkImageInfo PaintImage::CreateDecodeImageInfo(const SkISize& size,
SkColorType color_type) const {
DCHECK(GetSupportedDecodeSize(size) == size);
return SkImageInfo::Make(size.width(), size.height(), color_type,
kPremul_SkAlphaType);
}
bool PaintImage::Decode(void* memory, bool PaintImage::Decode(void* memory,
SkImageInfo* info, SkImageInfo* info,
sk_sp<SkColorSpace> color_space, sk_sp<SkColorSpace> color_space,
......
...@@ -116,6 +116,11 @@ class CC_PAINT_EXPORT PaintImage { ...@@ -116,6 +116,11 @@ class CC_PAINT_EXPORT PaintImage {
// GetSupportedDecodeSize(size). // GetSupportedDecodeSize(size).
SkISize GetSupportedDecodeSize(const SkISize& requested_size) const; SkISize GetSupportedDecodeSize(const SkISize& requested_size) const;
// Returns SkImageInfo that should be used to decode this image to the given
// size and color type. The size must be supported.
SkImageInfo CreateDecodeImageInfo(const SkISize& size,
SkColorType color_type) const;
// Decode the image into the given memory for the given SkImageInfo. // Decode the image into the given memory for the given SkImageInfo.
// - Size in |info| must be supported. // - Size in |info| must be supported.
// - The amount of memory allocated must be at least // - The amount of memory allocated must be at least
......
This diff is collapsed.
...@@ -142,12 +142,11 @@ class CC_EXPORT SoftwareImageDecodeCache ...@@ -142,12 +142,11 @@ class CC_EXPORT SoftwareImageDecodeCache
// Decode the given image and store it in the cache. This is only called by an // Decode the given image and store it in the cache. This is only called by an
// image decode task from a worker thread. // image decode task from a worker thread.
void DecodeImageInTask(const ImageKey& key, void DecodeImage(const ImageKey& key,
const PaintImage& paint_image, const DrawImage& image,
DecodeTaskType task_type); DecodeTaskType task_type);
void OnImageDecodeTaskCompleted(const ImageKey& key, void RemovePendingTask(const ImageKey& key, DecodeTaskType task_type);
DecodeTaskType task_type);
// MemoryDumpProvider overrides. // MemoryDumpProvider overrides.
bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
...@@ -156,30 +155,29 @@ class CC_EXPORT SoftwareImageDecodeCache ...@@ -156,30 +155,29 @@ class CC_EXPORT SoftwareImageDecodeCache
size_t GetNumCacheEntriesForTesting() const { return decoded_images_.size(); } size_t GetNumCacheEntriesForTesting() const { return decoded_images_.size(); }
private: private:
// CacheEntry is a convenience storage for discardable memory. It can also // DecodedImage is a convenience storage for discardable memory. It can also
// construct an image out of SkImageInfo and stored discardable memory. // construct an image out of SkImageInfo and stored discardable memory.
class CacheEntry { class DecodedImage {
public: public:
CacheEntry(); DecodedImage(const SkImageInfo& info,
CacheEntry(const SkImageInfo& info,
std::unique_ptr<base::DiscardableMemory> memory, std::unique_ptr<base::DiscardableMemory> memory,
const SkSize& src_rect_offset); const SkSize& src_rect_offset);
~CacheEntry(); ~DecodedImage();
void MoveImageMemoryTo(CacheEntry* entry);
sk_sp<SkImage> image() const { const sk_sp<SkImage>& image() const {
if (!memory) DCHECK(locked_);
return nullptr;
DCHECK(is_locked);
return image_; return image_;
} }
const SkSize& src_rect_offset() const { return src_rect_offset_; } const SkSize& src_rect_offset() const { return src_rect_offset_; }
bool is_locked() const { return locked_; }
bool Lock(); bool Lock();
void Unlock(); void Unlock();
// An ID which uniquely identifies this CacheEntry within the image decode const base::DiscardableMemory* memory() const { return memory_.get(); }
// An ID which uniquely identifies this DecodedImage within the image decode
// cache. Used in memory tracing. // cache. Used in memory tracing.
uint64_t tracing_id() const { return tracing_id_; } uint64_t tracing_id() const { return tracing_id_; }
// Mark this image as being used in either a draw or as a source for a // Mark this image as being used in either a draw or as a source for a
...@@ -188,21 +186,6 @@ class CC_EXPORT SoftwareImageDecodeCache ...@@ -188,21 +186,6 @@ class CC_EXPORT SoftwareImageDecodeCache
void mark_used() { usage_stats_.used = true; } void mark_used() { usage_stats_.used = true; }
void mark_out_of_raster() { usage_stats_.first_lock_out_of_raster = true; } void mark_out_of_raster() { usage_stats_.first_lock_out_of_raster = true; }
// Since this is an inner class, we expose these variables publicly for
// simplicity.
// TODO(vmpstr): A good simple clean-up would be to rethink this class
// and its interactions to instead expose a few functions which would also
// facilitate easier DCHECKs.
int ref_count = 0;
bool decode_failed = false;
bool is_locked = false;
bool is_budgeted = false;
scoped_refptr<TileTask> in_raster_task;
scoped_refptr<TileTask> out_of_raster_task;
std::unique_ptr<base::DiscardableMemory> memory;
private: private:
struct UsageStats { struct UsageStats {
// We can only create a decoded image in a locked state, so the initial // We can only create a decoded image in a locked state, so the initial
...@@ -214,7 +197,9 @@ class CC_EXPORT SoftwareImageDecodeCache ...@@ -214,7 +197,9 @@ class CC_EXPORT SoftwareImageDecodeCache
bool first_lock_out_of_raster = false; bool first_lock_out_of_raster = false;
}; };
bool locked_;
SkImageInfo image_info_; SkImageInfo image_info_;
std::unique_ptr<base::DiscardableMemory> memory_;
sk_sp<SkImage> image_; sk_sp<SkImage> image_;
SkSize src_rect_offset_; SkSize src_rect_offset_;
uint64_t tracing_id_; uint64_t tracing_id_;
...@@ -240,22 +225,62 @@ class CC_EXPORT SoftwareImageDecodeCache ...@@ -240,22 +225,62 @@ class CC_EXPORT SoftwareImageDecodeCache
}; };
using ImageMRUCache = base:: using ImageMRUCache = base::
HashingMRUCache<ImageKey, std::unique_ptr<CacheEntry>, ImageKeyHash>; HashingMRUCache<ImageKey, std::unique_ptr<DecodedImage>, ImageKeyHash>;
// Looks for the key in the cache and returns true if it was found and was
// successfully locked (or if it was already locked). Note that if this
// function returns true, then a ref count is increased for the image.
bool LockDecodedImageIfPossibleAndRef(const ImageKey& key);
// Actually decode the image. Note that this function can (and should) be // Actually decode the image. Note that this function can (and should) be
// called with no lock acquired, since it can do a lot of work. Note that it // called with no lock acquired, since it can do a lot of work. Note that it
// can also return nullptr to indicate the decode failed. // can also return nullptr to indicate the decode failed.
std::unique_ptr<CacheEntry> DecodeImageInternal(const ImageKey& key, std::unique_ptr<DecodedImage> DecodeImageInternal(
const ImageKey& key,
const DrawImage& draw_image); const DrawImage& draw_image);
// Get the decoded draw image for the given key and paint_image. Note that // Get the decoded draw image for the given key and draw_image. Note that this
// this function has to be called with no lock acquired, since it will acquire // function has to be called with no lock acquired, since it will acquire its
// its own locks and might call DecodeImageInternal above. Note that // own locks and might call DecodeImageInternal above. Also note that this
// when used internally, we still require that DrawWithImageFinished() is // function will use the provided key, even if
// called afterwards. // ImageKey::FromDrawImage(draw_image) would return a different key.
DecodedDrawImage GetDecodedImageForDrawInternal( // Note that when used internally, we still require that
// DrawWithImageFinished() is called afterwards.
DecodedDrawImage GetDecodedImageForDrawInternal(const ImageKey& key,
const DrawImage& draw_image);
// GetExactSizeImageDecode is called by DecodeImageInternal when the
// quality does not scale the image. Like DecodeImageInternal, it should be
// called with no lock acquired and it returns nullptr if the decoding failed.
std::unique_ptr<DecodedImage> GetExactSizeImageDecode(
const ImageKey& key, const ImageKey& key,
const PaintImage& paint_image); const PaintImage& image);
// GetSubrectImageDecode is similar to GetExactSizeImageDecode in that the
// image is decoded to exact scale. However, we extract a subrect (copy it
// out) and only return this subrect in order to cache a smaller amount of
// memory. Note that this uses GetExactSizeImageDecode to get the initial
// data, which ensures that we cache an unlocked version of the original image
// in case we need to extract multiple subrects (as would be the case in an
// atlas).
std::unique_ptr<DecodedImage> GetSubrectImageDecode(const ImageKey& key,
const PaintImage& image);
// GetScaledImageDecode is called by DecodeImageInternal when the quality
// requires the image be scaled. Like DecodeImageInternal, it should be
// called with no lock acquired and it returns nullptr if the decoding or
// scaling failed.
std::unique_ptr<DecodedImage> GetScaledImageDecode(const ImageKey& key,
const PaintImage& image);
void RefImage(const ImageKey& key);
void RefAtRasterImage(const ImageKey& key);
void UnrefAtRasterImage(const ImageKey& key);
// Helper function which dumps all images in a specific ImageMRUCache.
void DumpImageMemoryForCache(const ImageMRUCache& cache,
const char* cache_name,
base::trace_event::ProcessMemoryDump* pmd) const;
// Removes unlocked decoded images until the number of decoded images is // Removes unlocked decoded images until the number of decoded images is
// reduced within the given limit. // reduced within the given limit.
...@@ -271,21 +296,10 @@ class CC_EXPORT SoftwareImageDecodeCache ...@@ -271,21 +296,10 @@ class CC_EXPORT SoftwareImageDecodeCache
const TracingInfo& tracing_info, const TracingInfo& tracing_info,
DecodeTaskType type); DecodeTaskType type);
CacheEntry* AddCacheEntry(const ImageKey& key); void CacheDecodedImages(const ImageKey& key,
std::unique_ptr<DecodedImage> decoded_image);
void DecodeImageIfNecessary(const ImageKey& key, void CleanupDecodedImagesCache(const ImageKey& key,
const PaintImage& paint_image, ImageMRUCache::iterator it);
CacheEntry* cache_entry);
void AddBudgetForImage(const ImageKey& key, CacheEntry* entry);
void RemoveBudgetForImage(const ImageKey& key, CacheEntry* entry);
std::unique_ptr<CacheEntry> DoDecodeImage(const ImageKey& key,
const PaintImage& image);
std::unique_ptr<CacheEntry> GenerateCacheEntryFromCandidate(
const ImageKey& key,
const DecodedDrawImage& candidate);
void UnrefImage(const ImageKey& key);
std::unordered_map<ImageKey, scoped_refptr<TileTask>, ImageKeyHash> std::unordered_map<ImageKey, scoped_refptr<TileTask>, ImageKeyHash>
pending_in_raster_image_tasks_; pending_in_raster_image_tasks_;
...@@ -300,6 +314,7 @@ class CC_EXPORT SoftwareImageDecodeCache ...@@ -300,6 +314,7 @@ class CC_EXPORT SoftwareImageDecodeCache
// Decoded images and ref counts (predecode path). // Decoded images and ref counts (predecode path).
ImageMRUCache decoded_images_; ImageMRUCache decoded_images_;
std::unordered_map<ImageKey, int, ImageKeyHash> decoded_images_ref_counts_;
// A map of PaintImage::FrameKey to the ImageKeys for cached decodes of this // A map of PaintImage::FrameKey to the ImageKeys for cached decodes of this
// PaintImage. // PaintImage.
...@@ -308,6 +323,11 @@ class CC_EXPORT SoftwareImageDecodeCache ...@@ -308,6 +323,11 @@ class CC_EXPORT SoftwareImageDecodeCache
PaintImage::FrameKeyHash> PaintImage::FrameKeyHash>
frame_key_to_image_keys_; frame_key_to_image_keys_;
// Decoded image and ref counts (at-raster decode path).
ImageMRUCache at_raster_decoded_images_;
std::unordered_map<ImageKey, int, ImageKeyHash>
at_raster_decoded_images_ref_counts_;
MemoryBudget locked_images_budget_; MemoryBudget locked_images_budget_;
SkColorType color_type_; SkColorType color_type_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment