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

Side by Side Diff: ppapi/proxy/image_capture_resource.cc

Issue 848863002: PPAPI: implement GetSupportedPreviewSizes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compile error on Linux build Created 5 years, 11 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ppapi/proxy/image_capture_resource.h"
6
7 #include "ppapi/proxy/camera_capabilities_resource.h"
8 #include "ppapi/proxy/image_capture_config_resource.h"
9 #include "ppapi/proxy/plugin_globals.h"
10 #include "ppapi/proxy/plugin_resource_tracker.h"
11 #include "ppapi/proxy/ppapi_messages.h"
12 #include "ppapi/proxy/ppb_buffer_proxy.h"
13 #include "ppapi/shared_impl/proxy_lock.h"
14 #include "ppapi/shared_impl/var.h"
15
16 namespace ppapi {
17 namespace proxy {
18
19 ImageCaptureResource::ImageCaptureResource(Connection connection,
20 PP_Instance instance)
21 : PluginResource(connection, instance),
22 open_state_(BEFORE_OPEN),
23 get_capabilities_output_(NULL) {
24 SendCreate(RENDERER, PpapiHostMsg_ImageCapture_Create());
25 }
26
27 ImageCaptureResource::~ImageCaptureResource() {
28 }
29
30 void ImageCaptureResource::OnReplyReceived(
31 const ResourceMessageReplyParams& params,
32 const IPC::Message& msg) {
33 if (params.sequence()) {
34 PluginResource::OnReplyReceived(params, msg);
35 return;
36 }
37
38 PPAPI_BEGIN_MESSAGE_MAP(ImageCaptureResource, msg)
39
wuchengli 2015/01/19 14:05:03 remove extra blank line
Justin Chuang 2015/01/26 15:00:51 Done.
40 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_UNHANDLED(NOTREACHED())
wuchengli 2015/01/19 14:05:03 You mean everything should be already handled in l
Justin Chuang 2015/01/26 15:00:51 I think keeping it as-as is okay.
41 PPAPI_END_MESSAGE_MAP()
42 }
43
44 int32_t ImageCaptureResource::Open(PP_Var camera_source_id,
45 scoped_refptr<TrackedCallback> callback) {
46 if (open_state_ != BEFORE_OPEN)
47 return PP_ERROR_FAILED;
48
49 if (TrackedCallback::IsPending(open_callback_))
50 return PP_ERROR_INPROGRESS;
51
52 scoped_refptr<StringVar> source_string_var;
53 source_string_var = StringVar::FromPPVar(camera_source_id);
54 if (!source_string_var.get() || source_string_var->value().size() == 0)
55 return PP_ERROR_BADARGUMENT;
56
57 open_callback_ = callback;
58
59 Call<PpapiPluginMsg_ImageCapture_OpenReply>(
60 RENDERER,
61 PpapiHostMsg_ImageCapture_Open(source_string_var->value()),
62 base::Bind(&ImageCaptureResource::OnPluginMsgOpenReply,
63 base::Unretained(this)));
64 return PP_OK_COMPLETIONPENDING;
65 }
66
67 void ImageCaptureResource::Close() {
68 if (open_state_ == CLOSED)
69 return;
70
71 if (TrackedCallback::IsPending(open_callback_)) {
72 open_callback_->PostAbort();
73 open_callback_ = NULL;
74 }
75
76 if (TrackedCallback::IsPending(get_capabilities_callback_)) {
77 *get_capabilities_output_ = 0;
78 get_capabilities_callback_->PostAbort();
79 get_capabilities_callback_ = NULL;
80 get_capabilities_output_ = NULL;
81 }
82
83 Post(RENDERER, PpapiHostMsg_ImageCapture_Close());
84
85 open_state_ = CLOSED;
86 }
87
88 int32_t ImageCaptureResource::SetConfig(
89 PP_Resource config,
90 scoped_refptr<TrackedCallback> callback) {
91 return PP_ERROR_NOTSUPPORTED;
92 }
93
94 int32_t ImageCaptureResource::GetConfig(
95 PP_Resource* config,
96 scoped_refptr<TrackedCallback> callback) {
97 return PP_ERROR_NOTSUPPORTED;
98 }
99
100 int32_t ImageCaptureResource::GetCameraCapabilities(
101 PP_Resource* capabilities,
102 scoped_refptr<TrackedCallback> callback) {
103 if (!IsOpened())
104 return PP_ERROR_FAILED;
105
106 if (TrackedCallback::IsPending(get_capabilities_callback_))
107 return PP_ERROR_INPROGRESS;
108
109 if (camera_capabilities_.get()) {
110 *capabilities = camera_capabilities_->GetReference();
111 return PP_OK;
112 }
113
114 get_capabilities_output_ = capabilities;
115 get_capabilities_callback_ = callback;
116 Call<PpapiPluginMsg_ImageCapture_GetPreviewSizesReply>(
117 RENDERER,
118 PpapiPluginMsg_ImageCapture_GetPreviewSizes(),
119 base::Bind(&ImageCaptureResource::OnPluginMsgGetPreviewSizesReply,
120 base::Unretained(this)));
121 return PP_OK_COMPLETIONPENDING;
122 }
123
124 int32_t ImageCaptureResource::ReuseBuffers() {
125 return PP_ERROR_NOTSUPPORTED;
126 }
127
128 int32_t ImageCaptureResource::CaptureStillImage(
129 PPB_ImageCapture_Private_ShutterCallback shutter_callback,
130 PPB_ImageCapture_Private_PreviewCallback preview_callback,
131 PPB_ImageCapture_Private_JpegCallback jpeg_callback,
132 PPB_ImageCapture_Private_ErrorCallback error_callback,
133 uint64_t* sequence_id) {
134 return PP_ERROR_NOTSUPPORTED;
135 }
136
137 void ImageCaptureResource::OnPluginMsgOpenReply(
138 const ResourceMessageReplyParams& params) {
139 if (open_state_ == BEFORE_OPEN && params.result() == PP_OK)
140 open_state_ = OPENED;
141
142 // The callback may have been aborted by Close().
143 if (TrackedCallback::IsPending(open_callback_))
144 open_callback_->Run(params.result());
145 }
146
147 void ImageCaptureResource::OnPluginMsgGetPreviewSizesReply(
148 const ResourceMessageReplyParams& params,
149 const std::vector<PP_Size>& preview_sizes) {
150 // TODO(jchuang): support query of JPEG sizes, too.
wuchengli 2015/01/19 14:05:03 Remove TODO.
Justin Chuang 2015/01/26 15:00:51 Why not keep it?
151 if (!TrackedCallback::IsPending(get_capabilities_callback_))
152 return;
153
154 // Return camera capabilities.
155 int32_t result = params.result();
156 scoped_refptr<TrackedCallback> callback;
157 callback.swap(get_capabilities_callback_);
158 if (result == PP_OK) {
159 camera_capabilities_ = new CameraCapabilitiesResource(pp_instance());
160 camera_capabilities_->SetPreviewSizes(preview_sizes);
161 *get_capabilities_output_ = camera_capabilities_->GetReference();
162 }
163 get_capabilities_output_ = NULL;
164 callback->Run(result == PP_OK ? PP_OK : PP_ERROR_FAILED);
165 }
166
167 } // namespace proxy
168 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698