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

Unified Diff: content/browser/renderer_host/offscreen_canvas_surface_impl.cc

Issue 2479563005: Create manager to track OffscreenCanvasSurfaceImpl instances (Closed)
Patch Set: rebase Created 4 years, 1 month 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
Index: content/browser/renderer_host/offscreen_canvas_surface_impl.cc
diff --git a/content/browser/renderer_host/offscreen_canvas_surface_impl.cc b/content/browser/renderer_host/offscreen_canvas_surface_impl.cc
index bac06970c2382f730a49d63858dfaa89953644e6..75a04d626a3290799794070fe3a0baa2ea4acc44 100644
--- a/content/browser/renderer_host/offscreen_canvas_surface_impl.cc
+++ b/content/browser/renderer_host/offscreen_canvas_surface_impl.cc
@@ -8,6 +8,7 @@
#include "cc/surfaces/surface.h"
#include "cc/surfaces/surface_manager.h"
#include "content/browser/compositor/surface_utils.h"
+#include "content/browser/renderer_host/offscreen_canvas_surface_manager.h"
#include "content/public/browser/browser_thread.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
@@ -16,7 +17,12 @@ namespace content {
OffscreenCanvasSurfaceImpl::OffscreenCanvasSurfaceImpl()
: id_allocator_(new cc::SurfaceIdAllocator()) {}
-OffscreenCanvasSurfaceImpl::~OffscreenCanvasSurfaceImpl() {}
+OffscreenCanvasSurfaceImpl::~OffscreenCanvasSurfaceImpl() {
+ if (frame_sink_id_.is_valid()) {
+ OffscreenCanvasSurfaceManager::GetInstance()
+ ->UnregisterOffscreenCanvasSurfaceInstance(frame_sink_id_);
+ }
+}
// static
void OffscreenCanvasSurfaceImpl::Create(
@@ -28,11 +34,27 @@ void OffscreenCanvasSurfaceImpl::Create(
void OffscreenCanvasSurfaceImpl::GetSurfaceId(
const GetSurfaceIdCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ if (frame_sink_id_.is_valid()) {
+ // This IPC should be only called once for each HTMLCanvasElement. In this
+ // case, frame_sink_id_ is still unset.
+ // As the browser makes no assumption of correct behavior of renderer, in
+ // an unwanted situation when this function is invoked twice, we need to
+ // unregister the instance from manager.
+ OffscreenCanvasSurfaceManager::GetInstance()
+ ->UnregisterOffscreenCanvasSurfaceInstance(frame_sink_id_);
+ mojo::ReportBadMessage(
+ "The same OffscreenCanvasSurfaceImpl is registered to "
+ "OffscreenCanvasSurfaceManager twice.");
+ }
+
+ frame_sink_id_ = AllocateFrameSinkId();
+ cc::SurfaceId surface_id =
+ cc::SurfaceId(frame_sink_id_, id_allocator_->GenerateId());
- cc::LocalFrameId local_frame_id = id_allocator_->GenerateId();
- surface_id_ = cc::SurfaceId(AllocateFrameSinkId(), local_frame_id);
+ OffscreenCanvasSurfaceManager::GetInstance()
+ ->RegisterOffscreenCanvasSurfaceInstance(frame_sink_id_, this);
- callback.Run(surface_id_);
+ callback.Run(surface_id);
}
void OffscreenCanvasSurfaceImpl::Require(const cc::SurfaceId& surface_id,

Powered by Google App Engine
This is Rietveld 408576698