grcontext_for_gles2_interface.cc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright (c) 2013 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "gpu/skia_bindings/grcontext_for_gles2_interface.h"
  5. #include <stddef.h>
  6. #include <string.h>
  7. #include <utility>
  8. #include "base/lazy_instance.h"
  9. #include "base/system/sys_info.h"
  10. #include "base/trace_event/trace_event.h"
  11. #include "gpu/command_buffer/client/gles2_interface.h"
  12. #include "gpu/command_buffer/common/capabilities.h"
  13. #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h"
  14. #include "gpu/skia_bindings/gles2_implementation_with_grcontext_support.h"
  15. #include "third_party/skia/include/gpu/GrContextOptions.h"
  16. #include "third_party/skia/include/gpu/GrDirectContext.h"
  17. #include "third_party/skia/include/gpu/gl/GrGLInterface.h"
  18. namespace skia_bindings {
  19. GrContextForGLES2Interface::GrContextForGLES2Interface(
  20. gpu::gles2::GLES2Interface* gl,
  21. gpu::ContextSupport* context_support,
  22. const gpu::Capabilities& capabilities,
  23. size_t max_resource_cache_bytes,
  24. size_t max_glyph_cache_texture_bytes,
  25. bool support_bilerp_from_flyph_atlas)
  26. : context_support_(context_support) {
  27. GrContextOptions options;
  28. options.fGlyphCacheTextureMaximumBytes = max_glyph_cache_texture_bytes;
  29. options.fAvoidStencilBuffers = capabilities.avoid_stencil_buffers;
  30. options.fAllowPathMaskCaching = false;
  31. options.fShaderErrorHandler = this;
  32. // TODO(csmartdalton): enable internal multisampling after the related Skia
  33. // rolls are in.
  34. options.fInternalMultisampleCount = 0;
  35. options.fSupportBilerpFromGlyphAtlas = support_bilerp_from_flyph_atlas;
  36. sk_sp<GrGLInterface> interface(
  37. skia_bindings::CreateGLES2InterfaceBindings(gl, context_support));
  38. gr_context_ = GrDirectContext::MakeGL(std::move(interface), options);
  39. if (gr_context_) {
  40. gr_context_->setResourceCacheLimit(max_resource_cache_bytes);
  41. context_support_->SetGrContext(gr_context_.get());
  42. }
  43. }
  44. GrContextForGLES2Interface::~GrContextForGLES2Interface() {
  45. // At this point the GLES2Interface is going to be destroyed, so have
  46. // the GrContext clean up and not try to use it anymore.
  47. if (gr_context_) {
  48. gr_context_->releaseResourcesAndAbandonContext();
  49. context_support_->SetGrContext(nullptr);
  50. }
  51. }
  52. void GrContextForGLES2Interface::compileError(const char* shader,
  53. const char* errors) {
  54. LOG(ERROR) << "Skia shader compilation error\n"
  55. << "------------------------\n"
  56. << shader << "\nErrors:\n"
  57. << errors;
  58. }
  59. void GrContextForGLES2Interface::OnLostContext() {
  60. if (gr_context_)
  61. gr_context_->abandonContext();
  62. }
  63. void GrContextForGLES2Interface::FreeGpuResources() {
  64. if (gr_context_) {
  65. TRACE_EVENT_INSTANT0("gpu", "GrContext::freeGpuResources",
  66. TRACE_EVENT_SCOPE_THREAD);
  67. gr_context_->freeGpuResources();
  68. }
  69. }
  70. GrDirectContext* GrContextForGLES2Interface::get() {
  71. return gr_context_.get();
  72. }
  73. } // namespace skia_bindings