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 #ifndef CONTENT_COMMON_GPU_CLIENT_GRCONTEXT_FOR_WEBGRAPHICSCONTEXT3D_H_ | 5 #ifndef CONTENT_COMMON_GPU_CLIENT_GRCONTEXT_FOR_WEBGRAPHICSCONTEXT3D_H_ |
6 #define CONTENT_COMMON_GPU_CLIENT_GRCONTEXT_FOR_WEBGRAPHICSCONTEXT3D_H_ | 6 #define CONTENT_COMMON_GPU_CLIENT_GRCONTEXT_FOR_WEBGRAPHICSCONTEXT3D_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/threading/thread_checker.h" |
9 #include "skia/ext/refptr.h" | 11 #include "skia/ext/refptr.h" |
| 12 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" |
10 | 13 |
11 class GrContext; | 14 class GrContext; |
12 | 15 |
13 namespace gpu_blink { | 16 namespace gpu_blink { |
14 class WebGraphicsContext3DImpl; | 17 class WebGraphicsContext3DImpl; |
15 } | 18 } |
16 | 19 |
17 namespace content { | 20 namespace content { |
18 | 21 |
| 22 // Wrap WebGraphicsContext3DImpl into a GrGLInterface object, which allows |
| 23 // the WebGraphicsContext3DImpl to be jointly refcounted (indirectly) |
| 24 // by the GrContext and the context provider. This makes it legal for the |
| 25 // GrContext to be invoked when it outlives the context provider that created |
| 26 // it. By doing this we no longer have to worry about use after free errors |
| 27 // caused a lack of consideration for object destruction order. |
| 28 class GrGLInterfaceForWebGraphicsContext3D final : public GrGLInterface { |
| 29 public: |
| 30 GrGLInterfaceForWebGraphicsContext3D( |
| 31 scoped_ptr<gpu_blink::WebGraphicsContext3DImpl> context3d); |
| 32 ~GrGLInterfaceForWebGraphicsContext3D() final; |
| 33 |
| 34 void BindToCurrentThread(); |
| 35 |
| 36 gpu_blink::WebGraphicsContext3DImpl* WebContext3D() const { |
| 37 return context3d_.get(); |
| 38 } |
| 39 private: |
| 40 base::ThreadChecker context_thread_checker_; |
| 41 scoped_ptr<gpu_blink::WebGraphicsContext3DImpl> context3d_; |
| 42 }; |
| 43 |
19 // This class binds an offscreen GrContext to an offscreen context3d. The | 44 // This class binds an offscreen GrContext to an offscreen context3d. The |
20 // context3d is used by the GrContext so must be valid as long as this class | 45 // context3d is used by the GrContext so must be valid as long as this class |
21 // is alive. | 46 // is alive. |
22 class GrContextForWebGraphicsContext3D { | 47 class GrContextForWebGraphicsContext3D { |
23 public: | 48 public: |
24 explicit GrContextForWebGraphicsContext3D( | 49 explicit GrContextForWebGraphicsContext3D( |
25 gpu_blink::WebGraphicsContext3DImpl* context3d); | 50 skia::RefPtr<GrGLInterfaceForWebGraphicsContext3D> context3d); |
26 virtual ~GrContextForWebGraphicsContext3D(); | 51 virtual ~GrContextForWebGraphicsContext3D(); |
27 | 52 |
28 GrContext* get() { return gr_context_.get(); } | 53 GrContext* get() { return gr_context_.get(); } |
29 | 54 |
30 void OnLostContext(); | 55 void OnLostContext(); |
31 void FreeGpuResources(); | 56 void FreeGpuResources(); |
32 | 57 |
33 private: | 58 private: |
34 skia::RefPtr<class GrContext> gr_context_; | 59 skia::RefPtr<class GrContext> gr_context_; |
35 | 60 |
36 DISALLOW_COPY_AND_ASSIGN(GrContextForWebGraphicsContext3D); | 61 DISALLOW_COPY_AND_ASSIGN(GrContextForWebGraphicsContext3D); |
37 }; | 62 }; |
38 | 63 |
39 } // namespace content | 64 } // namespace content |
40 | 65 |
41 #endif // CONTENT_COMMON_GPU_CLIENT_GRCONTEXT_FOR_WEBGRAPHICSCONTEXT3D_H_ | 66 #endif // CONTENT_COMMON_GPU_CLIENT_GRCONTEXT_FOR_WEBGRAPHICSCONTEXT3D_H_ |
OLD | NEW |