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

Side by Side Diff: third_party/WebKit/Source/core/workers/MainThreadWorklet.cpp

Issue 2871513002: Worklet: Lazily create PaintWorkletGlobalScopes (Closed)
Patch Set: fix rebase failures Created 3 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/workers/MainThreadWorklet.h" 5 #include "core/workers/MainThreadWorklet.h"
6 6
7 #include "bindings/core/v8/ScriptPromiseResolver.h" 7 #include "bindings/core/v8/ScriptPromiseResolver.h"
8 #include "bindings/core/v8/ScriptSourceCode.h" 8 #include "bindings/core/v8/ScriptSourceCode.h"
9 #include "bindings/core/v8/V8BindingForCore.h" 9 #include "bindings/core/v8/V8BindingForCore.h"
10 #include "core/frame/LocalFrame.h" 10 #include "core/frame/LocalFrame.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 // type." 60 // type."
61 // workletGlobalScopeType is encoded into the class name (e.g., PaintWorklet). 61 // workletGlobalScopeType is encoded into the class name (e.g., PaintWorklet).
62 62
63 // Step 10: "If the worklet's WorkletGlobalScopes is empty, run the following 63 // Step 10: "If the worklet's WorkletGlobalScopes is empty, run the following
64 // steps:" 64 // steps:"
65 // 10.1: "Create a WorkletGlobalScope given workletGlobalScopeType, 65 // 10.1: "Create a WorkletGlobalScope given workletGlobalScopeType,
66 // moduleResponsesMap, and outsideSettings." 66 // moduleResponsesMap, and outsideSettings."
67 // 10.2: "Add the WorkletGlobalScope to worklet's WorkletGlobalScopes." 67 // 10.2: "Add the WorkletGlobalScope to worklet's WorkletGlobalScopes."
68 // "Depending on the type of worklet the user agent may create additional 68 // "Depending on the type of worklet the user agent may create additional
69 // WorkletGlobalScopes at this time." 69 // WorkletGlobalScopes at this time."
70 // TODO(nhiroki): Create WorkletGlobalScopes at this point. 70 while (NeedsToCreateGlobalScope())
71 global_scope_proxies_.insert(CreateGlobalScope());
72 DCHECK(!global_scope_proxies_.IsEmpty());
71 73
72 // Step 11: "Let pendingTaskStruct be a new pending tasks struct with counter 74 // Step 11: "Let pendingTaskStruct be a new pending tasks struct with counter
73 // initialized to the length of worklet's WorkletGlobalScopes." 75 // initialized to the length of worklet's WorkletGlobalScopes."
74 // TODO(nhiroki): Introduce the concept of "worklet's WorkletGlobalScopes" and
75 // use the length of it here.
76 constexpr int number_of_global_scopes = 1;
77 WorkletPendingTasks* pending_tasks = 76 WorkletPendingTasks* pending_tasks =
78 new WorkletPendingTasks(number_of_global_scopes, resolver); 77 new WorkletPendingTasks(global_scope_proxies_.size(), resolver);
79 78
80 // Step 12: "For each workletGlobalScope in the worklet's 79 // Step 12: "For each workletGlobalScope in the worklet's
81 // WorkletGlobalScopes, queue a task on the workletGlobalScope to fetch and 80 // WorkletGlobalScopes, queue a task on the workletGlobalScope to fetch and
82 // invoke a worklet script given workletGlobalScope, moduleURLRecord, 81 // invoke a worklet script given workletGlobalScope, moduleURLRecord,
83 // moduleResponsesMap, credentialOptions, outsideSettings, pendingTaskStruct, 82 // moduleResponsesMap, credentialOptions, outsideSettings, pendingTaskStruct,
84 // and promise." 83 // and promise."
85 // TODO(nhiroki): Queue a task instead of executing this here. 84 // TODO(nhiroki): Queue a task instead of executing this here.
86 GetWorkletGlobalScopeProxy()->FetchAndInvokeScript( 85 for (const auto& proxy : global_scope_proxies_) {
87 module_url_record, credentials_mode, pending_tasks); 86 proxy->FetchAndInvokeScript(module_url_record, credentials_mode,
87 pending_tasks);
88 }
88 } 89 }
89 90
90 void MainThreadWorklet::ContextDestroyed(ExecutionContext* execution_context) { 91 void MainThreadWorklet::ContextDestroyed(ExecutionContext* execution_context) {
91 DCHECK(IsMainThread()); 92 DCHECK(IsMainThread());
92 GetWorkletGlobalScopeProxy()->TerminateWorkletGlobalScope(); 93 for (const auto& proxy : global_scope_proxies_)
94 proxy->TerminateWorkletGlobalScope();
93 } 95 }
94 96
95 DEFINE_TRACE(MainThreadWorklet) { 97 DEFINE_TRACE(MainThreadWorklet) {
96 Worklet::Trace(visitor); 98 Worklet::Trace(visitor);
97 } 99 }
98 100
99 } // namespace blink 101 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698