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

Side by Side Diff: chrome/renderer/pepper_platform_context_3d_impl.cc

Issue 6685072: Move a bunch more random files from chrome\renderer to content\renderer. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 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) 2011 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 "chrome/renderer/pepper_platform_context_3d_impl.h"
6
7 #include "chrome/renderer/render_thread.h"
8 #include "content/renderer/command_buffer_proxy.h"
9 #include "content/renderer/ggl.h"
10 #include "content/renderer/gpu_channel_host.h"
11 #include "gpu/command_buffer/client/gles2_cmd_helper.h"
12 #include "gpu/command_buffer/client/gles2_implementation.h"
13
14 #ifdef ENABLE_GPU
15 PlatformContext3DImpl::PlatformContext3DImpl(ggl::Context* parent_context)
16 : parent_context_(ggl::GetWeakContextReference(parent_context)),
17 parent_texture_id_(0),
18 command_buffer_(NULL),
19 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
20 }
21
22 PlatformContext3DImpl::~PlatformContext3DImpl() {
23 if (command_buffer_) {
24 DCHECK(channel_.get());
25 channel_->DestroyCommandBuffer(command_buffer_);
26 command_buffer_ = NULL;
27 }
28
29 channel_ = NULL;
30
31 if (parent_context_.get() && parent_texture_id_ != 0) {
32 ggl::GetImplementation(parent_context_)->FreeTextureId(parent_texture_id_);
33 }
34
35 }
36
37 bool PlatformContext3DImpl::Init() {
38 // Ignore initializing more than once.
39 if (command_buffer_)
40 return true;
41
42 // Parent may already have been deleted.
43 if (!parent_context_.get())
44 return false;
45
46 RenderThread* render_thread = RenderThread::current();
47 if (!render_thread)
48 return false;
49
50 channel_ = render_thread->GetGpuChannel();
51 if (!channel_.get())
52 return false;
53
54 DCHECK(channel_->state() == GpuChannelHost::kConnected);
55
56 // Flush any remaining commands in the parent context to make sure the
57 // texture id accounting stays consistent.
58 gpu::gles2::GLES2Implementation* parent_gles2 =
59 ggl::GetImplementation(parent_context_);
60 parent_gles2->helper()->CommandBufferHelper::Finish();
61 parent_texture_id_ = parent_gles2->MakeTextureId();
62
63 // TODO(apatrick): Let Pepper plugins configure their back buffer surface.
64 static const int32 kAttribs[] = {
65 ggl::GGL_ALPHA_SIZE, 8,
66 ggl::GGL_DEPTH_SIZE, 24,
67 ggl::GGL_STENCIL_SIZE, 8,
68 ggl::GGL_SAMPLES, 0,
69 ggl::GGL_SAMPLE_BUFFERS, 0,
70 ggl::GGL_NONE,
71 };
72 std::vector<int32> attribs(kAttribs, kAttribs + ARRAYSIZE_UNSAFE(kAttribs));
73 CommandBufferProxy* parent_command_buffer =
74 ggl::GetCommandBufferProxy(parent_context_);
75 command_buffer_ = channel_->CreateOffscreenCommandBuffer(
76 parent_command_buffer,
77 gfx::Size(1, 1),
78 "*",
79 attribs,
80 parent_texture_id_);
81 if (!command_buffer_)
82 return false;
83 command_buffer_->SetChannelErrorCallback(callback_factory_.NewCallback(
84 &PlatformContext3DImpl::OnContextLost));
85
86 return true;
87 }
88
89 void PlatformContext3DImpl::SetSwapBuffersCallback(Callback0::Type* callback) {
90 DCHECK(command_buffer_);
91 command_buffer_->SetSwapBuffersCallback(callback);
92 }
93
94 unsigned PlatformContext3DImpl::GetBackingTextureId() {
95 DCHECK(command_buffer_);
96 return parent_texture_id_;
97 }
98
99 gpu::CommandBuffer* PlatformContext3DImpl::GetCommandBuffer() {
100 return command_buffer_;
101 }
102
103 void PlatformContext3DImpl::SetContextLostCallback(Callback0::Type* callback) {
104 context_lost_callback_.reset(callback);
105 }
106
107 void PlatformContext3DImpl::OnContextLost() {
108 DCHECK(command_buffer_);
109
110 if (context_lost_callback_.get())
111 context_lost_callback_->Run();
112 }
113
114 #endif // ENABLE_GPU
OLDNEW
« no previous file with comments | « chrome/renderer/pepper_platform_context_3d_impl.h ('k') | chrome/renderer/pepper_plugin_delegate_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698