OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkBBoxHierarchy.h" | 8 #include "SkBBoxHierarchy.h" |
9 #include "SkBlurImageFilter.h" | 9 #include "SkBlurImageFilter.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
11 #include "SkColorMatrixFilter.h" | 11 #include "SkColorMatrixFilter.h" |
12 #include "SkColorPriv.h" | 12 #include "SkColorPriv.h" |
13 #include "SkDashPathEffect.h" | 13 #include "SkDashPathEffect.h" |
14 #include "SkData.h" | 14 #include "SkData.h" |
15 #include "SkDecodingImageGenerator.h" | 15 #include "SkDecodingImageGenerator.h" |
16 #include "SkError.h" | 16 #include "SkError.h" |
17 #include "SkImageEncoder.h" | 17 #include "SkImageEncoder.h" |
18 #include "SkImageGenerator.h" | 18 #include "SkImageGenerator.h" |
19 #include "SkLayerInfo.h" | 19 #include "SkLayerInfo.h" |
20 #include "SkPaint.h" | 20 #include "SkPaint.h" |
21 #include "SkPicture.h" | 21 #include "SkPicture.h" |
22 #include "SkPictureRecorder.h" | 22 #include "SkPictureRecorder.h" |
23 #include "SkPictureUtils.h" | 23 #include "SkPictureUtils.h" |
24 #include "SkPixelRef.h" | 24 #include "SkPixelRef.h" |
25 #include "SkPixelSerializer.h" | |
26 #include "SkRRect.h" | 25 #include "SkRRect.h" |
27 #include "SkRandom.h" | 26 #include "SkRandom.h" |
28 #include "SkRecord.h" | 27 #include "SkRecord.h" |
29 #include "SkShader.h" | 28 #include "SkShader.h" |
30 #include "SkStream.h" | 29 #include "SkStream.h" |
31 | 30 |
32 #if SK_SUPPORT_GPU | 31 #if SK_SUPPORT_GPU |
33 #include "SkSurface.h" | 32 #include "SkSurface.h" |
34 #include "GrContextFactory.h" | 33 #include "GrContextFactory.h" |
35 #endif | 34 #endif |
(...skipping 1400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1436 SkPictureRecorder recorder; | 1435 SkPictureRecorder recorder; |
1437 SkCanvas* recordingCanvas = recorder.beginRecording(100, 100); | 1436 SkCanvas* recordingCanvas = recorder.beginRecording(100, 100); |
1438 recordingCanvas->drawBitmap(bm, 0, 0); | 1437 recordingCanvas->drawBitmap(bm, 0, 0); |
1439 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 1438 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
1440 | 1439 |
1441 SkCanvas canvas; | 1440 SkCanvas canvas; |
1442 canvas.drawPicture(picture); | 1441 canvas.drawPicture(picture); |
1443 } | 1442 } |
1444 #endif | 1443 #endif |
1445 | 1444 |
1446 // Encodes to PNG, unless there is already encoded data, in which case that gets | 1445 static SkData* encode_bitmap_to_data(size_t*, const SkBitmap& bm) { |
1447 // used. | 1446 return SkImageEncoder::EncodeData(bm, SkImageEncoder::kPNG_Type, 100); |
1448 // FIXME: Share with PictureRenderer.cpp? | 1447 } |
1449 class PngPixelSerializer : public SkPixelSerializer { | |
1450 public: | |
1451 virtual bool onUseEncodedData(const void*, size_t) SK_OVERRIDE { return true
; } | |
1452 virtual SkData* onEncodePixels(const SkImageInfo& info, void* pixels, | |
1453 size_t rowBytes) SK_OVERRIDE { | |
1454 SkBitmap bm; | |
1455 if (!bm.installPixels(info, pixels, rowBytes)) { | |
1456 return NULL; | |
1457 } | |
1458 return SkImageEncoder::EncodeData(bm, SkImageEncoder::kPNG_Type, 100); | |
1459 } | |
1460 }; | |
1461 | 1448 |
1462 static SkData* serialized_picture_from_bitmap(const SkBitmap& bitmap) { | 1449 static SkData* serialized_picture_from_bitmap(const SkBitmap& bitmap) { |
1463 SkPictureRecorder recorder; | 1450 SkPictureRecorder recorder; |
1464 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(bitmap.width()), | 1451 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(bitmap.width()), |
1465 SkIntToScalar(bitmap.height())); | 1452 SkIntToScalar(bitmap.height())); |
1466 canvas->drawBitmap(bitmap, 0, 0); | 1453 canvas->drawBitmap(bitmap, 0, 0); |
1467 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 1454 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
1468 | 1455 |
1469 SkDynamicMemoryWStream wStream; | 1456 SkDynamicMemoryWStream wStream; |
1470 PngPixelSerializer serializer; | 1457 picture->serialize(&wStream, &encode_bitmap_to_data); |
1471 picture->serialize(&wStream, &serializer); | |
1472 return wStream.copyToData(); | 1458 return wStream.copyToData(); |
1473 } | 1459 } |
1474 | 1460 |
1475 struct ErrorContext { | 1461 struct ErrorContext { |
1476 int fErrors; | 1462 int fErrors; |
1477 skiatest::Reporter* fReporter; | 1463 skiatest::Reporter* fReporter; |
1478 }; | 1464 }; |
1479 | 1465 |
1480 static void assert_one_parse_error_cb(SkError error, void* context) { | 1466 static void assert_one_parse_error_cb(SkError error, void* context) { |
1481 ErrorContext* errorContext = static_cast<ErrorContext*>(context); | 1467 ErrorContext* errorContext = static_cast<ErrorContext*>(context); |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1933 | 1919 |
1934 // The picture shares the immutable pixels but copies the mutable ones. | 1920 // The picture shares the immutable pixels but copies the mutable ones. |
1935 REPORTER_ASSERT(r, mut.pixelRef()->unique()); | 1921 REPORTER_ASSERT(r, mut.pixelRef()->unique()); |
1936 REPORTER_ASSERT(r, !immut.pixelRef()->unique()); | 1922 REPORTER_ASSERT(r, !immut.pixelRef()->unique()); |
1937 | 1923 |
1938 // When the picture goes away, it's just our bitmaps holding the refs. | 1924 // When the picture goes away, it's just our bitmaps holding the refs. |
1939 pic.reset(NULL); | 1925 pic.reset(NULL); |
1940 REPORTER_ASSERT(r, mut.pixelRef()->unique()); | 1926 REPORTER_ASSERT(r, mut.pixelRef()->unique()); |
1941 REPORTER_ASSERT(r, immut.pixelRef()->unique()); | 1927 REPORTER_ASSERT(r, immut.pixelRef()->unique()); |
1942 } | 1928 } |
OLD | NEW |