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

Side by Side Diff: content/common/gpu/client/gpu_memory_buffer_impl.cc

Issue 916083002: Add support for compressed GPU memory buffers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix ozone Created 5 years, 9 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/common/gpu/client/gpu_memory_buffer_impl.h" 5 #include "content/common/gpu/client/gpu_memory_buffer_impl.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/numerics/safe_math.h" 8 #include "base/numerics/safe_math.h"
9 #include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h" 9 #include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h"
10 #include "ui/gl/gl_bindings.h" 10 #include "ui/gl/gl_bindings.h"
11 #include "ui/gl/gl_image_memory.h"
11 12
12 #if defined(OS_MACOSX) 13 #if defined(OS_MACOSX)
13 #include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h" 14 #include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h"
14 #endif 15 #endif
15 16
16 #if defined(OS_ANDROID) 17 #if defined(OS_ANDROID)
17 #include "content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.h" 18 #include "content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.h"
18 #endif 19 #endif
19 20
20 #if defined(USE_OZONE) 21 #if defined(USE_OZONE)
21 #include "content/common/gpu/client/gpu_memory_buffer_impl_ozone_native_buffer.h " 22 #include "content/common/gpu/client/gpu_memory_buffer_impl_ozone_native_buffer.h "
22 #endif 23 #endif
23 24
24 namespace content { 25 namespace content {
25 26
26 GpuMemoryBufferImpl::GpuMemoryBufferImpl(gfx::GpuMemoryBufferId id, 27 GpuMemoryBufferImpl::GpuMemoryBufferImpl(gfx::GpuMemoryBufferId id,
27 const gfx::Size& size, 28 const gfx::Size& size,
28 Format format, 29 Format format,
29 const DestructionCallback& callback) 30 const DestructionCallback& callback)
30 : id_(id), 31 : id_(id),
31 size_(size), 32 size_(size),
32 format_(format), 33 format_(format),
33 callback_(callback), 34 callback_(callback),
34 mapped_(false), 35 mapped_(false),
35 destruction_sync_point_(0) { 36 destruction_sync_point_(0) {
37 DCHECK(gfx::GLImageMemory::ValidSize(size, format));
36 } 38 }
37 39
38 GpuMemoryBufferImpl::~GpuMemoryBufferImpl() { 40 GpuMemoryBufferImpl::~GpuMemoryBufferImpl() {
39 callback_.Run(destruction_sync_point_); 41 callback_.Run(destruction_sync_point_);
40 } 42 }
41 43
42 // static 44 // static
43 scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImpl::CreateFromHandle( 45 scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImpl::CreateFromHandle(
44 const gfx::GpuMemoryBufferHandle& handle, 46 const gfx::GpuMemoryBufferHandle& handle,
45 const gfx::Size& size, 47 const gfx::Size& size,
(...skipping 29 matching lines...) Expand all
75 ClientBuffer buffer) { 77 ClientBuffer buffer) {
76 return reinterpret_cast<GpuMemoryBufferImpl*>(buffer); 78 return reinterpret_cast<GpuMemoryBufferImpl*>(buffer);
77 } 79 }
78 80
79 // static 81 // static
80 bool GpuMemoryBufferImpl::StrideInBytes(size_t width, 82 bool GpuMemoryBufferImpl::StrideInBytes(size_t width,
81 Format format, 83 Format format,
82 size_t* stride_in_bytes) { 84 size_t* stride_in_bytes) {
83 base::CheckedNumeric<size_t> s = width; 85 base::CheckedNumeric<size_t> s = width;
84 switch (format) { 86 switch (format) {
87 case ATCIA:
88 case DXT5:
89 *stride_in_bytes = width;
90 return true;
91 case ATC:
92 case DXT1:
93 case ETC1:
94 DCHECK_EQ(width % 2, 0U);
95 s /= 2;
96 if (!s.IsValid())
97 return false;
98
99 *stride_in_bytes = s.ValueOrDie();
100 return true;
85 case RGBA_8888: 101 case RGBA_8888:
86 case RGBX_8888: 102 case RGBX_8888:
87 case BGRA_8888: 103 case BGRA_8888:
88 s *= 4; 104 s *= 4;
89 if (!s.IsValid()) 105 if (!s.IsValid())
90 return false; 106 return false;
91 107
92 *stride_in_bytes = s.ValueOrDie(); 108 *stride_in_bytes = s.ValueOrDie();
93 return true; 109 return true;
94 } 110 }
95 111
96 NOTREACHED(); 112 NOTREACHED();
97 return false; 113 return false;
98 } 114 }
99 115
100 gfx::GpuMemoryBuffer::Format GpuMemoryBufferImpl::GetFormat() const { 116 gfx::GpuMemoryBuffer::Format GpuMemoryBufferImpl::GetFormat() const {
101 return format_; 117 return format_;
102 } 118 }
103 119
104 bool GpuMemoryBufferImpl::IsMapped() const { 120 bool GpuMemoryBufferImpl::IsMapped() const {
105 return mapped_; 121 return mapped_;
106 } 122 }
107 123
108 ClientBuffer GpuMemoryBufferImpl::AsClientBuffer() { 124 ClientBuffer GpuMemoryBufferImpl::AsClientBuffer() {
109 return reinterpret_cast<ClientBuffer>(this); 125 return reinterpret_cast<ClientBuffer>(this);
110 } 126 }
111 127
112 } // namespace content 128 } // namespace content
OLDNEW
« no previous file with comments | « cc/test/test_gpu_memory_buffer_manager.cc ('k') | content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698