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

Side by Side Diff: gm/coloremoji.cpp

Issue 820523002: initial changes to add local matrix to primitive processor (Closed) Base URL: https://skia.googlesource.com/skia.git@cleanup-ccm-above-context
Patch Set: clean up of comment around get_transform_matrix 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 | « no previous file | include/gpu/GrPaint.h » ('j') | src/gpu/GrGeometryProcessor.h » ('J')
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 "gm.h" 8 #include "gm.h"
9 9
10 #include "Resources.h" 10 #include "Resources.h"
11 #include "SkCanvas.h" 11 #include "SkCanvas.h"
12 #include "SkStream.h" 12 #include "SkStream.h"
13 #include "SkTypeface.h" 13 #include "SkTypeface.h"
14 14
15 #include "SkGradientShader.h"
16
17 /*
18 * Spits out a dummy gradient to test blur with shader on paint
19 */
20 static SkShader* MakeLinear() {
21 static const SkPoint kPts[] = { { 0, 0 }, { 32, 32 } };
22 static const SkScalar kPos[] = { 0, SK_Scalar1/2, SK_Scalar1 };
23 static const SkColor kColors[] = {0x80F00080, 0xF0F08000, 0x800080F0 };
24 return SkGradientShader::CreateLinear(kPts, kColors, kPos,
25 SK_ARRAY_COUNT(kColors), SkShader::kCl amp_TileMode);
26 }
27
15 namespace skiagm { 28 namespace skiagm {
16 29
17 class ColorEmojiGM : public GM { 30 class ColorEmojiGM : public GM {
18 public: 31 public:
19 ColorEmojiGM() { 32 ColorEmojiGM() {
20 fTypeface = NULL; 33 fTypeface = NULL;
21 } 34 }
22 35
23 ~ColorEmojiGM() { 36 ~ColorEmojiGM() {
24 SkSafeUnref(fTypeface); 37 SkSafeUnref(fTypeface);
25 } 38 }
26 protected: 39 protected:
27 virtual void onOnceBeforeDraw() SK_OVERRIDE { 40 virtual void onOnceBeforeDraw() SK_OVERRIDE {
28 SkString filename = GetResourcePath("/Funkster.ttf"); 41 SkString filename = GetResourcePath("/Funkster.ttf");
29 SkAutoTUnref<SkFILEStream> stream(new SkFILEStream(filename.c_str())); 42 SkAutoTUnref<SkFILEStream> stream(new SkFILEStream(filename.c_str()));
30 if (!stream->isValid()) { 43 if (!stream->isValid()) {
31 SkDebugf("Could not find Funkster.ttf, please set --resourcePath cor rectly.\n"); 44 SkDebugf("Could not find Funkster.ttf, please set --resourcePath cor rectly.\n");
32 return; 45 return;
33 } 46 }
34 47
35 fTypeface = SkTypeface::CreateFromStream(stream); 48 fTypeface = SkTypeface::CreateFromStream(stream);
36 } 49 }
37 50
38 virtual SkString onShortName() { 51 virtual SkString onShortName() {
39 return SkString("coloremoji"); 52 return SkString("coloremoji");
40 } 53 }
41 54
42 virtual SkISize onISize() { 55 virtual SkISize onISize() {
43 return SkISize::Make(640, 480); 56 return SkISize::Make(640, 540);
44 } 57 }
45 58
46 virtual void onDraw(SkCanvas* canvas) { 59 virtual void onDraw(SkCanvas* canvas) {
47 60
48 canvas->drawColor(SK_ColorGRAY); 61 canvas->drawColor(SK_ColorGRAY);
49 62
50 SkPaint paint; 63 SkPaint paint;
51 paint.setTypeface(fTypeface); 64 paint.setTypeface(fTypeface);
52 65
53 const char* text = "hamburgerfons"; 66 const char* text = "hamburgerfons";
54 67
55 // draw text at different point sizes 68 // draw text at different point sizes
56 const int textSize[] = { 10, 30, 50 }; 69 const int textSize[] = { 10, 10, 30, 30, 50, 50 };
57 const int textYOffset[] = { 10, 40, 100}; 70 const int textYOffset[] = { 10, 25, 50, 85, 130, 190};
58 SkASSERT(sizeof(textSize) == sizeof(textYOffset)); 71 SkASSERT(sizeof(textSize) == sizeof(textYOffset));
59 for (size_t y = 0; y < sizeof(textSize) / sizeof(int); ++y) { 72 for (size_t y = 0; y < sizeof(textSize) / sizeof(int); y += 2) {
60 paint.setTextSize(SkIntToScalar(textSize[y])); 73 SkPaint localPaint;
61 canvas->drawText(text, strlen(text), 10, SkIntToScalar(textYOffset[y ]), paint); 74 localPaint.setTypeface(fTypeface);
75 localPaint.setTextSize(SkIntToScalar(textSize[y]));
76 canvas->drawText(text, strlen(text), 10, SkIntToScalar(textYOffset[y ]), localPaint);
77 // attach a shader to the paint to test fall back
78 localPaint.setShader(MakeLinear())->unref();
79 canvas->drawText(text, strlen(text), 10, SkIntToScalar(textYOffset[y + 1]), localPaint);
62 } 80 }
63 81
64 // setup work needed to draw text with different clips 82 // setup work needed to draw text with different clips
65 canvas->translate(10, 160); 83 canvas->translate(10, 250);
66 paint.setTextSize(40); 84 paint.setTextSize(40);
67 85
68 // compute the bounds of the text 86 // compute the bounds of the text
69 SkRect bounds; 87 SkRect bounds;
70 paint.measureText(text, strlen(text), &bounds); 88 paint.measureText(text, strlen(text), &bounds);
71 89
72 const SkScalar boundsHalfWidth = bounds.width() * SK_ScalarHalf; 90 const SkScalar boundsHalfWidth = bounds.width() * SK_ScalarHalf;
73 const SkScalar boundsHalfHeight = bounds.height() * SK_ScalarHalf; 91 const SkScalar boundsHalfHeight = bounds.height() * SK_ScalarHalf;
74 const SkScalar boundsQuarterWidth = boundsHalfWidth * SK_ScalarHalf; 92 const SkScalar boundsQuarterWidth = boundsHalfWidth * SK_ScalarHalf;
75 const SkScalar boundsQuarterHeight = boundsHalfHeight * SK_ScalarHalf; 93 const SkScalar boundsQuarterHeight = boundsHalfHeight * SK_ScalarHalf;
(...skipping 29 matching lines...) Expand all
105 123
106 typedef GM INHERITED; 124 typedef GM INHERITED;
107 }; 125 };
108 126
109 ////////////////////////////////////////////////////////////////////////////// 127 //////////////////////////////////////////////////////////////////////////////
110 128
111 static GM* MyFactory(void*) { return new ColorEmojiGM; } 129 static GM* MyFactory(void*) { return new ColorEmojiGM; }
112 static GMRegistry reg(MyFactory); 130 static GMRegistry reg(MyFactory);
113 131
114 } 132 }
OLDNEW
« no previous file with comments | « no previous file | include/gpu/GrPaint.h » ('j') | src/gpu/GrGeometryProcessor.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698