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

Side by Side Diff: gm/dftext.cpp

Issue 2142033002: Factor code to rotate a canvas about a point. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 5 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 #include "gm.h" 7 #include "gm.h"
8 #include "Resources.h" 8 #include "Resources.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkStream.h" 10 #include "SkStream.h"
11 #include "SkSurface.h" 11 #include "SkSurface.h"
12 #include "SkTypeface.h" 12 #include "SkTypeface.h"
13 #include "sk_tool_utils.h"
13 14
14 class DFTextGM : public skiagm::GM { 15 class DFTextGM : public skiagm::GM {
15 public: 16 public:
16 DFTextGM() { 17 DFTextGM() {
17 this->setBGColor(0xFFFFFFFF); 18 this->setBGColor(0xFFFFFFFF);
18 } 19 }
19 20
20 protected: 21 protected:
21 void onOnceBeforeDraw() override { 22 void onOnceBeforeDraw() override {
22 fEmojiTypeface = sk_tool_utils::emoji_typeface(); 23 fEmojiTypeface = sk_tool_utils::emoji_typeface();
23 fEmojiText = sk_tool_utils::emoji_sample_text(); 24 fEmojiText = sk_tool_utils::emoji_sample_text();
24 } 25 }
25 26
26 SkString onShortName() override { 27 SkString onShortName() override {
27 SkString name("dftext"); 28 SkString name("dftext");
28 name.append(sk_tool_utils::platform_os_emoji()); 29 name.append(sk_tool_utils::platform_os_emoji());
29 return name; 30 return name;
30 } 31 }
31 32
32 SkISize onISize() override { 33 SkISize onISize() override {
33 return SkISize::Make(1024, 768); 34 return SkISize::Make(1024, 768);
34 } 35 }
35 36
36 static void rotate_about(SkCanvas* canvas,
37 SkScalar degrees,
38 SkScalar px, SkScalar py) {
39 canvas->translate(px, py);
40 canvas->rotate(degrees);
41 canvas->translate(-px, -py);
42 }
43
44 virtual void onDraw(SkCanvas* inputCanvas) override { 37 virtual void onDraw(SkCanvas* inputCanvas) override {
45 SkScalar textSizes[] = { 9.0f, 9.0f*2.0f, 9.0f*5.0f, 9.0f*2.0f*5.0f }; 38 SkScalar textSizes[] = { 9.0f, 9.0f*2.0f, 9.0f*5.0f, 9.0f*2.0f*5.0f };
46 SkScalar scales[] = { 2.0f*5.0f, 5.0f, 2.0f, 1.0f }; 39 SkScalar scales[] = { 2.0f*5.0f, 5.0f, 2.0f, 1.0f };
47 40
48 // set up offscreen rendering with distance field text 41 // set up offscreen rendering with distance field text
49 #if SK_SUPPORT_GPU 42 #if SK_SUPPORT_GPU
50 GrContext* ctx = inputCanvas->getGrContext(); 43 GrContext* ctx = inputCanvas->getGrContext();
51 SkISize size = onISize(); 44 SkISize size = onISize();
52 SkImageInfo info = SkImageInfo::MakeN32(size.width(), size.height(), kPr emul_SkAlphaType, 45 SkImageInfo info = SkImageInfo::MakeN32(size.width(), size.height(), kPr emul_SkAlphaType,
53 sk_ref_sp(inputCanvas->imageInfo ().colorSpace())); 46 sk_ref_sp(inputCanvas->imageInfo ().colorSpace()));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 y += paint.getFontMetrics(nullptr)*scales[i]; 81 y += paint.getFontMetrics(nullptr)*scales[i];
89 } 82 }
90 83
91 // check rotation 84 // check rotation
92 for (size_t i = 0; i < 5; ++i) { 85 for (size_t i = 0; i < 5; ++i) {
93 SkScalar rotX = SkIntToScalar(10); 86 SkScalar rotX = SkIntToScalar(10);
94 SkScalar rotY = y; 87 SkScalar rotY = y;
95 88
96 SkAutoCanvasRestore acr(canvas, true); 89 SkAutoCanvasRestore acr(canvas, true);
97 canvas->translate(SkIntToScalar(10 + i * 200), -80); 90 canvas->translate(SkIntToScalar(10 + i * 200), -80);
98 rotate_about(canvas, SkIntToScalar(i * 5), rotX, rotY); 91 sk_tool_utils::rotate_about(canvas, SkIntToScalar(i * 5), rotX, rotY );
99 for (int ps = 6; ps <= 32; ps += 3) { 92 for (int ps = 6; ps <= 32; ps += 3) {
100 paint.setTextSize(SkIntToScalar(ps)); 93 paint.setTextSize(SkIntToScalar(ps));
101 canvas->drawText(text, textLen, rotX, rotY, paint); 94 canvas->drawText(text, textLen, rotX, rotY, paint);
102 rotY += paint.getFontMetrics(nullptr); 95 rotY += paint.getFontMetrics(nullptr);
103 } 96 }
104 } 97 }
105 98
106 // check scaling down 99 // check scaling down
107 paint.setLCDRenderText(true); 100 paint.setLCDRenderText(true);
108 x = SkIntToScalar(680); 101 x = SkIntToScalar(680);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 } 204 }
212 205
213 private: 206 private:
214 sk_sp<SkTypeface> fEmojiTypeface; 207 sk_sp<SkTypeface> fEmojiTypeface;
215 const char* fEmojiText; 208 const char* fEmojiText;
216 209
217 typedef skiagm::GM INHERITED; 210 typedef skiagm::GM INHERITED;
218 }; 211 };
219 212
220 DEF_GM(return new DFTextGM;) 213 DEF_GM(return new DFTextGM;)
OLDNEW
« no previous file with comments | « bench/BitmapBench.cpp ('k') | gm/fontscaler.cpp » ('j') | gm/strokes.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698