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

Side by Side Diff: src/core/SkPictureShader.cpp

Issue 1316233002: Style Change: NULL->nullptr (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-27 (Thursday) 10:25:06 EDT Created 5 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 | « src/core/SkPictureRecorder.cpp ('k') | src/core/SkPixelRef.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 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 "SkPictureShader.h" 8 #include "SkPictureShader.h"
9 9
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 const char* getCategory() const override { return "bitmap-shader"; } 78 const char* getCategory() const override { return "bitmap-shader"; }
79 SkDiscardableMemory* diagnostic_only_getDiscardable() const override { retur n nullptr; } 79 SkDiscardableMemory* diagnostic_only_getDiscardable() const override { retur n nullptr; }
80 80
81 static bool Visitor(const SkResourceCache::Rec& baseRec, void* contextShader ) { 81 static bool Visitor(const SkResourceCache::Rec& baseRec, void* contextShader ) {
82 const BitmapShaderRec& rec = static_cast<const BitmapShaderRec&>(baseRec ); 82 const BitmapShaderRec& rec = static_cast<const BitmapShaderRec&>(baseRec );
83 SkAutoTUnref<SkShader>* result = reinterpret_cast<SkAutoTUnref<SkShader> *>(contextShader); 83 SkAutoTUnref<SkShader>* result = reinterpret_cast<SkAutoTUnref<SkShader> *>(contextShader);
84 84
85 result->reset(SkRef(rec.fShader.get())); 85 result->reset(SkRef(rec.fShader.get()));
86 86
87 SkBitmap tile; 87 SkBitmap tile;
88 if (rec.fShader.get()->isABitmap(&tile, NULL, NULL)) { 88 if (rec.fShader.get()->isABitmap(&tile, nullptr, nullptr)) {
89 // FIXME: this doesn't protect the pixels from being discarded as so on as we unlock. 89 // FIXME: this doesn't protect the pixels from being discarded as so on as we unlock.
90 // Should be handled via a pixel ref generator instead 90 // Should be handled via a pixel ref generator instead
91 // (https://code.google.com/p/skia/issues/detail?id=3220). 91 // (https://code.google.com/p/skia/issues/detail?id=3220).
92 SkAutoLockPixels alp(tile, true); 92 SkAutoLockPixels alp(tile, true);
93 return tile.getPixels() != NULL; 93 return tile.getPixels() != nullptr;
94 } 94 }
95 return false; 95 return false;
96 } 96 }
97 }; 97 };
98 98
99 static bool cache_try_alloc_pixels(SkBitmap* bitmap) { 99 static bool cache_try_alloc_pixels(SkBitmap* bitmap) {
100 SkBitmap::Allocator* allocator = SkResourceCache::GetAllocator(); 100 SkBitmap::Allocator* allocator = SkResourceCache::GetAllocator();
101 101
102 return NULL != allocator 102 return nullptr != allocator
103 ? allocator->allocPixelRef(bitmap, NULL) 103 ? allocator->allocPixelRef(bitmap, nullptr)
104 : bitmap->tryAllocPixels(); 104 : bitmap->tryAllocPixels();
105 } 105 }
106 106
107 } // namespace 107 } // namespace
108 108
109 SkPictureShader::SkPictureShader(const SkPicture* picture, TileMode tmx, TileMod e tmy, 109 SkPictureShader::SkPictureShader(const SkPicture* picture, TileMode tmx, TileMod e tmy,
110 const SkMatrix* localMatrix, const SkRect* tile ) 110 const SkMatrix* localMatrix, const SkRect* tile )
111 : INHERITED(localMatrix) 111 : INHERITED(localMatrix)
112 , fPicture(SkRef(picture)) 112 , fPicture(SkRef(picture))
113 , fTile(tile ? *tile : picture->cullRect()) 113 , fTile(tile ? *tile : picture->cullRect())
(...skipping 20 matching lines...) Expand all
134 TileMode my = (TileMode)buffer.read32(); 134 TileMode my = (TileMode)buffer.read32();
135 SkRect tile; 135 SkRect tile;
136 buffer.readRect(&tile); 136 buffer.readRect(&tile);
137 137
138 SkAutoTUnref<SkPicture> picture; 138 SkAutoTUnref<SkPicture> picture;
139 139
140 if (buffer.isCrossProcess() && SkPicture::PictureIOSecurityPrecautionsEnable d()) { 140 if (buffer.isCrossProcess() && SkPicture::PictureIOSecurityPrecautionsEnable d()) {
141 if (buffer.isVersionLT(SkReadBuffer::kPictureShaderHasPictureBool_Versio n)) { 141 if (buffer.isVersionLT(SkReadBuffer::kPictureShaderHasPictureBool_Versio n)) {
142 // Older code blindly serialized pictures. We don't trust them. 142 // Older code blindly serialized pictures. We don't trust them.
143 buffer.validate(false); 143 buffer.validate(false);
144 return NULL; 144 return nullptr;
145 } 145 }
146 // Newer code won't serialize pictures in disallow-cross-process-picture mode. 146 // Newer code won't serialize pictures in disallow-cross-process-picture mode.
147 // Assert that they didn't serialize anything except a false here. 147 // Assert that they didn't serialize anything except a false here.
148 buffer.validate(!buffer.readBool()); 148 buffer.validate(!buffer.readBool());
149 } else { 149 } else {
150 // Old code always serialized the picture. New code writes a 'true' fir st if it did. 150 // Old code always serialized the picture. New code writes a 'true' fir st if it did.
151 if (buffer.isVersionLT(SkReadBuffer::kPictureShaderHasPictureBool_Versio n) || 151 if (buffer.isVersionLT(SkReadBuffer::kPictureShaderHasPictureBool_Versio n) ||
152 buffer.readBool()) { 152 buffer.readBool()) {
153 picture.reset(SkPicture::CreateFromBuffer(buffer)); 153 picture.reset(SkPicture::CreateFromBuffer(buffer));
154 } 154 }
(...skipping 25 matching lines...) Expand all
180 m.setConcat(matrix, this->getLocalMatrix()); 180 m.setConcat(matrix, this->getLocalMatrix());
181 if (localM) { 181 if (localM) {
182 m.preConcat(*localM); 182 m.preConcat(*localM);
183 } 183 }
184 184
185 // Use a rotation-invariant scale 185 // Use a rotation-invariant scale
186 SkPoint scale; 186 SkPoint scale;
187 // 187 //
188 // TODO: replace this with decomposeScale() -- but beware LayoutTest rebasel ines! 188 // TODO: replace this with decomposeScale() -- but beware LayoutTest rebasel ines!
189 // 189 //
190 if (!SkDecomposeUpper2x2(m, NULL, &scale, NULL)) { 190 if (!SkDecomposeUpper2x2(m, nullptr, &scale, nullptr)) {
191 // Decomposition failed, use an approximation. 191 // Decomposition failed, use an approximation.
192 scale.set(SkScalarSqrt(m.getScaleX() * m.getScaleX() + m.getSkewX() * m. getSkewX()), 192 scale.set(SkScalarSqrt(m.getScaleX() * m.getScaleX() + m.getSkewX() * m. getSkewX()),
193 SkScalarSqrt(m.getScaleY() * m.getScaleY() + m.getSkewY() * m. getSkewY())); 193 SkScalarSqrt(m.getScaleY() * m.getScaleY() + m.getSkewY() * m. getSkewY()));
194 } 194 }
195 SkSize scaledSize = SkSize::Make(SkScalarAbs(scale.x() * fTile.width()), 195 SkSize scaledSize = SkSize::Make(SkScalarAbs(scale.x() * fTile.width()),
196 SkScalarAbs(scale.y() * fTile.height())); 196 SkScalarAbs(scale.y() * fTile.height()));
197 197
198 // Clamp the tile size to about 4M pixels 198 // Clamp the tile size to about 4M pixels
199 static const SkScalar kMaxTileArea = 2048 * 2048; 199 static const SkScalar kMaxTileArea = 2048 * 2048;
200 SkScalar tileArea = SkScalarMul(scaledSize.width(), scaledSize.height()); 200 SkScalar tileArea = SkScalarMul(scaledSize.width(), scaledSize.height());
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 255
256 return tileShader.detach(); 256 return tileShader.detach();
257 } 257 }
258 258
259 size_t SkPictureShader::contextSize() const { 259 size_t SkPictureShader::contextSize() const {
260 return sizeof(PictureShaderContext); 260 return sizeof(PictureShaderContext);
261 } 261 }
262 262
263 SkShader::Context* SkPictureShader::onCreateContext(const ContextRec& rec, void* storage) const { 263 SkShader::Context* SkPictureShader::onCreateContext(const ContextRec& rec, void* storage) const {
264 SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(*rec.fMatrix, rec. fLocalMatrix)); 264 SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(*rec.fMatrix, rec. fLocalMatrix));
265 if (NULL == bitmapShader.get()) { 265 if (nullptr == bitmapShader.get()) {
266 return NULL; 266 return nullptr;
267 } 267 }
268 return PictureShaderContext::Create(storage, *this, rec, bitmapShader); 268 return PictureShaderContext::Create(storage, *this, rec, bitmapShader);
269 } 269 }
270 270
271 //////////////////////////////////////////////////////////////////////////////// ///////// 271 //////////////////////////////////////////////////////////////////////////////// /////////
272 272
273 SkShader::Context* SkPictureShader::PictureShaderContext::Create(void* storage, 273 SkShader::Context* SkPictureShader::PictureShaderContext::Create(void* storage,
274 const SkPictureShader& shader, const ContextRec& rec, SkShade r* bitmapShader) { 274 const SkPictureShader& shader, const ContextRec& rec, SkShade r* bitmapShader) {
275 PictureShaderContext* ctx = new (storage) PictureShaderContext(shader, rec, bitmapShader); 275 PictureShaderContext* ctx = new (storage) PictureShaderContext(shader, rec, bitmapShader);
276 if (NULL == ctx->fBitmapShaderContext) { 276 if (nullptr == ctx->fBitmapShaderContext) {
277 ctx->~PictureShaderContext(); 277 ctx->~PictureShaderContext();
278 ctx = NULL; 278 ctx = nullptr;
279 } 279 }
280 return ctx; 280 return ctx;
281 } 281 }
282 282
283 SkPictureShader::PictureShaderContext::PictureShaderContext( 283 SkPictureShader::PictureShaderContext::PictureShaderContext(
284 const SkPictureShader& shader, const ContextRec& rec, SkShader* bitmapSh ader) 284 const SkPictureShader& shader, const ContextRec& rec, SkShader* bitmapSh ader)
285 : INHERITED(shader, rec) 285 : INHERITED(shader, rec)
286 , fBitmapShader(SkRef(bitmapShader)) 286 , fBitmapShader(SkRef(bitmapShader))
287 { 287 {
288 fBitmapShaderContextStorage = sk_malloc_throw(bitmapShader->contextSize()); 288 fBitmapShaderContextStorage = sk_malloc_throw(bitmapShader->contextSize());
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 GrProcessorDataManager* procDataManage r, 342 GrProcessorDataManager* procDataManage r,
343 GrFragmentProcessor** fp) const { 343 GrFragmentProcessor** fp) const {
344 int maxTextureSize = 0; 344 int maxTextureSize = 0;
345 if (context) { 345 if (context) {
346 maxTextureSize = context->caps()->maxTextureSize(); 346 maxTextureSize = context->caps()->maxTextureSize();
347 } 347 }
348 SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(viewM, localMatrix , maxTextureSize)); 348 SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(viewM, localMatrix , maxTextureSize));
349 if (!bitmapShader) { 349 if (!bitmapShader) {
350 return false; 350 return false;
351 } 351 }
352 return bitmapShader->asFragmentProcessor(context, paint, viewM, NULL, paintC olor, 352 return bitmapShader->asFragmentProcessor(context, paint, viewM, nullptr, pai ntColor,
353 procDataManager, fp); 353 procDataManager, fp);
354 } 354 }
355 #else 355 #else
356 bool SkPictureShader::asFragmentProcessor(GrContext*, const SkPaint&, const SkMa trix&, 356 bool SkPictureShader::asFragmentProcessor(GrContext*, const SkPaint&, const SkMa trix&,
357 const SkMatrix*, GrColor*, GrProcessor DataManager*, 357 const SkMatrix*, GrColor*, GrProcessor DataManager*,
358 GrFragmentProcessor**) const { 358 GrFragmentProcessor**) const {
359 SkDEBUGFAIL("Should not call in GPU-less build"); 359 SkDEBUGFAIL("Should not call in GPU-less build");
360 return false; 360 return false;
361 } 361 }
362 #endif 362 #endif
OLDNEW
« no previous file with comments | « src/core/SkPictureRecorder.cpp ('k') | src/core/SkPixelRef.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698