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

Side by Side Diff: tests/PictureTest.cpp

Issue 784643002: Replace EncodeBitmap with an interface. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 6 years 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/SkWriteBuffer.cpp ('k') | tools/PictureRenderer.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 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"
25 #include "SkRRect.h" 26 #include "SkRRect.h"
26 #include "SkRandom.h" 27 #include "SkRandom.h"
27 #include "SkRecord.h" 28 #include "SkRecord.h"
28 #include "SkShader.h" 29 #include "SkShader.h"
29 #include "SkStream.h" 30 #include "SkStream.h"
30 31
31 #if SK_SUPPORT_GPU 32 #if SK_SUPPORT_GPU
32 #include "SkSurface.h" 33 #include "SkSurface.h"
33 #include "GrContextFactory.h" 34 #include "GrContextFactory.h"
34 #endif 35 #endif
(...skipping 1400 matching lines...) Expand 10 before | Expand all | Expand 10 after
1435 SkPictureRecorder recorder; 1436 SkPictureRecorder recorder;
1436 SkCanvas* recordingCanvas = recorder.beginRecording(100, 100); 1437 SkCanvas* recordingCanvas = recorder.beginRecording(100, 100);
1437 recordingCanvas->drawBitmap(bm, 0, 0); 1438 recordingCanvas->drawBitmap(bm, 0, 0);
1438 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); 1439 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
1439 1440
1440 SkCanvas canvas; 1441 SkCanvas canvas;
1441 canvas.drawPicture(picture); 1442 canvas.drawPicture(picture);
1442 } 1443 }
1443 #endif 1444 #endif
1444 1445
1445 static SkData* encode_bitmap_to_data(size_t*, const SkBitmap& bm) { 1446 // Encodes to PNG, unless there is already encoded data, in which case that gets
1446 return SkImageEncoder::EncodeData(bm, SkImageEncoder::kPNG_Type, 100); 1447 // used.
1447 } 1448 // FIXME: Share with PictureRenderer.cpp?
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 };
1448 1461
1449 static SkData* serialized_picture_from_bitmap(const SkBitmap& bitmap) { 1462 static SkData* serialized_picture_from_bitmap(const SkBitmap& bitmap) {
1450 SkPictureRecorder recorder; 1463 SkPictureRecorder recorder;
1451 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(bitmap.width()), 1464 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(bitmap.width()),
1452 SkIntToScalar(bitmap.height())); 1465 SkIntToScalar(bitmap.height()));
1453 canvas->drawBitmap(bitmap, 0, 0); 1466 canvas->drawBitmap(bitmap, 0, 0);
1454 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); 1467 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
1455 1468
1456 SkDynamicMemoryWStream wStream; 1469 SkDynamicMemoryWStream wStream;
1457 picture->serialize(&wStream, &encode_bitmap_to_data); 1470 PngPixelSerializer serializer;
1471 picture->serialize(&wStream, &serializer);
1458 return wStream.copyToData(); 1472 return wStream.copyToData();
1459 } 1473 }
1460 1474
1461 struct ErrorContext { 1475 struct ErrorContext {
1462 int fErrors; 1476 int fErrors;
1463 skiatest::Reporter* fReporter; 1477 skiatest::Reporter* fReporter;
1464 }; 1478 };
1465 1479
1466 static void assert_one_parse_error_cb(SkError error, void* context) { 1480 static void assert_one_parse_error_cb(SkError error, void* context) {
1467 ErrorContext* errorContext = static_cast<ErrorContext*>(context); 1481 ErrorContext* errorContext = static_cast<ErrorContext*>(context);
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
1918 1932
1919 // The picture shares the immutable pixels but copies the mutable ones. 1933 // The picture shares the immutable pixels but copies the mutable ones.
1920 REPORTER_ASSERT(r, mut.pixelRef()->unique()); 1934 REPORTER_ASSERT(r, mut.pixelRef()->unique());
1921 REPORTER_ASSERT(r, !immut.pixelRef()->unique()); 1935 REPORTER_ASSERT(r, !immut.pixelRef()->unique());
1922 1936
1923 // When the picture goes away, it's just our bitmaps holding the refs. 1937 // When the picture goes away, it's just our bitmaps holding the refs.
1924 pic.reset(NULL); 1938 pic.reset(NULL);
1925 REPORTER_ASSERT(r, mut.pixelRef()->unique()); 1939 REPORTER_ASSERT(r, mut.pixelRef()->unique());
1926 REPORTER_ASSERT(r, immut.pixelRef()->unique()); 1940 REPORTER_ASSERT(r, immut.pixelRef()->unique());
1927 } 1941 }
OLDNEW
« no previous file with comments | « src/core/SkWriteBuffer.cpp ('k') | tools/PictureRenderer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698