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";
|
|
|
|
|
2018-12-23 03:29:45 +00:00
|
|
|
SkFont font(sk_tool_utils::create_portable_typeface(), 20);
|
|
|
|
auto blob = SkTextBlob::MakeFromText(text, strlen(text), font);
|
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);
|
2018-12-23 03:29:45 +00:00
|
|
|
canvas->drawTextBlob(blob, 20, 60, SkPaint());
|
2015-05-26 19:32:23 +00:00
|
|
|
|
|
|
|
// This text should look fine
|
|
|
|
canvas->getGrContext()->freeGpuResources();
|
2018-12-23 03:29:45 +00:00
|
|
|
canvas->drawTextBlob(blob, 20, 160, SkPaint());
|
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
|
|
|
}
|