c1ce2f7966
This reverts commit 48825b11ad
.
Reason for revert: nanobench
Original change's description:
> Redefine the meaning of sample counts in GPU backend.
>
> Old: 0 -> nonMSAA
> 1+ -> MSAA
>
> New:
> 0 -> error/unsupported
> 1 -> nonMSAA
> 2+ -> MSAA
>
> We still allow 0 to mean nonMSAA in three sets of public APIs for backwards compatibility:
>
> 1) SkSurface factories
> 2) GrBackendRenderTarget constructors
> 3) GrCaps::getSampleCnt()'s requestedCount parameter
>
> However, we immediately clamp to 1 and treat 0 as invalid/non-renderable internally.
>
> This also changes the behavior when using a large sample count. We now fail in that case rather than using the largest sample available sample count. GrCaps::getSampleCount() will return 0 in this case.
>
>
> Bug: skia:
> Change-Id: Ida22c6b22c1365e563c9046b611e88bf5eb3ff33
> Reviewed-on: https://skia-review.googlesource.com/101560
> Reviewed-by: Greg Daniel <egdaniel@google.com>
> Commit-Queue: Brian Salomon <bsalomon@google.com>
TBR=egdaniel@google.com,bsalomon@google.com
Change-Id: Ic257619a8a5ee9ac15419ecf10259e42daed7f82
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/102662
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
117 lines
3.0 KiB
C++
117 lines
3.0 KiB
C++
/*
|
|
* Copyright 2017 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "HelloWorld.h"
|
|
|
|
#include "GrContext.h"
|
|
#include "SkCanvas.h"
|
|
#include "SkGradientShader.h"
|
|
#include "SkGraphics.h"
|
|
|
|
using namespace sk_app;
|
|
|
|
Application* Application::Create(int argc, char** argv, void* platformData) {
|
|
return new HelloWorld(argc, argv, platformData);
|
|
}
|
|
|
|
HelloWorld::HelloWorld(int argc, char** argv, void* platformData)
|
|
: fBackendType(Window::kNativeGL_BackendType)
|
|
, fRotationAngle(0) {
|
|
SkGraphics::Init();
|
|
|
|
fWindow = Window::CreateNativeWindow(platformData);
|
|
fWindow->setRequestedDisplayParams(DisplayParams());
|
|
|
|
// register callbacks
|
|
fWindow->pushLayer(this);
|
|
|
|
fWindow->attach(fBackendType);
|
|
}
|
|
|
|
HelloWorld::~HelloWorld() {
|
|
fWindow->detach();
|
|
delete fWindow;
|
|
}
|
|
|
|
void HelloWorld::updateTitle() {
|
|
if (!fWindow || fWindow->sampleCount() < 0) {
|
|
return;
|
|
}
|
|
|
|
SkString title("Hello World ");
|
|
title.append(Window::kRaster_BackendType == fBackendType ? "Raster" : "OpenGL");
|
|
fWindow->setTitle(title.c_str());
|
|
}
|
|
|
|
void HelloWorld::onBackendCreated() {
|
|
this->updateTitle();
|
|
fWindow->show();
|
|
fWindow->inval();
|
|
}
|
|
|
|
void HelloWorld::onPaint(SkCanvas* canvas) {
|
|
// Clear background
|
|
canvas->clear(SK_ColorWHITE);
|
|
|
|
SkPaint paint;
|
|
paint.setColor(SK_ColorRED);
|
|
|
|
// Draw a rectangle with red paint
|
|
SkRect rect = SkRect::MakeXYWH(10, 10, 128, 128);
|
|
canvas->drawRect(rect, paint);
|
|
|
|
// Set up a linear gradient and draw a circle
|
|
{
|
|
SkPoint linearPoints[] = { { 0, 0 }, { 300, 300 } };
|
|
SkColor linearColors[] = { SK_ColorGREEN, SK_ColorBLACK };
|
|
paint.setShader(SkGradientShader::MakeLinear(linearPoints, linearColors, nullptr, 2,
|
|
SkShader::kMirror_TileMode));
|
|
paint.setAntiAlias(true);
|
|
|
|
canvas->drawCircle(200, 200, 64, paint);
|
|
|
|
// Detach shader
|
|
paint.setShader(nullptr);
|
|
}
|
|
|
|
// Draw a message with a nice black paint
|
|
paint.setSubpixelText(true);
|
|
paint.setColor(SK_ColorBLACK);
|
|
paint.setTextSize(20);
|
|
|
|
canvas->save();
|
|
static const char message[] = "Hello World";
|
|
|
|
// Translate and rotate
|
|
canvas->translate(300, 300);
|
|
fRotationAngle += 0.2f;
|
|
if (fRotationAngle > 360) {
|
|
fRotationAngle -= 360;
|
|
}
|
|
canvas->rotate(fRotationAngle);
|
|
|
|
// Draw the text
|
|
canvas->drawText(message, strlen(message), 0, 0, paint);
|
|
|
|
canvas->restore();
|
|
}
|
|
|
|
void HelloWorld::onIdle() {
|
|
// Just re-paint continously
|
|
fWindow->inval();
|
|
}
|
|
|
|
bool HelloWorld::onChar(SkUnichar c, uint32_t modifiers) {
|
|
if (' ' == c) {
|
|
fBackendType = Window::kRaster_BackendType == fBackendType ? Window::kNativeGL_BackendType
|
|
: Window::kRaster_BackendType;
|
|
fWindow->detach();
|
|
fWindow->attach(fBackendType);
|
|
}
|
|
return true;
|
|
}
|