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-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkFont.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkTextBlob.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkTypeface.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/GrContext.h"
|
2020-06-29 19:36:12 +00:00
|
|
|
#include "src/gpu/GrRecordingContextPriv.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "tools/ToolUtils.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
class GrRenderTargetContext;
|
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);
|
|
|
|
}
|
|
|
|
|
2020-06-29 19:36:12 +00:00
|
|
|
void onDraw(GrRecordingContext* 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
|
2020-06-29 19:36:12 +00:00
|
|
|
if (GrContext* directContext = context->priv().asDirectContext()) {
|
|
|
|
directContext->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
|
|
|
}
|