Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: content/common/gpu/client/grcontext_for_webgraphicscontext3d.cc

Issue 1444683002: Revert of Fix gpu command buffer use after free by GrContext (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/trace_event/trace_event.h" 8 #include "base/trace_event/trace_event.h"
9 #include "gpu/blink/webgraphicscontext3d_impl.h" 9 #include "gpu/blink/webgraphicscontext3d_impl.h"
10 #include "gpu/command_buffer/client/gles2_lib.h" 10 #include "gpu/command_buffer/client/gles2_lib.h"
11 #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h"
12 #include "third_party/skia/include/gpu/GrContext.h" 11 #include "third_party/skia/include/gpu/GrContext.h"
12 #include "third_party/skia/include/gpu/gl/GrGLInterface.h"
13 13
14 using gpu_blink::WebGraphicsContext3DImpl; 14 using gpu_blink::WebGraphicsContext3DImpl;
15 15
16 namespace content { 16 namespace content {
17 17
18 namespace { 18 namespace {
19 19
20 // Singleton used to initialize and terminate the gles2 library. 20 // Singleton used to initialize and terminate the gles2 library.
21 class GLES2Initializer { 21 class GLES2Initializer {
22 public: 22 public:
23 GLES2Initializer() { gles2::Initialize(); } 23 GLES2Initializer() { gles2::Initialize(); }
24 24
25 ~GLES2Initializer() { gles2::Terminate(); } 25 ~GLES2Initializer() { gles2::Terminate(); }
26 26
27 private: 27 private:
28 DISALLOW_COPY_AND_ASSIGN(GLES2Initializer); 28 DISALLOW_COPY_AND_ASSIGN(GLES2Initializer);
29 }; 29 };
30 30
31 base::LazyInstance<GLES2Initializer> g_gles2_initializer = 31 base::LazyInstance<GLES2Initializer> g_gles2_initializer =
32 LAZY_INSTANCE_INITIALIZER; 32 LAZY_INSTANCE_INITIALIZER;
33 33
34 void BindWebGraphicsContext3DGLContextCallback(const GrGLInterface* interface) { 34 void BindWebGraphicsContext3DGLContextCallback(const GrGLInterface* interface) {
35 gles2::SetGLContext(static_cast<const GrGLInterfaceForWebGraphicsContext3D*>( 35 gles2::SetGLContext(reinterpret_cast<WebGraphicsContext3DImpl*>(
36 interface)->WebContext3D()->GetGLInterface()); 36 interface->fCallbackData)->GetGLInterface());
37 } 37 }
38 38
39 } // namespace anonymous 39 } // namespace anonymous
40 40
41 GrContextForWebGraphicsContext3D::GrContextForWebGraphicsContext3D( 41 GrContextForWebGraphicsContext3D::GrContextForWebGraphicsContext3D(
42 skia::RefPtr<GrGLInterfaceForWebGraphicsContext3D> gr_interface) { 42 WebGraphicsContext3DImpl* context3d) {
43 if (!gr_interface || !gr_interface->WebContext3D()) 43 if (!context3d)
44 return; 44 return;
45 45
46 // Ensure the gles2 library is initialized first in a thread safe way. 46 // Ensure the gles2 library is initialized first in a thread safe way.
47 g_gles2_initializer.Get(); 47 g_gles2_initializer.Get();
48 gles2::SetGLContext(gr_interface->WebContext3D()->GetGLInterface()); 48 gles2::SetGLContext(context3d->GetGLInterface());
49 skia::RefPtr<GrGLInterface> interface = skia::AdoptRef(
50 context3d->createGrGLInterface());
51 if (!interface)
52 return;
49 53
50 skia_bindings::InitCommandBufferSkiaGLBinding(gr_interface.get()); 54 interface->fCallback = BindWebGraphicsContext3DGLContextCallback;
51 55 interface->fCallbackData =
52 gr_interface->fCallback = BindWebGraphicsContext3DGLContextCallback; 56 reinterpret_cast<GrGLInterfaceCallbackData>(context3d);
53 57
54 gr_context_ = skia::AdoptRef(GrContext::Create( 58 gr_context_ = skia::AdoptRef(GrContext::Create(
55 kOpenGL_GrBackend, 59 kOpenGL_GrBackend,
56 reinterpret_cast<GrBackendContext>(gr_interface.get()))); 60 reinterpret_cast<GrBackendContext>(interface.get())));
57 if (gr_context_) { 61 if (gr_context_) {
58 // The limit of the number of GPU resources we hold in the GrContext's 62 // The limit of the number of GPU resources we hold in the GrContext's
59 // GPU cache. 63 // GPU cache.
60 static const int kMaxGaneshResourceCacheCount = 2048; 64 static const int kMaxGaneshResourceCacheCount = 2048;
61 // The limit of the bytes allocated toward GPU resources in the GrContext's 65 // The limit of the bytes allocated toward GPU resources in the GrContext's
62 // GPU cache. 66 // GPU cache.
63 static const size_t kMaxGaneshResourceCacheBytes = 96 * 1024 * 1024; 67 static const size_t kMaxGaneshResourceCacheBytes = 96 * 1024 * 1024;
64 68
65 gr_context_->setResourceCacheLimits(kMaxGaneshResourceCacheCount, 69 gr_context_->setResourceCacheLimits(kMaxGaneshResourceCacheCount,
66 kMaxGaneshResourceCacheBytes); 70 kMaxGaneshResourceCacheBytes);
67 } 71 }
68 } 72 }
69 73
70 GrContextForWebGraphicsContext3D::~GrContextForWebGraphicsContext3D() { 74 GrContextForWebGraphicsContext3D::~GrContextForWebGraphicsContext3D() {
71 } 75 }
72 76
73 void GrContextForWebGraphicsContext3D::OnLostContext() { 77 void GrContextForWebGraphicsContext3D::OnLostContext() {
74 if (gr_context_) 78 if (gr_context_)
75 gr_context_->abandonContext(); 79 gr_context_->abandonContext();
76 } 80 }
77 81
78 void GrContextForWebGraphicsContext3D::FreeGpuResources() { 82 void GrContextForWebGraphicsContext3D::FreeGpuResources() {
79 if (gr_context_) { 83 if (gr_context_) {
80 TRACE_EVENT_INSTANT0("gpu", "GrContext::freeGpuResources", \ 84 TRACE_EVENT_INSTANT0("gpu", "GrContext::freeGpuResources", \
81 TRACE_EVENT_SCOPE_THREAD); 85 TRACE_EVENT_SCOPE_THREAD);
82 gr_context_->freeGpuResources(); 86 gr_context_->freeGpuResources();
83 } 87 }
84 } 88 }
85 89
86 GrGLInterfaceForWebGraphicsContext3D::GrGLInterfaceForWebGraphicsContext3D(
87 scoped_ptr<gpu_blink::WebGraphicsContext3DImpl> context3d)
88 : context3d_(context3d.Pass()) {
89 }
90
91 void GrGLInterfaceForWebGraphicsContext3D::BindToCurrentThread() {
92 context_thread_checker_.DetachFromThread();
93 }
94
95 GrGLInterfaceForWebGraphicsContext3D::~GrGLInterfaceForWebGraphicsContext3D() {
96 DCHECK(context_thread_checker_.CalledOnValidThread());
97 #if !defined(NDEBUG)
98 // Set all the function pointers to zero, in order to crash if function
99 // pointers are used after free.
100 memset(&fFunctions, 0, sizeof(GrGLInterface::Functions));
101 #endif
102 }
103
104 } // namespace content 90 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu/client/grcontext_for_webgraphicscontext3d.h ('k') | gpu/blink/webgraphicscontext3d_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698