aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/GrMipMappedTest.cpp
diff options
context:
space:
mode:
authorGravatar Greg Daniel <egdaniel@google.com>2017-10-12 12:27:11 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-10-12 17:02:41 +0000
commit177e695589edb1f776cc5c28b9d3eee244d48284 (patch)
treeeaa617f0300127c65a90a6aea03dc85f7d136d46 /tests/GrMipMappedTest.cpp
parent18e5cbbe65cc70c6818cc6b135ff45f4653f960b (diff)
Add flag on GrBackendTexture to say whether texture is mipped or not
Bug: skia: Change-Id: Ia684e3daf779ec2feaaec64c04dabf5cb03cd07a Reviewed-on: https://skia-review.googlesource.com/57821 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
Diffstat (limited to 'tests/GrMipMappedTest.cpp')
-rw-r--r--tests/GrMipMappedTest.cpp97
1 files changed, 97 insertions, 0 deletions
diff --git a/tests/GrMipMappedTest.cpp b/tests/GrMipMappedTest.cpp
new file mode 100644
index 0000000000..166713a2bd
--- /dev/null
+++ b/tests/GrMipMappedTest.cpp
@@ -0,0 +1,97 @@
+/*
+ * 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 "SkTypes.h"
+
+#if SK_SUPPORT_GPU
+
+#include "GrBackendSurface.h"
+#include "GrContext.h"
+#include "GrContextPriv.h"
+#include "GrGpu.h"
+#include "GrRenderTargetContext.h"
+#include "GrSurfaceProxyPriv.h"
+#include "GrTest.h"
+#include "GrTexturePriv.h"
+#include "GrTextureProxy.h"
+#include "SkCanvas.h"
+#include "SkImage_Base.h"
+#include "SkGpuDevice.h"
+#include "SkSurface.h"
+#include "SkSurface_Gpu.h"
+#include "Test.h"
+
+// Test that the correct mip map states are on the GrTextures when wrapping GrBackendTextures in
+// SkImages and SkSurfaces
+DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrWrappedMipMappedTest, reporter, ctxInfo) {
+ GrContext* context = ctxInfo.grContext();
+ for (auto mipMapped : {GrMipMapped::kNo, GrMipMapped::kYes}) {
+ for (auto isRT : {false, true}) {
+ // CreateTestingOnlyBackendTexture currently doesn't support uploading data to mip maps
+ // so we don't send any. However, we pretend there is data for the checks below which is
+ // fine since we are never actually using these textures for any work on the gpu.
+ GrBackendObject backendHandle = context->getGpu()->createTestingOnlyBackendTexture(
+ nullptr, 8, 8, kRGBA_8888_GrPixelConfig, isRT, mipMapped);
+
+ GrBackend backend = context->contextPriv().getBackend();
+ GrBackendTexture backendTex = GrTest::CreateBackendTexture(backend,
+ 8,
+ 8,
+ kRGBA_8888_GrPixelConfig,
+ mipMapped,
+ backendHandle);
+
+ GrTextureProxy* proxy;
+ sk_sp<SkImage> image;
+ if (isRT) {
+ sk_sp<SkSurface> surface = SkSurface::MakeFromBackendTexture(
+ context,
+ backendTex,
+ kTopLeft_GrSurfaceOrigin,
+ 0,
+ nullptr,
+ nullptr);
+
+ SkGpuDevice* device = ((SkSurface_Gpu*)surface.get())->getDevice();
+ proxy = device->accessRenderTargetContext()->asTextureProxy();
+ } else {
+ image = SkImage::MakeFromTexture(context, backendTex,
+ kTopLeft_GrSurfaceOrigin,
+ kPremul_SkAlphaType, nullptr);
+ proxy = as_IB(image)->peekProxy();
+ }
+ REPORTER_ASSERT(reporter, proxy);
+ if (!proxy) {
+ context->getGpu()->deleteTestingOnlyBackendTexture(backendHandle);
+ return;
+ }
+
+ REPORTER_ASSERT(reporter, proxy->priv().isInstantiated());
+
+ GrTexture* texture = proxy->priv().peekTexture();
+ REPORTER_ASSERT(reporter, texture);
+ if (!texture) {
+ context->getGpu()->deleteTestingOnlyBackendTexture(backendHandle);
+ return;
+ }
+
+ if (GrMipMapped::kYes == mipMapped) {
+ REPORTER_ASSERT(reporter, texture->texturePriv().hasMipMaps());
+ if (isRT) {
+ REPORTER_ASSERT(reporter, texture->texturePriv().mipMapsAreDirty());
+ } else {
+ REPORTER_ASSERT(reporter, !texture->texturePriv().mipMapsAreDirty());
+ }
+ } else {
+ REPORTER_ASSERT(reporter, !texture->texturePriv().hasMipMaps());
+ }
+ context->getGpu()->deleteTestingOnlyBackendTexture(backendHandle);
+ }
+ }
+}
+
+#endif