-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GraphiteCacheController for scheduling graphite cache cleanup
Bug: 1472451 Change-Id: I7846235d3f0689e92a203209c6bd0ae582d43a72 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4797836 Reviewed-by: Sunny Sachanandani <sunnyps@chromium.org> Commit-Queue: Peng Huang <penghuang@chromium.org> Reviewed-by: Vasiliy Telezhnikov <vasilyt@chromium.org> Auto-Submit: Peng Huang <penghuang@chromium.org> Cr-Commit-Position: refs/heads/main@{#1187328}
- Loading branch information
Showing
11 changed files
with
174 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "gpu/command_buffer/service/graphite_cache_controller.h" | ||
|
||
#include "base/functional/callback_helpers.h" | ||
#include "base/time/time.h" | ||
#include "base/timer/timer.h" | ||
#include "third_party/skia/include/gpu/graphite/Context.h" | ||
#include "third_party/skia/include/gpu/graphite/Recorder.h" | ||
|
||
namespace gpu::raster { | ||
namespace { | ||
constexpr base::TimeDelta kCleanupDelay = base::Seconds(5); | ||
} | ||
|
||
GraphiteCacheController::GraphiteCacheController( | ||
skgpu::graphite::Context* context, | ||
skgpu::graphite::Recorder* recorder) | ||
: context_(context), recorder_(recorder) { | ||
timer_ = std::make_unique<base::RetainingOneShotTimer>( | ||
FROM_HERE, kCleanupDelay, | ||
base::BindRepeating(&GraphiteCacheController::PerformCleanup, | ||
GetWeakPtr())); | ||
} | ||
|
||
GraphiteCacheController::~GraphiteCacheController() = default; | ||
|
||
void GraphiteCacheController::ScheduleCleanup() { | ||
timer_->Reset(); | ||
} | ||
|
||
void GraphiteCacheController::PerformCleanup() { | ||
if (context_) { | ||
// TODO(crbug.com/1472451): cleanup resources in context_; | ||
} | ||
if (recorder_) { | ||
// TODO(crbug.com/1472451): cleanup resources in recorder_ | ||
} | ||
} | ||
|
||
} // namespace gpu::raster |
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,59 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef GPU_COMMAND_BUFFER_SERVICE_GRAPHITE_CACHE_CONTROLLER_H_ | ||
#define GPU_COMMAND_BUFFER_SERVICE_GRAPHITE_CACHE_CONTROLLER_H_ | ||
|
||
#include <memory> | ||
|
||
#include "base/memory/ref_counted.h" | ||
#include "base/memory/weak_ptr.h" | ||
#include "base/task/single_thread_task_runner.h" | ||
#include "gpu/gpu_gles2_export.h" | ||
|
||
namespace base { | ||
class RetainingOneShotTimer; | ||
} // namespace base | ||
|
||
namespace skgpu::graphite { | ||
class Context; | ||
class Recorder; | ||
} // namespace skgpu::graphite | ||
|
||
namespace gpu::raster { | ||
|
||
class GPU_GLES2_EXPORT GraphiteCacheController | ||
: public base::RefCounted<GraphiteCacheController> { | ||
public: | ||
// |context| and |recorder| are optional, GraphiteCacheController only purge | ||
// resource in non-null |context| and |recorder|. | ||
GraphiteCacheController(skgpu::graphite::Context* context, | ||
skgpu::graphite::Recorder* recorder); | ||
GraphiteCacheController(const GraphiteCacheController&) = delete; | ||
GraphiteCacheController& operator=(const GraphiteCacheController&) = delete; | ||
|
||
base::WeakPtr<GraphiteCacheController> GetWeakPtr() { | ||
return weak_factory_.GetWeakPtr(); | ||
} | ||
|
||
// Schedule cleanup for the graphite cache, the cleanup will be performed | ||
// until ScheduleCleanup() is called for a while. | ||
void ScheduleCleanup(); | ||
|
||
private: | ||
friend class base::RefCounted<GraphiteCacheController>; | ||
~GraphiteCacheController(); | ||
|
||
void PerformCleanup(); | ||
|
||
const raw_ptr<skgpu::graphite::Context> context_; | ||
const raw_ptr<skgpu::graphite::Recorder> recorder_; | ||
std::unique_ptr<base::RetainingOneShotTimer> timer_; | ||
|
||
base::WeakPtrFactory<GraphiteCacheController> weak_factory_{this}; | ||
}; | ||
|
||
} // namespace gpu::raster | ||
|
||
#endif // GPU_COMMAND_BUFFER_SERVICE_GRAPHITE_CACHE_CONTROLLER_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
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