Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(408)

Unified Diff: cc/tiles/software_image_decode_controller.cc

Issue 2256833006: cc, images: Add auto finish draw class to ensure robustness. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/tiles/software_image_decode_controller.cc
diff --git a/cc/tiles/software_image_decode_controller.cc b/cc/tiles/software_image_decode_controller.cc
index ee19c9a10168ba690b06c04cae8212f594bcb920..f262e86463ff86f9cc79f6f77619d049a3410e28 100644
--- a/cc/tiles/software_image_decode_controller.cc
+++ b/cc/tiles/software_image_decode_controller.cc
@@ -60,7 +60,25 @@ class AutoRemoveKeyFromTaskMap {
std::unordered_map<SoftwareImageDecodeController::ImageKey,
scoped_refptr<TileTask>,
SoftwareImageDecodeController::ImageKeyHash>* task_map_;
- SoftwareImageDecodeController::ImageKey key_;
+ const SoftwareImageDecodeController::ImageKey& key_;
+};
+
+class AutoDrawWithImageFinished {
+ public:
+ AutoDrawWithImageFinished(SoftwareImageDecodeController* controller,
+ const DrawImage& draw_image,
+ const DecodedDrawImage& decoded_draw_image)
+ : controller_(controller),
+ draw_image_(draw_image),
+ decoded_draw_image_(decoded_draw_image) {}
+ ~AutoDrawWithImageFinished() {
+ controller_->DrawWithImageFinished(draw_image_, decoded_draw_image_);
+ }
+
+ private:
+ SoftwareImageDecodeController* controller_;
+ const DrawImage& draw_image_;
+ const DecodedDrawImage& decoded_draw_image_;
};
class ImageDecodeTaskImpl : public TileTask {
@@ -550,10 +568,10 @@ SoftwareImageDecodeController::GetSubrectImageDecode(
auto decoded_draw_image = GetDecodedImageForDrawInternal(
original_size_key, original_size_draw_image);
- if (!decoded_draw_image.image()) {
- DrawWithImageFinished(original_size_draw_image, decoded_draw_image);
+ AutoDrawWithImageFinished auto_finish_draw(this, original_size_draw_image,
+ decoded_draw_image);
+ if (!decoded_draw_image.image())
return nullptr;
- }
SkImageInfo subrect_info = CreateImageInfo(
key.target_size().width(), key.target_size().height(), format_);
@@ -577,8 +595,6 @@ SoftwareImageDecodeController::GetSubrectImageDecode(
// We have a decoded image, and we're reading into already allocated memory.
// This should never fail.
DCHECK(result);
- // Release the original image, since we don't need it anymore.
- DrawWithImageFinished(original_size_draw_image, decoded_draw_image);
}
return base::WrapUnique(
new DecodedImage(subrect_info, std::move(subrect_pixels),
@@ -605,10 +621,10 @@ SoftwareImageDecodeController::GetScaledImageDecode(
auto decoded_draw_image = GetDecodedImageForDrawInternal(
original_size_key, original_size_draw_image);
- if (!decoded_draw_image.image()) {
- DrawWithImageFinished(original_size_draw_image, decoded_draw_image);
+ AutoDrawWithImageFinished auto_finish_draw(this, original_size_draw_image,
+ decoded_draw_image);
+ if (!decoded_draw_image.image())
return nullptr;
- }
SkPixmap decoded_pixmap;
bool result = decoded_draw_image.image()->peekPixels(&decoded_pixmap);
@@ -643,11 +659,6 @@ SoftwareImageDecodeController::GetScaledImageDecode(
DCHECK(result) << key.ToString();
}
- // Release the original sized decode. Any other intermediate result to release
- // would be the subrect memory. However, that's in a scoped_ptr and will be
- // deleted automatically when we return.
- DrawWithImageFinished(original_size_draw_image, decoded_draw_image);
-
return base::WrapUnique(
new DecodedImage(scaled_info, std::move(scaled_pixels),
SkSize::Make(-key.src_rect().x(), -key.src_rect().y()),
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698