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 #include "gl/GrGLGpu.h" | |
| 11 #include "SkSurface_Gpu.h" | |
| 12 #include "../include/gpu/gl/SkGLContext.h" | |
| 13 #include "../include/gpu/GrTypes.h" | |
| 14 | |
| 15 class TestStorageAllocator : public TextureStorageAllocator { | |
| 16 public: | |
| 17 unsigned textureStorageTarget() override { | |
| 18 return GR_GL_TEXTURE_2D; | |
| 19 } | |
| 20 bool allocateTextureStorage(GrBackendObject texture, unsigned width, unsigned height) override { | |
| 21 GrColor pixels[width * height]; | |
| 22 for (unsigned y = 0; y < height; ++y) { | |
| 23 for (unsigned x = 0; x < width; ++x) { | |
| 24 pixels[y * width + x] = 0; | |
| 25 } | |
| 26 } | |
| 27 | |
| 28 GrGLuint id; | |
| 29 GR_GL_CALL(m_gl, GenTextures(1, &id)); | |
| 30 GR_GL_CALL(m_gl, BindTexture(textureStorageTarget(), id)); | |
| 31 GR_GL_CALL(m_gl, TexImage2D(textureStorageTarget(), 0, GR_GL_RGBA, width, he ight, 0, GR_GL_RGBA, | |
| 32 GR_GL_UNSIGNED_BYTE, pixels)); | |
| 33 GrGLTextureInfo* info = reinterpret_cast<GrGLTextureInfo*>(texture); | |
| 34 info->fID = id; | |
| 35 info->fTarget = textureStorageTarget(); | |
| 36 m_mostRecentlyAllocatedStorage = id; | |
| 37 | |
| 38 return true; | |
| 39 } | |
| 40 void deallocateTextureStorage(GrBackendObject) override { | |
|
bsalomon
2016/01/26 22:20:55
why not delete?
erikchen
2016/01/27 21:55:15
Added implementation.
| |
| 41 } | |
| 42 | |
| 43 GrGLuint m_mostRecentlyAllocatedStorage; | |
| 44 const GrGLInterface* m_gl; | |
| 45 }; | |
| 46 | |
| 47 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TextureStorageAllocator, reporter, context, g lContext) { | |
| 48 static const int kWidth = 13; | |
| 49 static const int kHeight = 13; | |
| 50 | |
| 51 const GrGLInterface* gl = glContext->gl(); | |
| 52 TestStorageAllocator allocator; | |
| 53 allocator.m_gl = gl; | |
| 54 SkSurface* surface = SkSurface_Gpu::NewRenderTarget( | |
| 55 context, SkSurface_Gpu::kNo_Budgeted, SkImageInfo::MakeN32Premul(kWi dth, kHeight), 0, | |
| 56 NULL, &allocator); | |
| 57 REPORTER_ASSERT(reporter, surface); | |
| 58 GrGLuint id = allocator.m_mostRecentlyAllocatedStorage; | |
| 59 | |
| 60 SkImage* image = surface->newImageSnapshot(); | |
| 61 REPORTER_ASSERT(reporter, image->isTextureBacked()); | |
| 62 SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(1,1); | |
| 63 GrColor dest = 0x11223344; | |
| 64 REPORTER_ASSERT(reporter, image->readPixels(imageInfo, &dest, 4 * kWidth, 0, 0)); | |
| 65 REPORTER_ASSERT(reporter, GrColorUnpackG(dest) == 0); | |
| 66 | |
| 67 surface->getCanvas()->clear(SK_ColorGREEN); | |
| 68 SkImage* image2 = surface->newImageSnapshot(); | |
| 69 REPORTER_ASSERT(reporter, image2->isTextureBacked()); | |
| 70 REPORTER_ASSERT(reporter, allocator.m_mostRecentlyAllocatedStorage != id); | |
| 71 | |
| 72 REPORTER_ASSERT(reporter, image2->readPixels(imageInfo, &dest, 4 * kWidth, 0 , 0)); | |
| 73 REPORTER_ASSERT(reporter, GrColorUnpackG(dest) == 255); | |
| 74 | |
| 75 GR_GL_CALL(gl, DeleteTextures(1, &allocator.m_mostRecentlyAllocatedStorage)) ; | |
| 76 GR_GL_CALL(gl, DeleteTextures(1, &id)); | |
| 77 } | |
| 78 | |
| 79 #endif | |
| OLD | NEW |