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 1506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1517 DCHECK(!resource->image_id); | 1517 DCHECK(!resource->image_id); |
1518 DCHECK_NE(ETC1, resource->format); | 1518 DCHECK_NE(ETC1, resource->format); |
1519 | 1519 |
1520 DCHECK_EQ(RESOURCE_TYPE_GL_TEXTURE, resource->type); | 1520 DCHECK_EQ(RESOURCE_TYPE_GL_TEXTURE, resource->type); |
1521 GLES2Interface* gl = ContextGL(); | 1521 GLES2Interface* gl = ContextGL(); |
1522 DCHECK(gl); | 1522 DCHECK(gl); |
1523 if (!resource->gl_pixel_buffer_id) | 1523 if (!resource->gl_pixel_buffer_id) |
1524 resource->gl_pixel_buffer_id = buffer_id_allocator_->NextId(); | 1524 resource->gl_pixel_buffer_id = buffer_id_allocator_->NextId(); |
1525 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1525 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
1526 resource->gl_pixel_buffer_id); | 1526 resource->gl_pixel_buffer_id); |
1527 unsigned bytes_per_pixel = BitsPerPixel(resource->format) / 8; | 1527 |
1528 gl->BufferData( | 1528 base::CheckedNumeric<int> num_bytes = resource->size.height(); |
reveman
2015/06/24 18:02:26
why CheckedNumeric?
| |
1529 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1529 int bytes_per_row_aligned = |
reveman
2015/06/24 18:02:26
How about just bytes_per_row and round up to multi
| |
1530 resource->size.height() * | 1530 (resource->size.width() * BitsPerPixel(resource->format)) / 8; |
1531 MathUtil::RoundUp(bytes_per_pixel * resource->size.width(), 4u), | 1531 bytes_per_row_aligned = MathUtil::RoundUp(bytes_per_row, 4u); |
1532 NULL, GL_DYNAMIC_DRAW); | 1532 num_bytes *= bytes_per_row_aligned; |
1533 | |
1534 gl->BufferData(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | |
1535 num_bytes.ValueOrDie(), NULL, GL_DYNAMIC_DRAW); | |
1533 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 1536 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
1534 } | 1537 } |
1535 | 1538 |
1536 void ResourceProvider::ReleasePixelBuffer(ResourceId id) { | 1539 void ResourceProvider::ReleasePixelBuffer(ResourceId id) { |
1537 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 1540 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
1538 "ResourceProvider::ReleasePixelBuffer"); | 1541 "ResourceProvider::ReleasePixelBuffer"); |
1539 | 1542 |
1540 Resource* resource = GetResource(id); | 1543 Resource* resource = GetResource(id); |
1541 DCHECK(resource->origin == Resource::INTERNAL); | 1544 DCHECK(resource->origin == Resource::INTERNAL); |
1542 DCHECK_EQ(resource->exported_count, 0); | 1545 DCHECK_EQ(resource->exported_count, 0); |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1945 } | 1948 } |
1946 | 1949 |
1947 class GrContext* ResourceProvider::GrContext(bool worker_context) const { | 1950 class GrContext* ResourceProvider::GrContext(bool worker_context) const { |
1948 ContextProvider* context_provider = | 1951 ContextProvider* context_provider = |
1949 worker_context ? output_surface_->worker_context_provider() | 1952 worker_context ? output_surface_->worker_context_provider() |
1950 : output_surface_->context_provider(); | 1953 : output_surface_->context_provider(); |
1951 return context_provider ? context_provider->GrContext() : NULL; | 1954 return context_provider ? context_provider->GrContext() : NULL; |
1952 } | 1955 } |
1953 | 1956 |
1954 } // namespace cc | 1957 } // namespace cc |
OLD | NEW |