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

Side by Side Diff: src/pipe/SkGPipeWrite.cpp

Issue 283093002: Reland bug fixes from "4x allocation in PipeController is probably overkill." (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update-test Created 6 years, 7 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/DeferredCanvasTest.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 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "SkAnnotation.h" 9 #include "SkAnnotation.h"
10 #include "SkBitmapDevice.h" 10 #include "SkBitmapDevice.h"
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 }; 359 };
360 friend class AutoPipeNotify; 360 friend class AutoPipeNotify;
361 361
362 typedef SkCanvas INHERITED; 362 typedef SkCanvas INHERITED;
363 }; 363 };
364 364
365 void SkGPipeCanvas::flattenFactoryNames() { 365 void SkGPipeCanvas::flattenFactoryNames() {
366 const char* name; 366 const char* name;
367 while ((name = fFactorySet->getNextAddedFactoryName()) != NULL) { 367 while ((name = fFactorySet->getNextAddedFactoryName()) != NULL) {
368 size_t len = strlen(name); 368 size_t len = strlen(name);
369 if (this->needOpBytes(len)) { 369 if (this->needOpBytes(SkWriter32::WriteStringSize(name, len))) {
370 this->writeOp(kDef_Factory_DrawOp); 370 this->writeOp(kDef_Factory_DrawOp);
371 fWriter.writeString(name, len); 371 fWriter.writeString(name, len);
372 } 372 }
373 } 373 }
374 } 374 }
375 375
376 bool SkGPipeCanvas::shuttleBitmap(const SkBitmap& bm, int32_t slot) { 376 bool SkGPipeCanvas::shuttleBitmap(const SkBitmap& bm, int32_t slot) {
377 SkASSERT(shouldFlattenBitmaps(fFlags)); 377 SkASSERT(shouldFlattenBitmaps(fFlags));
378 SkWriteBuffer buffer; 378 SkWriteBuffer buffer;
379 buffer.setNamedFactoryRecorder(fFactorySet); 379 buffer.setNamedFactoryRecorder(fFactorySet);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 SkSafeUnref(fFactorySet); 467 SkSafeUnref(fFactorySet);
468 SkSafeUnref(fBitmapHeap); 468 SkSafeUnref(fBitmapHeap);
469 } 469 }
470 470
471 bool SkGPipeCanvas::needOpBytes(size_t needed) { 471 bool SkGPipeCanvas::needOpBytes(size_t needed) {
472 if (fDone) { 472 if (fDone) {
473 return false; 473 return false;
474 } 474 }
475 475
476 needed += 4; // size of DrawOp atom 476 needed += 4; // size of DrawOp atom
477 needed = SkTMax<size_t>(MIN_BLOCK_SIZE, needed);
478 needed = SkAlign4(needed);
477 if (fWriter.bytesWritten() + needed > fBlockSize) { 479 if (fWriter.bytesWritten() + needed > fBlockSize) {
478 // Before we wipe out any data that has already been written, read it 480 // Before we wipe out any data that has already been written, read it
479 // out. 481 // out.
480 this->doNotify(); 482 this->doNotify();
481 size_t blockSize = SkTMax<size_t>(MIN_BLOCK_SIZE, needed); 483 void* block = fController->requestBlock(needed, &fBlockSize);
482 void* block = fController->requestBlock(blockSize, &fBlockSize);
483 if (NULL == block) { 484 if (NULL == block) {
484 // Do not notify the readers, which would call this function again. 485 // Do not notify the readers, which would call this function again.
485 this->finish(false); 486 this->finish(false);
486 return false; 487 return false;
487 } 488 }
488 SkASSERT(SkIsAlign4(fBlockSize)); 489 SkASSERT(SkIsAlign4(fBlockSize));
489 fWriter.reset(block, fBlockSize); 490 fWriter.reset(block, fBlockSize);
490 fBytesNotified = 0; 491 fBytesNotified = 0;
491 } 492 }
492 return true; 493 return true;
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
929 void SkGPipeCanvas::drawVertices(VertexMode vmode, int vertexCount, 930 void SkGPipeCanvas::drawVertices(VertexMode vmode, int vertexCount,
930 const SkPoint vertices[], const SkPoint texs[], 931 const SkPoint vertices[], const SkPoint texs[],
931 const SkColor colors[], SkXfermode* xfer, 932 const SkColor colors[], SkXfermode* xfer,
932 const uint16_t indices[], int indexCount, 933 const uint16_t indices[], int indexCount,
933 const SkPaint& paint) { 934 const SkPaint& paint) {
934 if (0 == vertexCount) { 935 if (0 == vertexCount) {
935 return; 936 return;
936 } 937 }
937 938
938 NOTIFY_SETUP(this); 939 NOTIFY_SETUP(this);
939 size_t size = 4 + vertexCount * sizeof(SkPoint);
940 this->writePaint(paint); 940 this->writePaint(paint);
941 unsigned flags = 0; 941
942 unsigned flags = 0; // packs with the op, so needs no extra space
943
944 size_t size = 0;
945 size += 4; // vmode
946 size += 4; // vertex count
947 size += vertexCount * sizeof(SkPoint); // vertices
948
942 if (texs) { 949 if (texs) {
943 flags |= kDrawVertices_HasTexs_DrawOpFlag; 950 flags |= kDrawVertices_HasTexs_DrawOpFlag;
944 size += vertexCount * sizeof(SkPoint); 951 size += vertexCount * sizeof(SkPoint);
945 } 952 }
946 if (colors) { 953 if (colors) {
947 flags |= kDrawVertices_HasColors_DrawOpFlag; 954 flags |= kDrawVertices_HasColors_DrawOpFlag;
948 size += vertexCount * sizeof(SkColor); 955 size += vertexCount * sizeof(SkColor);
949 } 956 }
957 if (xfer && !SkXfermode::IsMode(xfer, SkXfermode::kModulate_Mode)) {
958 flags |= kDrawVertices_HasXfermode_DrawOpFlag;
959 size += sizeof(int32_t); // SkXfermode::Mode
960 }
950 if (indices && indexCount > 0) { 961 if (indices && indexCount > 0) {
951 flags |= kDrawVertices_HasIndices_DrawOpFlag; 962 flags |= kDrawVertices_HasIndices_DrawOpFlag;
952 size += 4 + SkAlign4(indexCount * sizeof(uint16_t)); 963 size += 4; // index count
953 } 964 size += SkAlign4(indexCount * sizeof(uint16_t)); // indices
954 if (xfer && !SkXfermode::IsMode(xfer, SkXfermode::kModulate_Mode)) {
955 flags |= kDrawVertices_HasXfermode_DrawOpFlag;
956 size += sizeof(int32_t); // mode enum
957 } 965 }
958 966
959 if (this->needOpBytes(size)) { 967 if (this->needOpBytes(size)) {
960 this->writeOp(kDrawVertices_DrawOp, flags, 0); 968 this->writeOp(kDrawVertices_DrawOp, flags, 0);
961 fWriter.write32(vmode); 969 fWriter.write32(vmode);
962 fWriter.write32(vertexCount); 970 fWriter.write32(vertexCount);
963 fWriter.write(vertices, vertexCount * sizeof(SkPoint)); 971 fWriter.write(vertices, vertexCount * sizeof(SkPoint));
964 if (texs) { 972 if (flags & kDrawVertices_HasTexs_DrawOpFlag) {
965 fWriter.write(texs, vertexCount * sizeof(SkPoint)); 973 fWriter.write(texs, vertexCount * sizeof(SkPoint));
966 } 974 }
967 if (colors) { 975 if (flags & kDrawVertices_HasColors_DrawOpFlag) {
968 fWriter.write(colors, vertexCount * sizeof(SkColor)); 976 fWriter.write(colors, vertexCount * sizeof(SkColor));
969 } 977 }
970 if (flags & kDrawVertices_HasXfermode_DrawOpFlag) { 978 if (flags & kDrawVertices_HasXfermode_DrawOpFlag) {
971 SkXfermode::Mode mode = SkXfermode::kModulate_Mode; 979 SkXfermode::Mode mode = SkXfermode::kModulate_Mode;
972 (void)xfer->asMode(&mode); 980 SkAssertResult(xfer->asMode(&mode));
973 fWriter.write32(mode); 981 fWriter.write32(mode);
974 } 982 }
975 if (indices && indexCount > 0) { 983 if (flags & kDrawVertices_HasIndices_DrawOpFlag) {
976 fWriter.write32(indexCount); 984 fWriter.write32(indexCount);
977 fWriter.writePad(indices, indexCount * sizeof(uint16_t)); 985 fWriter.writePad(indices, indexCount * sizeof(uint16_t));
978 } 986 }
979 } 987 }
980 } 988 }
981 989
982 void SkGPipeCanvas::drawData(const void* ptr, size_t size) { 990 void SkGPipeCanvas::drawData(const void* ptr, size_t size) {
983 if (size && ptr) { 991 if (size && ptr) {
984 NOTIFY_SETUP(this); 992 NOTIFY_SETUP(this);
985 unsigned data = 0; 993 unsigned data = 0;
(...skipping 16 matching lines...) Expand all
1002 1010
1003 void SkGPipeCanvas::addComment(const char* kywd, const char* value) { 1011 void SkGPipeCanvas::addComment(const char* kywd, const char* value) {
1004 // ignore for now 1012 // ignore for now
1005 } 1013 }
1006 1014
1007 void SkGPipeCanvas::endCommentGroup() { 1015 void SkGPipeCanvas::endCommentGroup() {
1008 // ignore for now 1016 // ignore for now
1009 } 1017 }
1010 1018
1011 void SkGPipeCanvas::flushRecording(bool detachCurrentBlock) { 1019 void SkGPipeCanvas::flushRecording(bool detachCurrentBlock) {
1012 doNotify(); 1020 this->doNotify();
1013 if (detachCurrentBlock) { 1021 if (detachCurrentBlock) {
1014 // force a new block to be requested for the next recorded command 1022 // force a new block to be requested for the next recorded command
1015 fBlockSize = 0; 1023 fBlockSize = 0;
1016 } 1024 }
1017 } 1025 }
1018 1026
1019 size_t SkGPipeCanvas::freeMemoryIfPossible(size_t bytesToFree) { 1027 size_t SkGPipeCanvas::freeMemoryIfPossible(size_t bytesToFree) {
1020 return (NULL == fBitmapHeap) ? 0 : fBitmapHeap->freeMemoryIfPossible(bytesTo Free); 1028 return (NULL == fBitmapHeap) ? 0 : fBitmapHeap->freeMemoryIfPossible(bytesTo Free);
1021 } 1029 }
1022 1030
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 return fCanvas->shuttleBitmap(bitmap, slot); 1250 return fCanvas->shuttleBitmap(bitmap, slot);
1243 } 1251 }
1244 1252
1245 void BitmapShuttle::removeCanvas() { 1253 void BitmapShuttle::removeCanvas() {
1246 if (NULL == fCanvas) { 1254 if (NULL == fCanvas) {
1247 return; 1255 return;
1248 } 1256 }
1249 fCanvas->unref(); 1257 fCanvas->unref();
1250 fCanvas = NULL; 1258 fCanvas = NULL;
1251 } 1259 }
OLDNEW
« no previous file with comments | « no previous file | tests/DeferredCanvasTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698