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

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

Issue 544233002: "NULL !=" = NULL (Closed) Base URL: https://skia.googlesource.com/skia.git@are
Patch Set: rebase Created 6 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/SkPicturePlayback.cpp ('k') | src/core/SkPictureRecorder.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 2011 Google Inc. 2 * Copyright 2011 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 "SkPictureRecord.h" 8 #include "SkPictureRecord.h"
9 #include "SkBBoxHierarchy.h" 9 #include "SkBBoxHierarchy.h"
10 #include "SkDevice.h" 10 #include "SkDevice.h"
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 */ 183 */
184 return kNoLayer_SaveLayerStrategy; 184 return kNoLayer_SaveLayerStrategy;
185 } 185 }
186 186
187 void SkPictureRecord::recordSaveLayer(const SkRect* bounds, const SkPaint* paint , 187 void SkPictureRecord::recordSaveLayer(const SkRect* bounds, const SkPaint* paint ,
188 SaveFlags flags) { 188 SaveFlags flags) {
189 fContentInfo.onSaveLayer(); 189 fContentInfo.onSaveLayer();
190 190
191 // op + bool for 'bounds' 191 // op + bool for 'bounds'
192 size_t size = 2 * kUInt32Size; 192 size_t size = 2 * kUInt32Size;
193 if (NULL != bounds) { 193 if (bounds) {
194 size += sizeof(*bounds); // + rect 194 size += sizeof(*bounds); // + rect
195 } 195 }
196 // + paint index + flags 196 // + paint index + flags
197 size += 2 * kUInt32Size; 197 size += 2 * kUInt32Size;
198 198
199 SkASSERT(kSaveLayerNoBoundsSize == size || kSaveLayerWithBoundsSize == size) ; 199 SkASSERT(kSaveLayerNoBoundsSize == size || kSaveLayerWithBoundsSize == size) ;
200 200
201 size_t initialOffset = this->addDraw(SAVE_LAYER, &size); 201 size_t initialOffset = this->addDraw(SAVE_LAYER, &size);
202 this->addRectPtr(bounds); 202 this->addRectPtr(bounds);
203 SkASSERT(initialOffset+getPaintOffset(SAVE_LAYER, size) == fWriter.bytesWrit ten()); 203 SkASSERT(initialOffset+getPaintOffset(SAVE_LAYER, size) == fWriter.bytesWrit ten());
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 { remove_save_layer2, kCollapseSaveLayer_OptType, kRescindLastSaveLa yer_Flag } 551 { remove_save_layer2, kCollapseSaveLayer_OptType, kRescindLastSaveLa yer_Flag }
552 }; 552 };
553 553
554 // This is called after an optimization has been applied to the command stream 554 // This is called after an optimization has been applied to the command stream
555 // in order to adjust the contents and state of the bounding box hierarchy and 555 // in order to adjust the contents and state of the bounding box hierarchy and
556 // state tree to reflect the optimization. 556 // state tree to reflect the optimization.
557 static void apply_optimization_to_bbh(PictureRecordOptType opt, SkPictureStateTr ee* stateTree, 557 static void apply_optimization_to_bbh(PictureRecordOptType opt, SkPictureStateTr ee* stateTree,
558 SkBBoxHierarchy* boundingHierarchy) { 558 SkBBoxHierarchy* boundingHierarchy) {
559 switch (opt) { 559 switch (opt) {
560 case kCollapseSaveLayer_OptType: 560 case kCollapseSaveLayer_OptType:
561 if (NULL != stateTree) { 561 if (stateTree) {
562 stateTree->saveCollapsed(); 562 stateTree->saveCollapsed();
563 } 563 }
564 break; 564 break;
565 case kRewind_OptType: 565 case kRewind_OptType:
566 if (NULL != boundingHierarchy) { 566 if (boundingHierarchy) {
567 boundingHierarchy->rewindInserts(); 567 boundingHierarchy->rewindInserts();
568 } 568 }
569 // Note: No need to touch the state tree for this to work correctly. 569 // Note: No need to touch the state tree for this to work correctly.
570 // Unused branches do not burden the playback, and pruning the tree 570 // Unused branches do not burden the playback, and pruning the tree
571 // would be O(N^2), so it is best to leave it alone. 571 // would be O(N^2), so it is best to leave it alone.
572 break; 572 break;
573 default: 573 default:
574 SkASSERT(0); 574 SkASSERT(0);
575 } 575 }
576 } 576 }
(...skipping 12 matching lines...) Expand all
589 } 589 }
590 590
591 if (fRestoreOffsetStack.count() == fFirstSavedLayerIndex) { 591 if (fRestoreOffsetStack.count() == fFirstSavedLayerIndex) {
592 fFirstSavedLayerIndex = kNoSavedLayerIndex; 592 fFirstSavedLayerIndex = kNoSavedLayerIndex;
593 } 593 }
594 594
595 size_t opt = 0; 595 size_t opt = 0;
596 if (fOptsEnabled) { 596 if (fOptsEnabled) {
597 for (opt = 0; opt < SK_ARRAY_COUNT(gPictureRecordOpts); ++opt) { 597 for (opt = 0; opt < SK_ARRAY_COUNT(gPictureRecordOpts); ++opt) {
598 if (0 != (gPictureRecordOpts[opt].fFlags & kSkipIfBBoxHierarchy_Flag ) 598 if (0 != (gPictureRecordOpts[opt].fFlags & kSkipIfBBoxHierarchy_Flag )
599 && NULL != fBoundingHierarchy) { 599 && fBoundingHierarchy) {
600 continue; 600 continue;
601 } 601 }
602 if ((*gPictureRecordOpts[opt].fProc)(&fWriter, fRestoreOffsetStack.t op(), &fPaints)) { 602 if ((*gPictureRecordOpts[opt].fProc)(&fWriter, fRestoreOffsetStack.t op(), &fPaints)) {
603 // Some optimization fired so don't add the RESTORE 603 // Some optimization fired so don't add the RESTORE
604 apply_optimization_to_bbh(gPictureRecordOpts[opt].fType, 604 apply_optimization_to_bbh(gPictureRecordOpts[opt].fType,
605 fStateTree, fBoundingHierarchy); 605 fStateTree, fBoundingHierarchy);
606 if (gPictureRecordOpts[opt].fFlags & kRescindLastSave_Flag) { 606 if (gPictureRecordOpts[opt].fFlags & kRescindLastSave_Flag) {
607 fContentInfo.rescindLastSave(); 607 fContentInfo.rescindLastSave();
608 } else if (gPictureRecordOpts[opt].fFlags & kRescindLastSaveLaye r_Flag) { 608 } else if (gPictureRecordOpts[opt].fFlags & kRescindLastSaveLaye r_Flag) {
609 fContentInfo.rescindLastSaveLayer(); 609 fContentInfo.rescindLastSaveLayer();
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 965
966 void SkPictureRecord::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src, 966 void SkPictureRecord::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src,
967 const SkRect& dst, const SkPaint* pai nt, 967 const SkRect& dst, const SkPaint* pai nt,
968 DrawBitmapRectFlags flags) { 968 DrawBitmapRectFlags flags) {
969 if (bitmap.drawsNothing() && kBeClever) { 969 if (bitmap.drawsNothing() && kBeClever) {
970 return; 970 return;
971 } 971 }
972 972
973 // id + paint index + bitmap index + bool for 'src' + flags 973 // id + paint index + bitmap index + bool for 'src' + flags
974 size_t size = 5 * kUInt32Size; 974 size_t size = 5 * kUInt32Size;
975 if (NULL != src) { 975 if (src) {
976 size += sizeof(*src); // + rect 976 size += sizeof(*src); // + rect
977 } 977 }
978 size += sizeof(dst); // + rect 978 size += sizeof(dst); // + rect
979 979
980 size_t initialOffset = this->addDraw(DRAW_BITMAP_RECT_TO_RECT, &size); 980 size_t initialOffset = this->addDraw(DRAW_BITMAP_RECT_TO_RECT, &size);
981 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_RECT_TO_RECT, size) 981 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_RECT_TO_RECT, size)
982 == fWriter.bytesWritten()); 982 == fWriter.bytesWritten());
983 this->addPaintPtr(paint); 983 this->addPaintPtr(paint);
984 this->addBitmap(bitmap); 984 this->addBitmap(bitmap);
985 this->addRectPtr(src); // may be null 985 this->addRectPtr(src); // may be null
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 uint32_t flags = 0; 1257 uint32_t flags = 0;
1258 if (texs) { 1258 if (texs) {
1259 flags |= DRAW_VERTICES_HAS_TEXS; 1259 flags |= DRAW_VERTICES_HAS_TEXS;
1260 } 1260 }
1261 if (colors) { 1261 if (colors) {
1262 flags |= DRAW_VERTICES_HAS_COLORS; 1262 flags |= DRAW_VERTICES_HAS_COLORS;
1263 } 1263 }
1264 if (indexCount > 0) { 1264 if (indexCount > 0) {
1265 flags |= DRAW_VERTICES_HAS_INDICES; 1265 flags |= DRAW_VERTICES_HAS_INDICES;
1266 } 1266 }
1267 if (NULL != xfer) { 1267 if (xfer) {
1268 SkXfermode::Mode mode; 1268 SkXfermode::Mode mode;
1269 if (xfer->asMode(&mode) && SkXfermode::kModulate_Mode != mode) { 1269 if (xfer->asMode(&mode) && SkXfermode::kModulate_Mode != mode) {
1270 flags |= DRAW_VERTICES_HAS_XFER; 1270 flags |= DRAW_VERTICES_HAS_XFER;
1271 } 1271 }
1272 } 1272 }
1273 1273
1274 // op + paint index + flags + vmode + vCount + vertices 1274 // op + paint index + flags + vmode + vCount + vertices
1275 size_t size = 5 * kUInt32Size + vertexCount * sizeof(SkPoint); 1275 size_t size = 5 * kUInt32Size + vertexCount * sizeof(SkPoint);
1276 if (flags & DRAW_VERTICES_HAS_TEXS) { 1276 if (flags & DRAW_VERTICES_HAS_TEXS) {
1277 size += vertexCount * sizeof(SkPoint); // + uvs 1277 size += vertexCount * sizeof(SkPoint); // + uvs
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1311 } 1311 }
1312 this->validate(initialOffset, size); 1312 this->validate(initialOffset, size);
1313 } 1313 }
1314 1314
1315 void SkPictureRecord::onDrawPatch(const SkPoint cubics[12], const SkColor colors [4], 1315 void SkPictureRecord::onDrawPatch(const SkPoint cubics[12], const SkColor colors [4],
1316 const SkPoint texCoords[4], SkXfermode* xmode, 1316 const SkPoint texCoords[4], SkXfermode* xmode,
1317 const SkPaint& paint) { 1317 const SkPaint& paint) {
1318 // op + paint index + patch 12 control points + flag + patch 4 colors + 4 te xture coordinates 1318 // op + paint index + patch 12 control points + flag + patch 4 colors + 4 te xture coordinates
1319 size_t size = 2 * kUInt32Size + SkPatchUtils::kNumCtrlPts * sizeof(SkPoint) + kUInt32Size; 1319 size_t size = 2 * kUInt32Size + SkPatchUtils::kNumCtrlPts * sizeof(SkPoint) + kUInt32Size;
1320 uint32_t flag = 0; 1320 uint32_t flag = 0;
1321 if (NULL != colors) { 1321 if (colors) {
1322 flag |= DRAW_VERTICES_HAS_COLORS; 1322 flag |= DRAW_VERTICES_HAS_COLORS;
1323 size += SkPatchUtils::kNumCorners * sizeof(SkColor); 1323 size += SkPatchUtils::kNumCorners * sizeof(SkColor);
1324 } 1324 }
1325 if (NULL != texCoords) { 1325 if (texCoords) {
1326 flag |= DRAW_VERTICES_HAS_TEXS; 1326 flag |= DRAW_VERTICES_HAS_TEXS;
1327 size += SkPatchUtils::kNumCorners * sizeof(SkPoint); 1327 size += SkPatchUtils::kNumCorners * sizeof(SkPoint);
1328 } 1328 }
1329 if (NULL != xmode) { 1329 if (xmode) {
1330 SkXfermode::Mode mode; 1330 SkXfermode::Mode mode;
1331 if (xmode->asMode(&mode) && SkXfermode::kModulate_Mode != mode) { 1331 if (xmode->asMode(&mode) && SkXfermode::kModulate_Mode != mode) {
1332 flag |= DRAW_VERTICES_HAS_XFER; 1332 flag |= DRAW_VERTICES_HAS_XFER;
1333 size += kUInt32Size; 1333 size += kUInt32Size;
1334 } 1334 }
1335 } 1335 }
1336 1336
1337 size_t initialOffset = this->addDraw(DRAW_PATCH, &size); 1337 size_t initialOffset = this->addDraw(DRAW_PATCH, &size);
1338 SkASSERT(initialOffset+getPaintOffset(DRAW_PATCH, size) == fWriter.bytesWrit ten()); 1338 SkASSERT(initialOffset+getPaintOffset(DRAW_PATCH, size) == fWriter.bytesWrit ten());
1339 this->addPaint(paint); 1339 this->addPaint(paint);
1340 this->addPatch(cubics); 1340 this->addPatch(cubics);
1341 this->addInt(flag); 1341 this->addInt(flag);
1342 1342
1343 // write optional parameters 1343 // write optional parameters
1344 if (NULL != colors) { 1344 if (colors) {
1345 fWriter.write(colors, SkPatchUtils::kNumCorners * sizeof(SkColor)); 1345 fWriter.write(colors, SkPatchUtils::kNumCorners * sizeof(SkColor));
1346 } 1346 }
1347 if (NULL != texCoords) { 1347 if (texCoords) {
1348 fWriter.write(texCoords, SkPatchUtils::kNumCorners * sizeof(SkPoint)); 1348 fWriter.write(texCoords, SkPatchUtils::kNumCorners * sizeof(SkPoint));
1349 } 1349 }
1350 if (flag & DRAW_VERTICES_HAS_XFER) { 1350 if (flag & DRAW_VERTICES_HAS_XFER) {
1351 SkXfermode::Mode mode = SkXfermode::kModulate_Mode; 1351 SkXfermode::Mode mode = SkXfermode::kModulate_Mode;
1352 xmode->asMode(&mode); 1352 xmode->asMode(&mode);
1353 this->addInt(mode); 1353 this->addInt(mode);
1354 } 1354 }
1355 this->validate(initialOffset, size); 1355 this->validate(initialOffset, size);
1356 } 1356 }
1357 1357
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1549 index = fTextBlobRefs.count(); 1549 index = fTextBlobRefs.count();
1550 *fTextBlobRefs.append() = blob; 1550 *fTextBlobRefs.append() = blob;
1551 blob->ref(); 1551 blob->ref();
1552 } 1552 }
1553 // follow the convention of recording a 1-based index 1553 // follow the convention of recording a 1-based index
1554 this->addInt(index + 1); 1554 this->addInt(index + 1);
1555 } 1555 }
1556 1556
1557 /////////////////////////////////////////////////////////////////////////////// 1557 ///////////////////////////////////////////////////////////////////////////////
1558 1558
OLDNEW
« no previous file with comments | « src/core/SkPicturePlayback.cpp ('k') | src/core/SkPictureRecorder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698