Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2016 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #include "Test.h" | |
| 9 #if SK_SUPPORT_GPU | |
| 10 | |
| 11 #include "GrContext.h" | |
| 12 #include "GrGpu.h" | |
| 13 #include "GrTextureStripAtlas.h" | |
| 14 #include "GrTypes.h" | |
| 15 #include "SkGpuDevice.h" | |
| 16 | |
| 17 // This tests that GrTextureStripAtlas flushes pending IO on the texture it acqu ires. | |
| 18 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrTextureStripAtlasFlush, reporter, ctxInfo) { | |
| 19 GrContext* context = ctxInfo.grContext(); | |
| 20 GrSurfaceDesc desc; | |
| 21 desc.fWidth = 32; | |
| 22 desc.fHeight = 32; | |
| 23 desc.fConfig = kRGBA_8888_GrPixelConfig; | |
| 24 GrTexture* texture = context->textureProvider()->createTexture(desc, SkBudge ted::kYes, nullptr, 0); | |
|
bsalomon
2016/08/24 13:31:10
nit, we wrap lines at 100 cols.
ajuma
2016/08/24 14:56:09
Fixed.
| |
| 25 | |
| 26 GrSurfaceDesc targetDesc = desc; | |
| 27 targetDesc.fFlags = kRenderTarget_GrSurfaceFlag; | |
| 28 GrTexture* target = context->textureProvider()->createTexture(targetDesc, Sk Budgeted::kYes, nullptr, 0); | |
| 29 | |
| 30 SkAutoTMalloc<uint32_t> pixels(desc.fWidth * desc.fHeight); | |
| 31 memset(pixels.get(), 0xFF, sizeof(uint32_t) * desc.fWidth * desc.fHeight); | |
| 32 texture->writePixels(0, 0, desc.fWidth, desc.fHeight, kRGBA_8888_GrPixelConf ig, pixels.get()); | |
| 33 | |
| 34 // Add a pending read to the texture, and then make it available for reuse. | |
| 35 context->copySurface(target, texture); | |
| 36 texture->unref(); | |
| 37 | |
| 38 // Create an atlas with parameters that allow it to reuse the texture. | |
| 39 GrTextureStripAtlas::Desc atlasDesc; | |
| 40 atlasDesc.fContext = context; | |
| 41 atlasDesc.fConfig = desc.fConfig; | |
| 42 atlasDesc.fWidth = desc.fWidth; | |
| 43 atlasDesc.fHeight = desc.fHeight; | |
| 44 atlasDesc.fRowHeight = 1; | |
| 45 GrTextureStripAtlas* atlas = GrTextureStripAtlas::GetAtlas(atlasDesc); | |
|
bsalomon
2016/08/24 13:31:10
Can we check that the atlas's texture is the same
ajuma
2016/08/24 14:56:09
Added a check that the texture is the same when we
| |
| 46 | |
| 47 // Write to the atlas' texture. | |
| 48 SkImageInfo info = SkImageInfo::MakeN32(desc.fWidth, desc.fHeight, kPremul_S kAlphaType); | |
| 49 size_t rowBytes = desc.fWidth * GrBytesPerPixel(desc.fConfig); | |
| 50 SkBitmap bitmap; | |
| 51 bitmap.allocPixels(info, rowBytes); | |
| 52 memset(bitmap.getPixels(), 1, rowBytes * desc.fHeight); | |
| 53 atlas->lockRow(bitmap); | |
| 54 | |
| 55 // The atlas' use of its texture shouldn't change which pixels got copied to the target. | |
| 56 SkAutoTMalloc<uint32_t> actualPixels(desc.fWidth * desc.fHeight); | |
| 57 bool success = target->readPixels(0, 0, desc.fWidth, desc.fHeight, kRGBA_888 8_GrPixelConfig, actualPixels.get()); | |
| 58 REPORTER_ASSERT(reporter, success); | |
| 59 REPORTER_ASSERT(reporter, | |
| 60 !memcmp(pixels.get(), actualPixels.get(), sizeof(uint32_t) * desc.fWidth * desc.fHeight)); | |
| 61 target->unref(); | |
| 62 } | |
| 63 | |
| 64 #endif | |
| OLD | NEW |