diff options
author | Mike Klein <mtklein@chromium.org> | 2017-01-20 17:25:34 -0500 |
---|---|---|
committer | Mike Klein <mtklein@chromium.org> | 2017-01-21 15:09:31 +0000 |
commit | efaad3cd53330f063e6feaee8b14ad43ca251184 (patch) | |
tree | 88247b45e36889a2339bc0471e692593cf038377 | |
parent | 17b5e5c591fc4d23efc668c3ba61cefad32c88d5 (diff) |
Remove SkColorCubeFilter. It is unused.
Change-Id: Iec5fc759e331de24caea1347f9510917260d379b
Reviewed-on: https://skia-review.googlesource.com/7363
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Klein <mtklein@chromium.org>
-rw-r--r-- | bench/ColorCubeBench.cpp | 102 | ||||
-rw-r--r-- | fuzz/FilterFuzz.cpp | 13 | ||||
-rw-r--r-- | gm/colorcube.cpp | 124 | ||||
-rw-r--r-- | gn/bench.gni | 1 | ||||
-rw-r--r-- | gn/effects.gni | 2 | ||||
-rw-r--r-- | gn/gm.gni | 1 | ||||
-rw-r--r-- | include/effects/SkColorCubeFilter.h | 77 | ||||
-rw-r--r-- | samplecode/SampleFilterFuzz.cpp | 13 | ||||
-rw-r--r-- | site/user/api/index.md | 1 | ||||
-rw-r--r-- | src/core/SkOpts.cpp | 2 | ||||
-rw-r--r-- | src/core/SkOpts.h | 9 | ||||
-rw-r--r-- | src/effects/SkColorCubeFilter.cpp | 329 | ||||
-rw-r--r-- | src/opts/SkColorCubeFilter_opts.h | 84 | ||||
-rw-r--r-- | src/opts/SkOpts_ssse3.cpp | 2 | ||||
-rw-r--r-- | src/ports/SkGlobalInitialization_default.cpp | 2 |
15 files changed, 3 insertions, 759 deletions
diff --git a/bench/ColorCubeBench.cpp b/bench/ColorCubeBench.cpp deleted file mode 100644 index 6a7774012d..0000000000 --- a/bench/ColorCubeBench.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2014 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ -#include "Benchmark.h" -#include "SkCanvas.h" -#include "SkColorCubeFilter.h" -#include "SkGradientShader.h" -#include "SkTemplates.h" - -class ColorCubeBench : public Benchmark { - SkISize fSize; - int fCubeDimension; - sk_sp<SkData> fCubeData; - SkBitmap fBitmap; - -public: - ColorCubeBench() : fCubeDimension(0) { - fSize = SkISize::Make(2880, 1800); // 2014 Macbook Pro resolution - } - -protected: - const char* onGetName() override { - return "colorcube"; - } - - void onDelayedSetup() override { - if (!SkToBool(fCubeData)) { - this->makeCubeData(); - this->make_bitmap(); - } - } - - void onDraw(int loops, SkCanvas* canvas) override { - this->test(loops, canvas); - } - - SkIPoint onGetSize() override { - return SkIPoint::Make(fSize.width(), fSize.height()); - } - -private: - static sk_sp<SkShader> MakeLinear(const SkISize& size) { - const SkPoint pts[2] = { - { 0, 0 }, - { SkIntToScalar(size.width()), SkIntToScalar(size.height()) } - }; - static const SkColor colors[] = { SK_ColorYELLOW, SK_ColorBLUE }; - return SkGradientShader::MakeLinear( - pts, colors, nullptr, 2, SkShader::kRepeat_TileMode, 0, &SkMatrix::I()); - } - - void make_bitmap() { - fBitmap.allocN32Pixels(fSize.width(), fSize.height()); - SkCanvas canvas(fBitmap); - canvas.clear(0x00000000); - SkPaint paint; - paint.setAntiAlias(true); - paint.setShader(MakeLinear(fSize)); - SkRect r = { 0, 0, SkIntToScalar(fSize.width()), SkIntToScalar(fSize.height()) }; - canvas.drawRect(r, paint); - } - - void makeCubeData() { - fCubeDimension = 32; - fCubeData = SkData::MakeUninitialized(sizeof(SkColor) * - fCubeDimension * fCubeDimension * fCubeDimension); - SkColor* pixels = (SkColor*)(fCubeData->writable_data()); - SkAutoTMalloc<uint8_t> lutMemory(fCubeDimension); - uint8_t* lut = lutMemory.get(); - const int maxIndex = fCubeDimension - 1; - for (int i = 0; i < fCubeDimension; ++i) { - // Make an invert lut, but the content of - // the lut shouldn't affect performance. - lut[i] = ((maxIndex - i) * 255) / maxIndex; - } - for (int r = 0; r < fCubeDimension; ++r) { - for (int g = 0; g < fCubeDimension; ++g) { - for (int b = 0; b < fCubeDimension; ++b) { - pixels[(fCubeDimension * ((fCubeDimension * b) + g)) + r] = - SkColorSetARGB(0xFF, lut[r], lut[g], lut[b]); - } - } - } - } - - void test(int loops, SkCanvas* canvas) { - SkPaint paint; - for (int i = 0; i < loops; i++) { - paint.setColorFilter(SkColorCubeFilter::Make(fCubeData, fCubeDimension)); - canvas->drawBitmap(fBitmap, 0, 0, &paint); - } - } - - typedef Benchmark INHERITED; -}; - -/////////////////////////////////////////////////////////////////////////////// - -DEF_BENCH( return new ColorCubeBench(); ) diff --git a/fuzz/FilterFuzz.cpp b/fuzz/FilterFuzz.cpp index 1953668d05..e3d30b5af7 100644 --- a/fuzz/FilterFuzz.cpp +++ b/fuzz/FilterFuzz.cpp @@ -12,7 +12,6 @@ #include "SkBlurImageFilter.h" #include "SkBlurMaskFilter.h" #include "SkCanvas.h" -#include "SkColorCubeFilter.h" #include "SkColorFilter.h" #include "SkColorFilterImageFilter.h" #include "SkColorMatrixFilter.h" @@ -578,7 +577,7 @@ static sk_sp<SkImageFilter> make_image_filter(bool canBeNull) { return filter; } - enum { ALPHA_THRESHOLD, MERGE, COLOR, LUT3D, BLUR, MAGNIFIER, + enum { ALPHA_THRESHOLD, MERGE, COLOR, BLUR, MAGNIFIER, BLENDMODE, OFFSET, MATRIX, MATRIX_CONVOLUTION, COMPOSE, DISTANT_LIGHT, POINT_LIGHT, SPOT_LIGHT, NOISE, DROP_SHADOW, MORPHOLOGY, BITMAP, DISPLACE, TILE, PICTURE, PAINT, NUM_FILTERS }; @@ -607,16 +606,6 @@ static sk_sp<SkImageFilter> make_image_filter(bool canBeNull) { : nullptr; break; } - case LUT3D: { - int cubeDimension; - bool a, b, c; - fuzz->next(&a, &b, &c); - sk_sp<SkData> lut3D(make_3Dlut(&cubeDimension, a, b, c)); - sk_sp<SkColorFilter> cf(SkColorCubeFilter::Make(std::move(lut3D), cubeDimension)); - filter = cf ? SkColorFilterImageFilter::Make(std::move(cf), make_image_filter()) - : nullptr; - break; - } case BLUR: { SkScalar sX = make_number(true); SkScalar sY = make_number(true); diff --git a/gm/colorcube.cpp b/gm/colorcube.cpp deleted file mode 100644 index dc183bc3ae..0000000000 --- a/gm/colorcube.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright 2014 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "gm.h" -#include "SkColorCubeFilter.h" -#include "SkData.h" -#include "SkGradientShader.h" -#include "SkTemplates.h" - -namespace skiagm { - -static sk_sp<SkShader> MakeLinear() { - constexpr SkPoint pts[2] = { - { 0, 0 }, - { SkIntToScalar(80), SkIntToScalar(80) } - }; - constexpr SkColor colors[] = { SK_ColorYELLOW, SK_ColorBLUE }; - return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kRepeat_TileMode, 0, - &SkMatrix::I()); -} - -class ColorCubeGM : public GM { -public: - ColorCubeGM() : fInitialized(false) { - this->setBGColor(0xFF000000); - } - -protected: - SkString onShortName() override { - return SkString("colorcube"); - } - - void make_3Dluts() { - make_3Dlut(&f3DLut4, 4, true, false, false); - make_3Dlut(&f3DLut8, 8, false, true, false); - make_3Dlut(&f3DLut16, 16, false, true, true); - make_3Dlut(&f3DLut32, 32, true, true, false); - make_3Dlut(&f3DLut64, 64, true, false, true); - } - - void make_bitmap() { - fBitmap.allocN32Pixels(80, 80); - SkCanvas canvas(fBitmap); - canvas.clear(0x00000000); - SkPaint paint; - paint.setAntiAlias(true); - paint.setShader(MakeLinear()); - canvas.drawRect(SkRect::MakeWH(80, 80), paint); - } - - void make_3Dlut(sk_sp<SkData>* data, int size, bool invR, bool invG, bool invB) { - *data = SkData::MakeUninitialized(sizeof(SkColor) * size * size * size); - SkColor* pixels = (SkColor*)((*data)->writable_data()); - SkAutoTMalloc<uint8_t> lutMemory(size); - SkAutoTMalloc<uint8_t> invLutMemory(size); - uint8_t* lut = lutMemory.get(); - uint8_t* invLut = invLutMemory.get(); - const int maxIndex = size - 1; - for (int i = 0; i < size; i++) { - lut[i] = (i * 255) / maxIndex; - invLut[i] = ((maxIndex - i) * 255) / maxIndex; - } - for (int r = 0; r < size; ++r) { - for (int g = 0; g < size; ++g) { - for (int b = 0; b < size; ++b) { - pixels[(size * ((size * b) + g)) + r] = sk_tool_utils::color_to_565( - SkColorSetARGB(0xFF, - invR ? invLut[r] : lut[r], - invG ? invLut[g] : lut[g], - invB ? invLut[b] : lut[b])); - } - } - } - } - - SkISize onISize() override { - return SkISize::Make(500, 100); - } - - void onDraw(SkCanvas* canvas) override { - if (!fInitialized) { - this->make_bitmap(); - this->make_3Dluts(); - fInitialized = true; - } - canvas->clear(0x00000000); - SkPaint paint; - paint.setColorFilter(SkColorCubeFilter::Make(f3DLut4, 4)); - canvas->drawBitmap(fBitmap, 10, 10, &paint); - - paint.setColorFilter(SkColorCubeFilter::Make(f3DLut8, 8)); - canvas->drawBitmap(fBitmap, 110, 10, &paint); - - paint.setColorFilter(SkColorCubeFilter::Make(f3DLut16, 16)); - canvas->drawBitmap(fBitmap, 210, 10, &paint); - - paint.setColorFilter(SkColorCubeFilter::Make(f3DLut32, 32)); - canvas->drawBitmap(fBitmap, 310, 10, &paint); - - paint.setColorFilter(SkColorCubeFilter::Make(f3DLut64, 64)); - canvas->drawBitmap(fBitmap, 410, 10, &paint); - } - -private: - typedef GM INHERITED; - bool fInitialized; - SkBitmap fBitmap; - sk_sp<SkData> f3DLut4; - sk_sp<SkData> f3DLut8; - sk_sp<SkData> f3DLut16; - sk_sp<SkData> f3DLut32; - sk_sp<SkData> f3DLut64; -}; - -////////////////////////////////////////////////////////////////////////////// - -static GM* MyFactory(void*) { return new ColorCubeGM; } -static GMRegistry reg(MyFactory); - -} diff --git a/gn/bench.gni b/gn/bench.gni index d6252927c9..b18adfea6b 100644 --- a/gn/bench.gni +++ b/gn/bench.gni @@ -30,7 +30,6 @@ bench_sources = [ "$_bench/CmapBench.cpp", "$_bench/CodecBench.cpp", "$_bench/ColorCodecBench.cpp", - "$_bench/ColorCubeBench.cpp", "$_bench/ColorFilterBench.cpp", "$_bench/ColorPrivBench.cpp", "$_bench/ControlBench.cpp", diff --git a/gn/effects.gni b/gn/effects.gni index b1a49c502f..b3459e36d9 100644 --- a/gn/effects.gni +++ b/gn/effects.gni @@ -23,7 +23,6 @@ skia_effects_sources = [ "$_src/effects/SkBlurMask.cpp", "$_src/effects/SkBlurMask.h", "$_src/effects/SkBlurMaskFilter.cpp", - "$_src/effects/SkColorCubeFilter.cpp", "$_src/effects/SkColorFilterImageFilter.cpp", "$_src/effects/SkColorMatrix.cpp", "$_src/effects/SkColorMatrixFilter.cpp", @@ -98,7 +97,6 @@ skia_effects_sources = [ "$_include/effects/SkBlurDrawLooper.h", "$_include/effects/SkBlurImageFilter.h", "$_include/effects/SkBlurMaskFilter.h", - "$_include/effects/SkColorCubeFilter.h", "$_include/effects/SkColorFilterImageFilter.h", "$_include/effects/SkColorMatrix.h", "$_include/effects/SkColorMatrixFilter.h", @@ -60,7 +60,6 @@ gm_sources = [ "$_gm/clipdrawdraw.cpp", "$_gm/clippedbitmapshaders.cpp", "$_gm/color4f.cpp", - "$_gm/colorcube.cpp", "$_gm/coloremoji.cpp", "$_gm/colorfilteralpha8.cpp", "$_gm/colorfilterimagefilter.cpp", diff --git a/include/effects/SkColorCubeFilter.h b/include/effects/SkColorCubeFilter.h deleted file mode 100644 index ea69d4d65d..0000000000 --- a/include/effects/SkColorCubeFilter.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2014 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkColorCubeFilter_DEFINED -#define SkColorCubeFilter_DEFINED - -#include "SkColorFilter.h" -#include "SkData.h" -#include "../private/SkOnce.h" -#include "../private/SkTemplates.h" - -class SK_API SkColorCubeFilter : public SkColorFilter { -public: - /** cubeData must containt a 3D data in the form of cube of the size: - * cubeDimension * cubeDimension * cubeDimension * sizeof(SkColor) - * This cube contains a transform where (x,y,z) maps to the (r,g,b). - * The alpha components of the colors must be 0xFF. - */ - static sk_sp<SkColorFilter> Make(sk_sp<SkData> cubeData, int cubeDimension); - - void filterSpan(const SkPMColor src[], int count, SkPMColor[]) const override; - uint32_t getFlags() const override; - -#if SK_SUPPORT_GPU - sk_sp<GrFragmentProcessor> asFragmentProcessor(GrContext*, SkColorSpace*) const override; -#endif - - SK_TO_STRING_OVERRIDE() - SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkColorCubeFilter) - -protected: - SkColorCubeFilter(sk_sp<SkData> cubeData, int cubeDimension); - void flatten(SkWriteBuffer&) const override; - -private: - /** The cache is initialized on-demand when getProcessingLuts is called. - */ - class ColorCubeProcesingCache { - public: - ColorCubeProcesingCache(int cubeDimension); - - void getProcessingLuts(const int* (*colorToIndex)[2], - const SkScalar* (*colorToFactors)[2], - const SkScalar** colorToScalar); - - int cubeDimension() const { return fCubeDimension; } - - private: - // Working pointers. If any of these is NULL, - // we need to recompute the corresponding cache values. - int* fColorToIndex[2]; - SkScalar* fColorToFactors[2]; - SkScalar* fColorToScalar; - - SkAutoTMalloc<uint8_t> fLutStorage; - - const int fCubeDimension; - - // Make sure we only initialize the caches once. - SkOnce fLutsInitOnce; - - static void initProcessingLuts(ColorCubeProcesingCache* cache); - }; - - sk_sp<SkData> fCubeData; - int32_t fUniqueID; - - mutable ColorCubeProcesingCache fCache; - - typedef SkColorFilter INHERITED; -}; - -#endif diff --git a/samplecode/SampleFilterFuzz.cpp b/samplecode/SampleFilterFuzz.cpp index 682db9220e..ef4eee8520 100644 --- a/samplecode/SampleFilterFuzz.cpp +++ b/samplecode/SampleFilterFuzz.cpp @@ -12,7 +12,6 @@ #include "SkBlurImageFilter.h" #include "SkBlurMaskFilter.h" #include "SkCanvas.h" -#include "SkColorCubeFilter.h" #include "SkColorFilter.h" #include "SkColorFilterImageFilter.h" #include "SkColorMatrixFilter.h" @@ -543,7 +542,7 @@ static sk_sp<SkImageFilter> make_image_filter(bool canBeNull) { return filter; } - enum { ALPHA_THRESHOLD, MERGE, COLOR, LUT3D, BLUR, MAGNIFIER, + enum { ALPHA_THRESHOLD, MERGE, COLOR, BLUR, MAGNIFIER, XFERMODE, OFFSET, MATRIX, MATRIX_CONVOLUTION, COMPOSE, DISTANT_LIGHT, POINT_LIGHT, SPOT_LIGHT, NOISE, DROP_SHADOW, MORPHOLOGY, BITMAP, DISPLACE, TILE, PICTURE, PAINT, NUM_FILTERS }; @@ -566,14 +565,6 @@ static sk_sp<SkImageFilter> make_image_filter(bool canBeNull) { : nullptr; break; } - case LUT3D: { - int cubeDimension; - sk_sp<SkData> lut3D(make_3Dlut(&cubeDimension, (R(2) == 1), (R(2) == 1), (R(2) == 1))); - sk_sp<SkColorFilter> cf(SkColorCubeFilter::Make(std::move(lut3D), cubeDimension)); - filter = cf ? SkColorFilterImageFilter::Make(std::move(cf), make_image_filter()) - : nullptr; - break; - } case BLUR: filter = SkBlurImageFilter::Make(make_scalar(true), make_scalar(true), @@ -653,7 +644,7 @@ static sk_sp<SkImageFilter> make_image_filter(bool canBeNull) { make_image_filter()) : SkLightingImageFilter::MakeSpotLitSpecular(SkPoint3::Make(0, 0, 0), make_point(), make_scalar(), - make_scalar(), make_color(), + make_scalar(), make_color(), make_scalar(), make_scalar(), SkIntToScalar(R(10)), make_image_filter()); diff --git a/site/user/api/index.md b/site/user/api/index.md index d54a02ef91..e0e4450890 100644 --- a/site/user/api/index.md +++ b/site/user/api/index.md @@ -53,7 +53,6 @@ Here's a partial list of the more important Skia classes: - [SkGradientShader](http://skia-doc.commondatastorage.googleapis.com/doxygen/doxygen/html/classSkGradientShader.html) - [SkTransparentShader](http://skia-doc.commondatastorage.googleapis.com/doxygen/doxygen/html/classSkTransparentShader.html) * [SkColorFilter](http://skia-doc.commondatastorage.googleapis.com/doxygen/doxygen/html/classSkColorFilter.html) - - [SkColorCubeFilter](http://skia-doc.commondatastorage.googleapis.com/doxygen/doxygen/html/classSkColorCubeFilter.html) - [SkColorMatrixFilter](http://skia-doc.commondatastorage.googleapis.com/doxygen/doxygen/html/classSkColorMatrixFilter.html) - [SkLumaColorFilter](http://skia-doc.commondatastorage.googleapis.com/doxygen/doxygen/html/classSkLumaColorFilter.html) - [SkModeColorFilter](http://skia-doc.commondatastorage.googleapis.com/doxygen/doxygen/html/classSkModeColorFilter.html) diff --git a/src/core/SkOpts.cpp b/src/core/SkOpts.cpp index 45fb2890f2..aa8aa9772f 100644 --- a/src/core/SkOpts.cpp +++ b/src/core/SkOpts.cpp @@ -42,7 +42,6 @@ #include "SkBlitRow_opts.h" #include "SkBlurImageFilter_opts.h" #include "SkChecksum_opts.h" -#include "SkColorCubeFilter_opts.h" #include "SkMorphologyImageFilter_opts.h" #include "SkRasterPipeline_opts.h" #include "SkSwizzler_opts.h" @@ -56,7 +55,6 @@ namespace SkOpts { // They'll still get a chance to be replaced with even better ones, e.g. using SSE4.1. #define DEFINE_DEFAULT(name) decltype(name) name = SK_OPTS_NS::name DEFINE_DEFAULT(create_xfermode); - DEFINE_DEFAULT(color_cube_filter_span); DEFINE_DEFAULT(box_blur_xx); DEFINE_DEFAULT(box_blur_xy); diff --git a/src/core/SkOpts.h b/src/core/SkOpts.h index b09d8cfd9f..2c6a118960 100644 --- a/src/core/SkOpts.h +++ b/src/core/SkOpts.h @@ -43,15 +43,6 @@ namespace SkOpts { extern void (*blit_row_color32)(SkPMColor*, const SkPMColor*, int, SkPMColor); extern void (*blit_row_s32a_opaque)(SkPMColor*, const SkPMColor*, int, U8CPU); - // This function is an optimized version of SkColorCubeFilter::filterSpan - extern void (*color_cube_filter_span)(const SkPMColor[], - int, - SkPMColor[], - const int * [2], - const SkScalar * [2], - int, - const SkColor*); - // Swizzle input into some sort of 8888 pixel, {premul,unpremul} x {rgba,bgra}. typedef void (*Swizzle_8888)(uint32_t*, const void*, int); extern Swizzle_8888 RGBA_to_BGRA, // i.e. just swap RB diff --git a/src/effects/SkColorCubeFilter.cpp b/src/effects/SkColorCubeFilter.cpp deleted file mode 100644 index 6907f030d0..0000000000 --- a/src/effects/SkColorCubeFilter.cpp +++ /dev/null @@ -1,329 +0,0 @@ -/* - * Copyright 2014 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "SkColorCubeFilter.h" -#include "SkColorPriv.h" -#include "SkOnce.h" -#include "SkOpts.h" -#include "SkReadBuffer.h" -#include "SkUnPreMultiply.h" -#include "SkWriteBuffer.h" -#if SK_SUPPORT_GPU -#include "GrContext.h" -#include "GrCoordTransform.h" -#include "GrInvariantOutput.h" -#include "GrTexturePriv.h" -#include "SkGr.h" -#include "glsl/GrGLSLFragmentProcessor.h" -#include "glsl/GrGLSLFragmentShaderBuilder.h" -#include "glsl/GrGLSLProgramDataManager.h" -#include "glsl/GrGLSLUniformHandler.h" -#endif - -/////////////////////////////////////////////////////////////////////////////// -namespace { - -int32_t SkNextColorCubeUniqueID() { - static int32_t gColorCubeUniqueID; - // do a loop in case our global wraps around, as we never want to return a 0 - int32_t genID; - do { - genID = sk_atomic_inc(&gColorCubeUniqueID) + 1; - } while (0 == genID); - return genID; -} - -} // end namespace - -static const int MIN_CUBE_SIZE = 4; -static const int MAX_CUBE_SIZE = 64; - -static bool is_valid_3D_lut(SkData* cubeData, int cubeDimension) { - size_t minMemorySize = sizeof(uint8_t) * 4 * cubeDimension * cubeDimension * cubeDimension; - return (cubeDimension >= MIN_CUBE_SIZE) && (cubeDimension <= MAX_CUBE_SIZE) && - (nullptr != cubeData) && (cubeData->size() >= minMemorySize); -} - -sk_sp<SkColorFilter> SkColorCubeFilter::Make(sk_sp<SkData> cubeData, int cubeDimension) { - if (!is_valid_3D_lut(cubeData.get(), cubeDimension)) { - return nullptr; - } - - return sk_sp<SkColorFilter>(new SkColorCubeFilter(std::move(cubeData), cubeDimension)); -} - -SkColorCubeFilter::SkColorCubeFilter(sk_sp<SkData> cubeData, int cubeDimension) - : fCubeData(std::move(cubeData)) - , fUniqueID(SkNextColorCubeUniqueID()) - , fCache(cubeDimension) -{} - -uint32_t SkColorCubeFilter::getFlags() const { - return this->INHERITED::getFlags() | kAlphaUnchanged_Flag; -} - -SkColorCubeFilter::ColorCubeProcesingCache::ColorCubeProcesingCache(int cubeDimension) - : fCubeDimension(cubeDimension) { - fColorToIndex[0] = fColorToIndex[1] = nullptr; - fColorToFactors[0] = fColorToFactors[1] = nullptr; - fColorToScalar = nullptr; -} - -void SkColorCubeFilter::ColorCubeProcesingCache::getProcessingLuts( - const int* (*colorToIndex)[2], const SkScalar* (*colorToFactors)[2], - const SkScalar** colorToScalar) { - fLutsInitOnce(SkColorCubeFilter::ColorCubeProcesingCache::initProcessingLuts, this); - - SkASSERT((fColorToIndex[0] != nullptr) && - (fColorToIndex[1] != nullptr) && - (fColorToFactors[0] != nullptr) && - (fColorToFactors[1] != nullptr) && - (fColorToScalar != nullptr)); - (*colorToIndex)[0] = fColorToIndex[0]; - (*colorToIndex)[1] = fColorToIndex[1]; - (*colorToFactors)[0] = fColorToFactors[0]; - (*colorToFactors)[1] = fColorToFactors[1]; - (*colorToScalar) = fColorToScalar; -} - -void SkColorCubeFilter::ColorCubeProcesingCache::initProcessingLuts( - SkColorCubeFilter::ColorCubeProcesingCache* cache) { - static const SkScalar inv8bit = SkScalarInvert(SkIntToScalar(255)); - - // We need 256 int * 2 for fColorToIndex, so a total of 512 int. - // We need 256 SkScalar * 2 for fColorToFactors and 256 SkScalar - // for fColorToScalar, so a total of 768 SkScalar. - cache->fLutStorage.reset(512 * sizeof(int) + 768 * sizeof(SkScalar)); - uint8_t* storage = cache->fLutStorage.get(); - cache->fColorToIndex[0] = (int*)storage; - cache->fColorToIndex[1] = cache->fColorToIndex[0] + 256; - cache->fColorToFactors[0] = (SkScalar*)(storage + (512 * sizeof(int))); - cache->fColorToFactors[1] = cache->fColorToFactors[0] + 256; - cache->fColorToScalar = cache->fColorToFactors[1] + 256; - - SkScalar size = SkIntToScalar(cache->fCubeDimension); - SkScalar scale = (size - SK_Scalar1) * inv8bit; - - for (int i = 0; i < 256; ++i) { - SkScalar index = scale * i; - cache->fColorToIndex[0][i] = SkScalarFloorToInt(index); - cache->fColorToIndex[1][i] = cache->fColorToIndex[0][i] + 1; - cache->fColorToScalar[i] = inv8bit * i; - if (cache->fColorToIndex[1][i] < cache->fCubeDimension) { - cache->fColorToFactors[1][i] = index - SkIntToScalar(cache->fColorToIndex[0][i]); - cache->fColorToFactors[0][i] = SK_Scalar1 - cache->fColorToFactors[1][i]; - } else { - cache->fColorToIndex[1][i] = cache->fColorToIndex[0][i]; - cache->fColorToFactors[0][i] = SK_Scalar1; - cache->fColorToFactors[1][i] = 0; - } - } -} - -void SkColorCubeFilter::filterSpan(const SkPMColor src[], int count, SkPMColor dst[]) const { - const int* colorToIndex[2]; - const SkScalar* colorToFactors[2]; - const SkScalar* colorToScalar; - fCache.getProcessingLuts(&colorToIndex, &colorToFactors, &colorToScalar); - - SkOpts::color_cube_filter_span(src, count, dst, colorToIndex, - colorToFactors, fCache.cubeDimension(), - (const SkColor*)fCubeData->data()); -} - -sk_sp<SkFlattenable> SkColorCubeFilter::CreateProc(SkReadBuffer& buffer) { - int cubeDimension = buffer.readInt(); - auto cubeData(buffer.readByteArrayAsData()); - if (!buffer.validate(is_valid_3D_lut(cubeData.get(), cubeDimension))) { - return nullptr; - } - return Make(std::move(cubeData), cubeDimension); -} - -void SkColorCubeFilter::flatten(SkWriteBuffer& buffer) const { - this->INHERITED::flatten(buffer); - buffer.writeInt(fCache.cubeDimension()); - buffer.writeDataAsByteArray(fCubeData.get()); -} - -#ifndef SK_IGNORE_TO_STRING -void SkColorCubeFilter::toString(SkString* str) const { - str->append("SkColorCubeFilter "); -} -#endif - -/////////////////////////////////////////////////////////////////////////////// -#if SK_SUPPORT_GPU - -class GrColorCubeEffect : public GrFragmentProcessor { -public: - static sk_sp<GrFragmentProcessor> Make(GrTexture* colorCube) { - return (nullptr != colorCube) ? sk_sp<GrFragmentProcessor>(new GrColorCubeEffect(colorCube)) - : nullptr; - } - - virtual ~GrColorCubeEffect(); - - const char* name() const override { return "ColorCube"; } - - int colorCubeSize() const { return fColorCubeSampler.texture()->width(); } - - - void onComputeInvariantOutput(GrInvariantOutput*) const override; - - class GLSLProcessor : public GrGLSLFragmentProcessor { - public: - void emitCode(EmitArgs&) override; - - static inline void GenKey(const GrProcessor&, const GrShaderCaps&, GrProcessorKeyBuilder*); - - protected: - void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override; - - private: - GrGLSLProgramDataManager::UniformHandle fColorCubeSizeUni; - GrGLSLProgramDataManager::UniformHandle fColorCubeInvSizeUni; - - typedef GrGLSLFragmentProcessor INHERITED; - }; - -private: - virtual void onGetGLSLProcessorKey(const GrShaderCaps& caps, - GrProcessorKeyBuilder* b) const override; - - GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; - - bool onIsEqual(const GrFragmentProcessor&) const override { return true; } - - GrColorCubeEffect(GrTexture* colorCube); - - TextureSampler fColorCubeSampler; - - typedef GrFragmentProcessor INHERITED; -}; - -/////////////////////////////////////////////////////////////////////////////// - -GrColorCubeEffect::GrColorCubeEffect(GrTexture* colorCube) - : fColorCubeSampler(colorCube, GrSamplerParams::kBilerp_FilterMode) { - this->initClassID<GrColorCubeEffect>(); - this->addTextureSampler(&fColorCubeSampler); -} - -GrColorCubeEffect::~GrColorCubeEffect() { -} - -void GrColorCubeEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps, - GrProcessorKeyBuilder* b) const { - GLSLProcessor::GenKey(*this, caps, b); -} - -GrGLSLFragmentProcessor* GrColorCubeEffect::onCreateGLSLInstance() const { - return new GLSLProcessor; -} - -void GrColorCubeEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { - inout->setToUnknown(GrInvariantOutput::kWill_ReadInput); -} - -/////////////////////////////////////////////////////////////////////////////// - -void GrColorCubeEffect::GLSLProcessor::emitCode(EmitArgs& args) { - if (nullptr == args.fInputColor) { - args.fInputColor = "vec4(1)"; - } - - GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; - fColorCubeSizeUni = uniformHandler->addUniform(kFragment_GrShaderFlag, - kFloat_GrSLType, kDefault_GrSLPrecision, - "Size"); - const char* colorCubeSizeUni = uniformHandler->getUniformCStr(fColorCubeSizeUni); - fColorCubeInvSizeUni = uniformHandler->addUniform(kFragment_GrShaderFlag, - kFloat_GrSLType, kDefault_GrSLPrecision, - "InvSize"); - const char* colorCubeInvSizeUni = uniformHandler->getUniformCStr(fColorCubeInvSizeUni); - - const char* nonZeroAlpha = "nonZeroAlpha"; - const char* unPMColor = "unPMColor"; - const char* cubeIdx = "cubeIdx"; - const char* cCoords1 = "cCoords1"; - const char* cCoords2 = "cCoords2"; - - // Note: if implemented using texture3D in OpenGL ES older than OpenGL ES 3.0, - // the shader might need "#extension GL_OES_texture_3D : enable". - - GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; - - // Unpremultiply color - fragBuilder->codeAppendf("\tfloat %s = max(%s.a, 0.00001);\n", nonZeroAlpha, args.fInputColor); - fragBuilder->codeAppendf("\tvec4 %s = vec4(%s.rgb / %s, %s);\n", - unPMColor, args.fInputColor, nonZeroAlpha, nonZeroAlpha); - - // Fit input color into the cube. - fragBuilder->codeAppendf( - "vec3 %s = vec3(%s.rg * vec2((%s - 1.0) * %s) + vec2(0.5 * %s), %s.b * (%s - 1.0));\n", - cubeIdx, unPMColor, colorCubeSizeUni, colorCubeInvSizeUni, colorCubeInvSizeUni, - unPMColor, colorCubeSizeUni); - - // Compute y coord for for texture fetches. - fragBuilder->codeAppendf("vec2 %s = vec2(%s.r, (floor(%s.b) + %s.g) * %s);\n", - cCoords1, cubeIdx, cubeIdx, cubeIdx, colorCubeInvSizeUni); - fragBuilder->codeAppendf("vec2 %s = vec2(%s.r, (ceil(%s.b) + %s.g) * %s);\n", - cCoords2, cubeIdx, cubeIdx, cubeIdx, colorCubeInvSizeUni); - - // Apply the cube. - fragBuilder->codeAppendf("%s = vec4(mix(", args.fOutputColor); - fragBuilder->appendTextureLookup(args.fTexSamplers[0], cCoords1); - fragBuilder->codeAppend(".bgr, "); - fragBuilder->appendTextureLookup(args.fTexSamplers[0], cCoords2); - - // Premultiply color by alpha. Note that the input alpha is not modified by this shader. - fragBuilder->codeAppendf(".bgr, fract(%s.b)) * vec3(%s), %s.a);\n", - cubeIdx, nonZeroAlpha, args.fInputColor); -} - -void GrColorCubeEffect::GLSLProcessor::onSetData(const GrGLSLProgramDataManager& pdman, - const GrProcessor& proc) { - const GrColorCubeEffect& colorCube = proc.cast<GrColorCubeEffect>(); - SkScalar size = SkIntToScalar(colorCube.colorCubeSize()); - pdman.set1f(fColorCubeSizeUni, SkScalarToFloat(size)); - pdman.set1f(fColorCubeInvSizeUni, SkScalarToFloat(SkScalarInvert(size))); -} - -void GrColorCubeEffect::GLSLProcessor::GenKey(const GrProcessor& proc, - const GrShaderCaps&, GrProcessorKeyBuilder* b) { -} - -sk_sp<GrFragmentProcessor> SkColorCubeFilter::asFragmentProcessor(GrContext* context, - SkColorSpace*) const { - static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); - GrUniqueKey key; - GrUniqueKey::Builder builder(&key, kDomain, 2); - builder[0] = fUniqueID; - builder[1] = fCache.cubeDimension(); - builder.finish(); - - GrSurfaceDesc desc; - desc.fWidth = fCache.cubeDimension(); - desc.fHeight = fCache.cubeDimension() * fCache.cubeDimension(); - desc.fConfig = kRGBA_8888_GrPixelConfig; - desc.fIsMipMapped = false; - - sk_sp<GrTexture> textureCube(context->textureProvider()->findAndRefTextureByUniqueKey(key)); - if (!textureCube) { - textureCube.reset(context->textureProvider()->createTexture( - desc, SkBudgeted::kYes, fCubeData->data(), 0)); - if (textureCube) { - context->textureProvider()->assignUniqueKeyToTexture(key, textureCube.get()); - } else { - return nullptr; - } - } - - return sk_sp<GrFragmentProcessor>(GrColorCubeEffect::Make(textureCube.get())); -} -#endif diff --git a/src/opts/SkColorCubeFilter_opts.h b/src/opts/SkColorCubeFilter_opts.h deleted file mode 100644 index 12acd78039..0000000000 --- a/src/opts/SkColorCubeFilter_opts.h +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef SkColorCubeFilter_opts_DEFINED -#define SkColorCubeFilter_opts_DEFINED - -#include "SkColor.h" -#include "SkNx.h" -#include "SkUnPreMultiply.h" - -namespace SK_OPTS_NS { - -static void color_cube_filter_span(const SkPMColor src[], - int count, - SkPMColor dst[], - const int* colorToIndex[2], - const SkScalar* colorToFactors[2], - int dim, - const SkColor* colorCube) { - uint8_t r, g, b, a; - - for (int i = 0; i < count; ++i) { - const SkPMColor input = src[i]; - a = input >> SK_A32_SHIFT; - - if (a != 255) { - const SkColor source = SkUnPreMultiply::PMColorToColor(input); - r = SkColorGetR(source); - g = SkColorGetG(source); - b = SkColorGetB(source); - } else { - r = SkGetPackedR32(input); - g = SkGetPackedG32(input); - b = SkGetPackedB32(input); - } - - const SkScalar g0 = colorToFactors[0][g], - g1 = colorToFactors[1][g], - b0 = colorToFactors[0][b], - b1 = colorToFactors[1][b]; - - const Sk4f g0b0(g0*b0), - g0b1(g0*b1), - g1b0(g1*b0), - g1b1(g1*b1); - - const int i00 = (colorToIndex[0][g] + colorToIndex[0][b] * dim) * dim; - const int i01 = (colorToIndex[0][g] + colorToIndex[1][b] * dim) * dim; - const int i10 = (colorToIndex[1][g] + colorToIndex[0][b] * dim) * dim; - const int i11 = (colorToIndex[1][g] + colorToIndex[1][b] * dim) * dim; - - Sk4f color(0.5f); // Starting from 0.5f gets us rounding for free. - for (int x = 0; x < 2; ++x) { - const int ix = colorToIndex[x][r]; - - const SkColor lutColor00 = colorCube[ix + i00]; - const SkColor lutColor01 = colorCube[ix + i01]; - const SkColor lutColor10 = colorCube[ix + i10]; - const SkColor lutColor11 = colorCube[ix + i11]; - - Sk4f sum = SkNx_cast<float>(Sk4b::Load(&lutColor00)) * g0b0; - sum = sum + SkNx_cast<float>(Sk4b::Load(&lutColor01)) * g0b1; - sum = sum + SkNx_cast<float>(Sk4b::Load(&lutColor10)) * g1b0; - sum = sum + SkNx_cast<float>(Sk4b::Load(&lutColor11)) * g1b1; - color = color + sum * Sk4f((float)colorToFactors[x][r]); - } - if (a != 255) { - color = color * Sk4f(a * (1.0f/255)); - } - - // color is BGRA (SkColor order), dst is SkPMColor order, so may need to swap R+B. - #if defined(SK_PMCOLOR_IS_RGBA) - color = SkNx_shuffle<2,1,0,3>(color); - #endif - uint8_t* dstBytes = (uint8_t*)(dst+i); - SkNx_cast<uint8_t>(color).store(dstBytes); - dstBytes[SK_A32_SHIFT/8] = a; - } -} - -} // namespace SK_OPTS NS - -#endif // SkColorCubeFilter_opts_DEFINED diff --git a/src/opts/SkOpts_ssse3.cpp b/src/opts/SkOpts_ssse3.cpp index ec968339a0..0d2fcf42ac 100644 --- a/src/opts/SkOpts_ssse3.cpp +++ b/src/opts/SkOpts_ssse3.cpp @@ -8,7 +8,6 @@ #include "SkOpts.h" #define SK_OPTS_NS ssse3 #include "SkBlitMask_opts.h" -#include "SkColorCubeFilter_opts.h" #include "SkSwizzler_opts.h" #include "SkXfermode_opts.h" @@ -16,7 +15,6 @@ namespace SkOpts { void Init_ssse3() { create_xfermode = ssse3::create_xfermode; blit_mask_d32_a8 = ssse3::blit_mask_d32_a8; - color_cube_filter_span = ssse3::color_cube_filter_span; RGBA_to_BGRA = ssse3::RGBA_to_BGRA; RGBA_to_rgbA = ssse3::RGBA_to_rgbA; diff --git a/src/ports/SkGlobalInitialization_default.cpp b/src/ports/SkGlobalInitialization_default.cpp index abf318af52..dd6ef873b3 100644 --- a/src/ports/SkGlobalInitialization_default.cpp +++ b/src/ports/SkGlobalInitialization_default.cpp @@ -14,7 +14,6 @@ #include "SkBlurDrawLooper.h" #include "SkBlurImageFilter.h" #include "SkBlurMaskFilter.h" -#include "SkColorCubeFilter.h" #include "SkColorFilterImageFilter.h" #include "SkColorMatrixFilterRowMajor255.h" #include "SkComposeImageFilter.h" @@ -81,7 +80,6 @@ void SkFlattenable::PrivateInitializer::InitEffects() { SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLayerRasterizer) // ColorFilter - SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkColorCubeFilter) SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkColorMatrixFilterRowMajor255) SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLumaColorFilter) SkAlphaThresholdFilter::InitializeFlattenables(); |