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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « expectations/gm/ignored-tests.txt ('k') | include/gpu/GrFragmentProcessor.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/coloremoji.cpp
diff --git a/gm/coloremoji.cpp b/gm/coloremoji.cpp
index 2eab864c0df1fb96ec6e3e8117cabb5d6d7d5fa7..9782dd82a015cac695fc246fa4b3e6f1d9898623 100644
--- a/gm/coloremoji.cpp
+++ b/gm/coloremoji.cpp
@@ -8,10 +8,40 @@
#include "gm.h"
#include "Resources.h"
+#include "SkBlurImageFilter.h"
+#include "SkColorFilterImageFilter.h"
+#include "SkColorMatrixFilter.h"
#include "SkCanvas.h"
+#include "SkGradientShader.h"
#include "SkStream.h"
#include "SkTypeface.h"
+/*
+ * Spits out a dummy gradient to test blur with shader on paint
+ */
+static SkShader* MakeLinear() {
+ static const SkPoint kPts[] = { { 0, 0 }, { 32, 32 } };
+ static const SkScalar kPos[] = { 0, SK_Scalar1/2, SK_Scalar1 };
+ static const SkColor kColors[] = {0x80F00080, 0xF0F08000, 0x800080F0 };
+ return SkGradientShader::CreateLinear(kPts, kColors, kPos,
+ SK_ARRAY_COUNT(kColors), SkShader::kClamp_TileMode);
+}
+
+static SkImageFilter* make_grayscale(SkImageFilter* input = NULL) {
+ SkScalar matrix[20];
+ memset(matrix, 0, 20 * sizeof(SkScalar));
+ matrix[0] = matrix[5] = matrix[10] = 0.2126f;
+ matrix[1] = matrix[6] = matrix[11] = 0.7152f;
+ matrix[2] = matrix[7] = matrix[12] = 0.0722f;
+ matrix[18] = 1.0f;
+ SkAutoTUnref<SkColorFilter> filter(SkColorMatrixFilter::Create(matrix));
+ return SkColorFilterImageFilter::Create(filter, input);
+}
+
+static SkImageFilter* make_blur(float amount, SkImageFilter* input = NULL) {
+ return SkBlurImageFilter::Create(amount, amount, input);
+}
+
namespace skiagm {
class ColorEmojiGM : public GM {
@@ -40,7 +70,7 @@ protected:
}
virtual SkISize onISize() {
- return SkISize::Make(640, 480);
+ return SkISize::Make(650, 480);
}
virtual void onDraw(SkCanvas* canvas) {
@@ -53,12 +83,42 @@ protected:
const char* text = "hamburgerfons";
// draw text at different point sizes
- const int textSize[] = { 10, 30, 50 };
- const int textYOffset[] = { 10, 40, 100};
+ const int textSize[] = { 10, 30, 50, };
+ const int textYOffset[] = { 10, 40, 100, };
SkASSERT(sizeof(textSize) == sizeof(textYOffset));
- for (size_t y = 0; y < sizeof(textSize) / sizeof(int); ++y) {
+ size_t y_offset = 0;
+ for (size_t y = 0; y < sizeof(textSize) / sizeof(int); y++) {
paint.setTextSize(SkIntToScalar(textSize[y]));
canvas->drawText(text, strlen(text), 10, SkIntToScalar(textYOffset[y]), paint);
+ y_offset += textYOffset[y];
+ }
+
+ // draw with shaders and image filters
+ for (int i = 0; i < 2; i++) {
+ for (int j = 0; j < 2; j++) {
+ for (int k = 0; k < 2; k++) {
+ SkPaint shaderPaint;
+ shaderPaint.setTypeface(fTypeface);
+ if (SkToBool(i)) {
+ shaderPaint.setShader(MakeLinear());
+ }
+
+ if (SkToBool(j) && SkToBool(k)) {
+ SkAutoTUnref<SkImageFilter> grayScale(make_grayscale(NULL));
+ SkAutoTUnref<SkImageFilter> blur(make_blur(3.0f, grayScale));
+ shaderPaint.setImageFilter(blur);
+ } else if (SkToBool(j)) {
+ SkAutoTUnref<SkImageFilter> blur(make_blur(3.0f, NULL));
+ shaderPaint.setImageFilter(blur);
+ } else if (SkToBool(k)) {
+ SkAutoTUnref<SkImageFilter> grayScale(make_grayscale(NULL));
+ shaderPaint.setImageFilter(grayScale);
+ }
+ shaderPaint.setTextSize(30);
+ canvas->drawText(text, strlen(text), 380, SkIntToScalar(y_offset), shaderPaint);
+ y_offset += 32;
+ }
+ }
}
// setup work needed to draw text with different clips
« 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