OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ui/gfx/compositor/compositor_cc.h" | 5 #include "ui/gfx/compositor/compositor_cc.h" |
6 | 6 |
7 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositor.h" | 7 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositor.h" |
8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFloatPoint.h" | 8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFloatPoint.h" |
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h" | 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h" |
10 #include "ui/gfx/compositor/layer.h" | 10 #include "ui/gfx/compositor/layer.h" |
| 11 #include "ui/gfx/gl/gl_context.h" |
| 12 #include "ui/gfx/gl/gl_surface.h" |
| 13 #include "ui/gfx/gl/gl_implementation.h" |
11 #include "webkit/glue/webthread_impl.h" | 14 #include "webkit/glue/webthread_impl.h" |
12 #include "webkit/gpu/webgraphicscontext3d_in_process_impl.h" | 15 #include "webkit/gpu/webgraphicscontext3d_in_process_impl.h" |
13 | 16 |
14 namespace { | 17 namespace { |
15 webkit_glue::WebThreadImpl* g_compositor_thread = NULL; | 18 webkit_glue::WebThreadImpl* g_compositor_thread = NULL; |
16 } // anonymous namespace | 19 } // anonymous namespace |
17 | 20 |
18 namespace ui { | 21 namespace ui { |
19 | 22 |
20 TextureCC::TextureCC() { | 23 SharedResourcesCC::SharedResourcesCC() : initialized_(false) { |
| 24 } |
| 25 |
| 26 |
| 27 SharedResourcesCC::~SharedResourcesCC() { |
| 28 } |
| 29 |
| 30 // static |
| 31 SharedResourcesCC* SharedResourcesCC::GetInstance() { |
| 32 // We use LeakySingletonTraits so that we don't race with |
| 33 // the tear down of the gl_bindings. |
| 34 SharedResourcesCC* instance = Singleton<SharedResourcesCC, |
| 35 LeakySingletonTraits<SharedResourcesCC> >::get(); |
| 36 if (instance->Initialize()) { |
| 37 return instance; |
| 38 } else { |
| 39 instance->Destroy(); |
| 40 return NULL; |
| 41 } |
| 42 } |
| 43 |
| 44 bool SharedResourcesCC::Initialize() { |
| 45 if (initialized_) |
| 46 return true; |
| 47 |
| 48 { |
| 49 // The following line of code exists soley to disable IO restrictions |
| 50 // on this thread long enough to perform the GL bindings. |
| 51 // TODO(wjmaclean) Remove this when GL initialisation cleaned up. |
| 52 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 53 if (!gfx::GLSurface::InitializeOneOff() || |
| 54 gfx::GetGLImplementation() == gfx::kGLImplementationNone) { |
| 55 LOG(ERROR) << "Could not load the GL bindings"; |
| 56 return false; |
| 57 } |
| 58 } |
| 59 |
| 60 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(false, gfx::Size(1, 1)); |
| 61 if (!surface_.get()) { |
| 62 LOG(ERROR) << "Unable to create offscreen GL surface."; |
| 63 return false; |
| 64 } |
| 65 |
| 66 context_ = gfx::GLContext::CreateGLContext( |
| 67 NULL, surface_.get(), gfx::PreferIntegratedGpu); |
| 68 if (!context_.get()) { |
| 69 LOG(ERROR) << "Unable to create GL context."; |
| 70 return false; |
| 71 } |
| 72 |
| 73 initialized_ = true; |
| 74 return true; |
| 75 } |
| 76 |
| 77 void SharedResourcesCC::Destroy() { |
| 78 context_ = NULL; |
| 79 surface_ = NULL; |
| 80 |
| 81 initialized_ = false; |
| 82 } |
| 83 |
| 84 bool SharedResourcesCC::MakeSharedContextCurrent() { |
| 85 DCHECK(initialized_); |
| 86 return context_->MakeCurrent(surface_.get()); |
| 87 } |
| 88 |
| 89 gfx::GLShareGroup* SharedResourcesCC::GetShareGroup() { |
| 90 DCHECK(initialized_); |
| 91 return context_->share_group(); |
| 92 } |
| 93 |
| 94 TextureCC::TextureCC() |
| 95 : texture_id_(0), |
| 96 flipped_(false) { |
21 } | 97 } |
22 | 98 |
23 void TextureCC::SetCanvas(const SkCanvas& canvas, | 99 void TextureCC::SetCanvas(const SkCanvas& canvas, |
24 const gfx::Point& origin, | 100 const gfx::Point& origin, |
25 const gfx::Size& overall_size) { | 101 const gfx::Size& overall_size) { |
| 102 NOTREACHED(); |
26 } | 103 } |
27 | 104 |
28 void TextureCC::Draw(const ui::TextureDrawParams& params, | 105 void TextureCC::Draw(const ui::TextureDrawParams& params, |
29 const gfx::Rect& clip_bounds_in_texture) { | 106 const gfx::Rect& clip_bounds_in_texture) { |
| 107 NOTREACHED(); |
30 } | 108 } |
31 | 109 |
32 CompositorCC::CompositorCC(CompositorDelegate* delegate, | 110 CompositorCC::CompositorCC(CompositorDelegate* delegate, |
33 gfx::AcceleratedWidget widget, | 111 gfx::AcceleratedWidget widget, |
34 const gfx::Size& size) | 112 const gfx::Size& size) |
35 : Compositor(delegate, size), | 113 : Compositor(delegate, size), |
36 widget_(widget), | 114 widget_(widget), |
37 root_web_layer_(WebKit::WebLayer::create(this)) { | 115 root_web_layer_(WebKit::WebLayer::create(this)) { |
38 WebKit::WebLayerTreeView::Settings settings; | 116 WebKit::WebLayerTreeView::Settings settings; |
39 settings.enableCompositorThread = !!g_compositor_thread; | 117 settings.enableCompositorThread = !!g_compositor_thread; |
(...skipping 10 matching lines...) Expand all Loading... |
50 WebKit::WebCompositor::setThread(g_compositor_thread); | 128 WebKit::WebCompositor::setThread(g_compositor_thread); |
51 } | 129 } |
52 | 130 |
53 void CompositorCC::TerminateThread() { | 131 void CompositorCC::TerminateThread() { |
54 DCHECK(g_compositor_thread); | 132 DCHECK(g_compositor_thread); |
55 delete g_compositor_thread; | 133 delete g_compositor_thread; |
56 g_compositor_thread = NULL; | 134 g_compositor_thread = NULL; |
57 } | 135 } |
58 | 136 |
59 Texture* CompositorCC::CreateTexture() { | 137 Texture* CompositorCC::CreateTexture() { |
60 return new TextureCC(); | 138 NOTREACHED(); |
| 139 return NULL; |
61 } | 140 } |
62 | 141 |
63 void CompositorCC::Blur(const gfx::Rect& bounds) { | 142 void CompositorCC::Blur(const gfx::Rect& bounds) { |
64 NOTIMPLEMENTED(); | 143 NOTIMPLEMENTED(); |
65 } | 144 } |
66 | 145 |
67 void CompositorCC::ScheduleDraw() { | 146 void CompositorCC::ScheduleDraw() { |
68 if (g_compositor_thread) | 147 if (g_compositor_thread) |
69 host_.composite(); | 148 host_.composite(); |
70 else | 149 else |
(...skipping 20 matching lines...) Expand all Loading... |
91 host_.composite(); | 170 host_.composite(); |
92 } | 171 } |
93 | 172 |
94 void CompositorCC::animateAndLayout(double frameBeginTime) { | 173 void CompositorCC::animateAndLayout(double frameBeginTime) { |
95 } | 174 } |
96 | 175 |
97 void CompositorCC::applyScrollDelta(const WebKit::WebSize&) { | 176 void CompositorCC::applyScrollDelta(const WebKit::WebSize&) { |
98 } | 177 } |
99 | 178 |
100 WebKit::WebGraphicsContext3D* CompositorCC::createContext3D() { | 179 WebKit::WebGraphicsContext3D* CompositorCC::createContext3D() { |
| 180 gfx::GLShareGroup* share_group = |
| 181 SharedResourcesCC::GetInstance()->GetShareGroup(); |
101 WebKit::WebGraphicsContext3D* context = | 182 WebKit::WebGraphicsContext3D* context = |
102 new webkit::gpu::WebGraphicsContext3DInProcessImpl(widget_, NULL); | 183 new webkit::gpu::WebGraphicsContext3DInProcessImpl(widget_, share_group); |
103 WebKit::WebGraphicsContext3D::Attributes attrs; | 184 WebKit::WebGraphicsContext3D::Attributes attrs; |
104 context->initialize(attrs, 0, true); | 185 context->initialize(attrs, 0, true); |
105 return context; | 186 return context; |
106 } | 187 } |
107 | 188 |
108 void CompositorCC::didRebindGraphicsContext(bool success) { | 189 void CompositorCC::didRebindGraphicsContext(bool success) { |
109 } | 190 } |
110 | 191 |
111 void CompositorCC::scheduleComposite() { | 192 void CompositorCC::scheduleComposite() { |
112 ScheduleDraw(); | 193 ScheduleDraw(); |
113 } | 194 } |
114 | 195 |
115 void CompositorCC::notifyNeedsComposite() { | 196 void CompositorCC::notifyNeedsComposite() { |
116 ScheduleDraw(); | 197 ScheduleDraw(); |
117 } | 198 } |
118 | 199 |
119 Compositor* Compositor::Create(CompositorDelegate* owner, | 200 Compositor* Compositor::Create(CompositorDelegate* owner, |
120 gfx::AcceleratedWidget widget, | 201 gfx::AcceleratedWidget widget, |
121 const gfx::Size& size) { | 202 const gfx::Size& size) { |
122 return new CompositorCC(owner, widget, size); | 203 return new CompositorCC(owner, widget, size); |
123 } | 204 } |
124 | 205 |
125 } // namespace ui | 206 } // namespace ui |
OLD | NEW |