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

Side by Side Diff: tests/SerializationTest.cpp

Issue 2043393002: Refactoring of GPU NormalMap handling out into its own class (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Fixed SK_API flags, got rid of NormalMapSource::Make Created 4 years, 6 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/ports/SkGlobalInitialization_default.cpp ('k') | no next file » | 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 2013 Google Inc. 2 * Copyright 2013 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 "Resources.h"
8 #include "SkAnnotationKeys.h" 9 #include "SkAnnotationKeys.h"
9 #include "Resources.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkFixed.h" 11 #include "SkFixed.h"
12 #include "SkFontDescriptor.h" 12 #include "SkFontDescriptor.h"
13 #include "SkImage.h" 13 #include "SkImage.h"
14 #include "SkImageSource.h" 14 #include "SkImageSource.h"
15 #include "SkLightingShader.h"
15 #include "SkMallocPixelRef.h" 16 #include "SkMallocPixelRef.h"
16 #include "SkOSFile.h" 17 #include "SkOSFile.h"
17 #include "SkPictureRecorder.h" 18 #include "SkPictureRecorder.h"
18 #include "SkTableColorFilter.h" 19 #include "SkTableColorFilter.h"
19 #include "SkTemplates.h" 20 #include "SkTemplates.h"
20 #include "SkTypeface.h" 21 #include "SkTypeface.h"
21 #include "SkWriteBuffer.h" 22 #include "SkWriteBuffer.h"
22 #include "SkValidatingReadBuffer.h" 23 #include "SkValidatingReadBuffer.h"
23 #include "SkXfermodeImageFilter.h" 24 #include "SkXfermodeImageFilter.h"
25 #include "sk_tool_utils.h"
24 #include "Test.h" 26 #include "Test.h"
25 27
26 static const uint32_t kArraySize = 64; 28 static const uint32_t kArraySize = 64;
27 static const int kBitmapSize = 256; 29 static const int kBitmapSize = 256;
28 30
29 template<typename T> 31 template<typename T>
30 static void TestAlignment(T* testObj, skiatest::Reporter* reporter) { 32 static void TestAlignment(T* testObj, skiatest::Reporter* reporter) {
31 // Test memory read/write functions directly 33 // Test memory read/write functions directly
32 unsigned char dataWritten[1024]; 34 unsigned char dataWritten[1024];
33 size_t bytesWrittenToMemory = testObj->writeToMemory(dataWritten); 35 size_t bytesWrittenToMemory = testObj->writeToMemory(dataWritten);
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 } 177 }
176 178
177 template<typename T> 179 template<typename T>
178 static T* TestFlattenableSerialization(T* testObj, bool shouldSucceed, 180 static T* TestFlattenableSerialization(T* testObj, bool shouldSucceed,
179 skiatest::Reporter* reporter) { 181 skiatest::Reporter* reporter) {
180 SkBinaryWriteBuffer writer; 182 SkBinaryWriteBuffer writer;
181 SerializationUtils<T>::Write(writer, testObj); 183 SerializationUtils<T>::Write(writer, testObj);
182 size_t bytesWritten = writer.bytesWritten(); 184 size_t bytesWritten = writer.bytesWritten();
183 REPORTER_ASSERT(reporter, SkAlign4(bytesWritten) == bytesWritten); 185 REPORTER_ASSERT(reporter, SkAlign4(bytesWritten) == bytesWritten);
184 186
187 SkASSERT(bytesWritten <= 4096);
185 unsigned char dataWritten[4096]; 188 unsigned char dataWritten[4096];
186 SkASSERT(bytesWritten <= sizeof(dataWritten));
187 writer.writeToMemory(dataWritten); 189 writer.writeToMemory(dataWritten);
188 190
189 // Make sure this fails when it should (test with smaller size, but still mu ltiple of 4) 191 // Make sure this fails when it should (test with smaller size, but still mu ltiple of 4)
190 SkValidatingReadBuffer buffer(dataWritten, bytesWritten - 4); 192 SkValidatingReadBuffer buffer(dataWritten, bytesWritten - 4);
191 T* obj = nullptr; 193 T* obj = nullptr;
192 SerializationUtils<T>::Read(buffer, &obj); 194 SerializationUtils<T>::Read(buffer, &obj);
193 REPORTER_ASSERT(reporter, !buffer.isValid()); 195 REPORTER_ASSERT(reporter, !buffer.isValid());
194 REPORTER_ASSERT(reporter, nullptr == obj); 196 REPORTER_ASSERT(reporter, nullptr == obj);
195 197
196 // Make sure this succeeds when it should 198 // Make sure this succeeds when it should
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 SkAutoTMalloc<unsigned char> data(size); 541 SkAutoTMalloc<unsigned char> data(size);
540 writer.writeToMemory(static_cast<void*>(data.get())); 542 writer.writeToMemory(static_cast<void*>(data.get()));
541 543
542 // Deserialize picture 544 // Deserialize picture
543 SkValidatingReadBuffer reader(static_cast<void*>(data.get()), size); 545 SkValidatingReadBuffer reader(static_cast<void*>(data.get()), size);
544 sk_sp<SkPicture> readPict(SkPicture::MakeFromBuffer(reader)); 546 sk_sp<SkPicture> readPict(SkPicture::MakeFromBuffer(reader));
545 REPORTER_ASSERT(reporter, readPict.get()); 547 REPORTER_ASSERT(reporter, readPict.get());
546 } 548 }
547 549
548 TestPictureTypefaceSerialization(reporter); 550 TestPictureTypefaceSerialization(reporter);
551
552 // Test SkLightingShader/NormalMapSource serialization
553 {
554 const int kTexSize = 2;
555
556 SkLights::Builder builder;
557
558 builder.add(SkLights::Light(SkColor3f::Make(1.0f, 1.0f, 1.0f),
559 SkVector3::Make(1.0f, 0.0f, 0.0f)));
560 builder.add(SkLights::Light(SkColor3f::Make(0.2f, 0.2f, 0.2f)));
561
562 sk_sp<SkLights> fLights = builder.finish();
563
564 SkBitmap diffuse = sk_tool_utils::create_checkerboard_bitmap(
565 kTexSize, kTexSize,
566 sk_tool_utils::color_to_565(0x0),
567 sk_tool_utils::color_to_565(0xFF804020),
568 8);
569
570 SkRect bitmapBounds = SkRect::MakeIWH(diffuse.width(), diffuse.height()) ;
571
572 SkMatrix matrix;
573 SkRect r = SkRect::MakeWH(SkIntToScalar(kTexSize), SkIntToScalar(kTexSiz e));
574 matrix.setRectToRect(bitmapBounds, r, SkMatrix::kFill_ScaleToFit);
575
576 SkVector invNormRotation = { SkScalarSqrt(0.3f), SkScalarSqrt(0.7f) };
577 SkBitmap normals;
578 normals.allocN32Pixels(kTexSize, kTexSize);
579
580 sk_tool_utils::create_frustum_normal_map(&normals, SkIRect::MakeWH(kTexS ize, kTexSize));
581 sk_sp<SkShader> lightingShader = SkLightingShader::Make(diffuse, normals , fLights,
582 invNormRotation, &matrix, &matrix);
583
584 SkAutoTUnref<SkShader>(TestFlattenableSerialization(lightingShader.get() , true, reporter));
585 // TODO test equality?
586
587 }
549 } 588 }
550 589
551 //////////////////////////////////////////////////////////////////////////////// /////////////////// 590 //////////////////////////////////////////////////////////////////////////////// ///////////////////
552 #include "SkAnnotation.h" 591 #include "SkAnnotation.h"
553 592
554 static sk_sp<SkPicture> copy_picture_via_serialization(SkPicture* src) { 593 static sk_sp<SkPicture> copy_picture_via_serialization(SkPicture* src) {
555 SkDynamicMemoryWStream wstream; 594 SkDynamicMemoryWStream wstream;
556 src->serialize(&wstream); 595 src->serialize(&wstream);
557 SkAutoTDelete<SkStreamAsset> rstream(wstream.detachAsStream()); 596 SkAutoTDelete<SkStreamAsset> rstream(wstream.detachAsStream());
558 return SkPicture::MakeFromStream(rstream); 597 return SkPicture::MakeFromStream(rstream);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 { r1, SkAnnotationKeys::Define_Named_Dest_Key(), d1 }, 660 { r1, SkAnnotationKeys::Define_Named_Dest_Key(), d1 },
622 { r2, SkAnnotationKeys::Link_Named_Dest_Key(), d2 }, 661 { r2, SkAnnotationKeys::Link_Named_Dest_Key(), d2 },
623 }; 662 };
624 663
625 sk_sp<SkPicture> pict0(recorder.finishRecordingAsPicture()); 664 sk_sp<SkPicture> pict0(recorder.finishRecordingAsPicture());
626 sk_sp<SkPicture> pict1(copy_picture_via_serialization(pict0.get())); 665 sk_sp<SkPicture> pict1(copy_picture_via_serialization(pict0.get()));
627 666
628 TestAnnotationCanvas canvas(reporter, recs, SK_ARRAY_COUNT(recs)); 667 TestAnnotationCanvas canvas(reporter, recs, SK_ARRAY_COUNT(recs));
629 canvas.drawPicture(pict1); 668 canvas.drawPicture(pict1);
630 } 669 }
OLDNEW
« no previous file with comments | « src/ports/SkGlobalInitialization_default.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698