2016-01-20 14:18:10 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// This test only works with the GPU backend.
|
|
|
|
|
|
|
|
#include "gm.h"
|
|
|
|
|
Revert "Revert "Plumb GrBackendTexture throughout skia.""
This reverts commit 7fa5c31c2c9af834bee66d5fcf476e250076c8d6.
Reason for revert: Relanding this change now that other fixes have landed.
Original change's description:
> Revert "Plumb GrBackendTexture throughout skia."
>
> This reverts commit 7da62b9059f3c1d31624a0e4da96ee5f908f9c12.
>
> Reason for revert: fix android roll
>
> Original change's description:
> > Plumb GrBackendTexture throughout skia.
> >
> > Bug: skia:
> > Change-Id: I1bae6768ee7229818a83ba608035a1f7867e6875
> > Reviewed-on: https://skia-review.googlesource.com/13645
> > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > Reviewed-by: Robert Phillips <robertphillips@google.com>
> >
>
> TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,brianosman@google.com,reviews@skia.org,stani@google.com
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
>
> Change-Id: I5cb8763cc837c83ebc6d10366fe2dd3efe35fb89
> Reviewed-on: https://skia-review.googlesource.com/13773
> Reviewed-by: Stan Iliev <stani@google.com>
> Commit-Queue: Stan Iliev <stani@google.com>
>
TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,reviews@skia.org,brianosman@google.com,stani@google.com
# Not skipping CQ checks because original CL landed > 1 day ago.
Change-Id: I92bc074e4fe37fa5c83186afadc472c03802e8f2
Reviewed-on: https://skia-review.googlesource.com/13975
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
2017-04-20 16:41:55 +00:00
|
|
|
#include "GrBackendSurface.h"
|
2016-01-20 14:18:10 +00:00
|
|
|
#include "GrContext.h"
|
2018-01-22 15:48:15 +00:00
|
|
|
#include "GrContextPriv.h"
|
2016-05-20 18:14:33 +00:00
|
|
|
#include "GrGpu.h"
|
|
|
|
#include "gl/GrGLContext.h"
|
2016-01-20 14:18:10 +00:00
|
|
|
#include "SkBitmap.h"
|
|
|
|
#include "SkGradientShader.h"
|
|
|
|
#include "SkImage.h"
|
|
|
|
|
|
|
|
namespace skiagm {
|
2019-02-07 22:23:36 +00:00
|
|
|
class RectangleTexture : public GpuGM {
|
2016-01-20 14:18:10 +00:00
|
|
|
public:
|
|
|
|
RectangleTexture() {
|
|
|
|
this->setBGColor(0xFFFFFFFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SkString onShortName() override {
|
|
|
|
return SkString("rectangle_texture");
|
|
|
|
}
|
|
|
|
|
2018-12-06 20:33:02 +00:00
|
|
|
SkISize onISize() override { return SkISize::Make(1200, 500); }
|
2016-01-20 14:18:10 +00:00
|
|
|
|
|
|
|
void fillPixels(int width, int height, void *pixels) {
|
|
|
|
SkBitmap bmp;
|
|
|
|
bmp.setInfo(SkImageInfo::MakeN32(width, height, kOpaque_SkAlphaType), width * 4);
|
|
|
|
bmp.setPixels(pixels);
|
|
|
|
SkPaint paint;
|
|
|
|
SkCanvas canvas(bmp);
|
|
|
|
SkPoint pts[] = { {0, 0}, {0, SkIntToScalar(height)} };
|
|
|
|
SkColor colors0[] = { 0xFF1060B0 , 0xFF102030 };
|
2019-04-03 14:27:45 +00:00
|
|
|
paint.setShader(SkGradientShader::MakeLinear(pts, colors0, nullptr, 2, SkTileMode::kClamp));
|
2016-01-20 14:18:10 +00:00
|
|
|
canvas.drawPaint(paint);
|
|
|
|
|
2018-12-06 20:33:02 +00:00
|
|
|
SkColor colors1[] = {0xFFA07010, 0xFFA02080};
|
2016-01-20 14:18:10 +00:00
|
|
|
paint.setAntiAlias(true);
|
2019-04-03 14:27:45 +00:00
|
|
|
paint.setShader(SkGradientShader::MakeLinear(pts, colors1, nullptr, 2, SkTileMode::kClamp));
|
2016-01-20 14:18:10 +00:00
|
|
|
canvas.drawCircle(SkIntToScalar(width) / 2, SkIntToScalar(height) / 2,
|
|
|
|
SkIntToScalar(width + height) / 5, paint);
|
|
|
|
}
|
|
|
|
|
2019-04-02 14:01:11 +00:00
|
|
|
static const GrGLContext* GetGLContextIfSupported(GrContext* context) {
|
2019-02-04 18:26:26 +00:00
|
|
|
GrGpu* gpu = context->priv().getGpu();
|
2016-01-20 14:18:10 +00:00
|
|
|
if (!gpu) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
const GrGLContext* glCtx = gpu->glContextForTesting();
|
|
|
|
if (!glCtx) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-04-02 18:54:51 +00:00
|
|
|
#if 0 // TODO(bsalomon): use extensions on GLES?
|
|
|
|
bool is_GL31 = glCtx->standard() == kGL_GrGLStandard
|
|
|
|
&& glCtx->version() >= GR_GL_VER(3, 1);
|
|
|
|
if (!is_GL31
|
|
|
|
&& !glCtx->hasExtension("GL_ARB_texture_rectangle")
|
|
|
|
&& !glCtx->hasExtension("GL_ANGLE_texture_rectangle")) {
|
2016-01-20 14:18:10 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2019-04-02 18:54:51 +00:00
|
|
|
#else
|
|
|
|
if (glCtx->standard() != kGL_GrGLStandard) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (glCtx->version() < GR_GL_VER(3,1)
|
|
|
|
&& !glCtx->hasExtension("GL_ARB_texture_rectangle")
|
|
|
|
&& !glCtx->hasExtension("GL_ANGLE_texture_rectangle")) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-04-02 14:01:11 +00:00
|
|
|
return glCtx;
|
|
|
|
}
|
|
|
|
|
|
|
|
sk_sp<SkImage> createRectangleTextureImg(GrContext* context, GrSurfaceOrigin origin, int width,
|
|
|
|
int height, const uint32_t* pixels) {
|
|
|
|
const GrGLContext* glCtx = GetGLContextIfSupported(context);
|
|
|
|
if (!glCtx) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-01-20 14:18:10 +00:00
|
|
|
|
|
|
|
// We will always create the GL texture as GL_RGBA, however the pixels uploaded may be
|
|
|
|
// be RGBA or BGRA, depending on how SkPMColor was compiled.
|
|
|
|
GrGLenum format;
|
|
|
|
if (kSkia8888_GrPixelConfig == kBGRA_8888_GrPixelConfig) {
|
|
|
|
format = GR_GL_BGRA;
|
|
|
|
} else {
|
|
|
|
SkASSERT(kSkia8888_GrPixelConfig == kRGBA_8888_GrPixelConfig);
|
|
|
|
format = GR_GL_RGBA;
|
|
|
|
}
|
|
|
|
|
|
|
|
const GrGLInterface* gl = glCtx->interface();
|
2018-12-06 20:33:02 +00:00
|
|
|
// Useful for debugging whether errors result from use of RECTANGLE
|
|
|
|
// static constexpr GrGLenum kTarget = GR_GL_TEXTURE_2D;
|
|
|
|
static constexpr GrGLenum kTarget = GR_GL_TEXTURE_RECTANGLE;
|
2016-03-21 16:04:26 +00:00
|
|
|
GrGLuint id = 0;
|
2016-01-20 14:18:10 +00:00
|
|
|
GR_GL_CALL(gl, GenTextures(1, &id));
|
2018-12-06 20:33:02 +00:00
|
|
|
GR_GL_CALL(gl, BindTexture(kTarget, id));
|
|
|
|
GR_GL_CALL(gl, TexParameteri(kTarget, GR_GL_TEXTURE_MAG_FILTER, GR_GL_NEAREST));
|
|
|
|
GR_GL_CALL(gl, TexParameteri(kTarget, GR_GL_TEXTURE_MIN_FILTER, GR_GL_NEAREST));
|
|
|
|
GR_GL_CALL(gl, TexParameteri(kTarget, GR_GL_TEXTURE_WRAP_S, GR_GL_CLAMP_TO_EDGE));
|
|
|
|
GR_GL_CALL(gl, TexParameteri(kTarget, GR_GL_TEXTURE_WRAP_T, GR_GL_CLAMP_TO_EDGE));
|
|
|
|
std::unique_ptr<uint32_t[]> tempPixels;
|
|
|
|
if (origin == kBottomLeft_GrSurfaceOrigin) {
|
|
|
|
tempPixels.reset(new uint32_t[width * height]);
|
|
|
|
for (int y = 0; y < height; ++y) {
|
|
|
|
std::copy_n(pixels + width * (height - y - 1), width, tempPixels.get() + width * y);
|
|
|
|
}
|
|
|
|
pixels = tempPixels.get();
|
|
|
|
}
|
|
|
|
GR_GL_CALL(gl, TexImage2D(kTarget, 0, GR_GL_RGBA, width, height, 0, format,
|
|
|
|
GR_GL_UNSIGNED_BYTE, pixels));
|
2016-01-20 14:18:10 +00:00
|
|
|
|
|
|
|
context->resetContext();
|
|
|
|
GrGLTextureInfo info;
|
|
|
|
info.fID = id;
|
2018-12-06 20:33:02 +00:00
|
|
|
info.fTarget = kTarget;
|
2017-12-18 19:48:15 +00:00
|
|
|
info.fFormat = GR_GL_RGBA8;
|
Revert "Revert "Plumb GrBackendTexture throughout skia.""
This reverts commit 7fa5c31c2c9af834bee66d5fcf476e250076c8d6.
Reason for revert: Relanding this change now that other fixes have landed.
Original change's description:
> Revert "Plumb GrBackendTexture throughout skia."
>
> This reverts commit 7da62b9059f3c1d31624a0e4da96ee5f908f9c12.
>
> Reason for revert: fix android roll
>
> Original change's description:
> > Plumb GrBackendTexture throughout skia.
> >
> > Bug: skia:
> > Change-Id: I1bae6768ee7229818a83ba608035a1f7867e6875
> > Reviewed-on: https://skia-review.googlesource.com/13645
> > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > Reviewed-by: Robert Phillips <robertphillips@google.com>
> >
>
> TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,brianosman@google.com,reviews@skia.org,stani@google.com
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
>
> Change-Id: I5cb8763cc837c83ebc6d10366fe2dd3efe35fb89
> Reviewed-on: https://skia-review.googlesource.com/13773
> Reviewed-by: Stan Iliev <stani@google.com>
> Commit-Queue: Stan Iliev <stani@google.com>
>
TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,reviews@skia.org,brianosman@google.com,stani@google.com
# Not skipping CQ checks because original CL landed > 1 day ago.
Change-Id: I92bc074e4fe37fa5c83186afadc472c03802e8f2
Reviewed-on: https://skia-review.googlesource.com/13975
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
2017-04-20 16:41:55 +00:00
|
|
|
|
2017-12-18 19:48:15 +00:00
|
|
|
GrBackendTexture rectangleTex(width, height, GrMipMapped::kNo, info);
|
Revert "Revert "Plumb GrBackendTexture throughout skia.""
This reverts commit 7fa5c31c2c9af834bee66d5fcf476e250076c8d6.
Reason for revert: Relanding this change now that other fixes have landed.
Original change's description:
> Revert "Plumb GrBackendTexture throughout skia."
>
> This reverts commit 7da62b9059f3c1d31624a0e4da96ee5f908f9c12.
>
> Reason for revert: fix android roll
>
> Original change's description:
> > Plumb GrBackendTexture throughout skia.
> >
> > Bug: skia:
> > Change-Id: I1bae6768ee7229818a83ba608035a1f7867e6875
> > Reviewed-on: https://skia-review.googlesource.com/13645
> > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > Reviewed-by: Robert Phillips <robertphillips@google.com>
> >
>
> TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,brianosman@google.com,reviews@skia.org,stani@google.com
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
>
> Change-Id: I5cb8763cc837c83ebc6d10366fe2dd3efe35fb89
> Reviewed-on: https://skia-review.googlesource.com/13773
> Reviewed-by: Stan Iliev <stani@google.com>
> Commit-Queue: Stan Iliev <stani@google.com>
>
TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,reviews@skia.org,brianosman@google.com,stani@google.com
# Not skipping CQ checks because original CL landed > 1 day ago.
Change-Id: I92bc074e4fe37fa5c83186afadc472c03802e8f2
Reviewed-on: https://skia-review.googlesource.com/13975
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
2017-04-20 16:41:55 +00:00
|
|
|
|
2018-12-06 20:33:02 +00:00
|
|
|
if (sk_sp<SkImage> image = SkImage::MakeFromAdoptedTexture(context, rectangleTex, origin,
|
2017-12-18 19:48:15 +00:00
|
|
|
kRGBA_8888_SkColorType)) {
|
2016-01-20 14:18:10 +00:00
|
|
|
return image;
|
|
|
|
}
|
|
|
|
GR_GL_CALL(gl, DeleteTextures(1, &id));
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-07 23:20:09 +00:00
|
|
|
DrawResult onDraw(GrContext* context, GrRenderTargetContext*, SkCanvas* canvas,
|
|
|
|
SkString* errorMsg) override {
|
2019-04-02 14:01:11 +00:00
|
|
|
if (!GetGLContextIfSupported(context)) {
|
|
|
|
*errorMsg = "this GM requires an OpenGL 3.1+ context";
|
|
|
|
return DrawResult::kSkip;
|
|
|
|
}
|
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr int kWidth = 50;
|
|
|
|
constexpr int kHeight = 50;
|
|
|
|
constexpr SkScalar kPad = 5.f;
|
2016-01-20 14:18:10 +00:00
|
|
|
|
|
|
|
SkPMColor pixels[kWidth * kHeight];
|
|
|
|
this->fillPixels(kWidth, kHeight, pixels);
|
|
|
|
|
2018-12-06 20:33:02 +00:00
|
|
|
sk_sp<SkImage> rectImgs[] = {
|
|
|
|
this->createRectangleTextureImg(context, kTopLeft_GrSurfaceOrigin, kWidth, kHeight,
|
|
|
|
pixels),
|
|
|
|
this->createRectangleTextureImg(context, kBottomLeft_GrSurfaceOrigin, kWidth,
|
|
|
|
kHeight, pixels),
|
|
|
|
};
|
|
|
|
SkASSERT(SkToBool(rectImgs[0]) == SkToBool(rectImgs[1]));
|
|
|
|
if (!rectImgs[0]) {
|
2019-02-07 23:20:09 +00:00
|
|
|
*errorMsg = "Could not create rectangle texture image.";
|
|
|
|
return DrawResult::kFail;
|
2016-01-20 14:18:10 +00:00
|
|
|
}
|
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr SkFilterQuality kQualities[] = {
|
2018-12-06 20:33:02 +00:00
|
|
|
kNone_SkFilterQuality,
|
|
|
|
kLow_SkFilterQuality,
|
|
|
|
kMedium_SkFilterQuality,
|
|
|
|
kHigh_SkFilterQuality,
|
2016-01-20 14:18:10 +00:00
|
|
|
};
|
|
|
|
|
2018-12-06 20:33:02 +00:00
|
|
|
constexpr SkScalar kScales[] = {1.0f, 1.2f, 0.75f};
|
2016-01-20 14:18:10 +00:00
|
|
|
|
|
|
|
canvas->translate(kPad, kPad);
|
2018-12-06 20:33:02 +00:00
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(rectImgs); ++i) {
|
|
|
|
for (auto s : kScales) {
|
|
|
|
canvas->save();
|
|
|
|
canvas->scale(s, s);
|
|
|
|
for (auto q : kQualities) {
|
|
|
|
// drawImage
|
|
|
|
SkPaint plainPaint;
|
|
|
|
plainPaint.setFilterQuality(q);
|
|
|
|
canvas->drawImage(rectImgs[i], 0, 0, &plainPaint);
|
|
|
|
canvas->translate(kWidth + kPad, 0);
|
|
|
|
|
|
|
|
// clamp/clamp shader
|
|
|
|
SkPaint clampPaint;
|
|
|
|
clampPaint.setFilterQuality(q);
|
|
|
|
clampPaint.setShader(rectImgs[i]->makeShader());
|
|
|
|
canvas->drawRect(SkRect::MakeWH(1.5f * kWidth, 1.5f * kHeight), clampPaint);
|
|
|
|
canvas->translate(kWidth * 1.5f + kPad, 0);
|
|
|
|
|
|
|
|
// repeat/mirror shader
|
|
|
|
SkPaint repeatPaint;
|
|
|
|
repeatPaint.setFilterQuality(q);
|
2019-04-03 14:27:45 +00:00
|
|
|
repeatPaint.setShader(rectImgs[i]->makeShader(SkTileMode::kRepeat,
|
|
|
|
SkTileMode::kMirror));
|
2018-12-06 20:33:02 +00:00
|
|
|
canvas->drawRect(SkRect::MakeWH(1.5f * kWidth, 1.5f * kHeight), repeatPaint);
|
|
|
|
canvas->translate(1.5f * kWidth + kPad, 0);
|
|
|
|
|
|
|
|
// drawImageRect with kStrict
|
|
|
|
auto srcRect = SkRect::MakeXYWH(.25f * rectImgs[i]->width(),
|
|
|
|
.25f * rectImgs[i]->height(),
|
|
|
|
.50f * rectImgs[i]->width(),
|
|
|
|
.50f * rectImgs[i]->height());
|
|
|
|
auto dstRect = SkRect::MakeXYWH(0, 0,
|
|
|
|
.50f * rectImgs[i]->width(),
|
|
|
|
.50f * rectImgs[i]->height());
|
|
|
|
canvas->drawImageRect(rectImgs[i], srcRect, dstRect, &plainPaint,
|
|
|
|
SkCanvas::kStrict_SrcRectConstraint);
|
|
|
|
canvas->translate(kWidth * .5f + kPad, 0);
|
|
|
|
}
|
|
|
|
canvas->restore();
|
|
|
|
canvas->translate(0, kPad + 1.5f * kHeight * s);
|
2016-01-20 14:18:10 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-07 23:20:09 +00:00
|
|
|
return DrawResult::kOk;
|
2016-01-20 14:18:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
DEF_GM(return new RectangleTexture;)
|
|
|
|
}
|