OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #include "cc/resources/resource_provider.h" | 5 #include "cc/resources/resource_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
(...skipping 1106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1117 } | 1117 } |
1118 | 1118 |
1119 void ResourceProvider::UnlockForWrite(ResourceId id) { | 1119 void ResourceProvider::UnlockForWrite(ResourceId id) { |
1120 Resource* resource = GetResource(id); | 1120 Resource* resource = GetResource(id); |
1121 DCHECK(resource->locked_for_write); | 1121 DCHECK(resource->locked_for_write); |
1122 DCHECK_EQ(resource->exported_count, 0); | 1122 DCHECK_EQ(resource->exported_count, 0); |
1123 DCHECK(resource->origin == Resource::Internal); | 1123 DCHECK(resource->origin == Resource::Internal); |
1124 resource->locked_for_write = false; | 1124 resource->locked_for_write = false; |
1125 } | 1125 } |
1126 | 1126 |
| 1127 const ResourceProvider::Resource* ResourceProvider::LockForExport( |
| 1128 ResourceId id) { |
| 1129 Resource* resource = GetResource(id); |
| 1130 if (resource->type == GLTexture) { |
| 1131 DCHECK(resource->origin != Resource::Internal); |
| 1132 DCHECK(resource->mailbox.IsTexture()); |
| 1133 GLES2Interface* gl = ContextGL(); |
| 1134 DCHECK(gl); |
| 1135 if (resource->mailbox.sync_point()) { |
| 1136 GLC(gl, gl->WaitSyncPointCHROMIUM(resource->mailbox.sync_point())); |
| 1137 resource->mailbox.set_sync_point(0); |
| 1138 } |
| 1139 } |
| 1140 |
| 1141 resource->exported_count++; |
| 1142 return resource; |
| 1143 } |
| 1144 |
| 1145 void ResourceProvider::UnlockForExport(ResourceId id) { |
| 1146 Resource* resource = GetResource(id); |
| 1147 DCHECK_GT(resource->exported_count, 0); |
| 1148 resource->exported_count--; |
| 1149 } |
| 1150 |
| 1151 ResourceProvider::ScopedExportLock::ScopedExportLock( |
| 1152 ResourceProvider* resource_provider, |
| 1153 ResourceProvider::ResourceId resource_id) |
| 1154 : resource_provider_(resource_provider), resource_id_(resource_id) { |
| 1155 resource_provider_->LockForExport(resource_id); |
| 1156 } |
| 1157 |
| 1158 ResourceProvider::ScopedExportLock::~ScopedExportLock() { |
| 1159 resource_provider_->UnlockForExport(resource_id_); |
| 1160 } |
| 1161 |
| 1162 const gpu::Mailbox& ResourceProvider::ScopedExportLock::GetMailbox() const { |
| 1163 return resource_provider_->GetResource(resource_id_)->mailbox.mailbox(); |
| 1164 } |
| 1165 |
1127 ResourceProvider::ScopedReadLockGL::ScopedReadLockGL( | 1166 ResourceProvider::ScopedReadLockGL::ScopedReadLockGL( |
1128 ResourceProvider* resource_provider, | 1167 ResourceProvider* resource_provider, |
1129 ResourceProvider::ResourceId resource_id) | 1168 ResourceProvider::ResourceId resource_id) |
1130 : resource_provider_(resource_provider), | 1169 : resource_provider_(resource_provider), |
1131 resource_id_(resource_id), | 1170 resource_id_(resource_id), |
1132 texture_id_(resource_provider->LockForRead(resource_id)->gl_id) { | 1171 texture_id_(resource_provider->LockForRead(resource_id)->gl_id) { |
1133 DCHECK(texture_id_); | 1172 DCHECK(texture_id_); |
1134 } | 1173 } |
1135 | 1174 |
1136 ResourceProvider::ScopedReadLockGL::~ScopedReadLockGL() { | 1175 ResourceProvider::ScopedReadLockGL::~ScopedReadLockGL() { |
(...skipping 1078 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2215 ContextProvider* context_provider = output_surface_->context_provider(); | 2254 ContextProvider* context_provider = output_surface_->context_provider(); |
2216 return context_provider ? context_provider->ContextGL() : NULL; | 2255 return context_provider ? context_provider->ContextGL() : NULL; |
2217 } | 2256 } |
2218 | 2257 |
2219 class GrContext* ResourceProvider::GrContext() const { | 2258 class GrContext* ResourceProvider::GrContext() const { |
2220 ContextProvider* context_provider = output_surface_->context_provider(); | 2259 ContextProvider* context_provider = output_surface_->context_provider(); |
2221 return context_provider ? context_provider->GrContext() : NULL; | 2260 return context_provider ? context_provider->GrContext() : NULL; |
2222 } | 2261 } |
2223 | 2262 |
2224 } // namespace cc | 2263 } // namespace cc |
OLD | NEW |