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 { | |
113 public: | |
114 explicit IdentityAllocator(void* buffer) : buffer_(buffer) {} | |
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) { | 112 void CopyBitmap(const SkBitmap& src, uint8_t* dst, SkColorType dst_colorType) { |
125 SkBitmap dst_bitmap; | 113 SkImageInfo dst_info = src.info(); |
126 IdentityAllocator allocator(dst); | 114 dst_info.fColorType = dst_colorType; |
enne (OOO)
2014/07/24 17:58:18
This was here before you, but you can you make thi
scroggo
2014/07/24 18:11:38
Done.
| |
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 2164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2305 if (gr_context) | 2296 if (gr_context) |
2306 gr_context->flush(); | 2297 gr_context->flush(); |
2307 | 2298 |
2308 // TODO(alokp): Use a trace macro to push/pop markers. | 2299 // TODO(alokp): Use a trace macro to push/pop markers. |
2309 // Using push/pop functions directly incurs cost to evaluate function | 2300 // Using push/pop functions directly incurs cost to evaluate function |
2310 // arguments even when tracing is disabled. | 2301 // arguments even when tracing is disabled. |
2311 gl->PopGroupMarkerEXT(); | 2302 gl->PopGroupMarkerEXT(); |
2312 } | 2303 } |
2313 | 2304 |
2314 } // namespace cc | 2305 } // namespace cc |
OLD | NEW |