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

Unified Diff: bench/ColorCubeBench.cpp

Issue 580863004: Adding 3D lut color filter (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Update to ToT Created 6 years, 2 months 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 | « no previous file | gm/colorcube.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bench/ColorCubeBench.cpp
diff --git a/bench/ColorCubeBench.cpp b/bench/ColorCubeBench.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..16ed4ce892f72950e7f5f08f0d52d559f466862e
--- /dev/null
+++ b/bench/ColorCubeBench.cpp
@@ -0,0 +1,112 @@
+/*
+ * 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"
+
+class ColorCubeBench : public Benchmark {
+ SkISize fSize;
+ int fCubeDimension;
+ SkData* fCubeData;
+ SkBitmap fBitmap;
+
+public:
+ ColorCubeBench()
+ : fCubeDimension(0)
+ , fCubeData(NULL) {
+ fSize = SkISize::Make(2880, 1800); // 2014 Macbook Pro resolution
+ }
+
+ ~ColorCubeBench() {
+ SkSafeUnref(fCubeData);
+ }
+
+protected:
+ virtual const char* onGetName() SK_OVERRIDE {
+ return "colorcube";
+ }
+
+ virtual void onPreDraw() SK_OVERRIDE {
+ if (!SkToBool(fCubeData)) {
+ this->makeCubeData();
+ this->make_bitmap();
+ }
+ }
+
+ virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
+ this->test(loops, canvas);
+ }
+
+ virtual SkIPoint onGetSize() SK_OVERRIDE {
+ return SkIPoint::Make(fSize.width(), fSize.height());
+ }
+
+private:
+ static 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::CreateLinear(
+ pts, colors, NULL, 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);
+ SkShader* shader = MakeLinear(fSize);
+ paint.setShader(shader);
+ SkRect r = { 0, 0, SkIntToScalar(fSize.width()), SkIntToScalar(fSize.height()) };
+ canvas.drawRect(r, paint);
+ shader->unref();
+ }
+
+ void makeCubeData() {
+ fCubeDimension = 32;
+ fCubeData = SkData::NewUninitialized(sizeof(SkColor) *
+ fCubeDimension * fCubeDimension * fCubeDimension);
+ SkColor* pixels = (SkColor*)(fCubeData->writable_data());
+ SkAutoMalloc lutMemory(fCubeDimension);
+ uint8_t* lut = (uint8_t*)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(const int loops, SkCanvas* canvas) {
+ SkAutoTUnref<SkColorFilter> colorCube(
+ SkColorCubeFilter::Create(fCubeData, fCubeDimension));
+ SkPaint paint;
+ paint.setColorFilter(colorCube);
+
+ for (int i = 0; i < loops; i++) {
+ canvas->drawBitmap(fBitmap, 0, 0, &paint);
+ }
+ }
+
+ typedef Benchmark INHERITED;
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
+DEF_BENCH( return new ColorCubeBench(); )
« no previous file with comments | « no previous file | gm/colorcube.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698