OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkCodec.h" | 8 #include "SkCodec.h" |
9 #include "SkCodecPriv.h" | 9 #include "SkCodecPriv.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 #include <cmath> // for std::round,floor,ceil | 35 #include <cmath> // for std::round,floor,ceil |
36 #include <limits> | 36 #include <limits> |
37 | 37 |
38 namespace { | 38 namespace { |
39 | 39 |
40 // Caluclates the number of tiles of tile_size that fit into the area in vertica
l and horizontal | 40 // Caluclates the number of tiles of tile_size that fit into the area in vertica
l and horizontal |
41 // directions. | 41 // directions. |
42 dng_point num_tiles_in_area(const dng_point &areaSize, | 42 dng_point num_tiles_in_area(const dng_point &areaSize, |
43 const dng_point_real64 &tileSize) { | 43 const dng_point_real64 &tileSize) { |
44 // FIXME: Add a ceil_div() helper in SkCodecPriv.h | 44 // FIXME: Add a ceil_div() helper in SkCodecPriv.h |
45 return dng_point((areaSize.v + tileSize.v - 1) / tileSize.v, | 45 return dng_point(static_cast<int32>((areaSize.v + tileSize.v - 1) / tileSize.v
), |
46 (areaSize.h + tileSize.h - 1) / tileSize.h); | 46 static_cast<int32>((areaSize.h + tileSize.h - 1) / tileSize.h
)); |
47 } | 47 } |
48 | 48 |
49 int num_tasks_required(const dng_point& tilesInTask, | 49 int num_tasks_required(const dng_point& tilesInTask, |
50 const dng_point& tilesInArea) { | 50 const dng_point& tilesInArea) { |
51 return ((tilesInArea.v + tilesInTask.v - 1) / tilesInTask.v) * | 51 return ((tilesInArea.v + tilesInTask.v - 1) / tilesInTask.v) * |
52 ((tilesInArea.h + tilesInTask.h - 1) / tilesInTask.h); | 52 ((tilesInArea.h + tilesInTask.h - 1) / tilesInTask.h); |
53 } | 53 } |
54 | 54 |
55 // Calculate the number of tiles to process per task, taking into account the ma
ximum number of | 55 // Calculate the number of tiles to process per task, taking into account the ma
ximum number of |
56 // tasks. It prefers to increase horizontally for better locality of reference. | 56 // tasks. It prefers to increase horizontally for better locality of reference. |
(...skipping 28 matching lines...) Expand all Loading... |
85 taskArea.r = Min_int32(taskArea.l + taskAreaSize.h, area.r); | 85 taskArea.r = Min_int32(taskArea.l + taskAreaSize.h, area.r); |
86 | 86 |
87 taskAreas.push_back(taskArea); | 87 taskAreas.push_back(taskArea); |
88 } | 88 } |
89 } | 89 } |
90 return taskAreas; | 90 return taskAreas; |
91 } | 91 } |
92 | 92 |
93 class SkDngHost : public dng_host { | 93 class SkDngHost : public dng_host { |
94 public: | 94 public: |
95 using dng_host::dng_host; | 95 explicit SkDngHost(dng_memory_allocator* allocater) : dng_host(allocater) {} |
96 | 96 |
97 void PerformAreaTask(dng_area_task& task, const dng_rect& area) override { | 97 void PerformAreaTask(dng_area_task& task, const dng_rect& area) override { |
98 // The area task gets split up into max_tasks sub-tasks. The max_tasks i
s defined by the | 98 // The area task gets split up into max_tasks sub-tasks. The max_tasks i
s defined by the |
99 // dng-sdks default implementation of dng_area_task::MaxThreads() which
returns 8 or 32 | 99 // dng-sdks default implementation of dng_area_task::MaxThreads() which
returns 8 or 32 |
100 // sub-tasks depending on the architecture. | 100 // sub-tasks depending on the architecture. |
101 const int maxTasks = static_cast<int>(task.MaxThreads()); | 101 const int maxTasks = static_cast<int>(task.MaxThreads()); |
102 | 102 |
103 SkTaskGroup taskGroup; | 103 SkTaskGroup taskGroup; |
104 | 104 |
105 // tileSize is typically 256x256 | 105 // tileSize is typically 256x256 |
106 const dng_point tileSize(task.FindTileSize(area)); | 106 const dng_point tileSize(task.FindTileSize(area)); |
107 const std::vector<dng_rect> taskAreas = compute_task_areas(maxTasks, are
a, tileSize); | 107 const std::vector<dng_rect> taskAreas = compute_task_areas(maxTasks, are
a, tileSize); |
108 const int numTasks = taskAreas.size(); | 108 const int numTasks = static_cast<int>(taskAreas.size()); |
109 | 109 |
110 task.Start(numTasks, tileSize, &Allocator(), Sniffer()); | 110 task.Start(numTasks, tileSize, &Allocator(), Sniffer()); |
111 for (int taskIndex = 0; taskIndex < numTasks; ++taskIndex) { | 111 for (int taskIndex = 0; taskIndex < numTasks; ++taskIndex) { |
112 taskGroup.add([&task, this, taskIndex, taskAreas, tileSize] { | 112 taskGroup.add([&task, this, taskIndex, taskAreas, tileSize] { |
113 task.ProcessOnThread(taskIndex, taskAreas[taskIndex], tileSize,
this->Sniffer()); | 113 task.ProcessOnThread(taskIndex, taskAreas[taskIndex], tileSize,
this->Sniffer()); |
114 }); | 114 }); |
115 } | 115 } |
116 | 116 |
117 taskGroup.wait(); | 117 taskGroup.wait(); |
118 task.Finish(numTasks); | 118 task.Finish(numTasks); |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 SkISize sizeFloor = this->onGetScaledDimensions(1.f / std::floor(fullShortEd
ge / shortEdge)); | 559 SkISize sizeFloor = this->onGetScaledDimensions(1.f / std::floor(fullShortEd
ge / shortEdge)); |
560 SkISize sizeCeil = this->onGetScaledDimensions(1.f / std::ceil(fullShortEdge
/ shortEdge)); | 560 SkISize sizeCeil = this->onGetScaledDimensions(1.f / std::ceil(fullShortEdge
/ shortEdge)); |
561 return sizeFloor == dim || sizeCeil == dim; | 561 return sizeFloor == dim || sizeCeil == dim; |
562 } | 562 } |
563 | 563 |
564 SkRawCodec::~SkRawCodec() {} | 564 SkRawCodec::~SkRawCodec() {} |
565 | 565 |
566 SkRawCodec::SkRawCodec(SkDngImage* dngImage) | 566 SkRawCodec::SkRawCodec(SkDngImage* dngImage) |
567 : INHERITED(dngImage->getImageInfo(), nullptr) | 567 : INHERITED(dngImage->getImageInfo(), nullptr) |
568 , fDngImage(dngImage) {} | 568 , fDngImage(dngImage) {} |
OLD | NEW |