Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 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_overlay_mac.h" | |
| 6 | |
| 7 #include <OpenGL/GL.h> | |
|
Andre
2015/07/23 18:14:02
I think it's lowercase gl.h
ccameron
2015/07/23 19:44:49
Done.
| |
| 8 | |
| 9 #include "content/common/gpu/gpu_messages.h" | |
| 10 #include "ui/accelerated_widget_mac/surface_handle_types.h" | |
| 11 #include "ui/base/cocoa/animation_utils.h" | |
| 12 #include "ui/base/cocoa/remote_layer_api.h" | |
| 13 #include "ui/gfx/geometry/dip_util.h" | |
| 14 #include "ui/gl/gl_image_io_surface.h" | |
| 15 | |
| 16 namespace content { | |
| 17 | |
| 18 ImageTransportSurfaceOverlayMac::ImageTransportSurfaceOverlayMac( | |
| 19 GpuChannelManager* manager, | |
| 20 GpuCommandBufferStub* stub, | |
| 21 gfx::PluginWindowHandle handle) | |
| 22 : scale_factor_(1), pending_overlay_image_(nullptr) { | |
| 23 helper_.reset(new ImageTransportHelper(this, manager, stub, handle)); | |
| 24 } | |
| 25 | |
| 26 ImageTransportSurfaceOverlayMac::~ImageTransportSurfaceOverlayMac() { | |
| 27 gfx::GLImageIOSurface::SetLayerForWidget(widget_, nil); | |
| 28 } | |
| 29 | |
| 30 bool ImageTransportSurfaceOverlayMac::Initialize() { | |
| 31 if (!helper_->Initialize()) | |
| 32 return false; | |
| 33 | |
| 34 // Create the CAContext to send this to the GPU process, and the layer for | |
| 35 // the context. | |
| 36 CGSConnectionID connection_id = CGSMainConnectionID(); | |
| 37 ca_context_.reset( | |
| 38 [[CAContext contextWithCGSConnection:connection_id options:@{}] retain]); | |
| 39 layer_.reset([[CALayer alloc] init]); | |
| 40 [ca_context_ setLayer:layer_]; | |
| 41 | |
| 42 // Register the CALayer so that it can be picked up in GLImageIOSurface. | |
| 43 static uintptr_t previous_widget = 0; | |
| 44 previous_widget += 1; | |
| 45 widget_ = reinterpret_cast<gfx::AcceleratedWidget>(previous_widget); | |
|
Andre
2015/07/23 18:14:02
I'm not sure this is better than before, code that
ccameron
2015/07/23 19:44:49
Changed it to a uintptr_t.
| |
| 46 gfx::GLImageIOSurface::SetLayerForWidget(widget_, layer_); | |
| 47 | |
| 48 return true; | |
| 49 } | |
| 50 | |
| 51 void ImageTransportSurfaceOverlayMac::Destroy() {} | |
| 52 | |
| 53 bool ImageTransportSurfaceOverlayMac::IsOffscreen() { | |
| 54 return false; | |
| 55 } | |
| 56 | |
| 57 gfx::SwapResult ImageTransportSurfaceOverlayMac::SwapBuffers() { | |
| 58 TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::SwapBuffers"); | |
| 59 | |
| 60 // A flush is required to ensure that all content appears in the layer. | |
| 61 { | |
| 62 TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::glFlush"); | |
| 63 glFlush(); | |
| 64 } | |
| 65 | |
| 66 // There should exist only one overlay image, and it should cover the whole | |
| 67 // surface. | |
| 68 DCHECK(pending_overlay_image_); | |
| 69 if (pending_overlay_image_) { | |
| 70 TRACE_EVENT0("gpu", "ImageTransportSurfaceOverlayMac::setContents"); | |
| 71 ScopedCAActionDisabler disabler; | |
| 72 gfx::Rect dip_bounds = gfx::ConvertRectToDIP( | |
| 73 scale_factor_, gfx::Rect(pixel_size_)); | |
| 74 gfx::RectF crop_rect(0, 0, 1, 1); | |
| 75 pending_overlay_image_->ScheduleOverlayPlane( | |
| 76 widget_, 0, gfx::OVERLAY_TRANSFORM_NONE, dip_bounds, crop_rect); | |
| 77 pending_overlay_image_ = nullptr; | |
| 78 } | |
| 79 | |
| 80 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | |
| 81 params.surface_handle = | |
| 82 ui::SurfaceHandleFromCAContextID([ca_context_ contextId]); | |
| 83 params.size = pixel_size_; | |
| 84 params.scale_factor = scale_factor_; | |
| 85 params.latency_info.swap(latency_info_); | |
| 86 helper_->SendAcceleratedSurfaceBuffersSwapped(params); | |
| 87 return gfx::SwapResult::SWAP_ACK; | |
| 88 } | |
| 89 | |
| 90 gfx::SwapResult ImageTransportSurfaceOverlayMac::PostSubBuffer(int x, | |
| 91 int y, | |
| 92 int width, | |
| 93 int height) { | |
| 94 return SwapBuffers(); | |
| 95 } | |
| 96 | |
| 97 bool ImageTransportSurfaceOverlayMac::SupportsPostSubBuffer() { | |
| 98 return true; | |
| 99 } | |
| 100 | |
| 101 gfx::Size ImageTransportSurfaceOverlayMac::GetSize() { | |
| 102 return gfx::Size(); | |
| 103 } | |
| 104 | |
| 105 void* ImageTransportSurfaceOverlayMac::GetHandle() { | |
| 106 return nullptr; | |
| 107 } | |
| 108 | |
| 109 bool ImageTransportSurfaceOverlayMac::ScheduleOverlayPlane( | |
| 110 int z_order, | |
| 111 gfx::OverlayTransform transform, | |
| 112 gfx::GLImage* image, | |
| 113 const gfx::Rect& bounds_rect, | |
| 114 const gfx::RectF& crop_rect) { | |
| 115 // For now we allow only the one full-surface overlay plane. | |
| 116 // TODO(ccameron): This will need to be updated when support for multiple | |
| 117 // planes is enabled. | |
| 118 DCHECK_EQ(z_order, 0); | |
| 119 DCHECK_EQ(bounds_rect.ToString(), gfx::Rect(pixel_size_).ToString()); | |
| 120 DCHECK_EQ(crop_rect.ToString(), gfx::RectF(0, 0, 1, 1).ToString()); | |
| 121 DCHECK_EQ(transform, gfx::OVERLAY_TRANSFORM_NONE); | |
| 122 DCHECK(!pending_overlay_image_); | |
| 123 pending_overlay_image_ = image; | |
| 124 return true; | |
| 125 } | |
| 126 | |
| 127 bool ImageTransportSurfaceOverlayMac::IsSurfaceless() const { | |
| 128 return true; | |
| 129 } | |
| 130 | |
| 131 void ImageTransportSurfaceOverlayMac::OnBufferPresented( | |
| 132 const AcceleratedSurfaceMsg_BufferPresented_Params& params) {} | |
| 133 | |
| 134 void ImageTransportSurfaceOverlayMac::OnResize(gfx::Size pixel_size, | |
| 135 float scale_factor) { | |
| 136 pixel_size_ = pixel_size; | |
| 137 scale_factor_ = scale_factor; | |
| 138 } | |
| 139 | |
| 140 void ImageTransportSurfaceOverlayMac::SetLatencyInfo( | |
| 141 const std::vector<ui::LatencyInfo>& latency_info) { | |
| 142 latency_info_.insert( | |
| 143 latency_info_.end(), latency_info.begin(), latency_info.end()); | |
| 144 } | |
| 145 | |
| 146 void ImageTransportSurfaceOverlayMac::WakeUpGpu() {} | |
| 147 | |
| 148 } // namespace content | |
| OLD | NEW |