aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/lightingshader.cpp
diff options
context:
space:
mode:
authorGravatar robertphillips <robertphillips@google.com>2015-08-19 13:11:23 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-08-19 13:11:23 -0700
commitf7d602a458f156723ec1a086f0fd132b1a9cc0e8 (patch)
tree6fbe3eb08cebe671d75d56edfda48967c374412f /gm/lightingshader.cpp
parenta060eba0836f98902ca078d5f9fc6191ba0c0a52 (diff)
Revert "Update SkLightingShader to support rotation"
This reverts commit 45b59ed6e4e231814dbdb9f707b3d2a7ee50de84. TBR=herb@google.com Review URL: https://codereview.chromium.org/1304673002
Diffstat (limited to 'gm/lightingshader.cpp')
-rw-r--r--gm/lightingshader.cpp84
1 files changed, 19 insertions, 65 deletions
diff --git a/gm/lightingshader.cpp b/gm/lightingshader.cpp
index c73ad5b4c8..7e33504477 100644
--- a/gm/lightingshader.cpp
+++ b/gm/lightingshader.cpp
@@ -19,7 +19,7 @@ static SkBitmap make_checkerboard(int texSize) {
sk_tool_utils::draw_checkerboard(&canvas,
sk_tool_utils::color_to_565(0x0),
sk_tool_utils::color_to_565(0xFF804020),
- 8);
+ 2);
return bitmap;
}
@@ -58,13 +58,10 @@ public:
LightingShaderGM() {
this->setBGColor(sk_tool_utils::color_to_565(0xFFCCCCCC));
- SkLightingShader::Lights::Builder builder;
+ fLight.fColor = SkColor3f::Make(1.0f, 1.0f, 1.0f);
+ fLight.fDirection = SkVector3::Make(0.0f, 0.0f, 1.0f);
- builder.add(SkLight(SkColor3f::Make(1.0f, 1.0f, 1.0f),
- SkVector3::Make(1.0f, 0.0f, 0.0f)));
- builder.add(SkLight(SkColor3f::Make(0.2f, 0.2f, 0.2f)));
-
- fLights.reset(builder.finish());
+ fAmbient = SkColor3f::Make(0.1f, 0.1f, 0.1f);
}
protected:
@@ -101,16 +98,11 @@ protected:
SkMatrix matrix;
matrix.setRectToRect(bitmapBounds, r, SkMatrix::kFill_ScaleToFit);
- const SkMatrix& ctm = canvas->getTotalMatrix();
-
- // TODO: correctly pull out the pure rotation
- SkVector invNormRotation = { ctm[SkMatrix::kMScaleX], ctm[SkMatrix::kMSkewY] };
-
SkAutoTUnref<SkShader> fShader(SkLightingShader::Create(
fDiffuse,
fNormalMaps[mapType],
- fLights,
- invNormRotation, &matrix, &matrix));
+ fLight, fAmbient,
+ &matrix));
SkPaint paint;
paint.setShader(fShader);
@@ -119,56 +111,17 @@ protected:
}
void onDraw(SkCanvas* canvas) override {
- SkMatrix m;
- SkRect r;
-
- {
- r = SkRect::MakeWH(SkIntToScalar(kTexSize), SkIntToScalar(kTexSize));
- this->drawRect(canvas, r, kHemi_NormalMap);
-
- canvas->save();
- m.setRotate(45.0f, r.centerX(), r.centerY());
- m.postTranslate(kGMSize/2.0f - kTexSize/2.0f, 0.0f);
- canvas->setMatrix(m);
- this->drawRect(canvas, r, kHemi_NormalMap);
- canvas->restore();
- }
-
- {
- r.offset(kGMSize - kTexSize, 0);
- this->drawRect(canvas, r, kFrustum_NormalMap);
-
- canvas->save();
- m.setRotate(45.0f, r.centerX(), r.centerY());
- m.postTranslate(0.0f, kGMSize/2.0f - kTexSize/2.0f);
- canvas->setMatrix(m);
- this->drawRect(canvas, r, kFrustum_NormalMap);
- canvas->restore();
- }
-
- {
- r.offset(0, kGMSize - kTexSize);
- this->drawRect(canvas, r, kTetra_NormalMap);
-
- canvas->save();
- m.setRotate(45.0f, r.centerX(), r.centerY());
- m.postTranslate(-kGMSize/2.0f + kTexSize/2.0f, 0.0f);
- canvas->setMatrix(m);
- this->drawRect(canvas, r, kTetra_NormalMap);
- canvas->restore();
- }
-
- {
- r.offset(kTexSize - kGMSize, 0);
- this->drawRect(canvas, r, kHemi_NormalMap);
-
- canvas->save();
- m.setRotate(45.0f, r.centerX(), r.centerY());
- m.postTranslate(0.0f, -kGMSize/2.0f + kTexSize/2.0f);
- canvas->setMatrix(m);
- this->drawRect(canvas, r, kHemi_NormalMap);
- canvas->restore();
- }
+ SkRect r = SkRect::MakeWH(SkIntToScalar(kTexSize), SkIntToScalar(kTexSize));
+ this->drawRect(canvas, r, kHemi_NormalMap);
+
+ r.offset(kGMSize - kTexSize, 0);
+ this->drawRect(canvas, r, kFrustum_NormalMap);
+
+ r.offset(0, kGMSize - kTexSize);
+ this->drawRect(canvas, r, kTetra_NormalMap);
+
+ r.offset(kTexSize - kGMSize, 0);
+ this->drawRect(canvas, r, kHemi_NormalMap);
}
private:
@@ -178,7 +131,8 @@ private:
SkBitmap fDiffuse;
SkBitmap fNormalMaps[kNormalMapCount];
- SkAutoTUnref<const SkLightingShader::Lights> fLights;
+ SkLightingShader::Light fLight;
+ SkColor3f fAmbient;
typedef GM INHERITED;
};