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

Side by Side Diff: cc/resources/resource_provider.cc

Issue 234403005: cc: Add CopyResource function to ResourceProvider API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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
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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 next_id_index_ = 0; 191 next_id_index_ = 0;
192 } 192 }
193 193
194 return ids_[next_id_index_++]; 194 return ids_[next_id_index_++];
195 } 195 }
196 196
197 private: 197 private:
198 DISALLOW_COPY_AND_ASSIGN(BufferIdAllocator); 198 DISALLOW_COPY_AND_ASSIGN(BufferIdAllocator);
199 }; 199 };
200 200
201 // Generic fence implementation for query objects. Fence has passed when query
202 // result is available.
203 class QueryFence : public ResourceProvider::Fence {
204 public:
205 QueryFence(gpu::gles2::GLES2Interface* gl, unsigned query_id)
206 : gl_(gl), query_id_(query_id) {}
207
208 // Overridden from ResourceProvider::Fence:
209 virtual bool HasPassed() OVERRIDE {
210 unsigned available = 1;
211 gl_->GetQueryObjectuivEXT(
212 query_id_, GL_QUERY_RESULT_AVAILABLE_EXT, &available);
213 return !!available;
214 }
215
216 private:
217 virtual ~QueryFence() {}
218
219 gpu::gles2::GLES2Interface* gl_;
220 unsigned query_id_;
221
222 DISALLOW_COPY_AND_ASSIGN(QueryFence);
223 };
224
201 } // namespace 225 } // namespace
202 226
203 ResourceProvider::Resource::Resource() 227 ResourceProvider::Resource::Resource()
204 : child_id(0), 228 : child_id(0),
205 gl_id(0), 229 gl_id(0),
206 gl_pixel_buffer_id(0), 230 gl_pixel_buffer_id(0),
207 gl_upload_query_id(0), 231 gl_upload_query_id(0),
232 gl_read_lock_query_id(0),
208 pixels(NULL), 233 pixels(NULL),
209 lock_for_read_count(0), 234 lock_for_read_count(0),
210 imported_count(0), 235 imported_count(0),
211 exported_count(0), 236 exported_count(0),
212 dirty_image(false), 237 dirty_image(false),
213 locked_for_write(false), 238 locked_for_write(false),
214 lost(false), 239 lost(false),
215 marked_for_deletion(false), 240 marked_for_deletion(false),
216 pending_set_pixels(false), 241 pending_set_pixels(false),
217 set_pixels_completion_forced(false), 242 set_pixels_completion_forced(false),
(...skipping 24 matching lines...) Expand all
242 GLenum target, 267 GLenum target,
243 GLenum filter, 268 GLenum filter,
244 GLenum texture_pool, 269 GLenum texture_pool,
245 GLint wrap_mode, 270 GLint wrap_mode,
246 TextureUsageHint hint, 271 TextureUsageHint hint,
247 ResourceFormat format) 272 ResourceFormat format)
248 : child_id(0), 273 : child_id(0),
249 gl_id(texture_id), 274 gl_id(texture_id),
250 gl_pixel_buffer_id(0), 275 gl_pixel_buffer_id(0),
251 gl_upload_query_id(0), 276 gl_upload_query_id(0),
277 gl_read_lock_query_id(0),
252 pixels(NULL), 278 pixels(NULL),
253 lock_for_read_count(0), 279 lock_for_read_count(0),
254 imported_count(0), 280 imported_count(0),
255 exported_count(0), 281 exported_count(0),
256 dirty_image(false), 282 dirty_image(false),
257 locked_for_write(false), 283 locked_for_write(false),
258 lost(false), 284 lost(false),
259 marked_for_deletion(false), 285 marked_for_deletion(false),
260 pending_set_pixels(false), 286 pending_set_pixels(false),
261 set_pixels_completion_forced(false), 287 set_pixels_completion_forced(false),
(...skipping 22 matching lines...) Expand all
284 ResourceProvider::Resource::Resource(uint8_t* pixels, 310 ResourceProvider::Resource::Resource(uint8_t* pixels,
285 SharedBitmap* bitmap, 311 SharedBitmap* bitmap,
286 const gfx::Size& size, 312 const gfx::Size& size,
287 Origin origin, 313 Origin origin,
288 GLenum filter, 314 GLenum filter,
289 GLint wrap_mode) 315 GLint wrap_mode)
290 : child_id(0), 316 : child_id(0),
291 gl_id(0), 317 gl_id(0),
292 gl_pixel_buffer_id(0), 318 gl_pixel_buffer_id(0),
293 gl_upload_query_id(0), 319 gl_upload_query_id(0),
320 gl_read_lock_query_id(0),
294 pixels(pixels), 321 pixels(pixels),
295 lock_for_read_count(0), 322 lock_for_read_count(0),
296 imported_count(0), 323 imported_count(0),
297 exported_count(0), 324 exported_count(0),
298 dirty_image(false), 325 dirty_image(false),
299 locked_for_write(false), 326 locked_for_write(false),
300 lost(false), 327 lost(false),
301 marked_for_deletion(false), 328 marked_for_deletion(false),
302 pending_set_pixels(false), 329 pending_set_pixels(false),
303 set_pixels_completion_forced(false), 330 set_pixels_completion_forced(false),
(...skipping 23 matching lines...) Expand all
327 354
328 ResourceProvider::Resource::Resource(const SharedBitmapId& bitmap_id, 355 ResourceProvider::Resource::Resource(const SharedBitmapId& bitmap_id,
329 const gfx::Size& size, 356 const gfx::Size& size,
330 Origin origin, 357 Origin origin,
331 GLenum filter, 358 GLenum filter,
332 GLint wrap_mode) 359 GLint wrap_mode)
333 : child_id(0), 360 : child_id(0),
334 gl_id(0), 361 gl_id(0),
335 gl_pixel_buffer_id(0), 362 gl_pixel_buffer_id(0),
336 gl_upload_query_id(0), 363 gl_upload_query_id(0),
364 gl_read_lock_query_id(0),
337 pixels(NULL), 365 pixels(NULL),
338 lock_for_read_count(0), 366 lock_for_read_count(0),
339 imported_count(0), 367 imported_count(0),
340 exported_count(0), 368 exported_count(0),
341 dirty_image(false), 369 dirty_image(false),
342 locked_for_write(false), 370 locked_for_write(false),
343 lost(false), 371 lost(false),
344 marked_for_deletion(false), 372 marked_for_deletion(false),
345 pending_set_pixels(false), 373 pending_set_pixels(false),
346 set_pixels_completion_forced(false), 374 set_pixels_completion_forced(false),
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 resource->direct_raster_buffer.reset(); 850 resource->direct_raster_buffer.reset();
823 resource->image_raster_buffer.reset(); 851 resource->image_raster_buffer.reset();
824 resource->pixel_raster_buffer.reset(); 852 resource->pixel_raster_buffer.reset();
825 853
826 if (resource->image_id) { 854 if (resource->image_id) {
827 DCHECK(resource->origin == Resource::Internal); 855 DCHECK(resource->origin == Resource::Internal);
828 GLES2Interface* gl = ContextGL(); 856 GLES2Interface* gl = ContextGL();
829 DCHECK(gl); 857 DCHECK(gl);
830 GLC(gl, gl->DestroyImageCHROMIUM(resource->image_id)); 858 GLC(gl, gl->DestroyImageCHROMIUM(resource->image_id));
831 } 859 }
832
833 if (resource->gl_upload_query_id) { 860 if (resource->gl_upload_query_id) {
834 DCHECK(resource->origin == Resource::Internal); 861 DCHECK(resource->origin == Resource::Internal);
835 GLES2Interface* gl = ContextGL(); 862 GLES2Interface* gl = ContextGL();
836 DCHECK(gl); 863 DCHECK(gl);
837 GLC(gl, gl->DeleteQueriesEXT(1, &resource->gl_upload_query_id)); 864 GLC(gl, gl->DeleteQueriesEXT(1, &resource->gl_upload_query_id));
838 } 865 }
866 if (resource->gl_read_lock_query_id) {
867 DCHECK(resource->origin == Resource::Internal);
868 GLES2Interface* gl = ContextGL();
869 DCHECK(gl);
870 GLC(gl, gl->DeleteQueriesEXT(1, &resource->gl_read_lock_query_id));
871 }
839 if (resource->gl_pixel_buffer_id) { 872 if (resource->gl_pixel_buffer_id) {
840 DCHECK(resource->origin == Resource::Internal); 873 DCHECK(resource->origin == Resource::Internal);
841 GLES2Interface* gl = ContextGL(); 874 GLES2Interface* gl = ContextGL();
842 DCHECK(gl); 875 DCHECK(gl);
843 GLC(gl, gl->DeleteBuffers(1, &resource->gl_pixel_buffer_id)); 876 GLC(gl, gl->DeleteBuffers(1, &resource->gl_pixel_buffer_id));
844 } 877 }
845 if (resource->mailbox.IsValid() && resource->origin == Resource::External) { 878 if (resource->mailbox.IsValid() && resource->origin == Resource::External) {
846 GLuint sync_point = resource->mailbox.sync_point(); 879 GLuint sync_point = resource->mailbox.sync_point();
847 if (resource->type == GLTexture) { 880 if (resource->type == GLTexture) {
848 DCHECK(resource->mailbox.IsTexture()); 881 DCHECK(resource->mailbox.IsTexture());
(...skipping 1326 matching lines...) Expand 10 before | Expand all | Expand 10 after
2175 DCHECK(resource->origin == Resource::Internal); 2208 DCHECK(resource->origin == Resource::Internal);
2176 DCHECK_EQ(resource->exported_count, 0); 2209 DCHECK_EQ(resource->exported_count, 0);
2177 2210
2178 if (resource->image_id) { 2211 if (resource->image_id) {
2179 GLES2Interface* gl = ContextGL(); 2212 GLES2Interface* gl = ContextGL();
2180 DCHECK(gl); 2213 DCHECK(gl);
2181 gl->UnmapImageCHROMIUM(resource->image_id); 2214 gl->UnmapImageCHROMIUM(resource->image_id);
2182 } 2215 }
2183 } 2216 }
2184 2217
2218 void ResourceProvider::CopyResource(ResourceId source_id, ResourceId dest_id) {
2219 TRACE_EVENT0("cc", "ResourceProvider::CopyResource");
2220
2221 Resource* source_resource = GetResource(source_id);
2222 DCHECK(!source_resource->lock_for_read_count);
2223 DCHECK(source_resource->origin == Resource::Internal);
2224 DCHECK_EQ(source_resource->exported_count, 0);
2225 DCHECK(ReadLockFenceHasPassed(source_resource));
2226 DCHECK(source_resource->allocated);
2227 LazyCreate(source_resource);
2228
2229 Resource* dest_resource = GetResource(dest_id);
2230 DCHECK(!dest_resource->locked_for_write);
2231 DCHECK(!dest_resource->lock_for_read_count);
2232 DCHECK(dest_resource->origin == Resource::Internal);
2233 DCHECK_EQ(dest_resource->exported_count, 0);
2234 DCHECK(ReadLockFenceHasPassed(dest_resource));
piman 2014/04/14 18:39:34 Do we actually need this? The ReadLockFence thing
reveman 2014/04/14 19:24:09 Right, these DCHECKs are not necessary as it's OK
piman 2014/04/14 19:34:35 Yes, understood for that part.
2235 LazyCreate(dest_resource);
2236
2237 DCHECK_EQ(source_resource->type, dest_resource->type);
2238 DCHECK_EQ(source_resource->size.ToString(), dest_resource->size.ToString());
piman 2014/04/14 18:39:34 nit: meh, this isn't a unit test... I'd rather DCH
reveman 2014/04/14 19:24:09 Done.
2239 DCHECK_EQ(source_resource->format, dest_resource->format);
2240
2241 if (source_resource->type == GLTexture) {
2242 GLES2Interface* gl = ContextGL();
2243 DCHECK(gl);
2244 if (source_resource->image_id && source_resource->dirty_image) {
2245 gl->BindTexture(source_resource->target, source_resource->gl_id);
2246 BindImageForSampling(source_resource);
2247 }
2248 if (!source_resource->gl_read_lock_query_id)
2249 gl->GenQueriesEXT(1, &source_resource->gl_read_lock_query_id);
2250 // Note: Use of COMMANDS_ISSUED target assumes that it's safe to access the
2251 // source resource once the command has been processed on the service side.
2252 // TODO(reveman): Implement COMMANDS_COMPLETED query that can be used to
2253 // accurately determine when it's safe to access the source resource again.
2254 gl->BeginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM,
2255 source_resource->gl_read_lock_query_id);
2256 DCHECK(!dest_resource->image_id);
2257 dest_resource->allocated = true;
2258 gl->CopyTextureCHROMIUM(dest_resource->target,
2259 source_resource->gl_id,
2260 dest_resource->gl_id,
2261 0,
2262 GLInternalFormat(dest_resource->format),
2263 GLDataType(dest_resource->format));
2264 // End query and create a read lock fence that will prevent access to
2265 // source resource until CopyTextureCHROMIUM command has completed.
2266 gl->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM);
2267 source_resource->read_lock_fence = make_scoped_refptr(
2268 new QueryFence(gl, source_resource->gl_read_lock_query_id));
2269 } else {
2270 DCHECK_EQ(Bitmap, source_resource->type);
2271 DCHECK_EQ(RGBA_8888, source_resource->format);
2272 LazyAllocate(dest_resource);
2273
2274 size_t bytes = SharedBitmap::CheckedSizeInBytes(source_resource->size);
2275 memcpy(dest_resource->pixels, source_resource->pixels, bytes);
2276 }
2277 }
2278
2185 GLint ResourceProvider::GetActiveTextureUnit(GLES2Interface* gl) { 2279 GLint ResourceProvider::GetActiveTextureUnit(GLES2Interface* gl) {
2186 GLint active_unit = 0; 2280 GLint active_unit = 0;
2187 gl->GetIntegerv(GL_ACTIVE_TEXTURE, &active_unit); 2281 gl->GetIntegerv(GL_ACTIVE_TEXTURE, &active_unit);
2188 return active_unit; 2282 return active_unit;
2189 } 2283 }
2190 2284
2191 GLES2Interface* ResourceProvider::ContextGL() const { 2285 GLES2Interface* ResourceProvider::ContextGL() const {
2192 ContextProvider* context_provider = output_surface_->context_provider(); 2286 ContextProvider* context_provider = output_surface_->context_provider();
2193 return context_provider ? context_provider->ContextGL() : NULL; 2287 return context_provider ? context_provider->ContextGL() : NULL;
2194 } 2288 }
2195 2289
2196 class GrContext* ResourceProvider::GrContext() const { 2290 class GrContext* ResourceProvider::GrContext() const {
2197 ContextProvider* context_provider = output_surface_->context_provider(); 2291 ContextProvider* context_provider = output_surface_->context_provider();
2198 return context_provider ? context_provider->GrContext() : NULL; 2292 return context_provider ? context_provider->GrContext() : NULL;
2199 } 2293 }
2200 2294
2201 } // namespace cc 2295 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698