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(
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,
SkImageInfo* info,
sk_sp<SkColorSpace> color_space,
......
......@@ -116,6 +116,11 @@ class CC_PAINT_EXPORT PaintImage {
// GetSupportedDecodeSize(size).
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.
// - Size in |info| must be supported.
// - The amount of memory allocated must be at least
......
This diff is collapsed.
......@@ -142,12 +142,11 @@ class CC_EXPORT SoftwareImageDecodeCache
// Decode the given image and store it in the cache. This is only called by an
// image decode task from a worker thread.
void DecodeImageInTask(const ImageKey& key,
const PaintImage& paint_image,
DecodeTaskType task_type);
void DecodeImage(const ImageKey& key,
const DrawImage& image,
DecodeTaskType task_type);
void OnImageDecodeTaskCompleted(const ImageKey& key,
DecodeTaskType task_type);
void RemovePendingTask(const ImageKey& key, DecodeTaskType task_type);
// MemoryDumpProvider overrides.
bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
......@@ -156,30 +155,29 @@ class CC_EXPORT SoftwareImageDecodeCache
size_t GetNumCacheEntriesForTesting() const { return decoded_images_.size(); }
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.
class CacheEntry {
class DecodedImage {
public:
CacheEntry();
CacheEntry(const SkImageInfo& info,
std::unique_ptr<base::DiscardableMemory> memory,
const SkSize& src_rect_offset);
~CacheEntry();
void MoveImageMemoryTo(CacheEntry* entry);
sk_sp<SkImage> image() const {
if (!memory)
return nullptr;
DCHECK(is_locked);
DecodedImage(const SkImageInfo& info,
std::unique_ptr<base::DiscardableMemory> memory,
const SkSize& src_rect_offset);
~DecodedImage();
const sk_sp<SkImage>& image() const {
DCHECK(locked_);
return image_;
}
const SkSize& src_rect_offset() const { return src_rect_offset_; }
bool is_locked() const { return locked_; }
bool Lock();
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.
uint64_t tracing_id() const { return tracing_id_; }
// Mark this image as being used in either a draw or as a source for a
......@@ -188,21 +186,6 @@ class CC_EXPORT SoftwareImageDecodeCache
void mark_used() { usage_stats_.used = 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:
struct UsageStats {
// We can only create a decoded image in a locked state, so the initial
......@@ -214,7 +197,9 @@ class CC_EXPORT SoftwareImageDecodeCache
bool first_lock_out_of_raster = false;
};
bool locked_;
SkImageInfo image_info_;
std::unique_ptr<base::DiscardableMemory> memory_;
sk_sp<SkImage> image_;
SkSize src_rect_offset_;
uint64_t tracing_id_;
......@@ -240,22 +225,62 @@ class CC_EXPORT SoftwareImageDecodeCache
};
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
// 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.
std::unique_ptr<CacheEntry> DecodeImageInternal(const ImageKey& key,
std::unique_ptr<DecodedImage> DecodeImageInternal(
const ImageKey& key,
const DrawImage& draw_image);
// Get the decoded draw image for the given key and draw_image. Note that this
// function has to be called with no lock acquired, since it will acquire its
// own locks and might call DecodeImageInternal above. Also note that this
// function will use the provided key, even if
// ImageKey::FromDrawImage(draw_image) would return a different key.
// Note that when used internally, we still require that
// DrawWithImageFinished() is called afterwards.
DecodedDrawImage GetDecodedImageForDrawInternal(const ImageKey& key,
const DrawImage& draw_image);
// Get the decoded draw image for the given key and paint_image. Note that
// this function has to be called with no lock acquired, since it will acquire
// its own locks and might call DecodeImageInternal above. Note that
// when used internally, we still require that DrawWithImageFinished() is
// called afterwards.
DecodedDrawImage GetDecodedImageForDrawInternal(
// 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 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
// reduced within the given limit.
......@@ -271,21 +296,10 @@ class CC_EXPORT SoftwareImageDecodeCache
const TracingInfo& tracing_info,
DecodeTaskType type);
CacheEntry* AddCacheEntry(const ImageKey& key);
void DecodeImageIfNecessary(const ImageKey& key,
const PaintImage& paint_image,
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);
void CacheDecodedImages(const ImageKey& key,
std::unique_ptr<DecodedImage> decoded_image);
void CleanupDecodedImagesCache(const ImageKey& key,
ImageMRUCache::iterator it);
std::unordered_map<ImageKey, scoped_refptr<TileTask>, ImageKeyHash>
pending_in_raster_image_tasks_;
......@@ -300,6 +314,7 @@ class CC_EXPORT SoftwareImageDecodeCache
// Decoded images and ref counts (predecode path).
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
// PaintImage.
......@@ -308,6 +323,11 @@ class CC_EXPORT SoftwareImageDecodeCache
PaintImage::FrameKeyHash>
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_;
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