2015-05-26 19:32:23 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gm.h"
|
2017-03-22 17:47:51 +00:00
|
|
|
#include "sk_tool_utils.h"
|
2015-05-26 19:32:23 +00:00
|
|
|
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkSurface.h"
|
|
|
|
#include "SkTextBlob.h"
|
2015-05-27 20:23:23 +00:00
|
|
|
#include "GrContext.h"
|
2015-05-26 19:32:23 +00:00
|
|
|
|
|
|
|
// This tests that we correctly regenerate textblobs after freeing all gpu resources crbug/491350
|
|
|
|
namespace skiagm {
|
|
|
|
class TextBlobUseAfterGpuFree : public GM {
|
|
|
|
public:
|
|
|
|
TextBlobUseAfterGpuFree() { }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SkString onShortName() override {
|
|
|
|
return SkString("textblobuseaftergpufree");
|
|
|
|
}
|
|
|
|
|
|
|
|
SkISize onISize() override {
|
|
|
|
return SkISize::Make(kWidth, kHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
void onDraw(SkCanvas* canvas) override {
|
|
|
|
// This GM exists to test a specific feature of the GPU backend.
|
2015-08-27 14:41:13 +00:00
|
|
|
if (nullptr == canvas->getGrContext()) {
|
2015-09-09 15:16:41 +00:00
|
|
|
skiagm::GM::DrawGpuOnlyMessage(canvas);
|
2015-05-26 19:32:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char text[] = "Hamburgefons";
|
|
|
|
|
|
|
|
SkPaint paint;
|
2015-07-24 19:09:25 +00:00
|
|
|
sk_tool_utils::set_portable_typeface(&paint);
|
2015-07-20 17:48:01 +00:00
|
|
|
paint.setAntiAlias(true);
|
2015-05-26 19:32:23 +00:00
|
|
|
paint.setTextSize(20);
|
|
|
|
|
|
|
|
SkTextBlobBuilder builder;
|
|
|
|
|
|
|
|
sk_tool_utils::add_to_text_blob(&builder, text, paint, 10, 10);
|
|
|
|
|
2016-09-13 17:00:23 +00:00
|
|
|
sk_sp<SkTextBlob> blob(builder.make());
|
2015-05-26 19:32:23 +00:00
|
|
|
|
|
|
|
// draw textblob
|
|
|
|
SkRect rect = SkRect::MakeLTRB(0.f, 0.f, SkIntToScalar(kWidth), kHeight / 2.f);
|
|
|
|
SkPaint rectPaint;
|
|
|
|
rectPaint.setColor(0xffffffff);
|
|
|
|
canvas->drawRect(rect, rectPaint);
|
2016-09-13 17:00:23 +00:00
|
|
|
canvas->drawTextBlob(blob, 10, 50, paint);
|
2015-05-26 19:32:23 +00:00
|
|
|
|
|
|
|
// This text should look fine
|
|
|
|
canvas->getGrContext()->freeGpuResources();
|
2016-09-13 17:00:23 +00:00
|
|
|
canvas->drawTextBlob(blob, 10, 150, paint);
|
2015-05-26 19:32:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-09-01 18:24:54 +00:00
|
|
|
static constexpr int kWidth = 200;
|
|
|
|
static constexpr int kHeight = 200;
|
2015-05-26 19:32:23 +00:00
|
|
|
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
DEF_GM(return new TextBlobUseAfterGpuFree;)
|
2015-05-26 19:32:23 +00:00
|
|
|
}
|