| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/browser/renderer_host/compositor_impl_android.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/logging.h" |
| 9 #include "content/browser/android/graphics_context.h" |
| 10 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" |
| 11 #include "content/common/gpu/client/gpu_channel_host.h" |
| 12 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
| 13 #include "content/common/gpu/gpu_process_launch_causes.h" |
| 14 #include "third_party/WebKit/Source/Platform/chromium/public/WebCompositor.h" |
| 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorOutput
Surface.h" |
| 16 |
| 17 namespace { |
| 18 |
| 19 // Adapts a pure WebGraphicsContext3D into a WebCompositorOutputSurface. |
| 20 class WebGraphicsContextToOutputSurfaceAdapter : |
| 21 public WebKit::WebCompositorOutputSurface { |
| 22 public: |
| 23 explicit WebGraphicsContextToOutputSurfaceAdapter( |
| 24 WebKit::WebGraphicsContext3D* context) |
| 25 : m_context3D(context) |
| 26 , m_client(0) |
| 27 { |
| 28 } |
| 29 |
| 30 virtual bool bindToClient( |
| 31 WebKit::WebCompositorOutputSurfaceClient* client) OVERRIDE |
| 32 { |
| 33 DCHECK(client); |
| 34 if (!m_context3D->makeContextCurrent()) |
| 35 return false; |
| 36 m_client = client; |
| 37 return true; |
| 38 } |
| 39 |
| 40 virtual const Capabilities& capabilities() const OVERRIDE |
| 41 { |
| 42 return m_capabilities; |
| 43 } |
| 44 |
| 45 virtual WebKit::WebGraphicsContext3D* context3D() const OVERRIDE |
| 46 { |
| 47 return m_context3D.get(); |
| 48 } |
| 49 |
| 50 virtual void sendFrameToParentCompositor( |
| 51 const WebKit::WebCompositorFrame&) OVERRIDE |
| 52 { |
| 53 } |
| 54 |
| 55 private: |
| 56 scoped_ptr<WebKit::WebGraphicsContext3D> m_context3D; |
| 57 Capabilities m_capabilities; |
| 58 WebKit::WebCompositorOutputSurfaceClient* m_client; |
| 59 }; |
| 60 |
| 61 } // anonymous namespace |
| 62 |
| 63 namespace content { |
| 64 |
| 65 // static |
| 66 Compositor* Compositor::Create() { |
| 67 return new CompositorImpl(); |
| 68 } |
| 69 |
| 70 // static |
| 71 void Compositor::Initialize() { |
| 72 WebKit::WebCompositor::initialize(NULL); |
| 73 } |
| 74 |
| 75 CompositorImpl::CompositorImpl() |
| 76 : root_layer_(WebKit::WebLayer::create()) { |
| 77 } |
| 78 |
| 79 CompositorImpl::~CompositorImpl() { |
| 80 } |
| 81 |
| 82 void CompositorImpl::OnSurfaceUpdated( |
| 83 const SurfacePresentedCallback& callback) { |
| 84 host_->composite(); |
| 85 uint32 sync_point = context_->InsertSyncPoint(); |
| 86 callback.Run(sync_point); |
| 87 } |
| 88 |
| 89 void CompositorImpl::SetRootLayer(WebKit::WebLayer* root_layer) { |
| 90 root_layer_->removeAllChildren(); |
| 91 root_layer_->addChild(root_layer); |
| 92 } |
| 93 |
| 94 void CompositorImpl::SetWindowSurface(ANativeWindow* window) { |
| 95 if (window) { |
| 96 context_.reset(GraphicsContext::CreateForUI(window)); |
| 97 WebKit::WebLayerTreeView::Settings settings; |
| 98 settings.refreshRate = 60.0; |
| 99 host_.reset(WebKit::WebLayerTreeView::create(this, *root_layer_, settings)); |
| 100 host_->setVisible(true); |
| 101 host_->setSurfaceReady(); |
| 102 } else { |
| 103 context_.reset(NULL); |
| 104 size_ = gfx::Size(); |
| 105 } |
| 106 } |
| 107 |
| 108 void CompositorImpl::SetWindowBounds(const gfx::Size& size) { |
| 109 if (size_ == size) |
| 110 return; |
| 111 |
| 112 size_ = size; |
| 113 host_->setViewportSize(size); |
| 114 root_layer_->setBounds(size); |
| 115 } |
| 116 |
| 117 void CompositorImpl::updateAnimations(double frameBeginTime) { |
| 118 } |
| 119 |
| 120 void CompositorImpl::layout() { |
| 121 } |
| 122 |
| 123 void CompositorImpl::applyScrollAndScale(const WebKit::WebSize& scrollDelta, |
| 124 float scaleFactor) { |
| 125 } |
| 126 |
| 127 WebKit::WebCompositorOutputSurface* CompositorImpl::createOutputSurface() { |
| 128 if (!context_.get()) |
| 129 return NULL; |
| 130 |
| 131 WebKit::WebGraphicsContext3D::Attributes attrs; |
| 132 attrs.shareResources = true; |
| 133 GpuChannelHostFactory* factory = BrowserGpuChannelHostFactory::instance(); |
| 134 GURL url("chrome://gpu/Compositor::createContext3D"); |
| 135 base::WeakPtr<WebGraphicsContext3DSwapBuffersClient> swap_client; |
| 136 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( |
| 137 new WebGraphicsContext3DCommandBufferImpl( |
| 138 context_->GetSurfaceID(), |
| 139 url, |
| 140 factory, |
| 141 swap_client)); |
| 142 if (!context->Initialize( |
| 143 attrs, |
| 144 false, |
| 145 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE)) { |
| 146 LOG(ERROR) << "Failed to create 3D context for compositor."; |
| 147 return NULL; |
| 148 } |
| 149 |
| 150 return new WebGraphicsContextToOutputSurfaceAdapter(context.release()); |
| 151 } |
| 152 |
| 153 void CompositorImpl::didRecreateOutputSurface(bool success) { |
| 154 } |
| 155 |
| 156 void CompositorImpl::didCommit() { |
| 157 } |
| 158 |
| 159 void CompositorImpl::didCommitAndDrawFrame() { |
| 160 } |
| 161 |
| 162 void CompositorImpl::didCompleteSwapBuffers() { |
| 163 } |
| 164 |
| 165 void CompositorImpl::scheduleComposite() { |
| 166 } |
| 167 |
| 168 } // namespace content |
| OLD | NEW |