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

Side by Side Diff: ui/gfx/surface/transport_dib_mac.cc

Issue 10351002: ui: Move surface/ directory out of gfx/, up to ui/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix gpu DEPS Created 8 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « ui/gfx/surface/transport_dib_linux.cc ('k') | ui/gfx/surface/transport_dib_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 "ui/gfx/surface/transport_dib.h"
6
7 #include <unistd.h>
8 #include <sys/stat.h>
9
10 #include "base/eintr_wrapper.h"
11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/shared_memory.h"
14 #include "skia/ext/platform_canvas.h"
15
16 TransportDIB::TransportDIB()
17 : size_(0) {
18 }
19
20 TransportDIB::TransportDIB(TransportDIB::Handle dib)
21 : shared_memory_(dib, false /* read write */),
22 size_(0) {
23 }
24
25 TransportDIB::~TransportDIB() {
26 }
27
28 // static
29 TransportDIB* TransportDIB::Create(size_t size, uint32 sequence_num) {
30 TransportDIB* dib = new TransportDIB;
31 if (!dib->shared_memory_.CreateAndMapAnonymous(size)) {
32 delete dib;
33 return NULL;
34 }
35
36 dib->size_ = size;
37 return dib;
38 }
39
40 // static
41 TransportDIB* TransportDIB::Map(Handle handle) {
42 scoped_ptr<TransportDIB> dib(CreateWithHandle(handle));
43 if (!dib->Map())
44 return NULL;
45 return dib.release();
46 }
47
48 // static
49 TransportDIB* TransportDIB::CreateWithHandle(Handle handle) {
50 return new TransportDIB(handle);
51 }
52
53 // static
54 bool TransportDIB::is_valid_handle(Handle dib) {
55 return dib.fd >= 0;
56 }
57
58 // static
59 bool TransportDIB::is_valid_id(Id id) {
60 return id != 0;
61 }
62
63 skia::PlatformCanvas* TransportDIB::GetPlatformCanvas(int w, int h) {
64 if (!memory() && !Map())
65 return NULL;
66 scoped_ptr<skia::PlatformCanvas> canvas(new skia::PlatformCanvas);
67 if (!canvas->initialize(w, h, true, reinterpret_cast<uint8_t*>(memory())))
68 return NULL;
69 return canvas.release();
70 }
71
72 bool TransportDIB::Map() {
73 if (!is_valid_handle(handle()))
74 return false;
75 if (memory())
76 return true;
77
78 struct stat st;
79 if ((fstat(shared_memory_.handle().fd, &st) != 0) ||
80 (!shared_memory_.Map(st.st_size))) {
81 return false;
82 }
83
84 size_ = st.st_size;
85 return true;
86 }
87
88 void* TransportDIB::memory() const {
89 return shared_memory_.memory();
90 }
91
92 TransportDIB::Id TransportDIB::id() const {
93 return shared_memory_.id();
94 }
95
96 TransportDIB::Handle TransportDIB::handle() const {
97 return shared_memory_.handle();
98 }
OLDNEW
« no previous file with comments | « ui/gfx/surface/transport_dib_linux.cc ('k') | ui/gfx/surface/transport_dib_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698