| 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" | |
| 11 #include "skia/ext/refptr.h" | 9 #include "skia/ext/refptr.h" |
| 12 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" | |
| 13 | 10 |
| 14 class GrContext; | 11 class GrContext; |
| 15 | 12 |
| 16 namespace gpu_blink { | 13 namespace gpu_blink { |
| 17 class WebGraphicsContext3DImpl; | 14 class WebGraphicsContext3DImpl; |
| 18 } | 15 } |
| 19 | 16 |
| 20 namespace content { | 17 namespace content { |
| 21 | 18 |
| 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 | |
| 44 // This class binds an offscreen GrContext to an offscreen context3d. The | 19 // This class binds an offscreen GrContext to an offscreen context3d. The |
| 45 // context3d is used by the GrContext so must be valid as long as this class | 20 // context3d is used by the GrContext so must be valid as long as this class |
| 46 // is alive. | 21 // is alive. |
| 47 class GrContextForWebGraphicsContext3D { | 22 class GrContextForWebGraphicsContext3D { |
| 48 public: | 23 public: |
| 49 explicit GrContextForWebGraphicsContext3D( | 24 explicit GrContextForWebGraphicsContext3D( |
| 50 skia::RefPtr<GrGLInterfaceForWebGraphicsContext3D> context3d); | 25 gpu_blink::WebGraphicsContext3DImpl* context3d); |
| 51 virtual ~GrContextForWebGraphicsContext3D(); | 26 virtual ~GrContextForWebGraphicsContext3D(); |
| 52 | 27 |
| 53 GrContext* get() { return gr_context_.get(); } | 28 GrContext* get() { return gr_context_.get(); } |
| 54 | 29 |
| 55 void OnLostContext(); | 30 void OnLostContext(); |
| 56 void FreeGpuResources(); | 31 void FreeGpuResources(); |
| 57 | 32 |
| 58 private: | 33 private: |
| 59 skia::RefPtr<class GrContext> gr_context_; | 34 skia::RefPtr<class GrContext> gr_context_; |
| 60 | 35 |
| 61 DISALLOW_COPY_AND_ASSIGN(GrContextForWebGraphicsContext3D); | 36 DISALLOW_COPY_AND_ASSIGN(GrContextForWebGraphicsContext3D); |
| 62 }; | 37 }; |
| 63 | 38 |
| 64 } // namespace content | 39 } // namespace content |
| 65 | 40 |
| 66 #endif // CONTENT_COMMON_GPU_CLIENT_GRCONTEXT_FOR_WEBGRAPHICSCONTEXT3D_H_ | 41 #endif // CONTENT_COMMON_GPU_CLIENT_GRCONTEXT_FOR_WEBGRAPHICSCONTEXT3D_H_ |
| OLD | NEW |