OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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 "content/common/gpu/client/grcontext_for_webgraphicscontext3d.h" | 5 #include "content/common/gpu/client/grcontext_for_webgraphicscontext3d.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <string.h> | 8 #include <string.h> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
14 #include "gpu/blink/webgraphicscontext3d_impl.h" | 14 #include "gpu/blink/webgraphicscontext3d_impl.h" |
15 #include "gpu/command_buffer/client/gles2_lib.h" | 15 #include "gpu/command_buffer/client/gles2_lib.h" |
16 #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h" | 16 #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h" |
17 #include "third_party/skia/include/gpu/GrContext.h" | 17 #include "third_party/skia/include/gpu/GrContext.h" |
18 | 18 |
19 using gpu_blink::WebGraphicsContext3DImpl; | 19 using gpu_blink::WebGraphicsContext3DImpl; |
20 | 20 |
21 namespace content { | 21 namespace content { |
22 | 22 |
23 namespace { | |
24 | |
25 // Singleton used to initialize and terminate the gles2 library. | |
26 class GLES2Initializer { | |
27 public: | |
28 GLES2Initializer() { gles2::Initialize(); } | |
29 | |
30 ~GLES2Initializer() { gles2::Terminate(); } | |
31 | |
32 private: | |
33 DISALLOW_COPY_AND_ASSIGN(GLES2Initializer); | |
34 }; | |
35 | |
36 base::LazyInstance<GLES2Initializer> g_gles2_initializer = | |
37 LAZY_INSTANCE_INITIALIZER; | |
38 | |
39 void BindWebGraphicsContext3DGLContextCallback(const GrGLInterface* interface) { | |
40 gles2::SetGLContext(static_cast<const GrGLInterfaceForWebGraphicsContext3D*>( | |
41 interface)->WebContext3D()->GetGLInterface()); | |
42 } | |
43 | |
44 } // namespace anonymous | |
45 | |
46 GrContextForWebGraphicsContext3D::GrContextForWebGraphicsContext3D( | 23 GrContextForWebGraphicsContext3D::GrContextForWebGraphicsContext3D( |
47 skia::RefPtr<GrGLInterfaceForWebGraphicsContext3D> gr_interface) { | 24 skia::RefPtr<GrGLInterfaceForWebGraphicsContext3D> gr_interface) { |
48 if (!gr_interface || !gr_interface->WebContext3D()) | 25 if (!gr_interface || !gr_interface->WebContext3D()) |
49 return; | 26 return; |
50 | 27 |
51 // Ensure the gles2 library is initialized first in a thread safe way. | 28 skia_bindings::InitGLES2InterfaceBindings( |
52 g_gles2_initializer.Get(); | 29 gr_interface.get(), gr_interface->WebContext3D()->GetGLInterface()); |
53 gles2::SetGLContext(gr_interface->WebContext3D()->GetGLInterface()); | |
54 | |
55 skia_bindings::InitCommandBufferSkiaGLBinding(gr_interface.get()); | |
56 | |
57 gr_interface->fCallback = BindWebGraphicsContext3DGLContextCallback; | |
58 | 30 |
59 gr_context_ = skia::AdoptRef(GrContext::Create( | 31 gr_context_ = skia::AdoptRef(GrContext::Create( |
60 kOpenGL_GrBackend, | 32 kOpenGL_GrBackend, |
61 reinterpret_cast<GrBackendContext>(gr_interface.get()))); | 33 reinterpret_cast<GrBackendContext>(gr_interface.get()))); |
62 if (gr_context_) { | 34 if (gr_context_) { |
63 // The limit of the number of GPU resources we hold in the GrContext's | 35 // The limit of the number of GPU resources we hold in the GrContext's |
64 // GPU cache. | 36 // GPU cache. |
65 static const int kMaxGaneshResourceCacheCount = 2048; | 37 static const int kMaxGaneshResourceCacheCount = 2048; |
66 // The limit of the bytes allocated toward GPU resources in the GrContext's | 38 // The limit of the bytes allocated toward GPU resources in the GrContext's |
67 // GPU cache. | 39 // GPU cache. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 GrGLInterfaceForWebGraphicsContext3D::~GrGLInterfaceForWebGraphicsContext3D() { | 71 GrGLInterfaceForWebGraphicsContext3D::~GrGLInterfaceForWebGraphicsContext3D() { |
100 DCHECK(context_thread_checker_.CalledOnValidThread()); | 72 DCHECK(context_thread_checker_.CalledOnValidThread()); |
101 #if !defined(NDEBUG) | 73 #if !defined(NDEBUG) |
102 // Set all the function pointers to zero, in order to crash if function | 74 // Set all the function pointers to zero, in order to crash if function |
103 // pointers are used after free. | 75 // pointers are used after free. |
104 memset(&fFunctions, 0, sizeof(GrGLInterface::Functions)); | 76 memset(&fFunctions, 0, sizeof(GrGLInterface::Functions)); |
105 #endif | 77 #endif |
106 } | 78 } |
107 | 79 |
108 } // namespace content | 80 } // namespace content |
OLD | NEW |