| 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 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 | 695 |
| 696 ResourceProvider::ResourceId ResourceProvider::CreateBitmap( | 696 ResourceProvider::ResourceId ResourceProvider::CreateBitmap( |
| 697 const gfx::Size& size, GLint wrap_mode) { | 697 const gfx::Size& size, GLint wrap_mode) { |
| 698 DCHECK(thread_checker_.CalledOnValidThread()); | 698 DCHECK(thread_checker_.CalledOnValidThread()); |
| 699 | 699 |
| 700 scoped_ptr<SharedBitmap> bitmap; | 700 scoped_ptr<SharedBitmap> bitmap; |
| 701 if (shared_bitmap_manager_) | 701 if (shared_bitmap_manager_) |
| 702 bitmap = shared_bitmap_manager_->AllocateSharedBitmap(size); | 702 bitmap = shared_bitmap_manager_->AllocateSharedBitmap(size); |
| 703 | 703 |
| 704 uint8_t* pixels; | 704 uint8_t* pixels; |
| 705 if (bitmap) | 705 if (bitmap) { |
| 706 pixels = bitmap->pixels(); | 706 pixels = bitmap->pixels(); |
| 707 else | 707 } else { |
| 708 pixels = new uint8_t[4 * size.GetArea()]; | 708 size_t bytes = SharedBitmap::CheckedSizeInBytes(size); |
| 709 pixels = new uint8_t[bytes]; |
| 710 } |
| 709 DCHECK(pixels); | 711 DCHECK(pixels); |
| 710 | 712 |
| 711 ResourceId id = next_id_++; | 713 ResourceId id = next_id_++; |
| 712 Resource resource( | 714 Resource resource( |
| 713 pixels, bitmap.release(), size, Resource::Internal, GL_LINEAR, wrap_mode); | 715 pixels, bitmap.release(), size, Resource::Internal, GL_LINEAR, wrap_mode); |
| 714 resource.allocated = true; | 716 resource.allocated = true; |
| 715 resources_[id] = resource; | 717 resources_[id] = resource; |
| 716 return id; | 718 return id; |
| 717 } | 719 } |
| 718 | 720 |
| (...skipping 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1806 gl->BufferData(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1808 gl->BufferData(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| 1807 resource->size.height() * | 1809 resource->size.height() * |
| 1808 RoundUp(bytes_per_pixel * resource->size.width(), 4u), | 1810 RoundUp(bytes_per_pixel * resource->size.width(), 4u), |
| 1809 NULL, | 1811 NULL, |
| 1810 GL_DYNAMIC_DRAW); | 1812 GL_DYNAMIC_DRAW); |
| 1811 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 1813 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
| 1812 } else { | 1814 } else { |
| 1813 DCHECK_EQ(Bitmap, resource->type); | 1815 DCHECK_EQ(Bitmap, resource->type); |
| 1814 if (resource->pixel_buffer) | 1816 if (resource->pixel_buffer) |
| 1815 return; | 1817 return; |
| 1816 | 1818 size_t bytes = SharedBitmap::CheckedSizeInBytes(resource->size); |
| 1817 resource->pixel_buffer = new uint8_t[4 * resource->size.GetArea()]; | 1819 resource->pixel_buffer = new uint8_t[bytes]; |
| 1818 } | 1820 } |
| 1819 } | 1821 } |
| 1820 | 1822 |
| 1821 void ResourceProvider::ReleasePixelBuffer(Resource* resource) { | 1823 void ResourceProvider::ReleasePixelBuffer(Resource* resource) { |
| 1822 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 1824 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
| 1823 "ResourceProvider::ReleasePixelBuffer"); | 1825 "ResourceProvider::ReleasePixelBuffer"); |
| 1824 | 1826 |
| 1825 DCHECK(resource->origin == Resource::Internal); | 1827 DCHECK(resource->origin == Resource::Internal); |
| 1826 DCHECK_EQ(resource->exported_count, 0); | 1828 DCHECK_EQ(resource->exported_count, 0); |
| 1827 DCHECK(!resource->image_id); | 1829 DCHECK(!resource->image_id); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1982 NULL); | 1984 NULL); |
| 1983 } | 1985 } |
| 1984 gl->EndQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM); | 1986 gl->EndQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM); |
| 1985 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 1987 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
| 1986 } else { | 1988 } else { |
| 1987 DCHECK_EQ(Bitmap, resource->type); | 1989 DCHECK_EQ(Bitmap, resource->type); |
| 1988 DCHECK(!resource->mailbox.IsValid()); | 1990 DCHECK(!resource->mailbox.IsValid()); |
| 1989 DCHECK(resource->pixel_buffer); | 1991 DCHECK(resource->pixel_buffer); |
| 1990 DCHECK_EQ(RGBA_8888, resource->format); | 1992 DCHECK_EQ(RGBA_8888, resource->format); |
| 1991 | 1993 |
| 1992 memcpy( | 1994 size_t bytes = SharedBitmap::CheckedSizeInBytes(resource->size); |
| 1993 resource->pixels, resource->pixel_buffer, 4 * resource->size.GetArea()); | 1995 memcpy(resource->pixels, resource->pixel_buffer, bytes); |
| 1994 delete[] resource->pixel_buffer; | 1996 delete[] resource->pixel_buffer; |
| 1995 resource->pixel_buffer = NULL; | 1997 resource->pixel_buffer = NULL; |
| 1996 } | 1998 } |
| 1997 | 1999 |
| 1998 resource->pending_set_pixels = true; | 2000 resource->pending_set_pixels = true; |
| 1999 resource->set_pixels_completion_forced = false; | 2001 resource->set_pixels_completion_forced = false; |
| 2000 } | 2002 } |
| 2001 | 2003 |
| 2002 void ResourceProvider::ForceSetPixelsToComplete(ResourceId id) { | 2004 void ResourceProvider::ForceSetPixelsToComplete(ResourceId id) { |
| 2003 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 2005 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2227 ContextProvider* context_provider = output_surface_->context_provider(); | 2229 ContextProvider* context_provider = output_surface_->context_provider(); |
| 2228 return context_provider ? context_provider->ContextGL() : NULL; | 2230 return context_provider ? context_provider->ContextGL() : NULL; |
| 2229 } | 2231 } |
| 2230 | 2232 |
| 2231 class GrContext* ResourceProvider::GrContext() const { | 2233 class GrContext* ResourceProvider::GrContext() const { |
| 2232 ContextProvider* context_provider = output_surface_->context_provider(); | 2234 ContextProvider* context_provider = output_surface_->context_provider(); |
| 2233 return context_provider ? context_provider->GrContext() : NULL; | 2235 return context_provider ? context_provider->GrContext() : NULL; |
| 2234 } | 2236 } |
| 2235 | 2237 |
| 2236 } // namespace cc | 2238 } // namespace cc |
| OLD | NEW |