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

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

Issue 347653005: Make cross-process CALayers work on Mac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@image_transport_1
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
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 "content/common/gpu/image_transport_surface_iosurface_mac.h" 5 #include "content/common/gpu/image_transport_surface_iosurface_mac.h"
6 6
7 #include "content/common/gpu/gpu_messages.h" 7 #include "content/common/gpu/gpu_messages.h"
8 #include "content/common/gpu/surface_handle_types_mac.h"
8 9
9 namespace content { 10 namespace content {
10 namespace { 11 namespace {
11 12
12 // IOSurface dimensions will be rounded up to a multiple of this value in order 13 // 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 // to reduce memory thrashing during resize. This must be a power of 2.
14 const uint32 kIOSurfaceDimensionRoundup = 64; 15 const uint32 kIOSurfaceDimensionRoundup = 64;
15 16
16 int RoundUpSurfaceDimension(int number) { 17 int RoundUpSurfaceDimension(int number) {
17 DCHECK(number >= 0); 18 DCHECK(number >= 0);
(...skipping 26 matching lines...) Expand all
44 IOSurfaceStorageProvider::~IOSurfaceStorageProvider() { 45 IOSurfaceStorageProvider::~IOSurfaceStorageProvider() {
45 DCHECK(!io_surface_); 46 DCHECK(!io_surface_);
46 } 47 }
47 48
48 gfx::Size IOSurfaceStorageProvider::GetRoundedSize(gfx::Size size) { 49 gfx::Size IOSurfaceStorageProvider::GetRoundedSize(gfx::Size size) {
49 return gfx::Size(RoundUpSurfaceDimension(size.width()), 50 return gfx::Size(RoundUpSurfaceDimension(size.width()),
50 RoundUpSurfaceDimension(size.height())); 51 RoundUpSurfaceDimension(size.height()));
51 } 52 }
52 53
53 bool IOSurfaceStorageProvider::AllocateColorBufferStorage( 54 bool IOSurfaceStorageProvider::AllocateColorBufferStorage(
54 CGLContextObj context, 55 CGLContextObj context, GLuint texture,
55 gfx::Size size) { 56 gfx::Size pixel_size, float scale_factor) {
56 // Allocate a new IOSurface, which is the GPU resource that can be 57 // Allocate a new IOSurface, which is the GPU resource that can be
57 // shared across processes. 58 // shared across processes.
58 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties; 59 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties;
59 properties.reset(CFDictionaryCreateMutable(kCFAllocatorDefault, 60 properties.reset(CFDictionaryCreateMutable(kCFAllocatorDefault,
60 0, 61 0,
61 &kCFTypeDictionaryKeyCallBacks, 62 &kCFTypeDictionaryKeyCallBacks,
62 &kCFTypeDictionaryValueCallBacks)); 63 &kCFTypeDictionaryValueCallBacks));
63 AddIntegerValue(properties, 64 AddIntegerValue(properties,
64 kIOSurfaceWidth, 65 kIOSurfaceWidth,
65 size.width()); 66 pixel_size.width());
66 AddIntegerValue(properties, 67 AddIntegerValue(properties,
67 kIOSurfaceHeight, 68 kIOSurfaceHeight,
68 size.height()); 69 pixel_size.height());
69 AddIntegerValue(properties, 70 AddIntegerValue(properties,
70 kIOSurfaceBytesPerElement, 4); 71 kIOSurfaceBytesPerElement, 4);
71 AddBooleanValue(properties, 72 AddBooleanValue(properties,
72 kIOSurfaceIsGlobal, true); 73 kIOSurfaceIsGlobal, true);
73 // I believe we should be able to unreference the IOSurfaces without 74 // I believe we should be able to unreference the IOSurfaces without
74 // synchronizing with the browser process because they are 75 // synchronizing with the browser process because they are
75 // ultimately reference counted by the operating system. 76 // ultimately reference counted by the operating system.
76 io_surface_.reset(IOSurfaceCreate(properties)); 77 io_surface_.reset(IOSurfaceCreate(properties));
77 io_surface_handle_ = IOSurfaceGetID(io_surface_); 78 io_surface_id_ = IOSurfaceGetID(io_surface_);
78 79
79 // Don't think we need to identify a plane. 80 // Don't think we need to identify a plane.
80 GLuint plane = 0; 81 GLuint plane = 0;
81 CGLError cglerror = CGLTexImageIOSurface2D( 82 CGLError cglerror = CGLTexImageIOSurface2D(
82 context, 83 context,
83 GL_TEXTURE_RECTANGLE_ARB, 84 GL_TEXTURE_RECTANGLE_ARB,
84 GL_RGBA, 85 GL_RGBA,
85 size.width(), 86 pixel_size.width(),
86 size.height(), 87 pixel_size.height(),
87 GL_BGRA, 88 GL_BGRA,
88 GL_UNSIGNED_INT_8_8_8_8_REV, 89 GL_UNSIGNED_INT_8_8_8_8_REV,
89 io_surface_.get(), 90 io_surface_.get(),
90 plane); 91 plane);
91 if (cglerror != kCGLNoError) { 92 if (cglerror != kCGLNoError) {
92 DLOG(ERROR) << "CGLTexImageIOSurface2D failed with CGL error: " << cglerror; 93 DLOG(ERROR) << "CGLTexImageIOSurface2D failed with CGL error: " << cglerror;
93 return false; 94 return false;
94 } 95 }
95 96
96 glFlush(); 97 glFlush();
97 return true; 98 return true;
98 } 99 }
99 100
100 void IOSurfaceStorageProvider::FreeColorBufferStorage() { 101 void IOSurfaceStorageProvider::FreeColorBufferStorage() {
101 io_surface_.reset(); 102 io_surface_.reset();
102 io_surface_handle_ = 0; 103 io_surface_id_ = 0;
103 } 104 }
104 105
105 uint64 IOSurfaceStorageProvider::GetSurfaceHandle() const { 106 uint64 IOSurfaceStorageProvider::GetSurfaceHandle() const {
106 return io_surface_handle_; 107 return SurfaceHandleFromIOSurfaceID(io_surface_id_);
108 }
109
110 void IOSurfaceStorageProvider::WillSwapBuffers() {
107 } 111 }
108 112
109 } // namespace content 113 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698