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.
|
|
|
|
*/
|
|
|
|
|
2019-03-20 16:12:10 +00:00
|
|
|
#include "ToolUtils.h"
|
2015-05-26 19:32:23 +00:00
|
|
|
#include "gm.h"
|
|
|
|
|
|
|
|
#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 {
|
2019-02-07 22:23:36 +00:00
|
|
|
class TextBlobUseAfterGpuFree : public GpuGM {
|
2015-05-26 19:32:23 +00:00
|
|
|
public:
|
|
|
|
TextBlobUseAfterGpuFree() { }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SkString onShortName() override {
|
|
|
|
return SkString("textblobuseaftergpufree");
|
|
|
|
}
|
|
|
|
|
|
|
|
SkISize onISize() override {
|
|
|
|
return SkISize::Make(kWidth, kHeight);
|
|
|
|
}
|
|
|
|
|
2019-02-07 22:23:36 +00:00
|
|
|
void onDraw(GrContext* context, GrRenderTargetContext*, SkCanvas* canvas) override {
|
2015-05-26 19:32:23 +00:00
|
|
|
const char text[] = "Hamburgefons";
|
|
|
|
|
2019-03-20 16:12:10 +00:00
|
|
|
SkFont font(ToolUtils::create_portable_typeface(), 20);
|
2018-12-23 03:29:45 +00:00
|
|
|
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
|
2019-02-07 22:23:36 +00:00
|
|
|
context->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
|
|
|
}
|