2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
11 #include "webrtc/modules/desktop_capture/shared_desktop_frame.h"
13 #include "webrtc/system_wrappers/interface/atomic32.h"
14 #include "webrtc/system_wrappers/interface/scoped_ptr.h"
18 class SharedDesktopFrame::Core {
20 Core(DesktopFrame* frame) : frame_(frame) {}
22 DesktopFrame* frame() { return frame_.get(); }
24 bool HasOneRef() { return ref_count_.Value() == 1; }
26 virtual int32_t AddRef() {
30 virtual int32_t Release() {
32 ref_count = --ref_count_;
42 scoped_ptr<DesktopFrame> frame_;
44 DISALLOW_COPY_AND_ASSIGN(Core);
47 SharedDesktopFrame::~SharedDesktopFrame() {}
50 SharedDesktopFrame* SharedDesktopFrame::Wrap(
51 DesktopFrame* desktop_frame) {
52 scoped_refptr<Core> core(new Core(desktop_frame));
53 return new SharedDesktopFrame(core);
56 DesktopFrame* SharedDesktopFrame::GetUnderlyingFrame() {
57 return core_->frame();
60 SharedDesktopFrame* SharedDesktopFrame::Share() {
61 SharedDesktopFrame* result = new SharedDesktopFrame(core_);
62 result->set_dpi(dpi());
63 result->set_capture_time_ms(capture_time_ms());
64 *result->mutable_updated_region() = updated_region();
68 bool SharedDesktopFrame::IsShared() {
69 return !core_->HasOneRef();
72 SharedDesktopFrame::SharedDesktopFrame(scoped_refptr<Core> core)
73 : DesktopFrame(core->frame()->size(), core->frame()->stride(),
74 core->frame()->data(), core->frame()->shared_memory()),