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

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: cleanup 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 | « expectations/gm/ignored-tests.txt ('k') | include/gpu/GrFragmentProcessor.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 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 "SkBlurImageFilter.h"
12 #include "SkColorFilterImageFilter.h"
13 #include "SkColorMatrixFilter.h"
11 #include "SkCanvas.h" 14 #include "SkCanvas.h"
15 #include "SkGradientShader.h"
12 #include "SkStream.h" 16 #include "SkStream.h"
13 #include "SkTypeface.h" 17 #include "SkTypeface.h"
14 18
19 /*
20 * Spits out a dummy gradient to test blur with shader on paint
21 */
22 static SkShader* MakeLinear() {
23 static const SkPoint kPts[] = { { 0, 0 }, { 32, 32 } };
24 static const SkScalar kPos[] = { 0, SK_Scalar1/2, SK_Scalar1 };
25 static const SkColor kColors[] = {0x80F00080, 0xF0F08000, 0x800080F0 };
26 return SkGradientShader::CreateLinear(kPts, kColors, kPos,
27 SK_ARRAY_COUNT(kColors), SkShader::kCl amp_TileMode);
28 }
29
30 static SkImageFilter* make_grayscale(SkImageFilter* input = NULL) {
31 SkScalar matrix[20];
32 memset(matrix, 0, 20 * sizeof(SkScalar));
33 matrix[0] = matrix[5] = matrix[10] = 0.2126f;
34 matrix[1] = matrix[6] = matrix[11] = 0.7152f;
35 matrix[2] = matrix[7] = matrix[12] = 0.0722f;
36 matrix[18] = 1.0f;
37 SkAutoTUnref<SkColorFilter> filter(SkColorMatrixFilter::Create(matrix));
38 return SkColorFilterImageFilter::Create(filter, input);
39 }
40
41 static SkImageFilter* make_blur(float amount, SkImageFilter* input = NULL) {
42 return SkBlurImageFilter::Create(amount, amount, input);
43 }
44
15 namespace skiagm { 45 namespace skiagm {
16 46
17 class ColorEmojiGM : public GM { 47 class ColorEmojiGM : public GM {
18 public: 48 public:
19 ColorEmojiGM() { 49 ColorEmojiGM() {
20 fTypeface = NULL; 50 fTypeface = NULL;
21 } 51 }
22 52
23 ~ColorEmojiGM() { 53 ~ColorEmojiGM() {
24 SkSafeUnref(fTypeface); 54 SkSafeUnref(fTypeface);
25 } 55 }
26 protected: 56 protected:
27 virtual void onOnceBeforeDraw() SK_OVERRIDE { 57 virtual void onOnceBeforeDraw() SK_OVERRIDE {
28 SkString filename = GetResourcePath("/Funkster.ttf"); 58 SkString filename = GetResourcePath("/Funkster.ttf");
29 SkAutoTUnref<SkFILEStream> stream(new SkFILEStream(filename.c_str())); 59 SkAutoTUnref<SkFILEStream> stream(new SkFILEStream(filename.c_str()));
30 if (!stream->isValid()) { 60 if (!stream->isValid()) {
31 SkDebugf("Could not find Funkster.ttf, please set --resourcePath cor rectly.\n"); 61 SkDebugf("Could not find Funkster.ttf, please set --resourcePath cor rectly.\n");
32 return; 62 return;
33 } 63 }
34 64
35 fTypeface = SkTypeface::CreateFromStream(stream); 65 fTypeface = SkTypeface::CreateFromStream(stream);
36 } 66 }
37 67
38 virtual SkString onShortName() { 68 virtual SkString onShortName() {
39 return SkString("coloremoji"); 69 return SkString("coloremoji");
40 } 70 }
41 71
42 virtual SkISize onISize() { 72 virtual SkISize onISize() {
43 return SkISize::Make(640, 480); 73 return SkISize::Make(650, 480);
44 } 74 }
45 75
46 virtual void onDraw(SkCanvas* canvas) { 76 virtual void onDraw(SkCanvas* canvas) {
47 77
48 canvas->drawColor(SK_ColorGRAY); 78 canvas->drawColor(SK_ColorGRAY);
49 79
50 SkPaint paint; 80 SkPaint paint;
51 paint.setTypeface(fTypeface); 81 paint.setTypeface(fTypeface);
52 82
53 const char* text = "hamburgerfons"; 83 const char* text = "hamburgerfons";
54 84
55 // draw text at different point sizes 85 // draw text at different point sizes
56 const int textSize[] = { 10, 30, 50 }; 86 const int textSize[] = { 10, 30, 50, };
57 const int textYOffset[] = { 10, 40, 100}; 87 const int textYOffset[] = { 10, 40, 100, };
58 SkASSERT(sizeof(textSize) == sizeof(textYOffset)); 88 SkASSERT(sizeof(textSize) == sizeof(textYOffset));
59 for (size_t y = 0; y < sizeof(textSize) / sizeof(int); ++y) { 89 size_t y_offset = 0;
90 for (size_t y = 0; y < sizeof(textSize) / sizeof(int); y++) {
60 paint.setTextSize(SkIntToScalar(textSize[y])); 91 paint.setTextSize(SkIntToScalar(textSize[y]));
61 canvas->drawText(text, strlen(text), 10, SkIntToScalar(textYOffset[y ]), paint); 92 canvas->drawText(text, strlen(text), 10, SkIntToScalar(textYOffset[y ]), paint);
93 y_offset += textYOffset[y];
94 }
95
96 // draw with shaders and image filters
97 for (int i = 0; i < 2; i++) {
98 for (int j = 0; j < 2; j++) {
99 for (int k = 0; k < 2; k++) {
100 SkPaint shaderPaint;
101 shaderPaint.setTypeface(fTypeface);
102 if (SkToBool(i)) {
103 shaderPaint.setShader(MakeLinear());
104 }
105
106 if (SkToBool(j) && SkToBool(k)) {
107 SkAutoTUnref<SkImageFilter> grayScale(make_grayscale(NUL L));
108 SkAutoTUnref<SkImageFilter> blur(make_blur(3.0f, graySca le));
109 shaderPaint.setImageFilter(blur);
110 } else if (SkToBool(j)) {
111 SkAutoTUnref<SkImageFilter> blur(make_blur(3.0f, NULL));
112 shaderPaint.setImageFilter(blur);
113 } else if (SkToBool(k)) {
114 SkAutoTUnref<SkImageFilter> grayScale(make_grayscale(NUL L));
115 shaderPaint.setImageFilter(grayScale);
116 }
117 shaderPaint.setTextSize(30);
118 canvas->drawText(text, strlen(text), 380, SkIntToScalar(y_of fset), shaderPaint);
119 y_offset += 32;
120 }
121 }
62 } 122 }
63 123
64 // setup work needed to draw text with different clips 124 // setup work needed to draw text with different clips
65 canvas->translate(10, 160); 125 canvas->translate(10, 160);
66 paint.setTextSize(40); 126 paint.setTextSize(40);
67 127
68 // compute the bounds of the text 128 // compute the bounds of the text
69 SkRect bounds; 129 SkRect bounds;
70 paint.measureText(text, strlen(text), &bounds); 130 paint.measureText(text, strlen(text), &bounds);
71 131
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 165
106 typedef GM INHERITED; 166 typedef GM INHERITED;
107 }; 167 };
108 168
109 ////////////////////////////////////////////////////////////////////////////// 169 //////////////////////////////////////////////////////////////////////////////
110 170
111 static GM* MyFactory(void*) { return new ColorEmojiGM; } 171 static GM* MyFactory(void*) { return new ColorEmojiGM; }
112 static GMRegistry reg(MyFactory); 172 static GMRegistry reg(MyFactory);
113 173
114 } 174 }
OLDNEW
« no previous file with comments | « expectations/gm/ignored-tests.txt ('k') | include/gpu/GrFragmentProcessor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698