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

Side by Side Diff: gpu/command_buffer/common/gpu_memory_buffer_support.cc

Issue 1849313002: Pull gpu CmdBuf service/client shared GpuMemoryBuffer code to common (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "gpu/command_buffer/service/image_factory.h" 5 #include "gpu/command_buffer/common/gpu_memory_buffer_support.h"
6 6
7 #include <GLES2/gl2.h>
8 #include <GLES2/gl2extchromium.h>
9
10 #include "base/logging.h"
7 #include "gpu/command_buffer/common/capabilities.h" 11 #include "gpu/command_buffer/common/capabilities.h"
8 #include "ui/gl/gl_bindings.h"
9 12
10 namespace gpu { 13 namespace gpu {
11 14
12 namespace { 15 namespace {
16
13 gfx::BufferFormat BufferFormatForInternalFormat(unsigned internalformat) { 17 gfx::BufferFormat BufferFormatForInternalFormat(unsigned internalformat) {
14 switch (internalformat) { 18 switch (internalformat) {
15 case GL_RED: 19 case GL_RED_EXT:
16 return gfx::BufferFormat::R_8; 20 return gfx::BufferFormat::R_8;
17 case GL_RGB: 21 case GL_RGB:
18 return gfx::BufferFormat::BGRX_8888; 22 return gfx::BufferFormat::BGRX_8888;
19 case GL_RGBA: 23 case GL_RGBA:
20 return gfx::BufferFormat::RGBA_8888; 24 return gfx::BufferFormat::RGBA_8888;
21 case GL_BGRA_EXT: 25 case GL_BGRA_EXT:
22 return gfx::BufferFormat::BGRA_8888; 26 return gfx::BufferFormat::BGRA_8888;
23 case GL_ATC_RGB_AMD: 27 case GL_ATC_RGB_AMD:
24 return gfx::BufferFormat::ATC; 28 return gfx::BufferFormat::ATC;
25 case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD: 29 case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD:
(...skipping 11 matching lines...) Expand all
37 case GL_RGB_YCBCR_422_CHROMIUM: 41 case GL_RGB_YCBCR_422_CHROMIUM:
38 return gfx::BufferFormat::UYVY_422; 42 return gfx::BufferFormat::UYVY_422;
39 default: 43 default:
40 NOTREACHED(); 44 NOTREACHED();
41 return gfx::BufferFormat::RGBA_8888; 45 return gfx::BufferFormat::RGBA_8888;
42 } 46 }
43 } 47 }
44 48
45 } // namespace 49 } // namespace
46 50
47 ImageFactory::ImageFactory() { 51 gfx::BufferFormat DefaultBufferFormatForImageFormat(unsigned internalformat) {
48 }
49
50 ImageFactory::~ImageFactory() {
51 }
52
53 // static
54 gfx::BufferFormat ImageFactory::DefaultBufferFormatForImageFormat(
55 unsigned internalformat) {
56 switch (internalformat) { 52 switch (internalformat) {
57 case GL_RGB: 53 case GL_RGB:
58 return gfx::BufferFormat::BGRX_8888; 54 return gfx::BufferFormat::BGRX_8888;
59 case GL_RGBA: 55 case GL_RGBA:
60 return gfx::BufferFormat::RGBA_8888; 56 return gfx::BufferFormat::RGBA_8888;
61 default: 57 default:
62 NOTREACHED(); 58 NOTREACHED();
63 return gfx::BufferFormat::RGBA_8888; 59 return gfx::BufferFormat::RGBA_8888;
64 } 60 }
65 } 61 }
66 62
67 // static 63 bool IsImageFormatCompatibleWithGpuMemoryBufferFormat(
68 bool ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat(
69 unsigned internalformat, 64 unsigned internalformat,
70 gfx::BufferFormat format) { 65 gfx::BufferFormat format) {
71 switch (format) { 66 switch (format) {
72 case gfx::BufferFormat::ATC: 67 case gfx::BufferFormat::ATC:
73 case gfx::BufferFormat::ATCIA: 68 case gfx::BufferFormat::ATCIA:
74 case gfx::BufferFormat::BGRA_8888: 69 case gfx::BufferFormat::BGRA_8888:
75 case gfx::BufferFormat::BGRX_8888: 70 case gfx::BufferFormat::BGRX_8888:
76 case gfx::BufferFormat::DXT1: 71 case gfx::BufferFormat::DXT1:
77 case gfx::BufferFormat::DXT5: 72 case gfx::BufferFormat::DXT5:
78 case gfx::BufferFormat::ETC1: 73 case gfx::BufferFormat::ETC1:
79 case gfx::BufferFormat::R_8: 74 case gfx::BufferFormat::R_8:
80 case gfx::BufferFormat::RGBA_8888: 75 case gfx::BufferFormat::RGBA_8888:
81 case gfx::BufferFormat::RGBX_8888: 76 case gfx::BufferFormat::RGBX_8888:
82 case gfx::BufferFormat::YUV_420: 77 case gfx::BufferFormat::YUV_420:
83 case gfx::BufferFormat::YUV_420_BIPLANAR: 78 case gfx::BufferFormat::YUV_420_BIPLANAR:
84 case gfx::BufferFormat::UYVY_422: 79 case gfx::BufferFormat::UYVY_422:
85 return format == BufferFormatForInternalFormat(internalformat); 80 return format == BufferFormatForInternalFormat(internalformat);
86 case gfx::BufferFormat::RGBA_4444: 81 case gfx::BufferFormat::RGBA_4444:
87 return internalformat == GL_RGBA; 82 return internalformat == GL_RGBA;
88 } 83 }
89 84
90 NOTREACHED(); 85 NOTREACHED();
91 return false; 86 return false;
92 } 87 }
93 88
94 // static 89 bool IsGpuMemoryBufferFormatSupported(gfx::BufferFormat format,
95 bool ImageFactory::IsGpuMemoryBufferFormatSupported( 90 const gpu::Capabilities& capabilities) {
96 gfx::BufferFormat format,
97 const gpu::Capabilities& capabilities) {
98 switch (format) { 91 switch (format) {
99 case gfx::BufferFormat::ATC: 92 case gfx::BufferFormat::ATC:
100 case gfx::BufferFormat::ATCIA: 93 case gfx::BufferFormat::ATCIA:
101 return capabilities.texture_format_atc; 94 return capabilities.texture_format_atc;
102 case gfx::BufferFormat::BGRA_8888: 95 case gfx::BufferFormat::BGRA_8888:
103 case gfx::BufferFormat::BGRX_8888: 96 case gfx::BufferFormat::BGRX_8888:
104 return capabilities.texture_format_bgra8888; 97 return capabilities.texture_format_bgra8888;
105 case gfx::BufferFormat::DXT1: 98 case gfx::BufferFormat::DXT1:
106 return capabilities.texture_format_dxt1; 99 return capabilities.texture_format_dxt1;
107 case gfx::BufferFormat::DXT5: 100 case gfx::BufferFormat::DXT5:
(...skipping 10 matching lines...) Expand all
118 case gfx::BufferFormat::YUV_420: 111 case gfx::BufferFormat::YUV_420:
119 return true; 112 return true;
120 case gfx::BufferFormat::YUV_420_BIPLANAR: 113 case gfx::BufferFormat::YUV_420_BIPLANAR:
121 return capabilities.image_ycbcr_420v; 114 return capabilities.image_ycbcr_420v;
122 } 115 }
123 116
124 NOTREACHED(); 117 NOTREACHED();
125 return false; 118 return false;
126 } 119 }
127 120
128 // static 121 bool IsImageSizeValidForGpuMemoryBufferFormat(const gfx::Size& size,
129 bool ImageFactory::IsImageSizeValidForGpuMemoryBufferFormat( 122 gfx::BufferFormat format) {
130 const gfx::Size& size,
131 gfx::BufferFormat format) {
132 switch (format) { 123 switch (format) {
133 case gfx::BufferFormat::ATC: 124 case gfx::BufferFormat::ATC:
134 case gfx::BufferFormat::ATCIA: 125 case gfx::BufferFormat::ATCIA:
135 case gfx::BufferFormat::DXT1: 126 case gfx::BufferFormat::DXT1:
136 case gfx::BufferFormat::DXT5: 127 case gfx::BufferFormat::DXT5:
137 case gfx::BufferFormat::ETC1: 128 case gfx::BufferFormat::ETC1:
138 // Compressed images must have a width and height that's evenly divisible 129 // Compressed images must have a width and height that's evenly divisible
139 // by the block size. 130 // by the block size.
140 return size.width() % 4 == 0 && size.height() % 4 == 0; 131 return size.width() % 4 == 0 && size.height() % 4 == 0;
141 case gfx::BufferFormat::R_8: 132 case gfx::BufferFormat::R_8:
142 case gfx::BufferFormat::RGBA_4444: 133 case gfx::BufferFormat::RGBA_4444:
143 case gfx::BufferFormat::RGBA_8888: 134 case gfx::BufferFormat::RGBA_8888:
144 case gfx::BufferFormat::RGBX_8888: 135 case gfx::BufferFormat::RGBX_8888:
145 case gfx::BufferFormat::BGRA_8888: 136 case gfx::BufferFormat::BGRA_8888:
146 case gfx::BufferFormat::BGRX_8888: 137 case gfx::BufferFormat::BGRX_8888:
147 return true; 138 return true;
148 case gfx::BufferFormat::YUV_420: 139 case gfx::BufferFormat::YUV_420:
149 case gfx::BufferFormat::YUV_420_BIPLANAR: 140 case gfx::BufferFormat::YUV_420_BIPLANAR:
150 // U and V planes are subsampled by a factor of 2. 141 // U and V planes are subsampled by a factor of 2.
151 return size.width() % 2 == 0 && size.height() % 2 == 0; 142 return size.width() % 2 == 0 && size.height() % 2 == 0;
152 case gfx::BufferFormat::UYVY_422: 143 case gfx::BufferFormat::UYVY_422:
153 return size.width() % 2 == 0; 144 return size.width() % 2 == 0;
154 } 145 }
155 146
156 NOTREACHED(); 147 NOTREACHED();
157 return false; 148 return false;
158 } 149 }
159 150
160 } // namespace gpu 151 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/common/gpu_memory_buffer_support.h ('k') | gpu/command_buffer/service/image_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698