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

Side by Side Diff: content/browser/renderer_host/image_transport_factory.cc

Issue 10941017: Change the scale factor of texture_size from the layer's one to an estimation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Introduce device_scale_factor to ui::Texture Created 8 years, 3 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
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/browser/renderer_host/image_transport_factory.h" 5 #include "content/browser/renderer_host/image_transport_factory.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 } 72 }
73 73
74 virtual GLHelper* GetGLHelper() OVERRIDE { 74 virtual GLHelper* GetGLHelper() OVERRIDE {
75 return NULL; 75 return NULL;
76 } 76 }
77 77
78 virtual uint32 InsertSyncPoint() OVERRIDE { 78 virtual uint32 InsertSyncPoint() OVERRIDE {
79 return 0; 79 return 0;
80 } 80 }
81 81
82 virtual void SetDeviceScaleFactor(float device_scale_factor) OVERRIDE {
83 }
84
82 // We don't generate lost context events, so we don't need to keep track of 85 // We don't generate lost context events, so we don't need to keep track of
83 // observers 86 // observers
84 virtual void AddObserver(ImageTransportFactoryObserver* observer) OVERRIDE { 87 virtual void AddObserver(ImageTransportFactoryObserver* observer) OVERRIDE {
85 } 88 }
86 89
87 virtual void RemoveObserver( 90 virtual void RemoveObserver(
88 ImageTransportFactoryObserver* observer) OVERRIDE { 91 ImageTransportFactoryObserver* observer) OVERRIDE {
89 } 92 }
90 93
91 private: 94 private:
92 DISALLOW_COPY_AND_ASSIGN(DefaultTransportFactory); 95 DISALLOW_COPY_AND_ASSIGN(DefaultTransportFactory);
93 }; 96 };
94 97
95 class ImageTransportClientTexture : public ui::Texture { 98 class ImageTransportClientTexture : public ui::Texture {
96 public: 99 public:
97 ImageTransportClientTexture( 100 ImageTransportClientTexture(
98 WebKit::WebGraphicsContext3D* host_context, 101 WebKit::WebGraphicsContext3D* host_context,
99 const gfx::Size& size, 102 const gfx::Size& size,
103 float device_scale_factor,
100 uint64 surface_id) 104 uint64 surface_id)
101 : ui::Texture(true, size), 105 : ui::Texture(true, size, device_scale_factor),
102 host_context_(host_context) { 106 host_context_(host_context) {
103 set_texture_id(surface_id); 107 set_texture_id(surface_id);
104 } 108 }
105 109
106 virtual WebKit::WebGraphicsContext3D* HostContext3D() { 110 virtual WebKit::WebGraphicsContext3D* HostContext3D() {
107 return host_context_; 111 return host_context_;
108 } 112 }
109 113
110 protected: 114 protected:
111 virtual ~ImageTransportClientTexture() {} 115 virtual ~ImageTransportClientTexture() {}
112 116
113 private: 117 private:
114 // A raw pointer. This |ImageTransportClientTexture| will be destroyed 118 // A raw pointer. This |ImageTransportClientTexture| will be destroyed
115 // before the |host_context_| via 119 // before the |host_context_| via
116 // |ImageTransportFactoryObserver::OnLostContext()| handlers. 120 // |ImageTransportFactoryObserver::OnLostContext()| handlers.
117 WebKit::WebGraphicsContext3D* host_context_; 121 WebKit::WebGraphicsContext3D* host_context_;
118 122
119 DISALLOW_COPY_AND_ASSIGN(ImageTransportClientTexture); 123 DISALLOW_COPY_AND_ASSIGN(ImageTransportClientTexture);
120 }; 124 };
121 125
122 class OwnedTexture : public ui::Texture, ImageTransportFactoryObserver { 126 class OwnedTexture : public ui::Texture, ImageTransportFactoryObserver {
123 public: 127 public:
124 OwnedTexture(WebKit::WebGraphicsContext3D* host_context, 128 OwnedTexture(WebKit::WebGraphicsContext3D* host_context,
125 const gfx::Size& size, 129 const gfx::Size& size,
130 float device_scale_factor,
126 unsigned int texture_id) 131 unsigned int texture_id)
127 : ui::Texture(true, size), 132 : ui::Texture(true, size, device_scale_factor),
128 host_context_(host_context) { 133 host_context_(host_context) {
129 ImageTransportFactory::GetInstance()->AddObserver(this); 134 ImageTransportFactory::GetInstance()->AddObserver(this);
130 set_texture_id(texture_id); 135 set_texture_id(texture_id);
131 } 136 }
132 137
133 // ui::Texture overrides: 138 // ui::Texture overrides:
134 virtual WebKit::WebGraphicsContext3D* HostContext3D() OVERRIDE { 139 virtual WebKit::WebGraphicsContext3D* HostContext3D() OVERRIDE {
135 return host_context_; 140 return host_context_;
136 } 141 }
137 142
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 205
201 DISALLOW_COPY_AND_ASSIGN(CompositorSwapClient); 206 DISALLOW_COPY_AND_ASSIGN(CompositorSwapClient);
202 }; 207 };
203 208
204 class GpuProcessTransportFactory : 209 class GpuProcessTransportFactory :
205 public ui::ContextFactory, 210 public ui::ContextFactory,
206 public ImageTransportFactory, 211 public ImageTransportFactory,
207 public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback { 212 public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback {
208 public: 213 public:
209 GpuProcessTransportFactory() 214 GpuProcessTransportFactory()
210 : ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) { 215 : ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)),
216 device_scale_factor_(1.0f) {
211 } 217 }
212 218
213 virtual ~GpuProcessTransportFactory() { 219 virtual ~GpuProcessTransportFactory() {
214 DCHECK(per_compositor_data_.empty()); 220 DCHECK(per_compositor_data_.empty());
215 } 221 }
216 222
217 virtual WebKit::WebGraphicsContext3D* CreateContext( 223 virtual WebKit::WebGraphicsContext3D* CreateContext(
218 ui::Compositor* compositor) OVERRIDE { 224 ui::Compositor* compositor) OVERRIDE {
219 PerCompositorData* data = per_compositor_data_[compositor]; 225 PerCompositorData* data = per_compositor_data_[compositor];
220 if (!data) 226 if (!data)
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 shared_context_->flush(); 285 shared_context_->flush();
280 } 286 }
281 287
282 virtual scoped_refptr<ui::Texture> CreateTransportClient( 288 virtual scoped_refptr<ui::Texture> CreateTransportClient(
283 const gfx::Size& size, 289 const gfx::Size& size,
284 uint64 transport_handle) { 290 uint64 transport_handle) {
285 if (!shared_context_.get()) 291 if (!shared_context_.get())
286 return NULL; 292 return NULL;
287 scoped_refptr<ImageTransportClientTexture> image( 293 scoped_refptr<ImageTransportClientTexture> image(
288 new ImageTransportClientTexture(shared_context_.get(), 294 new ImageTransportClientTexture(shared_context_.get(),
289 size, transport_handle)); 295 size, device_scale_factor_,
296 transport_handle));
290 return image; 297 return image;
291 } 298 }
292 299
293 virtual scoped_refptr<ui::Texture> CreateOwnedTexture( 300 virtual scoped_refptr<ui::Texture> CreateOwnedTexture(
294 const gfx::Size& size, 301 const gfx::Size& size,
295 unsigned int texture_id) OVERRIDE { 302 unsigned int texture_id) OVERRIDE {
296 if (!shared_context_.get()) 303 if (!shared_context_.get())
297 return NULL; 304 return NULL;
298 scoped_refptr<OwnedTexture> image( 305 scoped_refptr<OwnedTexture> image(
299 new OwnedTexture(shared_context_.get(), size, texture_id)); 306 new OwnedTexture(shared_context_.get(), size, device_scale_factor_,
307 texture_id));
300 return image; 308 return image;
301 } 309 }
302 310
303 virtual GLHelper* GetGLHelper() { 311 virtual GLHelper* GetGLHelper() {
304 if (!gl_helper_.get()) { 312 if (!gl_helper_.get()) {
305 CreateSharedContextLazy(); 313 CreateSharedContextLazy();
306 WebKit::WebGraphicsContext3D* context_for_thread = 314 WebKit::WebGraphicsContext3D* context_for_thread =
307 CreateOffscreenContext(); 315 CreateOffscreenContext();
308 if (!context_for_thread) 316 if (!context_for_thread)
309 return NULL; 317 return NULL;
310 gl_helper_.reset(new GLHelper(shared_context_.get(), 318 gl_helper_.reset(new GLHelper(shared_context_.get(),
311 context_for_thread)); 319 context_for_thread));
312 } 320 }
313 return gl_helper_.get(); 321 return gl_helper_.get();
314 } 322 }
315 323
316 virtual uint32 InsertSyncPoint() OVERRIDE { 324 virtual uint32 InsertSyncPoint() OVERRIDE {
317 if (!shared_context_.get()) 325 if (!shared_context_.get())
318 return 0; 326 return 0;
319 return shared_context_->insertSyncPoint(); 327 return shared_context_->insertSyncPoint();
320 } 328 }
321 329
330 virtual void SetDeviceScaleFactor(float device_scale_factor) OVERRIDE {
331 device_scale_factor_ = device_scale_factor;
332 }
333
322 virtual void AddObserver(ImageTransportFactoryObserver* observer) { 334 virtual void AddObserver(ImageTransportFactoryObserver* observer) {
323 observer_list_.AddObserver(observer); 335 observer_list_.AddObserver(observer);
324 } 336 }
325 337
326 virtual void RemoveObserver(ImageTransportFactoryObserver* observer) { 338 virtual void RemoveObserver(ImageTransportFactoryObserver* observer) {
327 observer_list_.RemoveObserver(observer); 339 observer_list_.RemoveObserver(observer);
328 } 340 }
329 341
330 // WebGraphicsContextLostCallback implementation, called for the shared 342 // WebGraphicsContextLostCallback implementation, called for the shared
331 // context. 343 // context.
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 observer_list_, 449 observer_list_,
438 OnLostResources()); 450 OnLostResources());
439 } 451 }
440 452
441 typedef std::map<ui::Compositor*, PerCompositorData*> PerCompositorDataMap; 453 typedef std::map<ui::Compositor*, PerCompositorData*> PerCompositorDataMap;
442 PerCompositorDataMap per_compositor_data_; 454 PerCompositorDataMap per_compositor_data_;
443 scoped_ptr<GLHelper> gl_helper_; 455 scoped_ptr<GLHelper> gl_helper_;
444 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> shared_context_; 456 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> shared_context_;
445 ObserverList<ImageTransportFactoryObserver> observer_list_; 457 ObserverList<ImageTransportFactoryObserver> observer_list_;
446 base::WeakPtrFactory<GpuProcessTransportFactory> callback_factory_; 458 base::WeakPtrFactory<GpuProcessTransportFactory> callback_factory_;
459 float device_scale_factor_;
447 460
448 DISALLOW_COPY_AND_ASSIGN(GpuProcessTransportFactory); 461 DISALLOW_COPY_AND_ASSIGN(GpuProcessTransportFactory);
449 }; 462 };
450 463
451 void CompositorSwapClient::OnLostContext() { 464 void CompositorSwapClient::OnLostContext() {
452 factory_->OnLostContext(compositor_); 465 factory_->OnLostContext(compositor_);
453 // Note: previous line destroyed this. Don't access members from now on. 466 // Note: previous line destroyed this. Don't access members from now on.
454 } 467 }
455 468
456 WebKit::WebGraphicsContext3D* CreateTestContext() { 469 WebKit::WebGraphicsContext3D* CreateTestContext() {
(...skipping 25 matching lines...) Expand all
482 void ImageTransportFactory::Terminate() { 495 void ImageTransportFactory::Terminate() {
483 ui::ContextFactory::SetInstance(NULL); 496 ui::ContextFactory::SetInstance(NULL);
484 delete g_factory; 497 delete g_factory;
485 g_factory = NULL; 498 g_factory = NULL;
486 } 499 }
487 500
488 // static 501 // static
489 ImageTransportFactory* ImageTransportFactory::GetInstance() { 502 ImageTransportFactory* ImageTransportFactory::GetInstance() {
490 return g_factory; 503 return g_factory;
491 } 504 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698