Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: src/image/SkImageShader.cpp

Issue 2355703003: Avoid bitmap copy in SkMakeBitmapShader, fix hwui unit test (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tests/ShaderTest.cpp » ('j') | tests/ShaderTest.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkBitmapProcShader.h" 8 #include "SkBitmapProcShader.h"
9 #include "SkBitmapProvider.h" 9 #include "SkBitmapProvider.h"
10 #include "SkColorShader.h" 10 #include "SkColorShader.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 // widen that, we have to reject bitmaps that are larger. 90 // widen that, we have to reject bitmaps that are larger.
91 // 91 //
92 static const int kMaxSize = 65535; 92 static const int kMaxSize = 65535;
93 93
94 return w > kMaxSize || h > kMaxSize; 94 return w > kMaxSize || h > kMaxSize;
95 } 95 }
96 96
97 // returns true and set color if the bitmap can be drawn as a single color 97 // returns true and set color if the bitmap can be drawn as a single color
98 // (for efficiency) 98 // (for efficiency)
99 static bool can_use_color_shader(const SkImage* image, SkColor* color) { 99 static bool can_use_color_shader(const SkImage* image, SkColor* color) {
100 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK 100 #if 1
reed1 2016/09/20 17:19:06 what was wrong with the FRAMEWORK flag?
101 // HWUI does not support color shaders (see b/22390304) 101 // HWUI does not support color shaders (see b/22390304)
102 return false; 102 return false;
103 #endif 103 #endif
104 104
105 if (1 != image->width() || 1 != image->height()) { 105 if (1 != image->width() || 1 != image->height()) {
106 return false; 106 return false;
107 } 107 }
108 108
109 SkPixmap pmap; 109 SkPixmap pmap;
110 if (!image->peekPixels(&pmap)) { 110 if (!image->peekPixels(&pmap)) {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 237
238 sk_sp<SkShader> SkMakeBitmapShader(const SkBitmap& src, SkShader::TileMode tmx, 238 sk_sp<SkShader> SkMakeBitmapShader(const SkBitmap& src, SkShader::TileMode tmx,
239 SkShader::TileMode tmy, const SkMatrix* local Matrix, 239 SkShader::TileMode tmy, const SkMatrix* local Matrix,
240 SkCopyPixelsMode cpm, SkTBlitterAllocator* al locator) { 240 SkCopyPixelsMode cpm, SkTBlitterAllocator* al locator) {
241 // Until we learn otherwise, it seems that any caller that is passing an all ocator must be 241 // Until we learn otherwise, it seems that any caller that is passing an all ocator must be
242 // assuming that the returned shader will have a stack-frame lifetime, so we assert that 242 // assuming that the returned shader will have a stack-frame lifetime, so we assert that
243 // they are also asking for kNever_SkCopyPixelsMode. If that proves otherwis e, we can remove 243 // they are also asking for kNever_SkCopyPixelsMode. If that proves otherwis e, we can remove
244 // or modify this assert. 244 // or modify this assert.
245 SkASSERT(!allocator || (kNever_SkCopyPixelsMode == cpm)); 245 SkASSERT(!allocator || (kNever_SkCopyPixelsMode == cpm));
246 246
247 return SkImageShader::Make(SkMakeImageFromRasterBitmap(src, cpm, allocator), 247 return SkImageShader::Make(SkMakeImageFromRasterBitmap(src, kNever_SkCopyPix elsMode, allocator),
reed1 2016/09/20 17:19:05 Can the caller make the decision to pass in kNever
248 tmx, tmy, localMatrix, allocator); 248 tmx, tmy, localMatrix, allocator);
249 } 249 }
250 250
251 static sk_sp<SkFlattenable> SkBitmapProcShader_CreateProc(SkReadBuffer& buffer) { 251 static sk_sp<SkFlattenable> SkBitmapProcShader_CreateProc(SkReadBuffer& buffer) {
252 SkMatrix lm; 252 SkMatrix lm;
253 buffer.readMatrix(&lm); 253 buffer.readMatrix(&lm);
254 sk_sp<SkImage> image = buffer.readBitmapAsImage(); 254 sk_sp<SkImage> image = buffer.readBitmapAsImage();
255 SkShader::TileMode mx = (SkShader::TileMode)buffer.readUInt(); 255 SkShader::TileMode mx = (SkShader::TileMode)buffer.readUInt();
256 SkShader::TileMode my = (SkShader::TileMode)buffer.readUInt(); 256 SkShader::TileMode my = (SkShader::TileMode)buffer.readUInt();
257 return image ? image->makeShader(mx, my, &lm) : nullptr; 257 return image ? image->makeShader(mx, my, &lm) : nullptr;
258 } 258 }
259 259
260 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkShader) 260 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkShader)
261 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkImageShader) 261 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkImageShader)
262 SkFlattenable::Register("SkBitmapProcShader", SkBitmapProcShader_CreateProc, kSk Shader_Type); 262 SkFlattenable::Register("SkBitmapProcShader", SkBitmapProcShader_CreateProc, kSk Shader_Type);
263 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 263 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
264 264
OLDNEW
« no previous file with comments | « no previous file | tests/ShaderTest.cpp » ('j') | tests/ShaderTest.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698