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

Side by Side Diff: content/browser/android/graphics_context.cc

Issue 10823051: ContentShell rendering support on Android. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address Ted's comments Created 8 years, 4 months 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 | Annotate | Revision Log
OLDNEW
(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/public/browser/android/graphics_context.h"
6
7 #include "base/memory/scoped_ptr.h"
8 #include "content/browser/android/draw_delegate_impl.h"
9 #include "content/browser/gpu/browser_gpu_channel_host_factory.h"
10 #include "content/browser/gpu/gpu_surface_tracker.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 "ui/gfx/native_widget_types.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsC ontext3D.h"
16
17 #include <android/native_window_jni.h>
18
19 using content::BrowserGpuChannelHostFactory;
20
21 namespace {
22
23 // GraphicsContext implementation using a gpu command buffer.
24 class CmdBufferGraphicsContext : public content::GraphicsContext {
25 public:
26 CmdBufferGraphicsContext(WebGraphicsContext3DCommandBufferImpl* context,
27 int surface_id,
28 ANativeWindow* window,
29 int texture_id1,
30 int texture_id2)
31 : context_(context),
32 surface_id_(surface_id),
33 window_(window) {
34 texture_id_[0] = texture_id1;
35 texture_id_[1] = texture_id2;
36 }
37
38 virtual ~CmdBufferGraphicsContext() {
39 context_->makeContextCurrent();
40 context_->deleteTexture(texture_id_[0]);
41 context_->deleteTexture(texture_id_[1]);
42 context_->finish();
43 GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get();
44 tracker->RemoveSurface(surface_id_);
45 ANativeWindow_release(window_);
46 }
47
48 virtual WebKit::WebGraphicsContext3D* GetContext3D() {
49 return context_.get();
50 }
51 virtual uint32 InsertSyncPoint() {
52 return context_->insertSyncPoint();
53 }
54 private:
jam 2012/07/31 22:46:15 nit: blank line above
55 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context_;
56 int surface_id_;
57 ANativeWindow* window_;
58 int texture_id_[2];
59 };
60
61 } // anonymous namespace
62
63 namespace content {
64
65 // static
66 GraphicsContext* GraphicsContext::CreateForUI(
67 ANativeWindow* window) {
68 DCHECK(window);
69 GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get();
70
71 ANativeWindow_acquire(window);
72 int surface_id = tracker->AddSurfaceForNativeWidget(window);
73
74 tracker->SetSurfaceHandle(
75 surface_id,
76 gfx::GLSurfaceHandle(gfx::kDummyPluginWindow, false));
77
78 WebKit::WebGraphicsContext3D::Attributes attrs;
79 attrs.shareResources = true;
80 GpuChannelHostFactory* factory = BrowserGpuChannelHostFactory::instance();
81 GURL url("chrome://gpu/GpuProcessTransportHelper::CreateContext");
82 base::WeakPtr<WebGraphicsContext3DSwapBuffersClient> swap_client;
83 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
84 new WebGraphicsContext3DCommandBufferImpl(
85 surface_id,
86 url,
87 factory,
88 swap_client));
89 if (!context->Initialize(
90 attrs,
91 false,
92 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE)) {
93 return NULL;
94 }
95
96 context->makeContextCurrent();
97
98 gfx::GLSurfaceHandle handle = gfx::GLSurfaceHandle(
99 gfx::kNullPluginWindow, true);
100 handle.parent_gpu_process_id = context->GetGPUProcessID();
101 handle.parent_client_id = context->GetChannelID();
102 handle.parent_context_id = context->GetContextID();
103 handle.parent_texture_id[0] = context->createTexture();
104 handle.parent_texture_id[1] = context->createTexture();
105 handle.sync_point = context->insertSyncPoint();
106
107 DrawDelegateImpl::GetInstance()->SetDrawSurface(handle);
108
109 return new CmdBufferGraphicsContext(
110 context.release(), surface_id, window,
111 handle.parent_texture_id[0],
112 handle.parent_texture_id[1]);
113 }
114
115 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698