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

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: address review feedback 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
« no previous file with comments | « cc/resources/resource_provider.h ('k') | cc/resources/resource_provider_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 894 matching lines...) Expand 10 before | Expand all | Expand 10 after
1743 } 1776 }
1744 1777
1745 SkCanvas* ResourceProvider::MapImageRasterBuffer(ResourceId id) { 1778 SkCanvas* ResourceProvider::MapImageRasterBuffer(ResourceId id) {
1746 Resource* resource = GetResource(id); 1779 Resource* resource = GetResource(id);
1747 AcquireImage(resource); 1780 AcquireImage(resource);
1748 if (!resource->image_raster_buffer.get()) 1781 if (!resource->image_raster_buffer.get())
1749 resource->image_raster_buffer.reset(new ImageRasterBuffer(resource, this)); 1782 resource->image_raster_buffer.reset(new ImageRasterBuffer(resource, this));
1750 return resource->image_raster_buffer->LockForWrite(); 1783 return resource->image_raster_buffer->LockForWrite();
1751 } 1784 }
1752 1785
1753 void ResourceProvider::UnmapImageRasterBuffer(ResourceId id) { 1786 bool ResourceProvider::UnmapImageRasterBuffer(ResourceId id) {
1754 Resource* resource = GetResource(id); 1787 Resource* resource = GetResource(id);
1755 resource->image_raster_buffer->UnlockForWrite();
1756 resource->dirty_image = true; 1788 resource->dirty_image = true;
1789 return resource->image_raster_buffer->UnlockForWrite();
1757 } 1790 }
1758 1791
1759 void ResourceProvider::AcquirePixelRasterBuffer(ResourceId id) { 1792 void ResourceProvider::AcquirePixelRasterBuffer(ResourceId id) {
1760 Resource* resource = GetResource(id); 1793 Resource* resource = GetResource(id);
1761 AcquirePixelBuffer(resource); 1794 AcquirePixelBuffer(resource);
1762 resource->pixel_raster_buffer.reset(new PixelRasterBuffer(resource, this)); 1795 resource->pixel_raster_buffer.reset(new PixelRasterBuffer(resource, this));
1763 } 1796 }
1764 1797
1765 void ResourceProvider::ReleasePixelRasterBuffer(ResourceId id) { 1798 void ResourceProvider::ReleasePixelRasterBuffer(ResourceId id) {
1766 Resource* resource = GetResource(id); 1799 Resource* resource = GetResource(id);
(...skipping 408 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(source_resource->allocated);
2226 LazyCreate(source_resource);
2227
2228 Resource* dest_resource = GetResource(dest_id);
2229 DCHECK(!dest_resource->locked_for_write);
2230 DCHECK(!dest_resource->lock_for_read_count);
2231 DCHECK(dest_resource->origin == Resource::Internal);
2232 DCHECK_EQ(dest_resource->exported_count, 0);
2233 LazyCreate(dest_resource);
2234
2235 DCHECK_EQ(source_resource->type, dest_resource->type);
2236 DCHECK_EQ(source_resource->format, dest_resource->format);
2237 DCHECK(source_resource->size == dest_resource->size);
2238
2239 if (source_resource->type == GLTexture) {
2240 GLES2Interface* gl = ContextGL();
2241 DCHECK(gl);
2242 if (source_resource->image_id && source_resource->dirty_image) {
2243 gl->BindTexture(source_resource->target, source_resource->gl_id);
2244 BindImageForSampling(source_resource);
2245 }
2246 if (!source_resource->gl_read_lock_query_id)
2247 gl->GenQueriesEXT(1, &source_resource->gl_read_lock_query_id);
2248 // Note: Use of COMMANDS_ISSUED target assumes that it's safe to access the
2249 // source resource once the command has been processed on the service side.
2250 // TODO(reveman): Implement COMMANDS_COMPLETED query that can be used to
2251 // accurately determine when it's safe to access the source resource again.
2252 gl->BeginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM,
2253 source_resource->gl_read_lock_query_id);
2254 DCHECK(!dest_resource->image_id);
2255 dest_resource->allocated = true;
2256 gl->CopyTextureCHROMIUM(dest_resource->target,
2257 source_resource->gl_id,
2258 dest_resource->gl_id,
2259 0,
2260 GLInternalFormat(dest_resource->format),
2261 GLDataType(dest_resource->format));
2262 // End query and create a read lock fence that will prevent access to
2263 // source resource until CopyTextureCHROMIUM command has completed.
2264 gl->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM);
2265 source_resource->read_lock_fence = make_scoped_refptr(
2266 new QueryFence(gl, source_resource->gl_read_lock_query_id));
2267 } else {
2268 DCHECK_EQ(Bitmap, source_resource->type);
2269 DCHECK_EQ(RGBA_8888, source_resource->format);
2270 LazyAllocate(dest_resource);
2271
2272 size_t bytes = SharedBitmap::CheckedSizeInBytes(source_resource->size);
2273 memcpy(dest_resource->pixels, source_resource->pixels, bytes);
2274 }
2275 }
2276
2185 GLint ResourceProvider::GetActiveTextureUnit(GLES2Interface* gl) { 2277 GLint ResourceProvider::GetActiveTextureUnit(GLES2Interface* gl) {
2186 GLint active_unit = 0; 2278 GLint active_unit = 0;
2187 gl->GetIntegerv(GL_ACTIVE_TEXTURE, &active_unit); 2279 gl->GetIntegerv(GL_ACTIVE_TEXTURE, &active_unit);
2188 return active_unit; 2280 return active_unit;
2189 } 2281 }
2190 2282
2191 GLES2Interface* ResourceProvider::ContextGL() const { 2283 GLES2Interface* ResourceProvider::ContextGL() const {
2192 ContextProvider* context_provider = output_surface_->context_provider(); 2284 ContextProvider* context_provider = output_surface_->context_provider();
2193 return context_provider ? context_provider->ContextGL() : NULL; 2285 return context_provider ? context_provider->ContextGL() : NULL;
2194 } 2286 }
2195 2287
2196 class GrContext* ResourceProvider::GrContext() const { 2288 class GrContext* ResourceProvider::GrContext() const {
2197 ContextProvider* context_provider = output_surface_->context_provider(); 2289 ContextProvider* context_provider = output_surface_->context_provider();
2198 return context_provider ? context_provider->GrContext() : NULL; 2290 return context_provider ? context_provider->GrContext() : NULL;
2199 } 2291 }
2200 2292
2201 } // namespace cc 2293 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/resource_provider.h ('k') | cc/resources/resource_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698