fix: leaked gfx::Canvas
in AutofillPopupView::OnPaint()
(#46384)
* perf: avoid redundant call to popup_bounds_in_view() * refactor: use a std::optional<> for paint_canvas local * fix: fix leaked gfx::Canvas in AutofillPopupView::OnPaint() * refactor: remove redundant get() call when testing smart pointer for nonempty * refactor: remove unnecessary draw_canvas variable * refactor: rename bitmap to offscreen_bitmap for symmetry * refactor: avoid another redundant call to popup_bounds_in_view()
This commit is contained in:
parent
5a6f1ede6a
commit
ac1ffb1bff
1 changed files with 18 additions and 14 deletions
|
@ -5,6 +5,7 @@
|
||||||
#include "shell/browser/ui/views/autofill_popup_view.h"
|
#include "shell/browser/ui/views/autofill_popup_view.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <optional>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "base/functional/bind.h"
|
#include "base/functional/bind.h"
|
||||||
|
@ -237,30 +238,33 @@ void AutofillPopupView::DoUpdateBoundsAndRedrawPopup() {
|
||||||
void AutofillPopupView::OnPaint(gfx::Canvas* canvas) {
|
void AutofillPopupView::OnPaint(gfx::Canvas* canvas) {
|
||||||
if (!popup_ || static_cast<size_t>(popup_->line_count()) != children().size())
|
if (!popup_ || static_cast<size_t>(popup_->line_count()) != children().size())
|
||||||
return;
|
return;
|
||||||
gfx::Canvas* draw_canvas = canvas;
|
|
||||||
SkBitmap bitmap;
|
|
||||||
|
|
||||||
std::unique_ptr<cc::SkiaPaintCanvas> paint_canvas;
|
gfx::Rect offscreen_bounds;
|
||||||
if (view_proxy_.get()) {
|
SkBitmap offscreen_bitmap;
|
||||||
bitmap.allocN32Pixels(popup_->popup_bounds_in_view().width(),
|
std::optional<cc::SkiaPaintCanvas> offscreen_paint_canvas;
|
||||||
popup_->popup_bounds_in_view().height(), true);
|
std::optional<gfx::Canvas> offscreen_draw_canvas;
|
||||||
paint_canvas = std::make_unique<cc::SkiaPaintCanvas>(bitmap);
|
if (view_proxy_) {
|
||||||
draw_canvas = new gfx::Canvas(paint_canvas.get(), 1.0);
|
offscreen_bounds = popup_->popup_bounds_in_view();
|
||||||
|
offscreen_bitmap.allocN32Pixels(offscreen_bounds.width(),
|
||||||
|
offscreen_bounds.height(), true);
|
||||||
|
offscreen_paint_canvas.emplace(offscreen_bitmap);
|
||||||
|
offscreen_draw_canvas.emplace(&offscreen_paint_canvas.value(), 1.0);
|
||||||
|
canvas = &offscreen_draw_canvas.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
draw_canvas->DrawColor(
|
canvas->DrawColor(
|
||||||
GetColorProvider()->GetColor(ui::kColorResultsTableNormalBackground));
|
GetColorProvider()->GetColor(ui::kColorResultsTableNormalBackground));
|
||||||
OnPaintBorder(draw_canvas);
|
OnPaintBorder(canvas);
|
||||||
|
|
||||||
for (int i = 0; i < popup_->line_count(); ++i) {
|
for (int i = 0; i < popup_->line_count(); ++i) {
|
||||||
gfx::Rect line_rect = popup_->GetRowBounds(i);
|
gfx::Rect line_rect = popup_->GetRowBounds(i);
|
||||||
|
|
||||||
DrawAutofillEntry(draw_canvas, i, line_rect);
|
DrawAutofillEntry(canvas, i, line_rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (view_proxy_.get()) {
|
if (view_proxy_) {
|
||||||
view_proxy_->SetBounds(popup_->popup_bounds_in_view());
|
view_proxy_->SetBounds(offscreen_bounds);
|
||||||
view_proxy_->SetBitmap(bitmap);
|
view_proxy_->SetBitmap(offscreen_bitmap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue