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

Side by Side Diff: gm/dftext.cpp

Issue 670533002: Add color emoji fallback for distance field text. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix nits Created 6 years, 2 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 | « expectations/gm/ignored-tests.txt ('k') | src/gpu/GrDistanceFieldTextContext.h » ('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 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 #include "gm.h" 7 #include "gm.h"
8 #include "Resources.h"
9 #include "SkCanvas.h"
10 #include "SkStream.h"
8 #include "SkSurface.h" 11 #include "SkSurface.h"
9 #include "SkTypeface.h" 12 #include "SkTypeface.h"
10 13
11 namespace skiagm { 14 class DFTextGM : public skiagm::GM {
12
13 class DFTextGM : public GM {
14 public: 15 public:
15 DFTextGM() { 16 DFTextGM() {
16 this->setBGColor(0xFFFFFFFF); 17 this->setBGColor(0xFFFFFFFF);
18 fTypeface = NULL;
17 } 19 }
18 20
19 virtual ~DFTextGM() { 21 virtual ~DFTextGM() {
22 SkSafeUnref(fTypeface);
20 } 23 }
21 24
22 protected: 25 protected:
26 virtual void onOnceBeforeDraw() SK_OVERRIDE {
27 SkString filename = GetResourcePath("/Funkster.ttf");
28 SkAutoTUnref<SkFILEStream> stream(new SkFILEStream(filename.c_str()));
29 if (!stream->isValid()) {
30 SkDebugf("Could not find Funkster.ttf, please set --resourcePath cor rectly.\n");
31 return;
32 }
33
34 fTypeface = SkTypeface::CreateFromStream(stream);
35 }
36
23 virtual uint32_t onGetFlags() const SK_OVERRIDE { 37 virtual uint32_t onGetFlags() const SK_OVERRIDE {
24 return kGPUOnly_Flag; 38 return kGPUOnly_Flag;
25 } 39 }
26 40
27 virtual SkString onShortName() { 41 virtual SkString onShortName() SK_OVERRIDE {
28 return SkString("dftext"); 42 return SkString("dftext");
29 } 43 }
30 44
31 virtual SkISize onISize() { 45 virtual SkISize onISize() SK_OVERRIDE {
32 return SkISize::Make(1024, 768); 46 return SkISize::Make(1024, 768);
33 } 47 }
34 48
35 static void rotate_about(SkCanvas* canvas, 49 static void rotate_about(SkCanvas* canvas,
36 SkScalar degrees, 50 SkScalar degrees,
37 SkScalar px, SkScalar py) { 51 SkScalar px, SkScalar py) {
38 canvas->translate(px, py); 52 canvas->translate(px, py);
39 canvas->rotate(degrees); 53 canvas->rotate(degrees);
40 canvas->translate(-px, -py); 54 canvas->translate(-px, -py);
41 } 55 }
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 #else 192 #else
179 paint.setTextSize(SkIntToScalar(22)); 193 paint.setTextSize(SkIntToScalar(22));
180 #endif 194 #endif
181 for (size_t i = 0; i < SK_ARRAY_COUNT(fg); ++i) { 195 for (size_t i = 0; i < SK_ARRAY_COUNT(fg); ++i) {
182 paint.setColor(fg[i]); 196 paint.setColor(fg[i]);
183 197
184 canvas->drawText(text, textLen, x, y, paint); 198 canvas->drawText(text, textLen, x, y, paint);
185 y += paint.getFontMetrics(NULL); 199 y += paint.getFontMetrics(NULL);
186 } 200 }
187 201
202 // check color emoji
203 paint.setTypeface(fTypeface);
204 canvas->drawText(text, textLen, 670, 100, paint);
205
188 #if SK_SUPPORT_GPU 206 #if SK_SUPPORT_GPU
189 // render offscreen buffer 207 // render offscreen buffer
190 if (surface) { 208 if (surface) {
191 SkAutoCanvasRestore acr(inputCanvas, true); 209 SkAutoCanvasRestore acr(inputCanvas, true);
192 // since we prepended this matrix already, we blit using identity 210 // since we prepended this matrix already, we blit using identity
193 inputCanvas->resetMatrix(); 211 inputCanvas->resetMatrix();
194 SkImage* image = surface->newImageSnapshot(); 212 SkImage* image = surface->newImageSnapshot();
195 inputCanvas->drawImage(image, 0, 0, NULL); 213 inputCanvas->drawImage(image, 0, 0, NULL);
196 image->unref(); 214 image->unref();
197 } 215 }
198 #endif 216 #endif
199 } 217 }
200 218
201 private: 219 private:
202 typedef GM INHERITED; 220 SkTypeface* fTypeface;
221
222 typedef skiagm::GM INHERITED;
203 }; 223 };
204 224
205 ////////////////////////////////////////////////////////////////////////////// 225 DEF_GM( return SkNEW(DFTextGM); )
206
207 static GM* MyFactory(void*) { return new DFTextGM; }
208 static GMRegistry reg(MyFactory);
209
210 }
OLDNEW
« no previous file with comments | « expectations/gm/ignored-tests.txt ('k') | src/gpu/GrDistanceFieldTextContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698