2016-04-01 18:51:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
|
|
|
#include "include/core/SkBitmap.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkMatrix.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkRect.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkShader.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/core/SkTileMode.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/Resources.h"
|
2016-04-01 18:51:00 +00:00
|
|
|
|
2019-02-07 23:20:09 +00:00
|
|
|
DEF_SIMPLE_GM_CAN_FAIL(bitmap_subset_shader, canvas, errorMsg, 256, 256) {
|
2016-04-01 18:51:00 +00:00
|
|
|
canvas->clear(SK_ColorWHITE);
|
|
|
|
|
|
|
|
SkBitmap source;
|
2017-12-08 15:21:31 +00:00
|
|
|
if (!GetResourceAsBitmap("images/color_wheel.png", &source)) {
|
2019-02-07 23:20:09 +00:00
|
|
|
*errorMsg = "Could not load images/color_wheel.png. "
|
|
|
|
"Did you forget to set the resourcePath?";
|
|
|
|
return skiagm::DrawResult::kFail;
|
2016-04-01 18:51:00 +00:00
|
|
|
}
|
|
|
|
SkIRect left = SkIRect::MakeWH(source.width()/2, source.height());
|
|
|
|
SkIRect right = SkIRect::MakeXYWH(source.width()/2, 0,
|
|
|
|
source.width()/2, source.height());
|
|
|
|
SkBitmap leftBitmap, rightBitmap;
|
|
|
|
source.extractSubset(&leftBitmap, left);
|
|
|
|
source.extractSubset(&rightBitmap, right);
|
|
|
|
|
|
|
|
SkMatrix matrix;
|
|
|
|
matrix.setScale(0.75f, 0.75f);
|
|
|
|
matrix.preRotate(30.0f);
|
2019-04-03 14:27:45 +00:00
|
|
|
SkTileMode tm = SkTileMode::kRepeat;
|
2016-04-01 18:51:00 +00:00
|
|
|
SkPaint paint;
|
2019-04-08 17:20:23 +00:00
|
|
|
paint.setShader(leftBitmap.makeShader(tm, tm, &matrix));
|
2016-04-01 18:51:00 +00:00
|
|
|
canvas->drawRect(SkRect::MakeWH(256.0f, 128.0f), paint);
|
2019-04-08 17:20:23 +00:00
|
|
|
paint.setShader(rightBitmap.makeShader(tm, tm, &matrix));
|
2016-04-01 18:51:00 +00:00
|
|
|
canvas->drawRect(SkRect::MakeXYWH(0, 128.0f, 256.0f, 128.0f), paint);
|
2019-02-07 23:20:09 +00:00
|
|
|
return skiagm::DrawResult::kOk;
|
2016-04-01 18:51:00 +00:00
|
|
|
}
|