OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "cc/resources/resource_provider.h" | 5 #include "cc/resources/resource_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
11 #include "base/debug/trace_event.h" | 11 #include "base/debug/trace_event.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "cc/base/util.h" | 15 #include "cc/base/util.h" |
16 #include "cc/output/gl_renderer.h" // For the GLC() macro. | 16 #include "cc/output/gl_renderer.h" // For the GLC() macro. |
17 #include "cc/resources/platform_color.h" | 17 #include "cc/resources/platform_color.h" |
18 #include "cc/resources/returned_resource.h" | 18 #include "cc/resources/returned_resource.h" |
19 #include "cc/resources/shared_bitmap_manager.h" | 19 #include "cc/resources/shared_bitmap_manager.h" |
20 #include "cc/resources/texture_uploader.h" | 20 #include "cc/resources/texture_uploader.h" |
21 #include "cc/resources/transferable_resource.h" | 21 #include "cc/resources/transferable_resource.h" |
22 #include "gpu/GLES2/gl2extchromium.h" | 22 #include "gpu/GLES2/gl2extchromium.h" |
23 #include "gpu/command_buffer/client/gles2_interface.h" | 23 #include "gpu/command_buffer/client/gles2_interface.h" |
24 #include "third_party/khronos/GLES2/gl2.h" | 24 #include "third_party/khronos/GLES2/gl2.h" |
25 #include "third_party/khronos/GLES2/gl2ext.h" | 25 #include "third_party/khronos/GLES2/gl2ext.h" |
26 #include "third_party/skia/include/core/SkSurface.h" | 26 #include "third_party/skia/include/core/SkSurface.h" |
27 #include "third_party/skia/include/gpu/GrContext.h" | 27 #include "third_party/skia/include/gpu/GrContext.h" |
| 28 #include "third_party/skia/include/utils/SkNullCanvas.h" |
28 #include "ui/gfx/frame_time.h" | 29 #include "ui/gfx/frame_time.h" |
29 #include "ui/gfx/rect.h" | 30 #include "ui/gfx/rect.h" |
30 #include "ui/gfx/vector2d.h" | 31 #include "ui/gfx/vector2d.h" |
31 | 32 |
32 using gpu::gles2::GLES2Interface; | 33 using gpu::gles2::GLES2Interface; |
33 | 34 |
34 namespace cc { | 35 namespace cc { |
35 | 36 |
36 class IdAllocator { | 37 class IdAllocator { |
37 public: | 38 public: |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 } | 448 } |
448 | 449 |
449 ResourceProvider::GpuRasterBuffer::~GpuRasterBuffer() { | 450 ResourceProvider::GpuRasterBuffer::~GpuRasterBuffer() { |
450 } | 451 } |
451 | 452 |
452 skia::RefPtr<SkCanvas> ResourceProvider::GpuRasterBuffer::AcquireSkCanvas() { | 453 skia::RefPtr<SkCanvas> ResourceProvider::GpuRasterBuffer::AcquireSkCanvas() { |
453 // Note that this function is called from a worker thread. | 454 // Note that this function is called from a worker thread. |
454 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 455 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
455 "ResourceProvider::GpuRasterBuffer::AcquireSkCanvas"); | 456 "ResourceProvider::GpuRasterBuffer::AcquireSkCanvas"); |
456 | 457 |
457 return surface_ ? skia::SharePtr(surface_->getCanvas()) | 458 skia::RefPtr<SkCanvas> canvas = surface_ |
458 : skia::RefPtr<SkCanvas>(); | 459 ? skia::SharePtr(surface_->getCanvas()) |
| 460 : skia::AdoptRef(SkCreateNullCanvas()); |
| 461 canvas->save(); |
| 462 return canvas; |
459 } | 463 } |
460 | 464 |
461 void ResourceProvider::GpuRasterBuffer::ReleaseSkCanvas( | 465 void ResourceProvider::GpuRasterBuffer::ReleaseSkCanvas( |
462 const skia::RefPtr<SkCanvas>& canvas) { | 466 const skia::RefPtr<SkCanvas>& canvas) { |
463 // Note that this function is called from a worker thread. | 467 // Note that this function is called from a worker thread. |
464 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 468 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
465 "ResourceProvider::GpuRasterBuffer::ReleaseSkCanvas"); | 469 "ResourceProvider::GpuRasterBuffer::ReleaseSkCanvas"); |
| 470 |
| 471 canvas->restore(); |
466 } | 472 } |
467 | 473 |
468 ResourceProvider::ImageRasterBuffer::ImageRasterBuffer( | 474 ResourceProvider::ImageRasterBuffer::ImageRasterBuffer( |
469 const Resource* resource, | 475 const Resource* resource, |
470 ResourceProvider* resource_provider) | 476 ResourceProvider* resource_provider) |
471 : resource_(resource), | 477 : resource_(resource), |
472 resource_provider_(resource_provider), | 478 resource_provider_(resource_provider), |
473 mapped_buffer_(NULL), | 479 mapped_buffer_(NULL), |
474 raster_bitmap_changed_(false), | 480 raster_bitmap_changed_(false), |
475 stride_(0) { | 481 stride_(0) { |
(...skipping 23 matching lines...) Expand all Loading... |
499 } | 505 } |
500 return raster_bitmap_changed_; | 506 return raster_bitmap_changed_; |
501 } | 507 } |
502 | 508 |
503 skia::RefPtr<SkCanvas> ResourceProvider::ImageRasterBuffer::AcquireSkCanvas() { | 509 skia::RefPtr<SkCanvas> ResourceProvider::ImageRasterBuffer::AcquireSkCanvas() { |
504 // Note that this function is called from a worker thread. | 510 // Note that this function is called from a worker thread. |
505 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 511 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
506 "ResourceProvider::ImageRasterBuffer::AcquireSkCanvas"); | 512 "ResourceProvider::ImageRasterBuffer::AcquireSkCanvas"); |
507 | 513 |
508 if (!mapped_buffer_) | 514 if (!mapped_buffer_) |
509 return skia::RefPtr<SkCanvas>(); | 515 return skia::AdoptRef(SkCreateNullCanvas()); |
510 | 516 |
511 MakeBitmap(&raster_bitmap_, | 517 MakeBitmap(&raster_bitmap_, |
512 mapped_buffer_, | 518 mapped_buffer_, |
513 resource_->format, | 519 resource_->format, |
514 resource_->size, | 520 resource_->size, |
515 stride_); | 521 stride_); |
516 raster_bitmap_changed_ = true; | 522 raster_bitmap_changed_ = true; |
517 return skia::AdoptRef(new SkCanvas(raster_bitmap_)); | 523 return skia::AdoptRef(new SkCanvas(raster_bitmap_)); |
518 } | 524 } |
519 | 525 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 } | 569 } |
564 return raster_bitmap_changed_; | 570 return raster_bitmap_changed_; |
565 } | 571 } |
566 | 572 |
567 skia::RefPtr<SkCanvas> ResourceProvider::PixelRasterBuffer::AcquireSkCanvas() { | 573 skia::RefPtr<SkCanvas> ResourceProvider::PixelRasterBuffer::AcquireSkCanvas() { |
568 // Note that this function is called from a worker thread. | 574 // Note that this function is called from a worker thread. |
569 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 575 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
570 "ResourceProvider::PixelRasterBuffer::AcquireSkCanvas"); | 576 "ResourceProvider::PixelRasterBuffer::AcquireSkCanvas"); |
571 | 577 |
572 if (!mapped_buffer_) | 578 if (!mapped_buffer_) |
573 return skia::RefPtr<SkCanvas>(); | 579 return skia::AdoptRef(SkCreateNullCanvas()); |
574 | 580 |
575 MakeBitmap(&raster_bitmap_, | 581 MakeBitmap(&raster_bitmap_, |
576 mapped_buffer_, | 582 mapped_buffer_, |
577 resource_->format, | 583 resource_->format, |
578 resource_->size, | 584 resource_->size, |
579 stride_); | 585 stride_); |
580 raster_bitmap_changed_ = true; | 586 raster_bitmap_changed_ = true; |
581 return skia::AdoptRef(new SkCanvas(raster_bitmap_)); | 587 return skia::AdoptRef(new SkCanvas(raster_bitmap_)); |
582 } | 588 } |
583 | 589 |
(...skipping 1717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2301 ContextProvider* context_provider = output_surface_->context_provider(); | 2307 ContextProvider* context_provider = output_surface_->context_provider(); |
2302 return context_provider ? context_provider->ContextGL() : NULL; | 2308 return context_provider ? context_provider->ContextGL() : NULL; |
2303 } | 2309 } |
2304 | 2310 |
2305 class GrContext* ResourceProvider::GrContext() const { | 2311 class GrContext* ResourceProvider::GrContext() const { |
2306 ContextProvider* context_provider = output_surface_->context_provider(); | 2312 ContextProvider* context_provider = output_surface_->context_provider(); |
2307 return context_provider ? context_provider->GrContext() : NULL; | 2313 return context_provider ? context_provider->GrContext() : NULL; |
2308 } | 2314 } |
2309 | 2315 |
2310 } // namespace cc | 2316 } // namespace cc |
OLD | NEW |