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

Side by Side Diff: tests/TextureStorageAllocator.cpp

Issue 1623653002: skia: Add support for CHROMIUM_image backed textures. (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Comments from bsalomon, round four. Created 4 years, 10 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
« src/image/SkSurface_Gpu.cpp ('K') | « tests/ResourceCacheTest.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 "GrContext.h"
12 #include "SkSurface_Gpu.h"
13 #include "../include/gpu/gl/SkGLContext.h"
14 #include "../include/gpu/GrTypes.h"
15
16 class TestStorageAllocator {
17 public:
18 static GrTextureStorageAllocator::Result allocateTextureStorage(void* ctx,
19 GrBackendObject texture, unsigned width, unsigned height, GrPixelConfi g config,
20 const void* srcData, GrSurfaceOrigin) {
21 TestStorageAllocator* allocator = static_cast<TestStorageAllocator*>(ctx);
22 if (!allocator->m_allowAllocation)
23 return GrTextureStorageAllocator::Result::kFailed;
24 GrColor pixels[width * height];
25 for (unsigned y = 0; y < height; ++y) {
26 for (unsigned x = 0; x < width; ++x) {
27 pixels[y * width + x] = 0;
28 }
29 }
30
31 GrGLuint id;
32 GrGLenum target = GR_GL_TEXTURE_2D;
33 GR_GL_CALL(allocator->m_gl, GenTextures(1, &id));
34 GR_GL_CALL(allocator->m_gl, BindTexture(target, id));
35 GR_GL_CALL(allocator->m_gl, TexImage2D(target, 0, GR_GL_RGBA, width, heigh t, 0, GR_GL_RGBA,
36 GR_GL_UNSIGNED_BYTE, pixels));
37 GrGLTextureInfo* info = reinterpret_cast<GrGLTextureInfo*>(texture);
38 info->fID = id;
39 info->fTarget = target;
40 allocator->m_mostRecentlyAllocatedStorage = id;
41 return GrTextureStorageAllocator::Result::kSucceededWithoutUpload;
42 }
43 static void deallocateTextureStorage(void* ctx, GrBackendObject texture) {
44 TestStorageAllocator* allocator = static_cast<TestStorageAllocator*>(ctx);
45 GrGLTextureInfo* info = reinterpret_cast<GrGLTextureInfo*>(texture);
46 GR_GL_CALL(allocator->m_gl, DeleteTextures(1, &(info->fID)));
47 }
48
49 GrGLuint m_mostRecentlyAllocatedStorage;
50 const GrGLInterface* m_gl;
51 bool m_allowAllocation;
52 };
53
54 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CustomTexture, reporter, context, glContext) {
55 static const int kWidth = 13;
56 static const int kHeight = 13;
57
58 const GrGLInterface* gl = glContext->gl();
59 TestStorageAllocator allocator;
60 allocator.m_allowAllocation = true;
61 allocator.m_gl = gl;
62 GrTextureStorageAllocator grAllocator;
63 grAllocator.fAllocateTextureStorage = &TestStorageAllocator::allocateTexture Storage;
64 grAllocator.fDeallocateTextureStorage= &TestStorageAllocator::deallocateText ureStorage;
65 grAllocator.fCtx = &allocator;
66
67 SkSurface* surface = SkSurface_Gpu::NewRenderTarget(
68 context, SkSurface_Gpu::kNo_Budgeted, SkImageInfo::MakeN32Premul(kWi dth, kHeight), 0,
69 NULL, grAllocator);
70 REPORTER_ASSERT(reporter, surface);
71 GrGLuint id = allocator.m_mostRecentlyAllocatedStorage;
72
73 SkImage* image = surface->newImageSnapshot();
74 REPORTER_ASSERT(reporter, image->isTextureBacked());
75 SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(1,1);
76 GrColor dest = 0x11223344;
77 REPORTER_ASSERT(reporter, image->readPixels(imageInfo, &dest, 4 * kWidth, 0, 0));
78 REPORTER_ASSERT(reporter, GrColorUnpackG(dest) == 0);
79
80 surface->getCanvas()->clear(SK_ColorGREEN);
81 SkImage* image2 = surface->newImageSnapshot();
82 REPORTER_ASSERT(reporter, image2->isTextureBacked());
83 REPORTER_ASSERT(reporter, allocator.m_mostRecentlyAllocatedStorage != id);
84
85 REPORTER_ASSERT(reporter, image2->readPixels(imageInfo, &dest, 4 * kWidth, 0 , 0));
86 REPORTER_ASSERT(reporter, GrColorUnpackG(dest) == 255);
87 }
88
89 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CustomTextureFailure, reporter, context, glCo ntext) {
90 static const int kWidth = 13;
91 static const int kHeight = 13;
92
93 const GrGLInterface* gl = glContext->gl();
94 TestStorageAllocator allocator;
95 allocator.m_allowAllocation = false;
96 allocator.m_gl = gl;
97 GrTextureStorageAllocator grAllocator;
98 grAllocator.fAllocateTextureStorage = &TestStorageAllocator::allocateTexture Storage;
99 grAllocator.fDeallocateTextureStorage= &TestStorageAllocator::deallocateText ureStorage;
100 grAllocator.fCtx = &allocator;
101 SkSurface* surface = SkSurface_Gpu::NewRenderTarget(
102 context, SkSurface_Gpu::kNo_Budgeted, SkImageInfo::MakeN32Premul(kWi dth, kHeight), 0,
103 NULL, grAllocator);
104 REPORTER_ASSERT(reporter, !surface);
105 }
106
107 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CustomTextureNotBudgeted, reporter, context, glContext) {
108 static const int kWidth = 13;
109 static const int kHeight = 13;
110
111 const GrGLInterface* gl = glContext->gl();
112 TestStorageAllocator allocator;
113 allocator.m_allowAllocation = true;
114 allocator.m_gl = gl;
115 GrTextureStorageAllocator grAllocator;
116 grAllocator.fAllocateTextureStorage = &TestStorageAllocator::allocateTexture Storage;
117 grAllocator.fDeallocateTextureStorage= &TestStorageAllocator::deallocateText ureStorage;
118 grAllocator.fCtx = &allocator;
119
120 SkSurface* surface = SkSurface_Gpu::NewRenderTarget(
121 context, SkSurface_Gpu::kYes_Budgeted, SkImageInfo::MakeN32Premul(kW idth, kHeight), 0,
122 NULL, grAllocator);
123 REPORTER_ASSERT(reporter, !surface);
124 }
125
126 #endif
OLDNEW
« src/image/SkSurface_Gpu.cpp ('K') | « tests/ResourceCacheTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698