summaryrefslogtreecommitdiffstats
path: root/cc/tiles
diff options
context:
space:
mode:
authorvmpstr <vmpstr@chromium.org>2016-03-11 15:55:38 -0800
committerCommit bot <commit-bot@chromium.org>2016-03-11 23:58:27 +0000
commit61c1b9da83fd9783d23421735c6a777899c6b127 (patch)
treed3dcc129c21654fa6cdef2d4d454870cb8be7925 /cc/tiles
parent377ed0be9fbb6010f256033a83e767d447961e93 (diff)
downloadchromium_src-61c1b9da83fd9783d23421735c6a777899c6b127.zip
chromium_src-61c1b9da83fd9783d23421735c6a777899c6b127.tar.gz
chromium_src-61c1b9da83fd9783d23421735c6a777899c6b127.tar.bz2
cc: ImageDecodes: Remove ref counting from SIDC::DecodedImage.
This patch removes ref counting from DecodedImage class in SoftwareImageDecodeController. BUG=592823 R=enne, ericrk CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel Review URL: https://codereview.chromium.org/1778673005 Cr-Commit-Position: refs/heads/master@{#380789}
Diffstat (limited to 'cc/tiles')
-rw-r--r--cc/tiles/software_image_decode_controller.cc35
-rw-r--r--cc/tiles/software_image_decode_controller.h17
2 files changed, 25 insertions, 27 deletions
diff --git a/cc/tiles/software_image_decode_controller.cc b/cc/tiles/software_image_decode_controller.cc
index f47213a..48bd02d 100644
--- a/cc/tiles/software_image_decode_controller.cc
+++ b/cc/tiles/software_image_decode_controller.cc
@@ -280,7 +280,7 @@ void SoftwareImageDecodeController::DecodeImage(const ImageKey& key,
decoded_images_.Erase(image_it);
}
- scoped_refptr<DecodedImage> decoded_image;
+ scoped_ptr<DecodedImage> decoded_image;
{
base::AutoUnlock unlock(lock_);
decoded_image = DecodeImageInternal(key, image);
@@ -321,7 +321,7 @@ void SoftwareImageDecodeController::DecodeImage(const ImageKey& key,
SanityCheckState(__LINE__, true);
}
-scoped_refptr<SoftwareImageDecodeController::DecodedImage>
+scoped_ptr<SoftwareImageDecodeController::DecodedImage>
SoftwareImageDecodeController::DecodeImageInternal(
const ImageKey& key,
const DrawImage& draw_image) {
@@ -360,7 +360,7 @@ SoftwareImageDecodeController::DecodeImageInternal(
}
}
- return make_scoped_refptr(new DecodedImage(
+ return make_scoped_ptr(new DecodedImage(
decoded_info, std::move(decoded_pixels), SkSize::Make(0, 0)));
}
@@ -433,7 +433,7 @@ SoftwareImageDecodeController::DecodeImageInternal(
// deleted automatically when we return.
DrawWithImageFinished(original_size_draw_image, decoded_draw_image);
- return make_scoped_refptr(
+ return make_scoped_ptr(
new DecodedImage(scaled_info, std::move(scaled_pixels),
SkSize::Make(-key.src_rect().x(), -key.src_rect().y())));
}
@@ -464,9 +464,10 @@ DecodedDrawImage SoftwareImageDecodeController::GetDecodedImageForDrawInternal(
auto decoded_images_it = decoded_images_.Get(key);
// If we found the image and it's locked, then return it. If it's not locked,
// erase it from the cache since it might be put into the at-raster cache.
- scoped_refptr<DecodedImage> decoded_image;
+ scoped_ptr<DecodedImage> scoped_decoded_image;
+ DecodedImage* decoded_image = nullptr;
if (decoded_images_it != decoded_images_.end()) {
- decoded_image = decoded_images_it->second;
+ decoded_image = decoded_images_it->second.get();
if (decoded_image->is_locked()) {
RefImage(key);
SanityCheckState(__LINE__, true);
@@ -474,6 +475,7 @@ DecodedDrawImage SoftwareImageDecodeController::GetDecodedImageForDrawInternal(
decoded_image->image(), decoded_image->src_rect_offset(),
GetScaleAdjustment(key), GetDecodedFilterQuality(key));
} else {
+ scoped_decoded_image = std::move(decoded_images_it->second);
decoded_images_.Erase(decoded_images_it);
}
}
@@ -485,8 +487,7 @@ DecodedDrawImage SoftwareImageDecodeController::GetDecodedImageForDrawInternal(
DCHECK(at_raster_images_it->second->is_locked());
RefAtRasterImage(key);
SanityCheckState(__LINE__, true);
- const scoped_refptr<DecodedImage>& at_raster_decoded_image =
- at_raster_images_it->second;
+ DecodedImage* at_raster_decoded_image = at_raster_images_it->second.get();
auto decoded_draw_image =
DecodedDrawImage(at_raster_decoded_image->image(),
at_raster_decoded_image->src_rect_offset(),
@@ -505,7 +506,8 @@ DecodedDrawImage SoftwareImageDecodeController::GetDecodedImageForDrawInternal(
// on the compositor thread. This means holding on to the lock might stall
// the compositor thread for the duration of the decode!
base::AutoUnlock unlock(lock_);
- decoded_image = DecodeImageInternal(key, draw_image);
+ scoped_decoded_image = DecodeImageInternal(key, draw_image);
+ decoded_image = scoped_decoded_image.get();
// Skip the image if we couldn't decode it.
if (!decoded_image)
@@ -513,25 +515,26 @@ DecodedDrawImage SoftwareImageDecodeController::GetDecodedImageForDrawInternal(
check_at_raster_cache = true;
}
+ DCHECK(decoded_image == scoped_decoded_image.get());
+
// While we unlocked the lock, it could be the case that another thread
// already decoded this already and put it in the at-raster cache. Look it up
// first.
- bool need_to_add_image_to_cache = true;
if (check_at_raster_cache) {
at_raster_images_it = at_raster_decoded_images_.Get(key);
if (at_raster_images_it != at_raster_decoded_images_.end()) {
// We have to drop our decode, since the one in the cache is being used by
// another thread.
decoded_image->Unlock();
- decoded_image = at_raster_images_it->second;
- need_to_add_image_to_cache = false;
+ decoded_image = at_raster_images_it->second.get();
+ scoped_decoded_image = nullptr;
}
}
// If we really are the first ones, or if the other thread already unlocked
// the image, then put our work into at-raster time cache.
- if (need_to_add_image_to_cache)
- at_raster_decoded_images_.Put(key, decoded_image);
+ if (scoped_decoded_image)
+ at_raster_decoded_images_.Put(key, std::move(scoped_decoded_image));
DCHECK(decoded_image);
DCHECK(decoded_image->is_locked());
@@ -604,7 +607,7 @@ void SoftwareImageDecodeController::UnrefAtRasterImage(const ImageKey& key) {
decoded_images_ref_counts_.end()) {
at_raster_image_it->second->Unlock();
}
- decoded_images_.Put(key, at_raster_image_it->second);
+ decoded_images_.Put(key, std::move(at_raster_image_it->second));
} else if (image_it->second->is_locked()) {
at_raster_image_it->second->Unlock();
} else {
@@ -612,7 +615,7 @@ void SoftwareImageDecodeController::UnrefAtRasterImage(const ImageKey& key) {
decoded_images_ref_counts_.end());
at_raster_image_it->second->Unlock();
decoded_images_.Erase(image_it);
- decoded_images_.Put(key, at_raster_image_it->second);
+ decoded_images_.Put(key, std::move(at_raster_image_it->second));
}
at_raster_decoded_images_.Erase(at_raster_image_it);
}
diff --git a/cc/tiles/software_image_decode_controller.h b/cc/tiles/software_image_decode_controller.h
index d68ac90..7e370bb 100644
--- a/cc/tiles/software_image_decode_controller.h
+++ b/cc/tiles/software_image_decode_controller.h
@@ -118,12 +118,12 @@ class CC_EXPORT SoftwareImageDecodeController : public ImageDecodeController {
private:
// DecodedImage is a convenience storage for discardable memory. It can also
// construct an image out of SkImageInfo and stored discardable memory.
- // TODO(vmpstr): Make this scoped_ptr.
- class DecodedImage : public base::RefCounted<DecodedImage> {
+ class DecodedImage {
public:
DecodedImage(const SkImageInfo& info,
scoped_ptr<base::DiscardableMemory> memory,
const SkSize& src_rect_offset);
+ ~DecodedImage();
SkImage* image() const {
DCHECK(locked_);
@@ -137,10 +137,6 @@ class CC_EXPORT SoftwareImageDecodeController : public ImageDecodeController {
void Unlock();
private:
- friend class base::RefCounted<DecodedImage>;
-
- ~DecodedImage();
-
bool locked_;
SkImageInfo image_info_;
scoped_ptr<base::DiscardableMemory> memory_;
@@ -175,8 +171,8 @@ class CC_EXPORT SoftwareImageDecodeController : public ImageDecodeController {
// 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.
- scoped_refptr<DecodedImage> DecodeImageInternal(const ImageKey& key,
- const DrawImage& draw_image);
+ scoped_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
@@ -207,9 +203,8 @@ class CC_EXPORT SoftwareImageDecodeController : public ImageDecodeController {
// ensure that they are safe to access on multiple threads.
base::Lock lock_;
- using ImageMRUCache = base::HashingMRUCache<ImageKey,
- scoped_refptr<DecodedImage>,
- ImageKeyHash>;
+ using ImageMRUCache =
+ base::HashingMRUCache<ImageKey, scoped_ptr<DecodedImage>, ImageKeyHash>;
// Decoded images and ref counts (predecode path).
ImageMRUCache decoded_images_;