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

Side by Side Diff: content/common/gpu/image_transport_surface_iosurface_mac.cc

Issue 334173006: Clean up GLSurfaceCGL (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Incorporate review feedback Created 6 years, 6 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/common/gpu/image_transport_surface_iosurface_mac.h"
6
7 #include "content/common/gpu/gpu_messages.h"
8
9 namespace content {
10 namespace {
11
12 // IOSurface dimensions will be rounded up to a multiple of this value in order
13 // to reduce memory thrashing during resize. This must be a power of 2.
14 const uint32 kIOSurfaceDimensionRoundup = 64;
15
16 int RoundUpSurfaceDimension(int number) {
17 DCHECK(number >= 0);
18 // Cast into unsigned space for portable bitwise ops.
19 uint32 unsigned_number = static_cast<uint32>(number);
20 uint32 roundup_sub_1 = kIOSurfaceDimensionRoundup - 1;
21 unsigned_number = (unsigned_number + roundup_sub_1) & ~roundup_sub_1;
22 return static_cast<int>(unsigned_number);
23 }
24
25 void AddBooleanValue(CFMutableDictionaryRef dictionary,
26 const CFStringRef key,
27 bool value) {
28 CFDictionaryAddValue(dictionary, key,
29 (value ? kCFBooleanTrue : kCFBooleanFalse));
30 }
31
32 void AddIntegerValue(CFMutableDictionaryRef dictionary,
33 const CFStringRef key,
34 int32 value) {
35 base::ScopedCFTypeRef<CFNumberRef> number(
36 CFNumberCreate(NULL, kCFNumberSInt32Type, &value));
37 CFDictionaryAddValue(dictionary, key, number.get());
38 }
39
40 } // namespace
41
42 IOSurfaceStorageProvider::IOSurfaceStorageProvider() {}
43
44 IOSurfaceStorageProvider::~IOSurfaceStorageProvider() {
45 DCHECK(!io_surface_);
46 }
47
48 gfx::Size IOSurfaceStorageProvider::GetRoundedSize(gfx::Size size) {
49 return gfx::Size(RoundUpSurfaceDimension(size.width()),
50 RoundUpSurfaceDimension(size.height()));
51 }
52
53 bool IOSurfaceStorageProvider::AllocateColorBufferStorage(
54 CGLContextObj context,
55 gfx::Size size) {
56 // Allocate a new IOSurface, which is the GPU resource that can be
57 // shared across processes.
58 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties;
59 properties.reset(CFDictionaryCreateMutable(kCFAllocatorDefault,
60 0,
61 &kCFTypeDictionaryKeyCallBacks,
62 &kCFTypeDictionaryValueCallBacks));
63 AddIntegerValue(properties,
64 kIOSurfaceWidth,
65 size.width());
66 AddIntegerValue(properties,
67 kIOSurfaceHeight,
68 size.height());
69 AddIntegerValue(properties,
70 kIOSurfaceBytesPerElement, 4);
71 AddBooleanValue(properties,
72 kIOSurfaceIsGlobal, true);
73 // I believe we should be able to unreference the IOSurfaces without
74 // synchronizing with the browser process because they are
75 // ultimately reference counted by the operating system.
76 io_surface_.reset(IOSurfaceCreate(properties));
77 io_surface_handle_ = IOSurfaceGetID(io_surface_);
78
79 // Don't think we need to identify a plane.
80 GLuint plane = 0;
81 CGLError cglerror = CGLTexImageIOSurface2D(
82 context,
83 GL_TEXTURE_RECTANGLE_ARB,
84 GL_RGBA,
85 size.width(),
86 size.height(),
87 GL_BGRA,
88 GL_UNSIGNED_INT_8_8_8_8_REV,
89 io_surface_.get(),
90 plane);
91 if (cglerror != kCGLNoError) {
92 DLOG(ERROR) << "CGLTexImageIOSurface2D failed with CGL error: " << cglerror;
93 return false;
94 }
95
96 glFlush();
97 return true;
98 }
99
100 void IOSurfaceStorageProvider::FreeColorBufferStorage() {
101 io_surface_.reset();
102 io_surface_handle_ = 0;
103 }
104
105 uint64 IOSurfaceStorageProvider::GetSurfaceHandle() const {
106 return io_surface_handle_;
107 }
108
109 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu/image_transport_surface_iosurface_mac.h ('k') | content/common/gpu/image_transport_surface_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698