Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| 11 #include "SkBitmapHeap.h" | 11 #include "SkBitmapHeap.h" |
| 12 #include "SkCanvas.h" | 12 #include "SkCanvas.h" |
| 13 #include "SkColorFilter.h" | 13 #include "SkColorFilter.h" |
| 14 #include "SkData.h" | 14 #include "SkData.h" |
| 15 #include "SkDrawLooper.h" | 15 #include "SkDrawLooper.h" |
| 16 #include "SkGPipe.h" | 16 #include "SkGPipe.h" |
| 17 #include "SkGPipePriv.h" | 17 #include "SkGPipePriv.h" |
| 18 #include "SkImageFilter.h" | 18 #include "SkImageFilter.h" |
| 19 #include "SkMaskFilter.h" | 19 #include "SkMaskFilter.h" |
| 20 #include "SkWriteBuffer.h" | 20 #include "SkWriteBuffer.h" |
| 21 #include "SkPaint.h" | 21 #include "SkPaint.h" |
| 22 #include "SkPatchUtils.h" | 22 #include "SkPatchUtils.h" |
| 23 #include "SkPathEffect.h" | 23 #include "SkPathEffect.h" |
| 24 #include "SkPictureFlat.h" | 24 #include "SkPictureFlat.h" |
| 25 #include "SkPtrRecorder.h" | |
| 25 #include "SkRasterizer.h" | 26 #include "SkRasterizer.h" |
| 26 #include "SkRRect.h" | 27 #include "SkRRect.h" |
| 27 #include "SkShader.h" | 28 #include "SkShader.h" |
| 28 #include "SkStream.h" | 29 #include "SkStream.h" |
| 29 #include "SkTextBlob.h" | 30 #include "SkTextBlob.h" |
| 30 #include "SkTSearch.h" | 31 #include "SkTSearch.h" |
| 31 #include "SkTypeface.h" | 32 #include "SkTypeface.h" |
| 32 #include "SkWriter32.h" | 33 #include "SkWriter32.h" |
| 33 | 34 |
| 34 enum { | 35 enum { |
| 35 kSizeOfFlatRRect = sizeof(SkRect) + 4 * sizeof(SkVector) | 36 kSizeOfFlatRRect = sizeof(SkRect) + 4 * sizeof(SkVector) |
| 36 }; | 37 }; |
| 37 | 38 |
|
robertphillips
2014/09/15 18:13:03
is_cross_process ?
f(malita)
2014/09/15 21:51:19
Done.
| |
| 38 static bool isCrossProcess(uint32_t flags) { | 39 static bool isCrossProcess(uint32_t flags) { |
| 39 return SkToBool(flags & SkGPipeWriter::kCrossProcess_Flag); | 40 return SkToBool(flags & SkGPipeWriter::kCrossProcess_Flag); |
| 40 } | 41 } |
| 41 | 42 |
| 42 static SkFlattenable* get_paintflat(const SkPaint& paint, unsigned paintFlat) { | 43 static SkFlattenable* get_paintflat(const SkPaint& paint, unsigned paintFlat) { |
| 43 SkASSERT(paintFlat < kCount_PaintFlats); | 44 SkASSERT(paintFlat < kCount_PaintFlats); |
| 44 switch (paintFlat) { | 45 switch (paintFlat) { |
| 45 case kColorFilter_PaintFlat: return paint.getColorFilter(); | 46 case kColorFilter_PaintFlat: return paint.getColorFilter(); |
| 46 case kDrawLooper_PaintFlat: return paint.getLooper(); | 47 case kDrawLooper_PaintFlat: return paint.getLooper(); |
| 47 case kMaskFilter_PaintFlat: return paint.getMaskFilter(); | 48 case kMaskFilter_PaintFlat: return paint.getMaskFilter(); |
| (...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 937 } | 938 } |
| 938 } | 939 } |
| 939 } | 940 } |
| 940 | 941 |
| 941 void SkGPipeCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, | 942 void SkGPipeCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, |
| 942 const SkPaint& paint) { | 943 const SkPaint& paint) { |
| 943 NOTIFY_SETUP(this); | 944 NOTIFY_SETUP(this); |
| 944 this->writePaint(paint); | 945 this->writePaint(paint); |
| 945 | 946 |
| 946 // FIXME: this is inefficient but avoids duplicating the blob serialization logic. | 947 // FIXME: this is inefficient but avoids duplicating the blob serialization logic. |
| 948 SkRefCntSet typefaceSet; | |
| 947 SkWriteBuffer blobBuffer; | 949 SkWriteBuffer blobBuffer; |
| 950 blobBuffer.setTypefaceRecorder(&typefaceSet); | |
| 948 blob->flatten(blobBuffer); | 951 blob->flatten(blobBuffer); |
| 949 | 952 |
| 950 size_t size = sizeof(uint32_t) + 2 * sizeof(SkScalar) + blobBuffer.bytesWrit ten(); | 953 // Unlike most draw ops (which only use one paint/typeface), text blobs may reference |
| 954 // an arbitrary number of typefaces. Since the one-paint-per-op model is not applicable, | |
| 955 // we need to serialize these explicitly. | |
| 956 int typefaceCount = typefaceSet.count(); | |
| 957 size_t typefaceSize = isCrossProcess(fFlags) ? sizeof(uint32_t) : sizeof(voi d*); | |
| 958 SkAutoSTMalloc<16, SkTypeface*> storage(typefaceCount); | |
| 959 SkTypeface** array = storage.get(); | |
| 960 typefaceSet.copyToArray((SkRefCnt**)array); | |
| 961 | |
| 962 // We need to convert to IDs before we start writing the blob as the lookup may write out | |
| 963 // kDef_Typeface_DrawOp blocks for new typefaces. | |
| 964 if (isCrossProcess(fFlags)) { | |
| 965 uint32_t* typefaceIDs = reinterpret_cast<uint32_t*>(array); | |
| 966 for (int i = 0; i < typefaceCount; ++i) { | |
| 967 // This overlaps/overrides 'array', but should be safe given | |
| 968 // that sizeof(uint32_t) <= sizeof(SkTypeface*) | |
| 969 typefaceIDs[i] = this->getTypefaceID(array[i]); | |
|
mtklein
2014/09/12 23:09:29
I can't help but think that if onDrawTextBlob() lo
reed1
2014/09/15 14:13:39
Hmm, seems like most of this function is common w/
f(malita)
2014/09/15 21:51:19
Added a couple of helpers to munge the typeface bu
| |
| 970 } | |
| 971 } | |
| 972 | |
| 973 // blob byte count + typeface count + x + y + blob data + an index (cross-pr ocess) | |
| 974 // or pointer (in-process) for each typeface | |
| 975 size_t size = 2 * sizeof(uint32_t) | |
| 976 + 2 * sizeof(SkScalar) | |
| 977 + blobBuffer.bytesWritten() | |
| 978 + typefaceCount * typefaceSize; | |
| 979 | |
| 951 if (this->needOpBytes(size)) { | 980 if (this->needOpBytes(size)) { |
| 952 this->writeOp(kDrawTextBlob_DrawOp); | 981 this->writeOp(kDrawTextBlob_DrawOp); |
| 982 size_t initialOffset = fWriter.bytesWritten(); | |
| 983 | |
| 953 fWriter.writeScalar(x); | 984 fWriter.writeScalar(x); |
| 954 fWriter.writeScalar(y); | 985 fWriter.writeScalar(y); |
| 986 | |
| 987 fWriter.write32(typefaceCount); | |
| 988 fWriter.write(array, typefaceCount * typefaceSize); | |
| 989 | |
| 955 fWriter.write32(SkToU32(blobBuffer.bytesWritten())); | 990 fWriter.write32(SkToU32(blobBuffer.bytesWritten())); |
| 956 uint32_t* pad = fWriter.reservePad(blobBuffer.bytesWritten()); | 991 uint32_t* pad = fWriter.reservePad(blobBuffer.bytesWritten()); |
| 957 blobBuffer.writeToMemory(pad); | 992 blobBuffer.writeToMemory(pad); |
| 993 | |
| 994 SkASSERT(initialOffset + size == fWriter.bytesWritten()); | |
| 958 } | 995 } |
| 959 } | 996 } |
| 960 | 997 |
| 961 void SkGPipeCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix* matr ix, | 998 void SkGPipeCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix* matr ix, |
| 962 const SkPaint* paint) { | 999 const SkPaint* paint) { |
| 963 // we want to playback the picture into individual draw calls | 1000 // we want to playback the picture into individual draw calls |
| 964 // | 1001 // |
| 965 // todo: do we always have to unroll? If the pipe is not cross-process, seem s like | 1002 // todo: do we always have to unroll? If the pipe is not cross-process, seem s like |
| 966 // we could just ref the picture and move on...? <reed, scroggo> | 1003 // we could just ref the picture and move on...? <reed, scroggo> |
| 967 // | 1004 // |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1336 return fCanvas->shuttleBitmap(bitmap, slot); | 1373 return fCanvas->shuttleBitmap(bitmap, slot); |
| 1337 } | 1374 } |
| 1338 | 1375 |
| 1339 void BitmapShuttle::removeCanvas() { | 1376 void BitmapShuttle::removeCanvas() { |
| 1340 if (NULL == fCanvas) { | 1377 if (NULL == fCanvas) { |
| 1341 return; | 1378 return; |
| 1342 } | 1379 } |
| 1343 fCanvas->unref(); | 1380 fCanvas->unref(); |
| 1344 fCanvas = NULL; | 1381 fCanvas = NULL; |
| 1345 } | 1382 } |
| OLD | NEW |