| 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 return kBGRA_8888_GrPixelConfig; | 102 return kBGRA_8888_GrPixelConfig; |
| 103 case RGBA_4444: | 103 case RGBA_4444: |
| 104 return kRGBA_4444_GrPixelConfig; | 104 return kRGBA_4444_GrPixelConfig; |
| 105 default: | 105 default: |
| 106 break; | 106 break; |
| 107 } | 107 } |
| 108 DCHECK(false) << "Unsupported resource format."; | 108 DCHECK(false) << "Unsupported resource format."; |
| 109 return kSkia8888_GrPixelConfig; | 109 return kSkia8888_GrPixelConfig; |
| 110 } | 110 } |
| 111 | 111 |
| 112 class IdentityAllocator : public SkBitmap::Allocator { | 112 void CopyBitmap(const SkBitmap& src, uint8_t* dst, SkColorType dst_color_type) { |
| 113 public: | 113 SkImageInfo dst_info = src.info(); |
| 114 explicit IdentityAllocator(void* buffer) : buffer_(buffer) {} | 114 dst_info.fColorType = dst_color_type; |
| 115 virtual bool allocPixelRef(SkBitmap* dst, SkColorTable*) OVERRIDE { | |
| 116 dst->setPixels(buffer_); | |
| 117 return true; | |
| 118 } | |
| 119 | |
| 120 private: | |
| 121 void* buffer_; | |
| 122 }; | |
| 123 | |
| 124 void CopyBitmap(const SkBitmap& src, uint8_t* dst, SkColorType dst_colorType) { | |
| 125 SkBitmap dst_bitmap; | |
| 126 IdentityAllocator allocator(dst); | |
| 127 src.copyTo(&dst_bitmap, dst_colorType, &allocator); | |
| 128 // TODO(kaanb): The GL pipeline assumes a 4-byte alignment for the | 115 // TODO(kaanb): The GL pipeline assumes a 4-byte alignment for the |
| 129 // bitmap data. This check will be removed once crbug.com/293728 is fixed. | 116 // bitmap data. There will be no need to call SkAlign4 once crbug.com/293728 |
| 130 CHECK_EQ(0u, dst_bitmap.rowBytes() % 4); | 117 // is fixed. |
| 118 const size_t dst_row_bytes = SkAlign4(dst_info.minRowBytes()); |
| 119 CHECK_EQ(0u, dst_row_bytes % 4); |
| 120 bool success = src.readPixels(dst_info, dst, dst_row_bytes, 0, 0); |
| 121 CHECK_EQ(true, success); |
| 131 } | 122 } |
| 132 | 123 |
| 133 class ScopedSetActiveTexture { | 124 class ScopedSetActiveTexture { |
| 134 public: | 125 public: |
| 135 ScopedSetActiveTexture(GLES2Interface* gl, GLenum unit) | 126 ScopedSetActiveTexture(GLES2Interface* gl, GLenum unit) |
| 136 : gl_(gl), unit_(unit) { | 127 : gl_(gl), unit_(unit) { |
| 137 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(gl_)); | 128 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(gl_)); |
| 138 | 129 |
| 139 if (unit_ != GL_TEXTURE0) | 130 if (unit_ != GL_TEXTURE0) |
| 140 GLC(gl_, gl_->ActiveTexture(unit_)); | 131 GLC(gl_, gl_->ActiveTexture(unit_)); |
| (...skipping 2138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2279 ContextProvider* context_provider = output_surface_->context_provider(); | 2270 ContextProvider* context_provider = output_surface_->context_provider(); |
| 2280 return context_provider ? context_provider->ContextGL() : NULL; | 2271 return context_provider ? context_provider->ContextGL() : NULL; |
| 2281 } | 2272 } |
| 2282 | 2273 |
| 2283 class GrContext* ResourceProvider::GrContext() const { | 2274 class GrContext* ResourceProvider::GrContext() const { |
| 2284 ContextProvider* context_provider = output_surface_->context_provider(); | 2275 ContextProvider* context_provider = output_surface_->context_provider(); |
| 2285 return context_provider ? context_provider->GrContext() : NULL; | 2276 return context_provider ? context_provider->GrContext() : NULL; |
| 2286 } | 2277 } |
| 2287 | 2278 |
| 2288 } // namespace cc | 2279 } // namespace cc |
| OLD | NEW |