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

Side by Side Diff: remoting/client/pepper/fake_browser.cc

Issue 2857011: Convert chromoting to pepperv2 API. (Closed)
Patch Set: break dep Created 10 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
« no previous file with comments | « remoting/client/pepper/fake_browser.h ('k') | remoting/client/pepper/pepper_main.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) 2010 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 <stdlib.h>
6
7 #include "remoting/client/pepper/fake_browser.h"
8
9 // Constant value for browser window.
10 static const int kWindowWidth = 100;
11 static const int kWindowHeight = 100;
12
13 // ----------------------------------------------------------------------------
14 // Browser callback routines
15 // These are simple implementations of the routines that the browser provides
16 // to the plugin as callbacks.
17 // ----------------------------------------------------------------------------
18
19 // Handler for getvalue.
20 // Must be of type NPN_GetValueProcPtr.
21 NPError Browser_GetValue(NPP instance, NPNVariable variable, void *ret_value) {
22 if (variable == NPNVPepperExtensions) {
23 NPNExtensions** ret = static_cast<NPNExtensions**>(ret_value);
24 *ret = Singleton<FakeBrowser>()->GetExtensions();
25 return NPERR_NO_ERROR;
26 }
27 return NPERR_GENERIC_ERROR;
28 }
29
30 // Extension handler for acquireDevice.
31 // Must be of type NPAcquireDevicePtr.
32 NPDevice* Extension_AcquireDevice(NPP instance, NPDeviceID device) {
33 if (device == NPPepper2DDevice) {
34 return Singleton<FakeBrowser>()->GetDevice2d();
35 }
36 // TODO(garykac): Add support for NPPepper3DDevice.
37 return NULL;
38 }
39
40 // Initialize 2D device context.
41 NPError Device_InitializeContext2D(NPP instance,
42 NPDeviceContext2D* context,
43 int extra_bytes) {
44 FakeBrowser* browser = Singleton<FakeBrowser>::get();
45 NPDeviceContext2D* context2d = static_cast<NPDeviceContext2D*>(context);
46 int width, height;
47 browser->GetWindowInfo(&width, &height);
48 int stride = (width * ARGB_PIXEL_SIZE) + extra_bytes;
49 context2d->region = browser->AllocPixelBuffer(stride);
50 context2d->stride = stride;
51
52 return NPERR_NO_ERROR;
53 }
54
55 // Device handler for initializeContext
56 // This initializes a 2D context where the stride == width.
57 // Must be of type NPDeviceInitializeContextPtr.
58 NPError Device_InitializeContext2D_NoExtraBytes(NPP instance,
59 const NPDeviceConfig* config,
60 NPDeviceContext* context) {
61 return Device_InitializeContext2D(instance,
62 static_cast<NPDeviceContext2D*>(context),
63 0);
64 }
65
66 // Device handler for initializeContext
67 // This initializes a 2D context where the stride > width.
68 // Must be of type NPDeviceInitializeContextPtr.
69 NPError Device_InitializeContext2D_ExtraBytes(NPP instance,
70 const NPDeviceConfig* config,
71 NPDeviceContext* context) {
72 return Device_InitializeContext2D(instance,
73 static_cast<NPDeviceContext2D*>(context),
74 8 /* extra_bytes */);
75 }
76
77 // Device handler for flushContext
78 // Must be of type NPDeviceFlushContextPtr.
79 NPError Device_FlushContext(NPP instance, NPDeviceContext* context,
80 NPDeviceFlushContextCallbackPtr callback,
81 void* userData) {
82 return NPERR_NO_ERROR;
83 }
84
85 // ----------------------------------------------------------------------------
86 // FakeBrowserFuncs
87 // Singleton class for creating/managing the NPNetscapeFuncs struct that we
88 // need to provide to the Pepper plugin.
89 // ----------------------------------------------------------------------------
90
91 FakeBrowser::FakeBrowser() {
92 // Setup fake versions of the browser funcs needed by the unit tests.
93 // There are dozens of browser funcs that can be set up, but we only worry
94 // about the ones needed for our unittests.
95 browser_funcs_.reset(new NPNetscapeFuncs());
96 browser_funcs_->getvalue = &Browser_GetValue;
97
98 // Setup fake extension funcs structure.
99 extensions_.reset(new NPNExtensions());
100 extensions_->acquireDevice = &Extension_AcquireDevice;
101
102 // Setup fake device funcs structure.
103 device2d_.reset(new NPDevice());
104 device2d_->initializeContext = &Device_InitializeContext2D_NoExtraBytes;
105 device2d_->flushContext = &Device_FlushContext;
106
107 // Fake browser window.
108 window_.reset(new NPWindow());
109 window_->x = 0;
110 window_->y = 0;
111 window_->width = kWindowWidth;
112 window_->height = kWindowHeight;
113
114 width_ = kWindowWidth;
115 height_ = kWindowHeight;
116
117 stride_ = 0;
118 pixel_buffer_.reset();
119 }
120
121 FakeBrowser::~FakeBrowser() {
122 FreePixelBuffer();
123 }
124
125 // Normally in our tests, the stride (ie, the number of bytes between the
126 // start of a row and the start of the next row) is equal to the number of
127 // bytes used to store the pixels for the row.
128 // Passing true to this routine sets things up so that there are a few extra
129 // padding bytes to the end of each row so that the stride is not the same
130 // as the row width.
131 void FakeBrowser::ForceStrideInDeviceContext(bool extra_bytes) {
132 if (extra_bytes) {
133 device2d_->initializeContext = &Device_InitializeContext2D_ExtraBytes;
134 } else {
135 device2d_->initializeContext = &Device_InitializeContext2D_NoExtraBytes;
136 }
137 }
138
139 // Allocate a pixel buffer for the plugin to use.
140 // The height and width of the buffer come from the window size.
141 // The stride value is used to force each row to be |stride| bytes in size.
142 // This is typically done to add extra padding bytes to the end of each row.
143 uint32* FakeBrowser::AllocPixelBuffer(int stride) {
144 // Don't allow the stride to be less than the window width.
145 if (stride < width_) {
146 stride = width_;
147 }
148 stride_ = stride;
149 pixel_buffer_.reset(new uint32[height_ * stride]);
150
151 return pixel_buffer_.get();
152 }
153
154 void FakeBrowser::FreePixelBuffer() {
155 stride_ = 0;
156 pixel_buffer_.reset();
157 }
OLDNEW
« no previous file with comments | « remoting/client/pepper/fake_browser.h ('k') | remoting/client/pepper/pepper_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698