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

Side by Side Diff: tests/FontHostStreamTest.cpp

Issue 1974783002: Revert of Move SkTypeface to sk_sp. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 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
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 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 "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkColor.h" 10 #include "SkColor.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 } 62 }
63 return true; 63 return true;
64 } 64 }
65 65
66 DEF_TEST(FontHostStream, reporter) { 66 DEF_TEST(FontHostStream, reporter) {
67 { 67 {
68 SkPaint paint; 68 SkPaint paint;
69 paint.setColor(SK_ColorGRAY); 69 paint.setColor(SK_ColorGRAY);
70 paint.setTextSize(SkIntToScalar(30)); 70 paint.setTextSize(SkIntToScalar(30));
71 71
72 paint.setTypeface(SkTypeface::MakeFromName("Georgia", SkTypeface::kNorma l)); 72 SkTypeface* fTypeface = SkTypeface::CreateFromName("Georgia",
73 SkTypeface::kNormal);
74 SkSafeUnref(paint.setTypeface(fTypeface));
73 75
74 SkIRect origRect = SkIRect::MakeWH(64, 64); 76 SkIRect origRect = SkIRect::MakeWH(64, 64);
75 SkBitmap origBitmap; 77 SkBitmap origBitmap;
76 create(&origBitmap, origRect); 78 create(&origBitmap, origRect);
77 SkCanvas origCanvas(origBitmap); 79 SkCanvas origCanvas(origBitmap);
78 80
79 SkIRect streamRect = SkIRect::MakeWH(64, 64); 81 SkIRect streamRect = SkIRect::MakeWH(64, 64);
80 SkBitmap streamBitmap; 82 SkBitmap streamBitmap;
81 create(&streamBitmap, streamRect); 83 create(&streamBitmap, streamRect);
82 SkCanvas streamCanvas(streamBitmap); 84 SkCanvas streamCanvas(streamBitmap);
83 85
84 SkPoint point = SkPoint::Make(24, 32); 86 SkPoint point = SkPoint::Make(24, 32);
85 87
86 // Test: origTypeface and streamTypeface from orig data draw the same 88 // Test: origTypeface and streamTypeface from orig data draw the same
87 drawBG(&origCanvas); 89 drawBG(&origCanvas);
88 origCanvas.drawText("A", 1, point.fX, point.fY, paint); 90 origCanvas.drawText("A", 1, point.fX, point.fY, paint);
89 91
90 sk_sp<SkTypeface> typeface(SkToBool(paint.getTypeface()) ? sk_ref_sp(pai nt.getTypeface()) 92 SkTypeface* origTypeface = paint.getTypeface();
91 : SkTypeface::M akeDefault()); 93 SkAutoTUnref<SkTypeface> aur;
94 if (nullptr == origTypeface) {
95 aur.reset(SkTypeface::RefDefault());
96 origTypeface = aur.get();
97 }
98
92 int ttcIndex; 99 int ttcIndex;
93 SkAutoTDelete<SkStreamAsset> fontData(typeface->openStream(&ttcIndex)); 100 SkAutoTDelete<SkStreamAsset> fontData(origTypeface->openStream(&ttcIndex ));
94 sk_sp<SkTypeface> streamTypeface(SkTypeface::MakeFromStream(fontData.rel ease())); 101 SkTypeface* streamTypeface = SkTypeface::CreateFromStream(fontData.relea se());
95 102
96 SkFontDescriptor desc; 103 SkFontDescriptor desc;
97 bool isLocalStream = false; 104 bool isLocalStream = false;
98 streamTypeface->getFontDescriptor(&desc, &isLocalStream); 105 streamTypeface->getFontDescriptor(&desc, &isLocalStream);
99 REPORTER_ASSERT(reporter, isLocalStream); 106 REPORTER_ASSERT(reporter, isLocalStream);
100 107
101 paint.setTypeface(streamTypeface); 108 SkSafeUnref(paint.setTypeface(streamTypeface));
102 drawBG(&streamCanvas); 109 drawBG(&streamCanvas);
103 streamCanvas.drawPosText("A", 1, &point, paint); 110 streamCanvas.drawPosText("A", 1, &point, paint);
104 111
105 REPORTER_ASSERT(reporter, 112 REPORTER_ASSERT(reporter,
106 compare(origBitmap, origRect, streamBitmap, streamRect)) ; 113 compare(origBitmap, origRect, streamBitmap, streamRect)) ;
107 } 114 }
108 //Make sure the typeface is deleted and removed. 115 //Make sure the typeface is deleted and removed.
109 SkGraphics::PurgeFontCache(); 116 SkGraphics::PurgeFontCache();
110 } 117 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698