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

Side by Side Diff: gpu/command_buffer/service/image_factory.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 2014 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/service/image_factory.h"
6 6
7 #include "gpu/command_buffer/common/capabilities.h"
8 #include "ui/gl/gl_bindings.h"
9
10 namespace gpu { 7 namespace gpu {
11 8
12 namespace {
13 gfx::BufferFormat BufferFormatForInternalFormat(unsigned internalformat) {
14 switch (internalformat) {
15 case GL_RED:
16 return gfx::BufferFormat::R_8;
17 case GL_RGB:
18 return gfx::BufferFormat::BGRX_8888;
19 case GL_RGBA:
20 return gfx::BufferFormat::RGBA_8888;
21 case GL_BGRA_EXT:
22 return gfx::BufferFormat::BGRA_8888;
23 case GL_ATC_RGB_AMD:
24 return gfx::BufferFormat::ATC;
25 case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD:
26 return gfx::BufferFormat::ATCIA;
27 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
28 return gfx::BufferFormat::DXT1;
29 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
30 return gfx::BufferFormat::DXT5;
31 case GL_ETC1_RGB8_OES:
32 return gfx::BufferFormat::ETC1;
33 case GL_RGB_YUV_420_CHROMIUM:
34 return gfx::BufferFormat::YUV_420;
35 case GL_RGB_YCBCR_420V_CHROMIUM:
36 return gfx::BufferFormat::YUV_420_BIPLANAR;
37 case GL_RGB_YCBCR_422_CHROMIUM:
38 return gfx::BufferFormat::UYVY_422;
39 default:
40 NOTREACHED();
41 return gfx::BufferFormat::RGBA_8888;
42 }
43 }
44
45 } // namespace
46
47 ImageFactory::ImageFactory() { 9 ImageFactory::ImageFactory() {
48 } 10 }
49 11
50 ImageFactory::~ImageFactory() { 12 ImageFactory::~ImageFactory() {
51 } 13 }
52 14
53 // static
54 gfx::BufferFormat ImageFactory::DefaultBufferFormatForImageFormat(
55 unsigned internalformat) {
56 switch (internalformat) {
57 case GL_RGB:
58 return gfx::BufferFormat::BGRX_8888;
59 case GL_RGBA:
60 return gfx::BufferFormat::RGBA_8888;
61 default:
62 NOTREACHED();
63 return gfx::BufferFormat::RGBA_8888;
64 }
65 }
66
67 // static
68 bool ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat(
69 unsigned internalformat,
70 gfx::BufferFormat format) {
71 switch (format) {
72 case gfx::BufferFormat::ATC:
73 case gfx::BufferFormat::ATCIA:
74 case gfx::BufferFormat::BGRA_8888:
75 case gfx::BufferFormat::BGRX_8888:
76 case gfx::BufferFormat::DXT1:
77 case gfx::BufferFormat::DXT5:
78 case gfx::BufferFormat::ETC1:
79 case gfx::BufferFormat::R_8:
80 case gfx::BufferFormat::RGBA_8888:
81 case gfx::BufferFormat::RGBX_8888:
82 case gfx::BufferFormat::YUV_420:
83 case gfx::BufferFormat::YUV_420_BIPLANAR:
84 case gfx::BufferFormat::UYVY_422:
85 return format == BufferFormatForInternalFormat(internalformat);
86 case gfx::BufferFormat::RGBA_4444:
87 return internalformat == GL_RGBA;
88 }
89
90 NOTREACHED();
91 return false;
92 }
93
94 // static
95 bool ImageFactory::IsGpuMemoryBufferFormatSupported(
96 gfx::BufferFormat format,
97 const gpu::Capabilities& capabilities) {
98 switch (format) {
99 case gfx::BufferFormat::ATC:
100 case gfx::BufferFormat::ATCIA:
101 return capabilities.texture_format_atc;
102 case gfx::BufferFormat::BGRA_8888:
103 case gfx::BufferFormat::BGRX_8888:
104 return capabilities.texture_format_bgra8888;
105 case gfx::BufferFormat::DXT1:
106 return capabilities.texture_format_dxt1;
107 case gfx::BufferFormat::DXT5:
108 return capabilities.texture_format_dxt5;
109 case gfx::BufferFormat::ETC1:
110 return capabilities.texture_format_etc1;
111 case gfx::BufferFormat::R_8:
112 return capabilities.texture_rg;
113 case gfx::BufferFormat::UYVY_422:
114 return capabilities.image_ycbcr_422;
115 case gfx::BufferFormat::RGBA_4444:
116 case gfx::BufferFormat::RGBA_8888:
117 case gfx::BufferFormat::RGBX_8888:
118 case gfx::BufferFormat::YUV_420:
119 return true;
120 case gfx::BufferFormat::YUV_420_BIPLANAR:
121 return capabilities.image_ycbcr_420v;
122 }
123
124 NOTREACHED();
125 return false;
126 }
127
128 // static
129 bool ImageFactory::IsImageSizeValidForGpuMemoryBufferFormat(
130 const gfx::Size& size,
131 gfx::BufferFormat format) {
132 switch (format) {
133 case gfx::BufferFormat::ATC:
134 case gfx::BufferFormat::ATCIA:
135 case gfx::BufferFormat::DXT1:
136 case gfx::BufferFormat::DXT5:
137 case gfx::BufferFormat::ETC1:
138 // Compressed images must have a width and height that's evenly divisible
139 // by the block size.
140 return size.width() % 4 == 0 && size.height() % 4 == 0;
141 case gfx::BufferFormat::R_8:
142 case gfx::BufferFormat::RGBA_4444:
143 case gfx::BufferFormat::RGBA_8888:
144 case gfx::BufferFormat::RGBX_8888:
145 case gfx::BufferFormat::BGRA_8888:
146 case gfx::BufferFormat::BGRX_8888:
147 return true;
148 case gfx::BufferFormat::YUV_420:
149 case gfx::BufferFormat::YUV_420_BIPLANAR:
150 // U and V planes are subsampled by a factor of 2.
151 return size.width() % 2 == 0 && size.height() % 2 == 0;
152 case gfx::BufferFormat::UYVY_422:
153 return size.width() % 2 == 0;
154 }
155
156 NOTREACHED();
157 return false;
158 }
159
160 } // namespace gpu 15 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/image_factory.h ('k') | gpu/command_buffer/service/in_process_command_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698