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

Side by Side Diff: content/renderer/pepper/pepper_graphics_2d_host.cc

Issue 61813003: Allow PPB_ImageData_Impl to be created in a way that is compatible with unittests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/pepper/pepper_graphics_2d_host.h" 5 #include "content/renderer/pepper/pepper_graphics_2d_host.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 156
157 // Valid when type == SCROLL. 157 // Valid when type == SCROLL.
158 gfx::Rect scroll_clip_rect; 158 gfx::Rect scroll_clip_rect;
159 int scroll_dx, scroll_dy; 159 int scroll_dx, scroll_dy;
160 160
161 // Valid when type == REPLACE. 161 // Valid when type == REPLACE.
162 scoped_refptr<PPB_ImageData_Impl> replace_image; 162 scoped_refptr<PPB_ImageData_Impl> replace_image;
163 }; 163 };
164 164
165 // static 165 // static
166 PepperGraphics2DHost* PepperGraphics2DHost::Create(RendererPpapiHost* host, 166 PepperGraphics2DHost* PepperGraphics2DHost::Create(
167 PP_Instance instance, 167 RendererPpapiHost* host,
168 PP_Resource resource, 168 PP_Instance instance,
169 const PP_Size& size, 169 PP_Resource resource,
170 PP_Bool is_always_opaque) { 170 const PP_Size& size,
171 PP_Bool is_always_opaque,
172 scoped_refptr<PPB_ImageData_Impl> backing_store) {
171 PepperGraphics2DHost* resource_host = 173 PepperGraphics2DHost* resource_host =
172 new PepperGraphics2DHost(host, instance, resource); 174 new PepperGraphics2DHost(host, instance, resource);
173 if (!resource_host->Init(size.width, size.height, 175 if (!resource_host->Init(size.width, size.height,
174 PP_ToBool(is_always_opaque))) { 176 PP_ToBool(is_always_opaque),
177 backing_store)) {
175 delete resource_host; 178 delete resource_host;
176 return NULL; 179 return NULL;
177 } 180 }
178 return resource_host; 181 return resource_host;
179 } 182 }
180 183
181 PepperGraphics2DHost::PepperGraphics2DHost(RendererPpapiHost* host, 184 PepperGraphics2DHost::PepperGraphics2DHost(RendererPpapiHost* host,
182 PP_Instance instance, 185 PP_Instance instance,
183 PP_Resource resource) 186 PP_Resource resource)
184 : ResourceHost(host->GetPpapiHost(), instance, resource), 187 : ResourceHost(host->GetPpapiHost(), instance, resource),
185 renderer_ppapi_host_(host), 188 renderer_ppapi_host_(host),
186 bound_instance_(NULL), 189 bound_instance_(NULL),
187 need_flush_ack_(false), 190 need_flush_ack_(false),
188 offscreen_flush_pending_(false), 191 offscreen_flush_pending_(false),
189 is_always_opaque_(false), 192 is_always_opaque_(false),
190 scale_(1.0f), 193 scale_(1.0f),
191 is_running_in_process_(host->IsRunningInProcess()), 194 is_running_in_process_(host->IsRunningInProcess()),
192 texture_mailbox_modified_(true) {} 195 texture_mailbox_modified_(true) {}
193 196
194 PepperGraphics2DHost::~PepperGraphics2DHost() { 197 PepperGraphics2DHost::~PepperGraphics2DHost() {
195 // Unbind from the instance when destroyed if we're still bound. 198 // Unbind from the instance when destroyed if we're still bound.
196 if (bound_instance_) 199 if (bound_instance_)
197 bound_instance_->BindGraphics(bound_instance_->pp_instance(), 0); 200 bound_instance_->BindGraphics(bound_instance_->pp_instance(), 0);
198 } 201 }
199 202
200 bool PepperGraphics2DHost::Init(int width, int height, bool is_always_opaque) { 203 bool PepperGraphics2DHost::Init(
204 int width,
205 int height,
206 bool is_always_opaque,
207 scoped_refptr<PPB_ImageData_Impl> backing_store) {
201 // The underlying PPB_ImageData_Impl will validate the dimensions. 208 // The underlying PPB_ImageData_Impl will validate the dimensions.
202 image_data_ = new PPB_ImageData_Impl(pp_instance(), 209 image_data_ = backing_store;
203 PPB_ImageData_Impl::PLATFORM);
204 if (!image_data_->Init(PPB_ImageData_Impl::GetNativeImageDataFormat(), 210 if (!image_data_->Init(PPB_ImageData_Impl::GetNativeImageDataFormat(),
205 width, height, true) || 211 width, height, true) ||
206 !image_data_->Map()) { 212 !image_data_->Map()) {
207 image_data_ = NULL; 213 image_data_ = NULL;
208 return false; 214 return false;
209 } 215 }
210 is_always_opaque_ = is_always_opaque; 216 is_always_opaque_ = is_always_opaque;
211 scale_ = 1.0f; 217 scale_ = 1.0f;
212 return true; 218 return true;
213 } 219 }
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 gfx::Point inverse_scaled_point = 796 gfx::Point inverse_scaled_point =
791 gfx::ToFlooredPoint(gfx::ScalePoint(*delta, inverse_scale)); 797 gfx::ToFlooredPoint(gfx::ScalePoint(*delta, inverse_scale));
792 if (original_delta != inverse_scaled_point) 798 if (original_delta != inverse_scaled_point)
793 return false; 799 return false;
794 } 800 }
795 801
796 return true; 802 return true;
797 } 803 }
798 804
799 } // namespace content 805 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_graphics_2d_host.h ('k') | content/renderer/pepper/ppb_image_data_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698