[GPU Security] Make GL context current in SharedImageStub::OnAddReference

SharedImageFactory::AddSecondaryReference() can materialize lazy GPU
backings (via CompoundImageBacking::OnAddSecondaryReference()), such as
GLTextureImageBacking. Previously, SharedImageStub::OnAddReference() did
not call MakeContextCurrent(), allowing lazy GL texture allocation to
run while an unrelated GL/EGL context (e.g., a passthrough WebGL context
in a separate share group or Dawn's OpenGL ES EGL context) was still
current on the GPU main thread.

Call MakeContextCurrent(/*needs_gl=*/true) before invoking
AddSecondaryReference() so that the SharedContextState GL context is
made current even when Skia is not using GL (e.g., Vulkan or Graphite,
where MakeContextCurrent(/*needs_gl=*/false) returns early without
switching GL contexts). Also fix the copy-pasted TRACE_EVENT0 name in
OnAddReference().

Add unit tests covering foreign GL context switching and the
lost-context error path.

Fixed: 513128270
Change-Id: If123162015e414890c513def1137325c5303e4c8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8893604
Reviewed-by: Kyle Charbonneau <kylechar@chromium.org>
Commit-Queue: vikas soni <vikassoni@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1760884}
NOKEYCHECK=True
GitOrigin-RevId: 59f83843405d3581af55a2ef5f370d81f693734e
2 files changed