forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reland "Create MemoryManagedPaintCanvas class"
This change was landed and reverted https://chromium-review.googlesource.com/c/chromium/src/+/1960469 We were flushing mid-draw and this was causing problems. Flush after DidDraw instead. Change-Id: I0d40c5f823014601203c84469749314add107e58 Bug: 1016727, 1015729, 1035865, 1035865 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1976501 Commit-Queue: Aaron Krajeski <aaronhk@chromium.org> Reviewed-by: Aaron Krajeski <aaronhk@chromium.org> Reviewed-by: Jeremy Roman <jbroman@chromium.org> Reviewed-by: Khushal <khushalsagar@chromium.org> Cr-Commit-Position: refs/heads/master@{#726913}
- Loading branch information
1 parent
f2053e9
commit 86ff5cc
Showing
12 changed files
with
257 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
third_party/blink/renderer/platform/graphics/memory_managed_paint_canvas.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2019 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "third_party/blink/renderer/platform/graphics/memory_managed_paint_canvas.h" | ||
|
||
namespace blink { | ||
|
||
MemoryManagedPaintCanvas::MemoryManagedPaintCanvas( | ||
cc::DisplayItemList* list, | ||
const SkRect& bounds, | ||
base::RepeatingClosure set_needs_flush_callback) | ||
: RecordPaintCanvas(list, bounds), | ||
set_needs_flush_callback_(std::move(set_needs_flush_callback)) {} | ||
|
||
MemoryManagedPaintCanvas::~MemoryManagedPaintCanvas() = default; | ||
|
||
void MemoryManagedPaintCanvas::drawImage(const cc::PaintImage& image, | ||
SkScalar left, | ||
SkScalar top, | ||
const cc::PaintFlags* flags) { | ||
DCHECK(!image.IsPaintWorklet()); | ||
RecordPaintCanvas::drawImage(image, left, top, flags); | ||
UpdateMemoryUsage(image); | ||
} | ||
|
||
void MemoryManagedPaintCanvas::drawImageRect( | ||
const cc::PaintImage& image, | ||
const SkRect& src, | ||
const SkRect& dst, | ||
const cc::PaintFlags* flags, | ||
PaintCanvas::SrcRectConstraint constraint) { | ||
RecordPaintCanvas::drawImageRect(image, src, dst, flags, constraint); | ||
UpdateMemoryUsage(image); | ||
} | ||
|
||
void MemoryManagedPaintCanvas::UpdateMemoryUsage(const cc::PaintImage& image) { | ||
if (cached_image_ids_.contains(image.content_id())) | ||
return; | ||
|
||
cached_image_ids_.insert(image.content_id()); | ||
total_stored_image_memory_ += | ||
image.GetSkImage()->imageInfo().computeMinByteSize(); | ||
|
||
if (total_stored_image_memory_ > kMaxPinnedMemory) | ||
set_needs_flush_callback_.Run(); | ||
} | ||
|
||
} // namespace blink |
52 changes: 52 additions & 0 deletions
52
third_party/blink/renderer/platform/graphics/memory_managed_paint_canvas.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2019 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_MEMORY_MANAGED_PAINT_CANVAS_H_ | ||
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_MEMORY_MANAGED_PAINT_CANVAS_H_ | ||
|
||
#include <memory> | ||
|
||
#include "cc/paint/record_paint_canvas.h" | ||
#include "third_party/blink/public/platform/platform.h" | ||
|
||
namespace blink { | ||
|
||
// MemoryManagedPaintCanvas overrides the potentially memory intensive image | ||
// drawing methods of PaintCanvas and keeps track of how much memory is | ||
// being pinned between flushes. This allows the rendering context to flush if | ||
// too much memory is used. | ||
class PLATFORM_EXPORT MemoryManagedPaintCanvas final | ||
: public cc::RecordPaintCanvas { | ||
public: | ||
MemoryManagedPaintCanvas(cc::DisplayItemList* list, | ||
const SkRect& bounds, | ||
base::RepeatingClosure set_needs_flush_callback); | ||
explicit MemoryManagedPaintCanvas(const cc::RecordPaintCanvas&) = delete; | ||
~MemoryManagedPaintCanvas() override; | ||
|
||
void drawImage(const cc::PaintImage& image, | ||
SkScalar left, | ||
SkScalar top, | ||
const cc::PaintFlags* flags) override; | ||
void drawImageRect(const cc::PaintImage& image, | ||
const SkRect& src, | ||
const SkRect& dst, | ||
const cc::PaintFlags* flags, | ||
SrcRectConstraint constraint) override; | ||
|
||
private: | ||
void UpdateMemoryUsage(const cc::PaintImage& image); | ||
|
||
base::flat_set<int> cached_image_ids_; | ||
uint64_t total_stored_image_memory_ = 0; | ||
|
||
base::RepeatingClosure set_needs_flush_callback_; | ||
|
||
// The same value as is used in content::WebGraphicsConext3DProviderImpl. | ||
static constexpr uint64_t kMaxPinnedMemory = 64 * 1024 * 1024; | ||
}; | ||
|
||
} // namespace blink | ||
|
||
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_MEMORY_MANAGED_PAINT_CANVAS_H_ |
41 changes: 41 additions & 0 deletions
41
third_party/blink/renderer/platform/graphics/memory_managed_paint_recorder.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright (C) 2019 Google Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | ||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | ||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#include "third_party/blink/renderer/platform/graphics/memory_managed_paint_recorder.h" | ||
|
||
namespace blink { | ||
|
||
MemoryManagedPaintRecorder::MemoryManagedPaintRecorder( | ||
base::RepeatingClosure set_needs_flush_callback) | ||
: set_needs_flush_callback_(std::move(set_needs_flush_callback)) {} | ||
|
||
std::unique_ptr<cc::RecordPaintCanvas> MemoryManagedPaintRecorder::CreateCanvas( | ||
cc::DisplayItemList* list, | ||
const SkRect& bounds) { | ||
return std::make_unique<MemoryManagedPaintCanvas>(list, bounds, | ||
set_needs_flush_callback_); | ||
} | ||
|
||
} // namespace blink |
Oops, something went wrong.