blob: 64db40ce9bc80f5e54022ef1973bc163d296dff5 [file] [log] [blame]
Avi Drissman4a8573c2022-09-09 19:35:541// Copyright 2018 The Chromium Authors
Aldo Culquicondor9152d532018-09-25 14:55:142// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/vr/cmd_buffer_surface_provider.h"
6
Hans Wennborg1790e6b2020-04-24 19:10:337#include "base/check_op.h"
Aldo Culquicondor9152d532018-09-25 14:55:148#include "gpu/command_buffer/client/gles2_implementation.h"
9#include "gpu/command_buffer/client/gles2_lib.h"
10#include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h"
Kaylee Lubicka077f79232024-09-04 01:32:5511#include "third_party/skia/include/gpu/ganesh/GrDirectContext.h"
Kevin Lubick07fb7132023-09-29 14:36:1012#include "third_party/skia/include/gpu/ganesh/gl/GrGLDirectContext.h"
Kaylee Lubicka077f79232024-09-04 01:32:5513#include "third_party/skia/include/gpu/ganesh/gl/GrGLInterface.h"
Aldo Culquicondor9152d532018-09-25 14:55:1414#include "ui/gfx/geometry/size.h"
15
16namespace vr {
17
18CmdBufferSurfaceProvider::CmdBufferSurfaceProvider() {
19 auto* gles2_implementation =
20 static_cast<gpu::gles2::GLES2Implementation*>(gles2::GetGLContext());
21 DCHECK(gles2_implementation);
22 sk_sp<const GrGLInterface> gr_interface =
23 skia_bindings::CreateGLES2InterfaceBindings(gles2_implementation,
24 gles2_implementation);
Kevin Lubick07fb7132023-09-29 14:36:1025 gr_context_ = GrDirectContexts::MakeGL(std::move(gr_interface));
Aldo Culquicondor9152d532018-09-25 14:55:1426 DCHECK(gr_context_);
Aldo Culquicondor9152d532018-09-25 14:55:1427}
28
29CmdBufferSurfaceProvider::~CmdBufferSurfaceProvider() = default;
30
Vasiliy Telezhnikov2fa8baf2023-06-20 20:44:1031std::unique_ptr<SkiaSurfaceProvider::Texture>
32CmdBufferSurfaceProvider::CreateTextureWithSkia(
33 const gfx::Size& size,
34 base::FunctionRef<void(SkCanvas*)> paint) {
35 // We need to store and restore previous FBO after skia draw.
36 GLint prev_fbo = 0;
37 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &prev_fbo);
Aldo Culquicondor9152d532018-09-25 14:55:1438
Vasiliy Telezhnikov2fa8baf2023-06-20 20:44:1039 auto texture = CreateTextureWithSkiaImpl(gr_context_.get(), size, paint);
40
Adlai Hollerabb78ea2020-09-16 11:27:5741 gr_context_->resetContext();
Vasiliy Telezhnikov2fa8baf2023-06-20 20:44:1042 glBindFramebuffer(GL_FRAMEBUFFER, prev_fbo);
Aldo Culquicondor