OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #if defined(OS_WIN) | 5 #if defined(OS_WIN) |
6 #include <windows.h> | 6 #include <windows.h> |
7 #endif | 7 #endif |
8 | 8 |
9 #include "content/common/gpu/gpu_channel.h" | 9 #include "content/common/gpu/gpu_channel.h" |
10 | 10 |
(...skipping 20 matching lines...) Expand all Loading... | |
31 #include "ipc/ipc_channel_proxy.h" | 31 #include "ipc/ipc_channel_proxy.h" |
32 #include "ui/gl/gl_context.h" | 32 #include "ui/gl/gl_context.h" |
33 #include "ui/gl/gl_image.h" | 33 #include "ui/gl/gl_image.h" |
34 #include "ui/gl/gl_surface.h" | 34 #include "ui/gl/gl_surface.h" |
35 | 35 |
36 #if defined(OS_POSIX) | 36 #if defined(OS_POSIX) |
37 #include "ipc/ipc_channel_posix.h" | 37 #include "ipc/ipc_channel_posix.h" |
38 #endif | 38 #endif |
39 | 39 |
40 #if defined(OS_ANDROID) | 40 #if defined(OS_ANDROID) |
41 #include "content/common/gpu/stream_texture_manager_android.h" | 41 #include "content/common/android/surface_texture_peer.h" |
42 #include "ui/gl/android/gl_image_stream.h" | |
42 #endif | 43 #endif |
43 | 44 |
44 namespace content { | 45 namespace content { |
45 namespace { | 46 namespace { |
46 | 47 |
47 // Number of milliseconds between successive vsync. Many GL commands block | 48 // Number of milliseconds between successive vsync. Many GL commands block |
48 // on vsync, so thresholds for preemption should be multiples of this. | 49 // on vsync, so thresholds for preemption should be multiples of this. |
49 const int64 kVsyncIntervalMs = 17; | 50 const int64 kVsyncIntervalMs = 17; |
50 | 51 |
51 // Amount of time that we will wait for an IPC to be processed before | 52 // Amount of time that we will wait for an IPC to be processed before |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
449 weak_factory_(this), | 450 weak_factory_(this), |
450 num_stubs_descheduled_(0) { | 451 num_stubs_descheduled_(0) { |
451 DCHECK(gpu_channel_manager); | 452 DCHECK(gpu_channel_manager); |
452 DCHECK(client_id); | 453 DCHECK(client_id); |
453 | 454 |
454 channel_id_ = IPC::Channel::GenerateVerifiedChannelID("gpu"); | 455 channel_id_ = IPC::Channel::GenerateVerifiedChannelID("gpu"); |
455 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 456 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
456 log_messages_ = command_line->HasSwitch(switches::kLogPluginMessages); | 457 log_messages_ = command_line->HasSwitch(switches::kLogPluginMessages); |
457 disallowed_features_.multisampling = | 458 disallowed_features_.multisampling = |
458 command_line->HasSwitch(switches::kDisableGLMultisampling); | 459 command_line->HasSwitch(switches::kDisableGLMultisampling); |
459 #if defined(OS_ANDROID) | |
460 stream_texture_manager_.reset(new StreamTextureManagerAndroid(this)); | |
461 #endif | |
462 } | 460 } |
463 | 461 |
464 | 462 |
465 bool GpuChannel::Init(base::MessageLoopProxy* io_message_loop, | 463 bool GpuChannel::Init(base::MessageLoopProxy* io_message_loop, |
466 base::WaitableEvent* shutdown_event) { | 464 base::WaitableEvent* shutdown_event) { |
467 DCHECK(!channel_.get()); | 465 DCHECK(!channel_.get()); |
468 | 466 |
469 // Map renderer ID to a (single) channel to that process. | 467 // Map renderer ID to a (single) channel to that process. |
470 channel_.reset(new IPC::SyncChannel( | 468 channel_.reset(new IPC::SyncChannel( |
471 channel_id_, | 469 channel_id_, |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
893 stubs_.Remove(route_id); | 891 stubs_.Remove(route_id); |
894 // In case the renderer is currently blocked waiting for a sync reply from the | 892 // In case the renderer is currently blocked waiting for a sync reply from the |
895 // stub, we need to make sure to reschedule the GpuChannel here. | 893 // stub, we need to make sure to reschedule the GpuChannel here. |
896 if (need_reschedule) { | 894 if (need_reschedule) { |
897 // This stub won't get a chance to reschedule, so update the count now. | 895 // This stub won't get a chance to reschedule, so update the count now. |
898 StubSchedulingChanged(true); | 896 StubSchedulingChanged(true); |
899 } | 897 } |
900 } | 898 } |
901 | 899 |
902 #if defined(OS_ANDROID) | 900 #if defined(OS_ANDROID) |
901 namespace { | |
902 | |
903 void SendFrameAvailable(const base::WeakPtr<GpuChannel>& channel, | |
904 int32 route_id) { | |
905 if (channel) | |
906 channel->Send(new GpuStreamTextureMsg_FrameAvailable(route_id)); | |
907 } | |
908 | |
909 void SendMatrixChanged(const base::WeakPtr<GpuChannel>& channel, | |
910 int32 route_id, | |
911 const gfx::GLImageStream::Matrix& matrix) { | |
912 if (channel) { | |
913 GpuStreamTextureMsg_MatrixChanged_Params params; | |
914 memcpy(¶ms.m00, matrix.components, sizeof(matrix.components)); | |
915 channel->Send(new GpuStreamTextureMsg_MatrixChanged(route_id, params)); | |
916 } | |
917 } | |
918 | |
919 } // anonymous namespace | |
920 | |
903 void GpuChannel::OnRegisterStreamTextureProxy( | 921 void GpuChannel::OnRegisterStreamTextureProxy( |
904 int32 stream_id, int32* route_id) { | 922 int32 stream_id, int32* route_id) { |
905 // Note that route_id is only used for notifications sent out from here. | |
906 // StreamTextureManager owns all texture objects and for incoming messages | |
907 // it finds the correct object based on stream_id. | |
908 *route_id = GenerateRouteID(); | 923 *route_id = GenerateRouteID(); |
909 stream_texture_manager_->RegisterStreamTextureProxy(stream_id, *route_id); | 924 scoped_refptr<gfx::GLImage> image(image_manager_->LookupImage(stream_id)); |
reveman
2013/08/14 15:22:44
LookupStreamImage? to remove the need for AsGLImag
no sievers
2013/08/14 18:16:48
AsGLImageStream allows me to limit the visibility
| |
925 if (!image) | |
926 return; | |
927 | |
928 scoped_refptr<gfx::GLImageStream> stream(image->AsGLImageStream()); | |
929 if (!stream) | |
930 return; | |
931 | |
932 base::Closure frame_callback = | |
933 base::Bind(&SendFrameAvailable, weak_factory_.GetWeakPtr(), *route_id); | |
934 gfx::GLImageStream::MatrixChangedCallBack matrix_callback = | |
935 base::Bind(&SendMatrixChanged, weak_factory_.GetWeakPtr(), *route_id); | |
936 | |
937 stream->SetMatrixChangedCallback(matrix_callback); | |
938 stream->SetFrameAvailableCallback(frame_callback); | |
910 } | 939 } |
911 | 940 |
912 void GpuChannel::OnEstablishStreamTexture( | 941 void GpuChannel::OnEstablishStreamTexture( |
913 int32 stream_id, int32 primary_id, int32 secondary_id) { | 942 int32 stream_id, int32 primary_id, int32 secondary_id) { |
914 stream_texture_manager_->EstablishStreamTexture( | 943 scoped_refptr<gfx::GLImage> image(image_manager_->LookupImage(stream_id)); |
915 stream_id, primary_id, secondary_id); | 944 if (!image) |
945 return; | |
946 | |
947 scoped_refptr<gfx::GLImageStream> stream(image->AsGLImageStream()); | |
948 if (!stream) | |
949 return; | |
950 | |
951 SurfaceTexturePeer::GetInstance()->EstablishSurfaceTexturePeer( | |
952 renderer_pid(), | |
953 stream->GetSurfaceTexture(), | |
954 primary_id, | |
955 secondary_id); | |
916 } | 956 } |
917 | 957 |
918 void GpuChannel::OnSetStreamTextureSize( | 958 void GpuChannel::OnSetStreamTextureSize( |
919 int32 stream_id, const gfx::Size& size) { | 959 int32 stream_id, const gfx::Size& size) { |
920 stream_texture_manager_->SetStreamTextureSize(stream_id, size); | 960 scoped_refptr<gfx::GLImage> image(image_manager_->LookupImage(stream_id)); |
961 if (!image) | |
962 return; | |
963 | |
964 scoped_refptr<gfx::GLImageStream> stream(image->AsGLImageStream()); | |
965 if (!stream) | |
966 return; | |
967 | |
968 stream->SetSize(size); | |
921 } | 969 } |
922 #endif | 970 #endif |
923 | 971 |
924 void GpuChannel::OnCollectRenderingStatsForSurface( | 972 void GpuChannel::OnCollectRenderingStatsForSurface( |
925 int32 surface_id, GpuRenderingStats* stats) { | 973 int32 surface_id, GpuRenderingStats* stats) { |
926 for (StubMap::Iterator<GpuCommandBufferStub> it(&stubs_); | 974 for (StubMap::Iterator<GpuCommandBufferStub> it(&stubs_); |
927 !it.IsAtEnd(); it.Advance()) { | 975 !it.IsAtEnd(); it.Advance()) { |
928 int texture_upload_count = | 976 int texture_upload_count = |
929 it.GetCurrentValue()->decoder()->GetTextureUploadCount(); | 977 it.GetCurrentValue()->decoder()->GetTextureUploadCount(); |
930 base::TimeDelta total_texture_upload_time = | 978 base::TimeDelta total_texture_upload_time = |
(...skipping 24 matching lines...) Expand all Loading... | |
955 } | 1003 } |
956 } | 1004 } |
957 | 1005 |
958 void GpuChannel::CacheShader(const std::string& key, | 1006 void GpuChannel::CacheShader(const std::string& key, |
959 const std::string& shader) { | 1007 const std::string& shader) { |
960 gpu_channel_manager_->Send( | 1008 gpu_channel_manager_->Send( |
961 new GpuHostMsg_CacheShader(client_id_, key, shader)); | 1009 new GpuHostMsg_CacheShader(client_id_, key, shader)); |
962 } | 1010 } |
963 | 1011 |
964 } // namespace content | 1012 } // namespace content |
OLD | NEW |