aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorGravatar Brian Osman <brianosman@google.com>2017-01-26 09:32:33 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-01-26 15:27:49 +0000
commit964dec3948721808491b21b4ff4ff41a466443ec (patch)
tree57e3d48e97aecafc872a9cce6285e9edea775cf8 /tools
parentd6016013bdf843013f7fb8648fc5a64ce7e77005 (diff)
Move SkGammaColorFilter to tools, limit to sRGB
Similarly, limit GrGammaEffect to sRGB (and rename it). BUG=skia: Change-Id: I88feef11ab7040bca2fa4c2eed71923ded87a0d0 Reviewed-on: https://skia-review.googlesource.com/7375 Commit-Queue: Brian Osman <brianosman@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/sk_tool_utils.cpp42
-rw-r--r--tools/sk_tool_utils.h6
-rw-r--r--tools/viewer/sk_app/mac/RasterWindowContext_mac.cpp5
3 files changed, 51 insertions, 2 deletions
diff --git a/tools/sk_tool_utils.cpp b/tools/sk_tool_utils.cpp
index 93f5b107f2..0383897bd8 100644
--- a/tools/sk_tool_utils.cpp
+++ b/tools/sk_tool_utils.cpp
@@ -22,6 +22,38 @@
DEFINE_bool(portableFonts, false, "Use portable fonts");
+#if SK_SUPPORT_GPU
+#include "effects/GrSRGBEffect.h"
+#include "SkColorFilter.h"
+
+// Color filter that just wraps GrSRGBEffect
+class SkSRGBColorFilter : public SkColorFilter {
+public:
+ static sk_sp<SkColorFilter> Make(GrSRGBEffect::Mode mode) {
+ return sk_sp<SkColorFilter>(new SkSRGBColorFilter(mode));
+ }
+
+ sk_sp<GrFragmentProcessor> asFragmentProcessor(GrContext*, SkColorSpace*) const override {
+ return GrSRGBEffect::Make(fMode);
+ }
+
+ void filterSpan(const SkPMColor src[], int count, SkPMColor dst[]) const override {
+ SK_ABORT("SkSRGBColorFilter is only implemented for GPU");
+ }
+ Factory getFactory() const override { return nullptr; }
+
+#ifndef SK_IGNORE_TO_STRING
+ void toString(SkString* str) const override {}
+#endif
+
+private:
+ SkSRGBColorFilter(GrSRGBEffect::Mode mode) : fMode(mode) {}
+
+ GrSRGBEffect::Mode fMode;
+ typedef SkColorFilter INHERITED;
+};
+#endif
+
namespace sk_tool_utils {
/* these are the default fonts chosen by Chrome for serif, sans-serif, and monospace */
@@ -586,4 +618,14 @@ void copy_to_g8(SkBitmap* dst, const SkBitmap& src) {
}
}
+#if SK_SUPPORT_GPU
+sk_sp<SkColorFilter> MakeLinearToSRGBColorFilter() {
+ return SkSRGBColorFilter::Make(GrSRGBEffect::Mode::kLinearToSRGB);
+}
+
+sk_sp<SkColorFilter> MakeSRGBToLinearColorFilter() {
+ return SkSRGBColorFilter::Make(GrSRGBEffect::Mode::kSRGBToLinear);
+}
+#endif
+
} // namespace sk_tool_utils
diff --git a/tools/sk_tool_utils.h b/tools/sk_tool_utils.h
index ffe8084f7f..e319411349 100644
--- a/tools/sk_tool_utils.h
+++ b/tools/sk_tool_utils.h
@@ -19,6 +19,7 @@
class SkBitmap;
class SkCanvas;
+class SkColorFilter;
class SkPaint;
class SkPath;
class SkRRect;
@@ -254,6 +255,11 @@ namespace sk_tool_utils {
void copy_to_g8(SkBitmap* dst, const SkBitmap& src);
+#if SK_SUPPORT_GPU
+ sk_sp<SkColorFilter> MakeLinearToSRGBColorFilter();
+ sk_sp<SkColorFilter> MakeSRGBToLinearColorFilter();
+#endif
+
} // namespace sk_tool_utils
#endif // sk_tool_utils_DEFINED
diff --git a/tools/viewer/sk_app/mac/RasterWindowContext_mac.cpp b/tools/viewer/sk_app/mac/RasterWindowContext_mac.cpp
index fd2f2effb1..4749bc79a2 100644
--- a/tools/viewer/sk_app/mac/RasterWindowContext_mac.cpp
+++ b/tools/viewer/sk_app/mac/RasterWindowContext_mac.cpp
@@ -8,7 +8,8 @@
#include "../GLWindowContext.h"
#include "SkCanvas.h"
-#include "SkGammaColorFilter.h"
+#include "SkColorFilter.h"
+#include "sk_tool_utils.h"
#include "WindowContextFactory_mac.h"
#include "SDL.h"
@@ -123,7 +124,7 @@ void RasterWindowContext_mac::onSwapBuffers() {
SkPaint gammaPaint;
gammaPaint.setBlendMode(SkBlendMode::kSrc);
if (doGamma) {
- gammaPaint.setColorFilter(SkGammaColorFilter::Make(1.0f / 2.2f));
+ gammaPaint.setColorFilter(sk_tool_utils::MakeLinearToSRGBColorFilter());
}
sk_sp<SkSurface> gpuSurface = INHERITED::getBackbufferSurface();