1eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips/* 2eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips * Copyright 2016 Google Inc. 3eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips * 4eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips * Use of this source code is governed by a BSD-style license that can be 5eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips * found in the LICENSE file. 6eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips */ 7eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips 8eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips// This is a GPU-backend specific test. 9eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips 10eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips#include "Test.h" 11eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips 1281dd3e0c66c6c521a4548205e7e29d6c4972f644Robert Phillips// MDB TODO: the early instantiation of the renderTargetContext's backing GrRenderTargetProxy 1381dd3e0c66c6c521a4548205e7e29d6c4972f644Robert Phillips// mixes this test up. Re-enable once backing GPU resources are distributed by MDB at flush time. 141119dc366e15ef737d05d3a087410ea40c508101Robert Phillips#if 0 151119dc366e15ef737d05d3a087410ea40c508101Robert Phillips 16eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips#if SK_SUPPORT_GPU 17eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips#include "GrTextureProxy.h" 18eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips#include "GrRenderTargetContext.h" 19eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips 20eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillipsstatic const int kSize = 64; 21eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips 22dd3b3f41829d32d7eaf3eb4903570d49c2ba9ff8Robert Phillipsstatic sk_sp<GrRenderTargetContext> get_rtc(GrContext* ctx) { 23dd3b3f41829d32d7eaf3eb4903570d49c2ba9ff8Robert Phillips return ctx->makeDeferredRenderTargetContext(SkBackingFit::kExact, 24dd3b3f41829d32d7eaf3eb4903570d49c2ba9ff8Robert Phillips kSize, kSize, 25dd3b3f41829d32d7eaf3eb4903570d49c2ba9ff8Robert Phillips kRGBA_8888_GrPixelConfig, nullptr); 26eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips} 27eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips 28eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillipsstatic void check_is_wrapped_status(skiatest::Reporter* reporter, 29eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips GrRenderTargetContext* rtCtx, 30eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips bool wrappedExpectation) { 31eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips REPORTER_ASSERT(reporter, rtCtx->isWrapped_ForTesting() == wrappedExpectation); 32eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips 33f200a90f3e58ce20753420cadced850d7d00dca1Robert Phillips GrTextureProxy* tProxy = rtCtx->asTextureProxy(); 34eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips REPORTER_ASSERT(reporter, tProxy); 35eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips 36eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips REPORTER_ASSERT(reporter, tProxy->isWrapped_ForTesting() == wrappedExpectation); 37eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips} 38eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips 39eaa862569dc91d55fc79d057df6e69b139e46888Robert PhillipsDEF_GPUTEST_FOR_RENDERING_CONTEXTS(RenderTargetContextTest, reporter, ctxInfo) { 40eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips GrContext* ctx = ctxInfo.grContext(); 41eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips 42eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips // Calling instantiate on a GrRenderTargetContext's textureProxy also instantiates the 43eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips // GrRenderTargetContext 44eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips { 45dd3b3f41829d32d7eaf3eb4903570d49c2ba9ff8Robert Phillips sk_sp<GrRenderTargetContext> rtCtx(get_rtc(ctx)); 46eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips 47eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips check_is_wrapped_status(reporter, rtCtx.get(), false); 48eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips 49f200a90f3e58ce20753420cadced850d7d00dca1Robert Phillips GrTextureProxy* tProxy = rtCtx->asTextureProxy(); 50eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips REPORTER_ASSERT(reporter, tProxy); 51eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips 5281dd3e0c66c6c521a4548205e7e29d6c4972f644Robert Phillips REPORTER_ASSERT(reporter, tProxy->instantiate(ctx->resourceProvider())); 53eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips 54eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips check_is_wrapped_status(reporter, rtCtx.get(), true); 55eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips } 56eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips 57eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips // readPixels switches a deferred rtCtx to wrapped 58eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips { 59dd3b3f41829d32d7eaf3eb4903570d49c2ba9ff8Robert Phillips sk_sp<GrRenderTargetContext> rtCtx(get_rtc(ctx)); 60eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips 61eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips check_is_wrapped_status(reporter, rtCtx.get(), false); 62eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips 63eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips SkImageInfo dstInfo = SkImageInfo::MakeN32Premul(kSize, kSize); 64eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips SkAutoTMalloc<uint32_t> dstBuffer(kSize * kSize); 65eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips static const size_t kRowBytes = sizeof(uint32_t) * kSize; 66eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips 67eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips bool result = rtCtx->readPixels(dstInfo, dstBuffer.get(), kRowBytes, 0, 0); 68eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips REPORTER_ASSERT(reporter, result); 69eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips 70eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips check_is_wrapped_status(reporter, rtCtx.get(), true); 71eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips } 72eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips 73eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips // TODO: in a future world we should be able to add a test that the majority of 7463fd760a37905c45d26fc3d49cac261fad1b4808Ben Wagner // GrRenderTargetContext calls do not force the instantiation of a deferred 75eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips // GrRenderTargetContext 76eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips} 77eaa862569dc91d55fc79d057df6e69b139e46888Robert Phillips#endif 781119dc366e15ef737d05d3a087410ea40c508101Robert Phillips#endif 79