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 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 format); | 548 format); |
549 resource.allocated = false; | 549 resource.allocated = false; |
550 resources_[id] = resource; | 550 resources_[id] = resource; |
551 return id; | 551 return id; |
552 } | 552 } |
553 | 553 |
554 ResourceProvider::ResourceId ResourceProvider::CreateBitmap( | 554 ResourceProvider::ResourceId ResourceProvider::CreateBitmap( |
555 const gfx::Size& size, GLint wrap_mode) { | 555 const gfx::Size& size, GLint wrap_mode) { |
556 DCHECK(thread_checker_.CalledOnValidThread()); | 556 DCHECK(thread_checker_.CalledOnValidThread()); |
557 | 557 |
558 scoped_ptr<SharedBitmap> bitmap; | 558 scoped_ptr<SharedBitmap> bitmap = |
559 if (shared_bitmap_manager_) | 559 shared_bitmap_manager_->AllocateSharedBitmap(size); |
560 bitmap = shared_bitmap_manager_->AllocateSharedBitmap(size); | 560 uint8_t* pixels = bitmap->pixels(); |
561 | |
562 uint8_t* pixels; | |
563 if (bitmap) { | |
564 pixels = bitmap->pixels(); | |
565 } else { | |
566 size_t bytes = SharedBitmap::CheckedSizeInBytes(size); | |
567 pixels = new uint8_t[bytes]; | |
568 } | |
569 DCHECK(pixels); | 561 DCHECK(pixels); |
570 | 562 |
571 ResourceId id = next_id_++; | 563 ResourceId id = next_id_++; |
572 Resource resource( | 564 Resource resource( |
573 pixels, bitmap.release(), size, Resource::Internal, GL_LINEAR, wrap_mode); | 565 pixels, bitmap.release(), size, Resource::Internal, GL_LINEAR, wrap_mode); |
574 resource.allocated = true; | 566 resource.allocated = true; |
575 resources_[id] = resource; | 567 resources_[id] = resource; |
576 return id; | 568 return id; |
577 } | 569 } |
578 | 570 |
(...skipping 1562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2141 ContextProvider* context_provider = output_surface_->context_provider(); | 2133 ContextProvider* context_provider = output_surface_->context_provider(); |
2142 return context_provider ? context_provider->ContextGL() : NULL; | 2134 return context_provider ? context_provider->ContextGL() : NULL; |
2143 } | 2135 } |
2144 | 2136 |
2145 class GrContext* ResourceProvider::GrContext() const { | 2137 class GrContext* ResourceProvider::GrContext() const { |
2146 ContextProvider* context_provider = output_surface_->context_provider(); | 2138 ContextProvider* context_provider = output_surface_->context_provider(); |
2147 return context_provider ? context_provider->GrContext() : NULL; | 2139 return context_provider ? context_provider->GrContext() : NULL; |
2148 } | 2140 } |
2149 | 2141 |
2150 } // namespace cc | 2142 } // namespace cc |
OLD | NEW |