Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(203)

Side by Side Diff: tests/TextureStorageAllocator.cpp

Issue 1886613003: Remove GrTextureStorageAllocator. This was added from Chromium but never used and not expected to b… (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/image/SkSurface_Gpu.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 "gl/GLTestContext.h"
12 #include "GrContext.h"
13 #include "SkSurface_Gpu.h"
14 #include "../include/gpu/GrTypes.h"
15 #include "../include/private/SkTemplates.h"
16
17 class TestStorageAllocator {
18 public:
19 static GrTextureStorageAllocator::Result allocateTextureStorage(void* ctx,
20 GrBackendObject texture, unsigned width, unsigned height, GrPixelConfi g config,
21 const void* srcData, GrSurfaceOrigin) {
22 TestStorageAllocator* allocator = static_cast<TestStorageAllocator*>(ctx);
23 if (!allocator->m_allowAllocation)
24 return GrTextureStorageAllocator::Result::kFailed;
25 SkAutoTMalloc<uint8_t> pixels(width * height * 4);
26 memset(pixels.get(), 0, width * height * 4);
27
28 GrGLuint id;
29 GrGLenum target = GR_GL_TEXTURE_2D;
30 GR_GL_CALL(allocator->m_gl, GenTextures(1, &id));
31 GR_GL_CALL(allocator->m_gl, BindTexture(target, id));
32 GR_GL_CALL(allocator->m_gl, TexParameteri(target, GR_GL_TEXTURE_MAG_FILTER , GR_GL_NEAREST));
33 GR_GL_CALL(allocator->m_gl, TexParameteri(target, GR_GL_TEXTURE_MIN_FILTER , GR_GL_NEAREST));
34 GR_GL_CALL(allocator->m_gl, TexParameteri(target, GR_GL_TEXTURE_WRAP_S, GR _GL_CLAMP_TO_EDGE));
35 GR_GL_CALL(allocator->m_gl, TexParameteri(target, GR_GL_TEXTURE_WRAP_T, GR _GL_CLAMP_TO_EDGE));
36 GR_GL_CALL(allocator->m_gl, TexImage2D(target, 0, GR_GL_RGBA, width, heigh t, 0, GR_GL_RGBA,
37 GR_GL_UNSIGNED_BYTE, pixels.get()));
38
39 GrGLTextureInfo* info = reinterpret_cast<GrGLTextureInfo*>(texture);
40 info->fID = id;
41 info->fTarget = target;
42 allocator->m_mostRecentlyAllocatedStorage = id;
43 return GrTextureStorageAllocator::Result::kSucceededWithoutUpload;
44 }
45 static void deallocateTextureStorage(void* ctx, GrBackendObject texture) {
46 TestStorageAllocator* allocator = static_cast<TestStorageAllocator*>(ctx);
47 GrGLTextureInfo* info = reinterpret_cast<GrGLTextureInfo*>(texture);
48 GR_GL_CALL(allocator->m_gl, DeleteTextures(1, &(info->fID)));
49 }
50
51 GrGLuint m_mostRecentlyAllocatedStorage;
52 const GrGLInterface* m_gl;
53 bool m_allowAllocation;
54 };
55
56 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(CustomTexture, reporter, ctxInfo) {
57 GrContext* context = ctxInfo.fGrContext;
58 sk_gpu_test::GLTestContext* glContext = ctxInfo.fGLContext;
59 static const int kWidth = 13;
60 static const int kHeight = 13;
61
62 const GrGLInterface* gl = glContext->gl();
63 TestStorageAllocator allocator;
64 allocator.m_allowAllocation = true;
65 allocator.m_gl = gl;
66 GrTextureStorageAllocator grAllocator;
67 grAllocator.fAllocateTextureStorage = &TestStorageAllocator::allocateTexture Storage;
68 grAllocator.fDeallocateTextureStorage= &TestStorageAllocator::deallocateText ureStorage;
69 grAllocator.fCtx = &allocator;
70
71 auto surface(SkSurface_Gpu::MakeRenderTarget(
72 context, SkBudgeted::kNo, SkImageInfo::MakeN32Premul(kWidth, kHeight ), 0,
73 NULL, grAllocator));
74 REPORTER_ASSERT(reporter, surface);
75 GrGLuint id = allocator.m_mostRecentlyAllocatedStorage;
76
77 sk_sp<SkImage> image(surface->makeImageSnapshot());
78 REPORTER_ASSERT(reporter, image->isTextureBacked());
79 SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(1,1);
80 GrColor dest = 0x11223344;
81 REPORTER_ASSERT(reporter, image->readPixels(imageInfo, &dest, 4 * kWidth, 0, 0));
82 REPORTER_ASSERT(reporter, GrColorUnpackG(dest) == 0);
83
84 surface->getCanvas()->clear(SK_ColorGREEN);
85 sk_sp<SkImage> image2(surface->makeImageSnapshot());
86 REPORTER_ASSERT(reporter, image2->isTextureBacked());
87 REPORTER_ASSERT(reporter, allocator.m_mostRecentlyAllocatedStorage != id);
88
89 REPORTER_ASSERT(reporter, image2->readPixels(imageInfo, &dest, 4 * kWidth, 0 , 0));
90 REPORTER_ASSERT(reporter, GrColorUnpackG(dest) == 255);
91 }
92
93 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(CustomTextureFailure, reporter, ctxInfo) {
94 static const int kWidth = 13;
95 static const int kHeight = 13;
96
97 const GrGLInterface* gl = ctxInfo.fGLContext->gl();
98 TestStorageAllocator allocator;
99 allocator.m_allowAllocation = false;
100 allocator.m_gl = gl;
101 GrTextureStorageAllocator grAllocator;
102 grAllocator.fAllocateTextureStorage = &TestStorageAllocator::allocateTexture Storage;
103 grAllocator.fDeallocateTextureStorage= &TestStorageAllocator::deallocateText ureStorage;
104 grAllocator.fCtx = &allocator;
105 auto surface(SkSurface_Gpu::MakeRenderTarget(
106 ctxInfo.fGrContext, SkBudgeted::kNo, SkImageInfo::MakeN32Premul(kWid th, kHeight), 0,
107 NULL, grAllocator));
108 REPORTER_ASSERT(reporter, !surface);
109 }
110
111 #endif
OLDNEW
« no previous file with comments | « src/image/SkSurface_Gpu.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698