2016-11-04 15:59: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 is a GPU-backend specific test.
|
|
|
|
|
|
|
|
#include "Test.h"
|
|
|
|
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
#include "GrSurfaceProxy.h"
|
Revert "Revert "Revert "Revert "Move GrTextureProvider to src""""
This reverts commit 580ffa0fb17bc4e924776eafd941bf1fab397cde.
Reason for revert: Okay, it landed.
Original change's description:
> Revert "Revert "Revert "Move GrTextureProvider to src"""
>
> This reverts commit 2fe8373bb1d56f531f8a2e03a3087b0aa73e199c.
>
> Reason for revert: Google3 fix isn't landing.
>
> Original change's description:
> > Revert "Revert "Move GrTextureProvider to src""
> >
> > This reverts commit 13d7f5d7c2872ed4298330758e173ae605578cb2.
> >
> > Reason for revert: Fixed client code. Re-landing.
> >
> > Original change's description:
> > > Revert "Move GrTextureProvider to src"
> > >
> > > This reverts commit 24429c68c56683252e3fc2a79d9b660eaf96ec0c.
> > >
> > > Reason for revert: Breaking a roll
> > >
> > > Original change's description:
> > > > Move GrTextureProvider to src
> > > >
> > > > With this hidden, we can make further simplification. Just want to test
> > > > this change against our external clients first, to make sure we're okay
> > > > to proceed.
> > > >
> > > > BUG=skia:
> > > >
> > > > Change-Id: I47f8c8f2912201c2890bc2f9a9d68aa92649a2d4
> > > > Reviewed-on: https://skia-review.googlesource.com/9072
> > > > Commit-Queue: Brian Osman <brianosman@google.com>
> > > > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > > >
> > >
> > > TBR=bsalomon@google.com,brianosman@google.com,benjaminwagner@google.com,reviews@skia.org
> > > NOPRESUBMIT=true
> > > NOTREECHECKS=true
> > > NOTRY=true
> > > BUG=skia:
> > >
> > > Change-Id: I43cc135731245c29e24bbecf06ee46c562955c03
> > > Reviewed-on: https://skia-review.googlesource.com/9123
> > > Reviewed-by: Brian Osman <brianosman@google.com>
> > > Commit-Queue: Brian Osman <brianosman@google.com>
> > >
> >
> > TBR=bsalomon@google.com,benjaminwagner@google.com,reviews@skia.org,brianosman@google.com
> > NOPRESUBMIT=true
> > NOTREECHECKS=true
> > NOTRY=true
> > BUG=skia:
> >
> > Change-Id: Ibcb2ea34654315327c46ea8e4de5bf14376d9bdf
> > Reviewed-on: https://skia-review.googlesource.com/9127
> > Reviewed-by: Brian Osman <brianosman@google.com>
> > Commit-Queue: Brian Osman <brianosman@google.com>
> >
>
> TBR=bsalomon@google.com,benjaminwagner@google.com,reviews@skia.org,brianosman@google.com
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=skia:
>
> Change-Id: If5c06c7608d76c45438d03fefb21c4edd7da4f36
> Reviewed-on: https://skia-review.googlesource.com/9128
> Reviewed-by: Brian Osman <brianosman@google.com>
> Commit-Queue: Brian Osman <brianosman@google.com>
>
TBR=bsalomon@google.com,benjaminwagner@google.com,reviews@skia.org,brianosman@google.com
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:
Change-Id: I48da978fb73f914c09176e2fefa2882bc8a464a7
Reviewed-on: https://skia-review.googlesource.com/9150
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2017-03-02 18:36:27 +00:00
|
|
|
#include "GrTextureProvider.h"
|
2016-11-04 15:59:10 +00:00
|
|
|
#include "GrTextureProxy.h"
|
|
|
|
#include "GrRenderTargetProxy.h"
|
|
|
|
|
2016-11-09 11:50:43 +00:00
|
|
|
static sk_sp<GrSurfaceProxy> make_wrapped_FBO0(GrTextureProvider* provider,
|
|
|
|
skiatest::Reporter* reporter,
|
|
|
|
const GrSurfaceDesc& desc) {
|
2016-11-04 15:59:10 +00:00
|
|
|
GrBackendRenderTargetDesc backendDesc;
|
|
|
|
backendDesc.fWidth = desc.fWidth;
|
|
|
|
backendDesc.fHeight = desc.fHeight;
|
|
|
|
backendDesc.fConfig = desc.fConfig;
|
|
|
|
backendDesc.fOrigin = desc.fOrigin;
|
|
|
|
backendDesc.fSampleCnt = desc.fSampleCnt;
|
|
|
|
backendDesc.fStencilBits = 8;
|
|
|
|
backendDesc.fRenderTargetHandle = 0;
|
|
|
|
|
|
|
|
sk_sp<GrRenderTarget> defaultFBO(provider->wrapBackendRenderTarget(backendDesc));
|
|
|
|
SkASSERT(!defaultFBO->asTexture());
|
|
|
|
|
2016-11-09 11:50:43 +00:00
|
|
|
return GrSurfaceProxy::MakeWrapped(std::move(defaultFBO));
|
2016-11-04 15:59:10 +00:00
|
|
|
}
|
|
|
|
|
2016-11-09 11:50:43 +00:00
|
|
|
static sk_sp<GrSurfaceProxy> make_wrapped_offscreen_rt(GrTextureProvider* provider,
|
|
|
|
skiatest::Reporter* reporter,
|
|
|
|
const GrSurfaceDesc& desc,
|
|
|
|
SkBudgeted budgeted) {
|
2016-11-04 15:59:10 +00:00
|
|
|
SkASSERT(kRenderTarget_GrSurfaceFlag == desc.fFlags);
|
|
|
|
|
|
|
|
sk_sp<GrTexture> tex(provider->createTexture(desc, budgeted));
|
|
|
|
|
2016-11-09 11:50:43 +00:00
|
|
|
return GrSurfaceProxy::MakeWrapped(std::move(tex));
|
2016-11-04 15:59:10 +00:00
|
|
|
}
|
|
|
|
|
2016-11-09 11:50:43 +00:00
|
|
|
static sk_sp<GrSurfaceProxy> make_wrapped_texture(GrTextureProvider* provider,
|
2016-11-04 15:59:10 +00:00
|
|
|
const GrSurfaceDesc& desc,
|
|
|
|
SkBudgeted budgeted) {
|
|
|
|
sk_sp<GrTexture> tex(provider->createTexture(desc, budgeted));
|
|
|
|
|
2016-11-09 11:50:43 +00:00
|
|
|
return GrSurfaceProxy::MakeWrapped(std::move(tex));
|
2016-11-04 15:59:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test converting between RenderTargetProxies and TextureProxies for wrapped
|
|
|
|
// Proxies
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyConversionTest, reporter, ctxInfo) {
|
|
|
|
GrTextureProvider* provider = ctxInfo.grContext()->textureProvider();
|
|
|
|
|
|
|
|
GrSurfaceDesc desc;
|
|
|
|
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
|
|
|
desc.fWidth = 64;
|
|
|
|
desc.fHeight = 64;
|
|
|
|
desc.fConfig = kRGBA_8888_GrPixelConfig;
|
|
|
|
|
|
|
|
if (kOpenGL_GrBackend == ctxInfo.backend()) {
|
|
|
|
// External on-screen render target.
|
2016-11-09 11:50:43 +00:00
|
|
|
sk_sp<GrSurfaceProxy> sProxy(make_wrapped_FBO0(provider, reporter, desc));
|
2016-11-04 15:59:10 +00:00
|
|
|
|
|
|
|
// RenderTarget-only
|
2016-11-09 11:50:43 +00:00
|
|
|
GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
|
|
|
|
REPORTER_ASSERT(reporter, rtProxy);
|
2016-11-04 15:59:10 +00:00
|
|
|
REPORTER_ASSERT(reporter, !rtProxy->asTextureProxy());
|
2016-11-09 11:50:43 +00:00
|
|
|
REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
|
2016-11-04 15:59:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// Internal offscreen render target.
|
2016-11-09 11:50:43 +00:00
|
|
|
sk_sp<GrSurfaceProxy> sProxy(make_wrapped_offscreen_rt(provider,
|
|
|
|
reporter, desc,
|
|
|
|
SkBudgeted::kYes));
|
2016-11-04 15:59:10 +00:00
|
|
|
|
|
|
|
// Both RenderTarget and Texture
|
2016-11-09 11:50:43 +00:00
|
|
|
GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
|
|
|
|
REPORTER_ASSERT(reporter, rtProxy);
|
2016-11-04 15:59:10 +00:00
|
|
|
GrTextureProxy* tProxy = rtProxy->asTextureProxy();
|
|
|
|
REPORTER_ASSERT(reporter, tProxy);
|
2016-11-09 11:50:43 +00:00
|
|
|
REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy);
|
|
|
|
REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
|
2016-11-04 15:59:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// Internal offscreen render target - but through GrTextureProxy
|
2016-11-09 11:50:43 +00:00
|
|
|
sk_sp<GrSurfaceProxy> sProxy(make_wrapped_texture(provider, desc, SkBudgeted::kYes));
|
2016-11-04 15:59:10 +00:00
|
|
|
|
|
|
|
// Both RenderTarget and Texture
|
2016-11-09 11:50:43 +00:00
|
|
|
GrTextureProxy* tProxy = sProxy->asTextureProxy();
|
|
|
|
REPORTER_ASSERT(reporter, tProxy);
|
2016-11-04 15:59:10 +00:00
|
|
|
GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy();
|
|
|
|
REPORTER_ASSERT(reporter, rtProxy);
|
2016-11-09 11:50:43 +00:00
|
|
|
REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy);
|
|
|
|
REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
|
2016-11-04 15:59:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
desc.fFlags = kNone_GrSurfaceFlags; // force no-RT
|
|
|
|
|
2016-11-09 11:50:43 +00:00
|
|
|
sk_sp<GrSurfaceProxy> sProxy(make_wrapped_texture(provider, desc, SkBudgeted::kYes));
|
2016-11-04 15:59:10 +00:00
|
|
|
|
|
|
|
// Texture-only
|
2016-11-09 11:50:43 +00:00
|
|
|
GrTextureProxy* tProxy = sProxy->asTextureProxy();
|
|
|
|
REPORTER_ASSERT(reporter, tProxy);
|
|
|
|
REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
|
2016-11-04 15:59:10 +00:00
|
|
|
REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test converting between RenderTargetProxies and TextureProxies for deferred
|
|
|
|
// Proxies
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DefferredProxyConversionTest, reporter, ctxInfo) {
|
|
|
|
const GrCaps& caps = *ctxInfo.grContext()->caps();
|
2017-02-28 21:30:28 +00:00
|
|
|
GrTextureProvider* texProvider = ctxInfo.grContext()->textureProvider();
|
2016-11-04 15:59:10 +00:00
|
|
|
|
|
|
|
GrSurfaceDesc desc;
|
|
|
|
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
|
|
|
desc.fWidth = 64;
|
|
|
|
desc.fHeight = 64;
|
|
|
|
desc.fConfig = kRGBA_8888_GrPixelConfig;
|
|
|
|
|
|
|
|
{
|
2017-02-28 21:30:28 +00:00
|
|
|
sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeDeferred(texProvider, caps, desc,
|
2016-11-09 11:50:43 +00:00
|
|
|
SkBackingFit::kApprox,
|
|
|
|
SkBudgeted::kYes));
|
2016-11-04 15:59:10 +00:00
|
|
|
|
|
|
|
// Both RenderTarget and Texture
|
2016-11-09 11:50:43 +00:00
|
|
|
GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
|
|
|
|
REPORTER_ASSERT(reporter, rtProxy);
|
2016-11-04 15:59:10 +00:00
|
|
|
GrTextureProxy* tProxy = rtProxy->asTextureProxy();
|
|
|
|
REPORTER_ASSERT(reporter, tProxy);
|
2016-11-09 11:50:43 +00:00
|
|
|
REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy);
|
|
|
|
REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
|
2016-11-04 15:59:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2017-02-28 21:30:28 +00:00
|
|
|
sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeDeferred(texProvider, caps, desc,
|
2016-11-09 11:50:43 +00:00
|
|
|
SkBackingFit::kApprox,
|
|
|
|
SkBudgeted::kYes));
|
2016-11-04 15:59:10 +00:00
|
|
|
|
|
|
|
// Both RenderTarget and Texture - but via GrTextureProxy
|
2016-11-09 11:50:43 +00:00
|
|
|
GrTextureProxy* tProxy = sProxy->asTextureProxy();
|
|
|
|
REPORTER_ASSERT(reporter, tProxy);
|
2016-11-04 15:59:10 +00:00
|
|
|
GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy();
|
|
|
|
REPORTER_ASSERT(reporter, rtProxy);
|
2016-11-09 11:50:43 +00:00
|
|
|
REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy);
|
|
|
|
REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
|
2016-11-04 15:59:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
desc.fFlags = kNone_GrSurfaceFlags; // force no-RT
|
|
|
|
|
2017-02-28 21:30:28 +00:00
|
|
|
sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeDeferred(texProvider, caps, desc,
|
2016-11-09 11:50:43 +00:00
|
|
|
SkBackingFit::kApprox,
|
|
|
|
SkBudgeted::kYes));
|
2016-11-04 15:59:10 +00:00
|
|
|
|
|
|
|
// Texture-only
|
2016-11-09 11:50:43 +00:00
|
|
|
GrTextureProxy* tProxy = sProxy->asTextureProxy();
|
|
|
|
REPORTER_ASSERT(reporter, tProxy);
|
|
|
|
REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
|
2016-11-04 15:59:10 +00:00
|
|
|
REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|