blob: ab828b6aa64daed2d1d9c258bf3ac9cea987a917 [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"
Robert Phillipsdbb0b7d2020-07-29 16:07:4411#include "third_party/skia/include/gpu/GrDirectContext.h"
Aldo Culquicondor9152d532018-09-25 14:55:1412#include "third_party/skia/include/gpu/gl/GrGLInterface.h"
13#include "ui/gfx/geometry/size.h"
14
15namespace vr {
16
17CmdBufferSurfaceProvider::CmdBufferSurfaceProvider() {
18 auto* gles2_implementation =
19 static_cast<gpu::gles2::GLES2Implementation*>(gles2::GetGLContext());
20 DCHECK(gles2_implementation);
21 sk_sp<const GrGLInterface> gr_interface =
22 skia_bindings::CreateGLES2InterfaceBindings(gles2_implementation,
23 gles2_implementation);
Robert Phillipsdbb0b7d2020-07-29 16:07:4424 gr_context_ = GrDirectContext::MakeGL(std::move(gr_interface));
Aldo Culquicondor9152d532018-09-25 14:55:1425 DCHECK(gr_context_);
Aldo Culquicondor9152d532018-09-25 14:55:1426}
27
28CmdBufferSurfaceProvider::~CmdBufferSurfaceProvider() = default;
29
Vasiliy Telezhnikov2fa8baf2023-06-20 20:44:1030std::unique_ptr<SkiaSurfaceProvider::Texture>
31CmdBufferSurfaceProvider::CreateTextureWithSkia(
32 const gfx::Size& size,
33 base::FunctionRef<void(SkCanvas*)> paint) {
34 // We need to store and restore previous FBO after skia draw.
35 GLint prev_fbo = 0;
36 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &prev_fbo);
Aldo Culquicondor9152d532018-09-25 14:55:1437
Vasiliy Telezhnikov2fa8baf2023-06-20 20:44:1038 auto texture = CreateTextureWithSkiaImpl(gr_context_.get(), size, paint);
39
Adlai Hollerabb78ea2020-09-16 11:27:5740 gr_context_->resetContext();
Vasiliy Telezhnikov2fa8baf2023-06-20 20:44:1041 glBindFramebuffer(GL_FRAMEBUFFER, prev_fbo);
Aldo Culquicondor9152d532018-09-25 14:55:1442
Vasiliy Telezhnikov2fa8baf2023-06-20 20:44:1043 return texture;
Aldo Culquicondor9152d532018-09-25 14:55:1444}
45
46} // namespace vr